Commits

Trammell Hudson committed e3e2af4

Moon drawing works

  • Participants
  • Parent commits fd57744

Comments (0)

Files changed (6)

 SRCS += main.c
 SRCS += lunar.c
 SRCS += draw.c
+SRCS += image.c
 SRCS += sin_table.c
 
 include ../Makefile.rules
+#include "image.h"
+
+/** We need enough memory to buffer a screen row.
+ * \todo Determine how much slower image drawing is if
+ * we read a pixel at a time
+ */
+static uint8_t image_row[SCREEN_WIDTH*3];
+
+#if 0
+/** Draw a single row from an image at the given offset */
+static void
+image_draw_row(
+	uint32_t x,
+	uint32_t y,
+	uint32_t offset
+)
+{
+	spiflash_read(offset, image_row, sizeof(image_row));
+	pulse_set_draw_window(
+		x,
+		y,
+		x + DIGIT_WIDTH - 1,
+		y
+	);
+
+	for (unsigned j = 0 ; j < DIGIT_WIDTH ; j++)
+	{
+		uint8_t * pixel = image_row[j];
+		color24_t c = { pixel[0], pixel[1], pixel[2] };
+		pulse_draw_point24(c);
+	}
+}
+#endif
+
+
+void
+image_draw_gray(
+	PulseResource id,
+	int32_t x,
+	int32_t y
+)
+{
+	
+	image_resource_t resource;
+	image_resource(id, &resource);
+	
+	uint32_t offset = resource.offset;
+	const uint32_t width = 3 * resource.width;
+
+	for (unsigned row = 0 ; row < resource.height ; row++)
+	{
+		spiflash_read(offset, image_row, width);
+		offset += width;
+
+		pulse_set_draw_window(
+			x,
+			y + row,
+			x + width - 1,
+			y + row
+		);
+
+		for (unsigned col = 0 ; col < width ; col++)
+		{
+			uint8_t lum = image_row[col];
+			color24_t color = { lum, lum, lum };
+			pulse_draw_point24(color);
+		}
+	}
+}
+#ifndef _image_h_
+#define _image_h_
+/** \file
+ * Image drawing routines
+ */
+
+#include "resources.h"
+#include "spiflash.h"
+#include "pulse_os.h"
+#include "pulse_types.h"
+
+
+static inline void
+image_resource(
+	PulseResource id,
+	image_resource_t * const resource
+)
+{
+	spiflash_read(
+		SPIFLASH_BASE + id * sizeof(*resource),
+		resource,
+		sizeof(*resource)
+	);
+}
+
+
+/** Return the absolute address of the image in the flash */
+static uint32_t
+image_offset(
+	PulseResource id
+)
+{
+	image_resource_t resource;
+	image_resource(id, &resource);
+	return resource.offset;
+}
+
+
+/** Draw a grayscale image that is packed into an RGB bitmap. */
+extern void
+image_draw_gray(
+	PulseResource id,
+	int32_t x,
+	int32_t y
+);
+
+
+#endif
 #include "sin_table.h"
 
 
+static uint8_t last_sec;
+static PulseResource image_id;
+
 void
 init(void)
 {
 button_down(void)
 {
 	init();
+	last_sec = 0;
+	image_id = 0;
 }
 
 
 
 
 
+
 static void
 circle_line(
 	color24_t color,
 	const uint8_t new_min = cur_ms % 60; cur_ms /= 60;
 	const uint8_t new_hour = cur_ms % 12; // cur_ms %= 24;
 
+	if (last_sec == new_sec)
+		return;
+	last_sec = new_sec;
+
+	if (image_id < IMAGE_M000
+	||  image_id >= IMAGE_M346)
+		image_id = IMAGE_M000;
+
+	image_draw_gray(image_id, 0, 0);
+	image_id++;
+	
+
 #if 0
 	const uint16_t sec_angle = ((new_sec * 6 + (ms*6) / 1000) * 32768) / 180;
 	const uint16_t min_angle = ((new_min * 6 + (new_sec*6) / 60) * 32768) / 180;

lunar/resources.h

+#ifndef _resources_h_
+#define _resources_h_
+
+/** \file
+ * Access to the inpulse_resources.bin files.
+ */
+#include <stdint.h>
+
+
+typedef struct
+{
+	uint8_t type; // 00 == NULL, 01 == image, 02 == font
+	uint32_t offset; // in big endian.
+	uint8_t height;
+	uint8_t width;
+	uint8_t unknown2; // always 0?
+} __attribute__((__packed__))
+image_resource_t;
+
+
+// Image pixels are stored in 24-bit form
+typedef struct
+{
+	uint8_t red;
+	uint8_t blue;
+	uint8_t green;
+} __attribute__((__packed__))
+image_pixel_t;
+
+#endif
+#ifndef _spiflash_h_
+#define _spiflash_h_
+
+/** \file
+ * Access to SPI flash memory in the inpulse watch.
+ *
+ * Based on Andrew Witte's spiflash.h
+ *
+ * \todo get_resource_metadata() reverse engineering to find the offset
+ * of text in spiflash.
+ */
+
+// prototype of private API function for raw SPI flash reads
+void spiflash_read(int addr, void *buffer, int size);
+
+// Location of resource base in flash
+#define SPIFLASH_BASE (0x40000)
+
+// End of normal resources is defined in this generated file
+#include "spi_resources.h"
+
+#endif