summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2022-09-19 07:30:08 +1000
committerGitHub <noreply@github.com>2022-09-19 07:30:08 +1000
commit1849897444629403fc2e473da6d6f74f8f4f1b8c (patch)
tree6eeb53a35498b557dfc1e09031d11894ceb21209 /quantum
parente9bdc4eeb14b12d49d7841c5a0090a68c25ff7ae (diff)
[QP] Add RGB565 surface. Docs clarification, cleanup, tabsification, and reordering. (#18396)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/painter/qp.h4
-rw-r--r--quantum/painter/qp_draw_image.c43
-rw-r--r--quantum/painter/qp_draw_text.c49
-rw-r--r--quantum/painter/qp_stream.c47
-rw-r--r--quantum/painter/qp_stream.h5
-rw-r--r--quantum/painter/rules.mk29
6 files changed, 116 insertions, 61 deletions
diff --git a/quantum/painter/qp.h b/quantum/painter/qp.h
index fb6904de22..69bc435961 100644
--- a/quantum/painter/qp.h
+++ b/quantum/painter/qp.h
@@ -432,6 +432,10 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter Drivers
+#ifdef QUANTUM_PAINTER_RGB565_SURFACE_ENABLE
+# include "qp_rgb565_surface.h"
+#endif // QUANTUM_PAINTER_RGB565_SURFACE_ENABLE
+
#ifdef QUANTUM_PAINTER_ILI9163_ENABLE
# include "qp_ili9163.h"
#endif // QUANTUM_PAINTER_ILI9163_ENABLE
diff --git a/quantum/painter/qp_draw_image.c b/quantum/painter/qp_draw_image.c
index 5822758dce..e9b975f23a 100644
--- a/quantum/painter/qp_draw_image.c
+++ b/quantum/painter/qp_draw_image.c
@@ -25,10 +25,10 @@ typedef struct qgf_image_handle_t {
static qgf_image_handle_t image_descriptors[QUANTUM_PAINTER_NUM_IMAGES] = {0};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Quantum Painter External API: qp_load_image_mem
+// Helper: load image from stream
-painter_image_handle_t qp_load_image_mem(const void *buffer) {
- qp_dprintf("qp_load_image_mem: entry\n");
+static painter_image_handle_t qp_load_image_internal(bool (*stream_factory)(qgf_image_handle_t *image, void *arg), void *arg) {
+ qp_dprintf("qp_load_image: entry\n");
qgf_image_handle_t *image = NULL;
// Find a free slot
@@ -41,20 +41,18 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
// Drop out if not found
if (!image) {
- qp_dprintf("qp_load_image_mem: fail (no free slot)\n");
+ qp_dprintf("qp_load_image: fail (no free slot)\n");
return NULL;
}
- // Assume we can read the graphics descriptor
- image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t));
-
- // Update the length of the stream to match, and rewind to the start
- image->mem_stream.length = qgf_get_total_size(&image->stream);
- image->mem_stream.position = 0;
+ if (!stream_factory(image, arg)) {
+ qp_dprintf("qp_load_image: fail (could not create stream)\n");
+ return NULL;
+ }
// Now that we know the length, validate the input data
if (!qgf_validate_stream(&image->stream)) {
- qp_dprintf("qp_load_image_mem: fail (failed validation)\n");
+ qp_dprintf("qp_load_image: fail (failed validation)\n");
return NULL;
}
@@ -63,11 +61,31 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
// Validation success, we can return the handle
image->validate_ok = true;
- qp_dprintf("qp_load_image_mem: ok\n");
+ qp_dprintf("qp_load_image: ok\n");
return (painter_image_handle_t)image;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter External API: qp_load_image_mem
+
+static inline bool image_mem_stream_factory(qgf_image_handle_t *image, void *arg) {
+ void *buffer = arg;
+
+ // Assume we can read the graphics descriptor
+ image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t));
+
+ // Update the length of the stream to match, and rewind to the start
+ image->mem_stream.length = qgf_get_total_size(&image->stream);
+ image->mem_stream.position = 0;
+
+ return true;
+}
+
+painter_image_handle_t qp_load_image_mem(const void *buffer) {
+ return qp_load_image_internal(image_mem_stream_factory, (void *)buffer);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_close_image
bool qp_close_image(painter_image_handle_t image) {
@@ -79,6 +97,7 @@ bool qp_close_image(painter_image_handle_t image) {
// Free up this image for use elsewhere.
qgf_image->validate_ok = false;
+ qp_stream_close(&qgf_image->stream);
return true;
}
diff --git a/quantum/painter/qp_draw_text.c b/quantum/painter/qp_draw_text.c
index f99e082cad..0f5473abd0 100644
--- a/quantum/painter/qp_draw_text.c
+++ b/quantum/painter/qp_draw_text.c
@@ -36,10 +36,10 @@ typedef struct qff_font_handle_t {
static qff_font_handle_t font_descriptors[QUANTUM_PAINTER_NUM_FONTS] = {0};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Quantum Painter External API: qp_load_font_mem
+// Helper: load font from stream
-painter_font_handle_t qp_load_font_mem(const void *buffer) {
- qp_dprintf("qp_load_font_mem: entry\n");
+static painter_font_handle_t qp_load_font_internal(bool (*stream_factory)(qff_font_handle_t *font, void *arg), void *arg) {
+ qp_dprintf("qp_load_font: entry\n");
qff_font_handle_t *font = NULL;
// Find a free slot
@@ -52,20 +52,18 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
// Drop out if not found
if (!font) {
- qp_dprintf("qp_load_font_mem: fail (no free slot)\n");
+ qp_dprintf("qp_load_font: fail (no free slot)\n");
return NULL;
}
- // Assume we can read the graphics descriptor
- font->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qff_font_descriptor_v1_t));
-
- // Update the length of the stream to match, and rewind to the start
- font->mem_stream.length = qff_get_total_size(&font->stream);
- font->mem_stream.position = 0;
+ if (!stream_factory(font, arg)) {
+ qp_dprintf("qp_load_font: fail (could not create stream)\n");
+ return NULL;
+ }
// Now that we know the length, validate the input data
if (!qff_validate_stream(&font->stream)) {
- qp_dprintf("qp_load_font_mem: fail (failed validation)\n");
+ qp_dprintf("qp_load_font: fail (failed validation)\n");
return NULL;
}
@@ -76,12 +74,12 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
void *ram_buffer = malloc(font->mem_stream.length);
if (ram_buffer == NULL) {
- qp_dprintf("qp_load_font_mem: could not allocate enough RAM for font, falling back to original\n");
+ qp_dprintf("qp_load_font: could not allocate enough RAM for font, falling back to original\n");
} else {
do {
// Copy the data into RAM
if (qp_stream_read(ram_buffer, 1, font->mem_stream.length, &font->mem_stream) != font->mem_stream.length) {
- qp_dprintf("qp_load_font_mem: could not copy from flash to RAM, falling back to original\n");
+ qp_dprintf("qp_load_font: could not copy from flash to RAM, falling back to original\n");
break;
}
@@ -102,18 +100,38 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
qff_read_font_descriptor(&font->stream, &font->base.line_height, &font->has_ascii_table, &font->num_unicode_glyphs, &font->bpp, &font->has_palette, &font->compression_scheme, NULL);
if (!qp_internal_bpp_capable(font->bpp)) {
- qp_dprintf("qp_load_font_mem: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)font->bpp);
+ qp_dprintf("qp_load_font: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)font->bpp);
qp_close_font((painter_font_handle_t)font);
return NULL;
}
// Validation success, we can return the handle
font->validate_ok = true;
- qp_dprintf("qp_load_font_mem: ok\n");
+ qp_dprintf("qp_load_font: ok\n");
return (painter_font_handle_t)font;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter External API: qp_load_font_mem
+
+static inline bool font_mem_stream_factory(qff_font_handle_t *font, void *arg) {
+ void *buffer = arg;
+
+ // Assume we can read the graphics descriptor
+ font->mem_stream = qp_make_memory_stream(buffer, sizeof(qff_font_descriptor_v1_t));
+
+ // Update the length of the stream to match, and rewind to the start
+ font->mem_stream.length = qff_get_total_size(&font->stream);
+ font->mem_stream.position = 0;
+
+ return true;
+}
+
+painter_font_handle_t qp_load_font_mem(const void *buffer) {
+ return qp_load_font_internal(font_mem_stream_factory, (void *)buffer);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_close_font
bool qp_close_font(painter_font_handle_t font) {
@@ -133,6 +151,7 @@ bool qp_close_font(painter_font_handle_t font) {
#endif // QUANTUM_PAINTER_LOAD_FONTS_TO_RAM
// Free up this font for use elsewhere.
+ qp_stream_close(&qff_font->stream);
qff_font->validate_ok = false;
return true;
}
diff --git a/quantum/painter/qp_stream.c b/quantum/painter/qp_stream.c
index f00ae5ed38..1198cf793d 100644
--- a/quantum/painter/qp_stream.c
+++ b/quantum/painter/qp_stream.c
@@ -38,7 +38,7 @@ uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint3
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Memory streams
-int16_t mem_get(qp_stream_t *stream) {
+static inline int16_t mem_get(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
if (s->position >= s->length) {
s->is_eof = true;
@@ -47,7 +47,7 @@ int16_t mem_get(qp_stream_t *stream) {
return s->buffer[s->position++];
}
-bool mem_put(qp_stream_t *stream, uint8_t c) {
+static inline bool mem_put(qp_stream_t *stream, uint8_t c) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
if (s->position >= s->length) {
s->is_eof = true;
@@ -57,7 +57,7 @@ bool mem_put(qp_stream_t *stream, uint8_t c) {
return true;
}
-int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
+static inline int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
// Handle as per fseek
@@ -95,26 +95,23 @@ int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
return 0;
}
-int32_t mem_tell(qp_stream_t *stream) {
+static inline int32_t mem_tell(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
return s->position;
}
-bool mem_is_eof(qp_stream_t *stream) {
+static inline bool mem_is_eof(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
return s->is_eof;
}
+static inline void mem_close(qp_stream_t *stream) {
+ // No-op.
+}
+
qp_memory_stream_t qp_make_memory_stream(void *buffer, int32_t length) {
qp_memory_stream_t stream = {
- .base =
- {
- .get = mem_get,
- .put = mem_put,
- .seek = mem_seek,
- .tell = mem_tell,
- .is_eof = mem_is_eof,
- },
+ .base = {.get = mem_get, .put = mem_put, .seek = mem_seek, .tell = mem_tell, .is_eof = mem_is_eof, .close = mem_close},
.buffer = (uint8_t *)buffer,
.length = length,
.position = 0,
@@ -127,43 +124,41 @@ qp_memory_stream_t qp_make_memory_stream(void *buffer, int32_t length) {
#ifdef QP_STREAM_HAS_FILE_IO
-int16_t file_get(qp_stream_t *stream) {
+static inline int16_t file_get(qp_stream_t *stream) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
int c = fgetc(s->file);
if (c < 0 || feof(s->file)) return STREAM_EOF;
return (uint16_t)c;
}
-bool file_put(qp_stream_t *stream, uint8_t c) {
+static inline bool file_put(qp_stream_t *stream, uint8_t c) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return fputc(c, s->file) == c;
}
-int file_seek(qp_stream_t *stream, int32_t offset, int origin) {
+static inline int file_seek(qp_stream_t *stream, int32_t offset, int origin) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return fseek(s->file, offset, origin);
}
-int32_t file_tell(qp_stream_t *stream) {
+static inline int32_t file_tell(qp_stream_t *stream) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return (int32_t)ftell(s->file);
}
-bool file_is_eof(qp_stream_t *stream) {
+static inline bool file_is_eof(qp_stream_t *stream) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return (bool)feof(s->file);
}
+static inline void file_close(qp_stream_t *stream) {
+ qp_file_stream_t *s = (qp_file_stream_t *)stream;
+ fclose(s->file);
+}
+
qp_file_stream_t qp_make_file_stream(FILE *f) {
qp_file_stream_t stream = {
- .base =
- {
- .get = file_get,
- .put = file_put,
- .seek = file_seek,
- .tell = file_tell,
- .is_eof = file_is_eof,
- },
+ .base = {.get = file_get, .put = file_put, .seek = file_seek, .tell = file_tell, .is_eof = file_is_eof, .close = file_close},
.file = f,
};
return stream;
diff --git a/quantum/painter/qp_stream.h b/quantum/painter/qp_stream.h
index 878b9bf530..c0e745adc1 100644
--- a/quantum/painter/qp_stream.h
+++ b/quantum/painter/qp_stream.h
@@ -41,6 +41,8 @@ typedef struct qp_stream_t qp_stream_t;
uint32_t qp_stream_read_impl(void *output_buf, uint32_t member_size, uint32_t num_members, qp_stream_t *stream);
uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint32_t num_members, qp_stream_t *stream);
+#define qp_stream_close(stream_ptr) (((qp_stream_t *)(stream_ptr))->close((qp_stream_t *)(stream_ptr)))
+
#define STREAM_EOF ((int16_t)(-1))
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -52,6 +54,7 @@ struct qp_stream_t {
int (*seek)(qp_stream_t *stream, int32_t offset, int origin);
int32_t (*tell)(qp_stream_t *stream);
bool (*is_eof)(qp_stream_t *stream);
+ void (*close)(qp_stream_t *stream);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -77,6 +80,6 @@ typedef struct qp_file_stream_t {
FILE * file;
} qp_file_stream_t;
-qp_file_stream_t qo_make_file_stream(FILE *f);
+qp_file_stream_t qp_make_file_stream(FILE *f);
#endif // QP_STREAM_HAS_FILE_IO
diff --git a/quantum/painter/rules.mk b/quantum/painter/rules.mk
index 4420bccf63..5ac374a96e 100644
--- a/quantum/painter/rules.mk
+++ b/quantum/painter/rules.mk
@@ -3,7 +3,15 @@ QUANTUM_PAINTER_DRIVERS ?=
QUANTUM_PAINTER_ANIMATIONS_ENABLE ?= yes
# The list of permissible drivers that can be listed in QUANTUM_PAINTER_DRIVERS
-VALID_QUANTUM_PAINTER_DRIVERS := ili9163_spi ili9341_spi ili9488_spi st7789_spi st7735_spi gc9a01_spi ssd1351_spi
+VALID_QUANTUM_PAINTER_DRIVERS := \
+ rgb565_surface \
+ ili9163_spi \
+ ili9341_spi \
+ ili9488_spi \
+ st7735_spi \
+ st7789_spi \
+ gc9a01_spi \
+ ssd1351_spi
#-------------------------------------------------------------------------------
@@ -40,6 +48,13 @@ define handle_quantum_painter_driver
ifeq ($$(filter $$(strip $$(CURRENT_PAINTER_DRIVER)),$$(VALID_QUANTUM_PAINTER_DRIVERS)),)
$$(error "$$(CURRENT_PAINTER_DRIVER)" is not a valid Quantum Painter driver)
+ else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),rgb565_surface)
+ OPT_DEFS += -DQUANTUM_PAINTER_RGB565_SURFACE_ENABLE
+ COMMON_VPATH += \
+ $(DRIVER_PATH)/painter/generic
+ SRC += \
+ $(DRIVER_PATH)/painter/generic/qp_rgb565_surface.c \
+
else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),ili9163_spi)
QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes
QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes
@@ -73,27 +88,27 @@ define handle_quantum_painter_driver
$(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \
$(DRIVER_PATH)/painter/ili9xxx/qp_ili9488.c \
- else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7789_spi)
+ else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7735_spi)
QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes
QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes
- OPT_DEFS += -DQUANTUM_PAINTER_ST7789_ENABLE -DQUANTUM_PAINTER_ST7789_SPI_ENABLE
+ OPT_DEFS += -DQUANTUM_PAINTER_ST7735_ENABLE -DQUANTUM_PAINTER_ST7735_SPI_ENABLE
COMMON_VPATH += \
$(DRIVER_PATH)/painter/tft_panel \
$(DRIVER_PATH)/painter/st77xx
SRC += \
$(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \
- $(DRIVER_PATH)/painter/st77xx/qp_st7789.c
+ $(DRIVER_PATH)/painter/st77xx/qp_st7735.c
- else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7735_spi)
+ else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7789_spi)
QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes
QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes
- OPT_DEFS += -DQUANTUM_PAINTER_ST7735_ENABLE -DQUANTUM_PAINTER_ST7735_SPI_ENABLE
+ OPT_DEFS += -DQUANTUM_PAINTER_ST7789_ENABLE -DQUANTUM_PAINTER_ST7789_SPI_ENABLE
COMMON_VPATH += \
$(DRIVER_PATH)/painter/tft_panel \
$(DRIVER_PATH)/painter/st77xx
SRC += \
$(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \
- $(DRIVER_PATH)/painter/st77xx/qp_st7735.c
+ $(DRIVER_PATH)/painter/st77xx/qp_st7789.c
else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),gc9a01_spi)
QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes