From f3ec4c7df784718590bb499ff98f51b9dc87f8aa Mon Sep 17 00:00:00 2001 From: elpekenin Date: Tue, 19 Sep 2023 16:04:52 +0200 Subject: [PATCH 1/7] Initial --- drivers/painter/ili9xxx/qp_ili9xxx.c | 17 ++++++ drivers/painter/ili9xxx/qp_ili9xxx.h | 8 +++ drivers/painter/st77xx/qp_st77xx.c | 17 ++++++ drivers/painter/st77xx/qp_st77xx.h | 8 +++ quantum/painter/qp.h | 11 ++++ quantum/painter/rules.mk | 86 +++++++++++++++------------- 6 files changed, 107 insertions(+), 40 deletions(-) create mode 100644 drivers/painter/ili9xxx/qp_ili9xxx.c create mode 100644 drivers/painter/ili9xxx/qp_ili9xxx.h create mode 100644 drivers/painter/st77xx/qp_st77xx.c create mode 100644 drivers/painter/st77xx/qp_st77xx.h diff --git a/drivers/painter/ili9xxx/qp_ili9xxx.c b/drivers/painter/ili9xxx/qp_ili9xxx.c new file mode 100644 index 000000000000..d1e1ac9d701e --- /dev/null +++ b/drivers/painter/ili9xxx/qp_ili9xxx.c @@ -0,0 +1,17 @@ +// Copyright 2023 Pablo Martinez (@elpekenin) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "qp_comms.h" +#include "qp_ili9xxx_opcodes.h" + +bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert) { + if (!device) { + qp_dprintf("qp_ili9xxx_set_inversion: fail (un-initialized pointer).\n"); + return false; + } + + qp_comms_command(device, invert ? ILI9XXX_CMD_INVERT_ON : ILI9XXX_CMD_INVERT_OFF); + + qp_dprintf("qp_ili9xxx_set_inversion: ok.\n"); + return true; +} diff --git a/drivers/painter/ili9xxx/qp_ili9xxx.h b/drivers/painter/ili9xxx/qp_ili9xxx.h new file mode 100644 index 000000000000..0a8ea348a9ca --- /dev/null +++ b/drivers/painter/ili9xxx/qp_ili9xxx.h @@ -0,0 +1,8 @@ +// Copyright 2023 Pablo Martinez (@elpekenin) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "qp.h" + +bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert); diff --git a/drivers/painter/st77xx/qp_st77xx.c b/drivers/painter/st77xx/qp_st77xx.c new file mode 100644 index 000000000000..5993a680fb92 --- /dev/null +++ b/drivers/painter/st77xx/qp_st77xx.c @@ -0,0 +1,17 @@ +// Copyright 2023 Pablo Martinez (@elpekenin) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "qp_comms.h" +#include "qp_st77xx_opcodes.h" + +bool qp_st77xx_set_inversion(painter_device_t device, bool invert) { + if (!device) { + qp_dprintf("qp_st77xx_set_inversion: fail (un-initialized pointer).\n"); + return false; + } + + qp_comms_command(device, invert ? ST77XX_CMD_INVERT_ON : ST77XX_CMD_INVERT_OFF); + + qp_dprintf("qp_st77xx_set_inversion: ok.\n"); + return true; +} diff --git a/drivers/painter/st77xx/qp_st77xx.h b/drivers/painter/st77xx/qp_st77xx.h new file mode 100644 index 000000000000..07379aa4f3b7 --- /dev/null +++ b/drivers/painter/st77xx/qp_st77xx.h @@ -0,0 +1,8 @@ +// Copyright 2023 Pablo Martinez (@elpekenin) +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "qp.h" + +bool qp_st77xx_set_inversion(painter_device_t device, bool invert); diff --git a/quantum/painter/qp.h b/quantum/painter/qp.h index 7222d3b41373..ef06c096bc0b 100644 --- a/quantum/painter/qp.h +++ b/quantum/painter/qp.h @@ -453,6 +453,17 @@ int16_t qp_drawtext(painter_device_t device, uint16_t x, uint16_t y, painter_fon */ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, painter_font_handle_t font, const char *str, uint8_t hue_fg, uint8_t sat_fg, uint8_t val_fg, uint8_t hue_bg, uint8_t sat_bg, uint8_t val_bg); +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Quantum Painter Families + +#ifdef QUANTUM_PAINTER_ILI9XXX_ENABLE +# include "qp_ili9xxx.h" +#endif // QUANTUM_PAINTER_ILI9XXX_ENABLE + +#ifdef QUANTUM_PAINTER_ST77XX_ENABLE +# include "qp_st77xx.h" +#endif // QUANTUM_PAINTER_ST77XX_ENABLE + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Quantum Painter Drivers diff --git a/quantum/painter/rules.mk b/quantum/painter/rules.mk index 7752936cbdc3..6e62526857bf 100644 --- a/quantum/painter/rules.mk +++ b/quantum/painter/rules.mk @@ -44,6 +44,10 @@ endif # Comms flags QUANTUM_PAINTER_NEEDS_COMMS_SPI ?= no +# Family flags +QUANTUM_PAINTER_ILI9XXX ?= no +QUANTUM_PAINTER_ST77XX ?= no + # Handler for each driver define handle_quantum_painter_driver CURRENT_PAINTER_DRIVER := $1 @@ -59,59 +63,29 @@ define handle_quantum_painter_driver $(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 + QUANTUM_PAINTER_ILI9XXX := yes OPT_DEFS += -DQUANTUM_PAINTER_ILI9163_ENABLE -DQUANTUM_PAINTER_ILI9163_SPI_ENABLE - COMMON_VPATH += \ - $(DRIVER_PATH)/painter/tft_panel \ - $(DRIVER_PATH)/painter/ili9xxx - SRC += \ - $(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \ - $(DRIVER_PATH)/painter/ili9xxx/qp_ili9163.c \ + SRC += $(DRIVER_PATH)/painter/ili9xxx/qp_ili9163.c else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),ili9341_spi) - QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes - QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes + QUANTUM_PAINTER_ILI9XXX := yes OPT_DEFS += -DQUANTUM_PAINTER_ILI9341_ENABLE -DQUANTUM_PAINTER_ILI9341_SPI_ENABLE - COMMON_VPATH += \ - $(DRIVER_PATH)/painter/tft_panel \ - $(DRIVER_PATH)/painter/ili9xxx - SRC += \ - $(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \ - $(DRIVER_PATH)/painter/ili9xxx/qp_ili9341.c \ + SRC += $(DRIVER_PATH)/painter/ili9xxx/qp_ili9341.c else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),ili9488_spi) - QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes - QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes + QUANTUM_PAINTER_ILI9XXX := yes OPT_DEFS += -DQUANTUM_PAINTER_ILI9488_ENABLE -DQUANTUM_PAINTER_ILI9488_SPI_ENABLE - COMMON_VPATH += \ - $(DRIVER_PATH)/painter/tft_panel \ - $(DRIVER_PATH)/painter/ili9xxx - SRC += \ - $(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \ - $(DRIVER_PATH)/painter/ili9xxx/qp_ili9488.c \ + SRC += $(DRIVER_PATH)/painter/ili9xxx/qp_ili9488.c else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7735_spi) - QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes - QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes + QUANTUM_PAINTER_ST77XX := yes 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_st7735.c + SRC += $(DRIVER_PATH)/painter/st77xx/qp_st7735.c else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7789_spi) - QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes - QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes + QUANTUM_PAINTER_ST77XX := yes 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_st7789.c + SRC += $(DRIVER_PATH)/painter/st77xx/qp_st7789.c else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),gc9a01_spi) QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes @@ -141,6 +115,38 @@ endef # Iterate through the listed drivers for the build, including what's necessary $(foreach qp_driver,$(QUANTUM_PAINTER_DRIVERS),$(eval $(call handle_quantum_painter_driver,$(qp_driver)))) +# If ILI9XXX is used, set up the required files +ifeq ($(strip $(QUANTUM_PAINTER_ILI9XXX)), yes) + QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes + QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes + + OPT_DEFS += -DQUANTUM_PAINTER_ILI9XXX_ENABLE + + COMMON_VPATH += \ + $(DRIVER_PATH)/painter/tft_panel \ + $(DRIVER_PATH)/painter/ili9xxx + + SRC += \ + $(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \ + $(DRIVER_PATH)/painter/ili9xxx/qp_ili9xxx.c +endif + +# If ST77XX is used, set up the required files +ifeq ($(strip $(QUANTUM_PAINTER_ST77XX)), yes) + QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes + QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes + + OPT_DEFS += -DQUANTUM_PAINTER_ST77XX_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_st77xx.c +endif + # If SPI comms is needed, set up the required files ifeq ($(strip $(QUANTUM_PAINTER_NEEDS_COMMS_SPI)), yes) OPT_DEFS += -DQUANTUM_PAINTER_SPI_ENABLE From ccfcb7bcc7445ac7496498d9676a43d5d7704638 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Tue, 19 Sep 2023 16:29:55 +0200 Subject: [PATCH 2/7] Docs + remaining devices --- docs/quantum_painter.md | 27 ++++++++++++++++----------- drivers/painter/gc9a01/qp_gc9a01.c | 12 ++++++++++++ drivers/painter/gc9a01/qp_gc9a01.h | 2 ++ drivers/painter/ili9xxx/qp_ili9xxx.c | 4 ++-- drivers/painter/ssd1351/qp_ssd1351.c | 12 ++++++++++++ drivers/painter/ssd1351/qp_ssd1351.h | 2 ++ drivers/painter/st77xx/qp_st77xx.c | 4 ++-- 7 files changed, 48 insertions(+), 15 deletions(-) diff --git a/docs/quantum_painter.md b/docs/quantum_painter.md index 5e399183f8b2..8cc48835e3fb 100644 --- a/docs/quantum_painter.md +++ b/docs/quantum_painter.md @@ -551,6 +551,17 @@ void housekeeping_task_user(void) { } ``` +#### ** Display Color Inversion ** + +```c +bool qp_gc9a01_set_inversion(painter_device_t device, bool invert); +bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert); +bool qp_ssd1351_set_inversion(painter_device_t device, bool invert); +bool qp_st77xx_set_inversion(painter_device_t device, bool invert); +``` + +This set of functions allow changing the inversion (ie: red is drawn blue, and so on) of a display, this may be needed when the default init sequence for a device does not match your hardware. + ### ** Drawing Primitives ** @@ -730,9 +741,7 @@ The `qp_drawimage` and `qp_drawimage_recolor` functions draw the supplied image static painter_image_handle_t my_image; void keyboard_post_init_kb(void) { my_image = qp_load_image_mem(gfx_my_image); - if (my_image != NULL) { - qp_drawimage(display, (239 - my_image->width), (319 - my_image->height), my_image); - } + qp_drawimage(display, (239 - my_image->width), (319 - my_image->height), my_image); } ``` @@ -755,9 +764,7 @@ static painter_image_handle_t my_image; static deferred_token my_anim; void keyboard_post_init_kb(void) { my_image = qp_load_image_mem(gfx_my_image); - if (my_image != NULL) { - my_anim = qp_animate(display, (239 - my_image->width), (319 - my_image->height), my_image); - } + my_anim = qp_animate(display, (239 - my_image->width), (319 - my_image->height), my_image); } ``` @@ -843,11 +850,9 @@ The `qp_drawtext` and `qp_drawtext_recolor` functions draw the supplied string t static painter_font_handle_t my_font; void keyboard_post_init_kb(void) { my_font = qp_load_font_mem(font_noto11); - if (my_font != NULL) { - static const char *text = "Hello from QMK!"; - int16_t width = qp_textwidth(my_font, text); - qp_drawtext(display, (239 - width), (319 - my_font->line_height), my_font, text); - } + static const char *text = "Hello from QMK!"; + int16_t width = qp_textwidth(my_font, text); + qp_drawtext(display, (239 - width), (319 - my_font->line_height), my_font, text); } ``` diff --git a/drivers/painter/gc9a01/qp_gc9a01.c b/drivers/painter/gc9a01/qp_gc9a01.c index a2eb2cf57c03..d20727f9ddc7 100644 --- a/drivers/painter/gc9a01/qp_gc9a01.c +++ b/drivers/painter/gc9a01/qp_gc9a01.c @@ -90,6 +90,18 @@ __attribute__((weak)) bool qp_gc9a01_init(painter_device_t device, painter_rotat return true; } +bool qp_gc9a01_set_inversion(painter_device_t device, bool invert) { + if (!device) { + qp_dprintf("qp_gc9a01_set_inversion: fail (un-initialized pointer)\n"); + return false; + } + + qp_comms_command(device, invert ? GC9A01_CMD_INVERT_ON : GC9A01_CMD_INVERT_OFF); + + qp_dprintf("qp_gc9a01_set_inversion: ok\n"); + return true; +} + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver vtable //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/drivers/painter/gc9a01/qp_gc9a01.h b/drivers/painter/gc9a01/qp_gc9a01.h index e2b193956405..75d3494ca6ba 100644 --- a/drivers/painter/gc9a01/qp_gc9a01.h +++ b/drivers/painter/gc9a01/qp_gc9a01.h @@ -35,3 +35,5 @@ */ painter_device_t qp_gc9a01_make_spi_device(uint16_t panel_width, uint16_t panel_height, pin_t chip_select_pin, pin_t dc_pin, pin_t reset_pin, uint16_t spi_divisor, int spi_mode); #endif // QUANTUM_PAINTER_GC9A01_SPI_ENABLE + +bool qp_gc9a01_set_inversion(painter_device_t device, bool invert); diff --git a/drivers/painter/ili9xxx/qp_ili9xxx.c b/drivers/painter/ili9xxx/qp_ili9xxx.c index d1e1ac9d701e..3f3af0dc1e31 100644 --- a/drivers/painter/ili9xxx/qp_ili9xxx.c +++ b/drivers/painter/ili9xxx/qp_ili9xxx.c @@ -6,12 +6,12 @@ bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert) { if (!device) { - qp_dprintf("qp_ili9xxx_set_inversion: fail (un-initialized pointer).\n"); + qp_dprintf("qp_ili9xxx_set_inversion: fail (un-initialized pointer)\n"); return false; } qp_comms_command(device, invert ? ILI9XXX_CMD_INVERT_ON : ILI9XXX_CMD_INVERT_OFF); - qp_dprintf("qp_ili9xxx_set_inversion: ok.\n"); + qp_dprintf("qp_ili9xxx_set_inversion: ok\n"); return true; } diff --git a/drivers/painter/ssd1351/qp_ssd1351.c b/drivers/painter/ssd1351/qp_ssd1351.c index 434b7f032781..9ed77ebd5982 100644 --- a/drivers/painter/ssd1351/qp_ssd1351.c +++ b/drivers/painter/ssd1351/qp_ssd1351.c @@ -59,6 +59,18 @@ __attribute__((weak)) bool qp_ssd1351_init(painter_device_t device, painter_rota return true; } +bool qp_ssd1351_set_inversion(painter_device_t device, bool invert) { + if (!device) { + qp_dprintf("qp_ssd1351_set_inversion: fail (un-initialized pointer)\n"); + return false; + } + + qp_comms_command(device, invert ? SSD1351_INVERTDISPLAY : SSD1351_NORMALDISPLAY); + + qp_dprintf("qp_ssd1351_set_inversion: ok\n"); + return true; +} + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Driver vtable diff --git a/drivers/painter/ssd1351/qp_ssd1351.h b/drivers/painter/ssd1351/qp_ssd1351.h index 0df34f204d5c..42710816eeb5 100644 --- a/drivers/painter/ssd1351/qp_ssd1351.h +++ b/drivers/painter/ssd1351/qp_ssd1351.h @@ -35,3 +35,5 @@ */ painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel_height, pin_t chip_select_pin, pin_t dc_pin, pin_t reset_pin, uint16_t spi_divisor, int spi_mode); #endif // QUANTUM_PAINTER_SSD1351_SPI_ENABLE + +bool qp_ssd1351_set_inversion(painter_device_t device, bool invert); diff --git a/drivers/painter/st77xx/qp_st77xx.c b/drivers/painter/st77xx/qp_st77xx.c index 5993a680fb92..9b166f8285be 100644 --- a/drivers/painter/st77xx/qp_st77xx.c +++ b/drivers/painter/st77xx/qp_st77xx.c @@ -6,12 +6,12 @@ bool qp_st77xx_set_inversion(painter_device_t device, bool invert) { if (!device) { - qp_dprintf("qp_st77xx_set_inversion: fail (un-initialized pointer).\n"); + qp_dprintf("qp_st77xx_set_inversion: fail (un-initialized pointer)\n"); return false; } qp_comms_command(device, invert ? ST77XX_CMD_INVERT_ON : ST77XX_CMD_INVERT_OFF); - qp_dprintf("qp_st77xx_set_inversion: ok.\n"); + qp_dprintf("qp_st77xx_set_inversion: ok\n"); return true; } From eadeedc2e4f9cb41aa56db2a433f9001f96dd431 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Thu, 21 Sep 2023 08:05:40 +0200 Subject: [PATCH 3/7] Doxygen --- drivers/painter/gc9a01/qp_gc9a01.h | 7 +++++++ drivers/painter/ili9xxx/qp_ili9xxx.h | 7 +++++++ drivers/painter/ssd1351/qp_ssd1351.h | 7 +++++++ drivers/painter/st77xx/qp_st77xx.h | 7 +++++++ 4 files changed, 28 insertions(+) diff --git a/drivers/painter/gc9a01/qp_gc9a01.h b/drivers/painter/gc9a01/qp_gc9a01.h index 75d3494ca6ba..228d2dda5de8 100644 --- a/drivers/painter/gc9a01/qp_gc9a01.h +++ b/drivers/painter/gc9a01/qp_gc9a01.h @@ -36,4 +36,11 @@ painter_device_t qp_gc9a01_make_spi_device(uint16_t panel_width, uint16_t panel_height, pin_t chip_select_pin, pin_t dc_pin, pin_t reset_pin, uint16_t spi_divisor, int spi_mode); #endif // QUANTUM_PAINTER_GC9A01_SPI_ENABLE +/** + * Function to control color inversion on a GC9A01 device. + * + * @param device[in] device handle to operate on. + * @param invert[in] whether to invert colors or not. + * @return Whether the operation was successful. + */ bool qp_gc9a01_set_inversion(painter_device_t device, bool invert); diff --git a/drivers/painter/ili9xxx/qp_ili9xxx.h b/drivers/painter/ili9xxx/qp_ili9xxx.h index 0a8ea348a9ca..a3d8be6d381d 100644 --- a/drivers/painter/ili9xxx/qp_ili9xxx.h +++ b/drivers/painter/ili9xxx/qp_ili9xxx.h @@ -5,4 +5,11 @@ #include "qp.h" +/** + * Function to control color inversion on a ILI9XXX device. + * + * @param device[in] device handle to operate on. + * @param invert[in] whether to invert colors or not. + * @return Whether the operation was successful. + */ bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert); diff --git a/drivers/painter/ssd1351/qp_ssd1351.h b/drivers/painter/ssd1351/qp_ssd1351.h index 42710816eeb5..eb358f8246d7 100644 --- a/drivers/painter/ssd1351/qp_ssd1351.h +++ b/drivers/painter/ssd1351/qp_ssd1351.h @@ -36,4 +36,11 @@ painter_device_t qp_ssd1351_make_spi_device(uint16_t panel_width, uint16_t panel_height, pin_t chip_select_pin, pin_t dc_pin, pin_t reset_pin, uint16_t spi_divisor, int spi_mode); #endif // QUANTUM_PAINTER_SSD1351_SPI_ENABLE +/** + * Function to control color inversion on a SSD1351 device. + * + * @param device[in] device handle to operate on. + * @param invert[in] whether to invert colors or not. + * @return Whether the operation was successful. + */ bool qp_ssd1351_set_inversion(painter_device_t device, bool invert); diff --git a/drivers/painter/st77xx/qp_st77xx.h b/drivers/painter/st77xx/qp_st77xx.h index 07379aa4f3b7..860058c37049 100644 --- a/drivers/painter/st77xx/qp_st77xx.h +++ b/drivers/painter/st77xx/qp_st77xx.h @@ -5,4 +5,11 @@ #include "qp.h" +/** + * Function to control color inversion on a ST77XX device. + * + * @param device[in] device handle to operate on. + * @param invert[in] whether to invert colors or not. + * @return Whether the operation was successful. + */ bool qp_st77xx_set_inversion(painter_device_t device, bool invert); From 2e2038f291a3234fd831fe315abce84624843765 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Thu, 21 Sep 2023 08:24:18 +0200 Subject: [PATCH 4/7] Reword error messages --- drivers/painter/gc9a01/qp_gc9a01.c | 2 +- drivers/painter/ili9xxx/qp_ili9xxx.c | 2 +- drivers/painter/ssd1351/qp_ssd1351.c | 2 +- drivers/painter/st77xx/qp_st77xx.c | 2 +- quantum/painter/lvgl/qp_lvgl.c | 2 +- quantum/painter/qp.c | 16 ++++++++-------- quantum/painter/qp_comms.c | 8 ++++---- quantum/painter/qp_draw_circle.c | 2 +- quantum/painter/qp_draw_core.c | 6 +++--- quantum/painter/qp_draw_ellipse.c | 2 +- quantum/painter/qp_draw_image.c | 2 +- quantum/painter/qp_draw_text.c | 2 +- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/painter/gc9a01/qp_gc9a01.c b/drivers/painter/gc9a01/qp_gc9a01.c index d20727f9ddc7..e314585d25ab 100644 --- a/drivers/painter/gc9a01/qp_gc9a01.c +++ b/drivers/painter/gc9a01/qp_gc9a01.c @@ -92,7 +92,7 @@ __attribute__((weak)) bool qp_gc9a01_init(painter_device_t device, painter_rotat bool qp_gc9a01_set_inversion(painter_device_t device, bool invert) { if (!device) { - qp_dprintf("qp_gc9a01_set_inversion: fail (un-initialized pointer)\n"); + qp_dprintf("qp_gc9a01_set_inversion: fail (un-initialized device handle)\n"); return false; } diff --git a/drivers/painter/ili9xxx/qp_ili9xxx.c b/drivers/painter/ili9xxx/qp_ili9xxx.c index 3f3af0dc1e31..867dfc170beb 100644 --- a/drivers/painter/ili9xxx/qp_ili9xxx.c +++ b/drivers/painter/ili9xxx/qp_ili9xxx.c @@ -6,7 +6,7 @@ bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert) { if (!device) { - qp_dprintf("qp_ili9xxx_set_inversion: fail (un-initialized pointer)\n"); + qp_dprintf("qp_ili9xxx_set_inversion: fail (un-initialized device handle)\n"); return false; } diff --git a/drivers/painter/ssd1351/qp_ssd1351.c b/drivers/painter/ssd1351/qp_ssd1351.c index 9ed77ebd5982..ceb54fb8c62f 100644 --- a/drivers/painter/ssd1351/qp_ssd1351.c +++ b/drivers/painter/ssd1351/qp_ssd1351.c @@ -61,7 +61,7 @@ __attribute__((weak)) bool qp_ssd1351_init(painter_device_t device, painter_rota bool qp_ssd1351_set_inversion(painter_device_t device, bool invert) { if (!device) { - qp_dprintf("qp_ssd1351_set_inversion: fail (un-initialized pointer)\n"); + qp_dprintf("qp_ssd1351_set_inversion: fail (un-initialized device handle)\n"); return false; } diff --git a/drivers/painter/st77xx/qp_st77xx.c b/drivers/painter/st77xx/qp_st77xx.c index 9b166f8285be..926fcc446d06 100644 --- a/drivers/painter/st77xx/qp_st77xx.c +++ b/drivers/painter/st77xx/qp_st77xx.c @@ -6,7 +6,7 @@ bool qp_st77xx_set_inversion(painter_device_t device, bool invert) { if (!device) { - qp_dprintf("qp_st77xx_set_inversion: fail (un-initialized pointer)\n"); + qp_dprintf("qp_st77xx_set_inversion: fail (un-initialized device handle)\n"); return false; } diff --git a/quantum/painter/lvgl/qp_lvgl.c b/quantum/painter/lvgl/qp_lvgl.c index 2e433d776162..e5e26009991f 100644 --- a/quantum/painter/lvgl/qp_lvgl.c +++ b/quantum/painter/lvgl/qp_lvgl.c @@ -62,7 +62,7 @@ bool qp_lvgl_attach(painter_device_t device) { painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_lvgl_attach: fail (validation_ok == false)\n"); + qp_dprintf("qp_lvgl_attach: fail (bad device handle)\n"); qp_lvgl_detach(); return false; } diff --git a/quantum/painter/qp.c b/quantum/painter/qp.c index f27bb7892add..8f21aea7ca35 100644 --- a/quantum/painter/qp.c +++ b/quantum/painter/qp.c @@ -31,7 +31,7 @@ bool qp_init(painter_device_t device, painter_rotation_t rotation) { painter_driver_t *driver = (painter_driver_t *)device; if (!driver) { - qp_dprintf("qp_init: fail (pointer to NULL)\n"); + qp_dprintf("qp_init: fail (un-initialized device handle)\n"); return false; } @@ -71,7 +71,7 @@ bool qp_power(painter_device_t device, bool power_on) { qp_dprintf("qp_power: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_power: fail (validation_ok == false)\n"); + qp_dprintf("qp_power: fail (bad device handle)\n"); return false; } @@ -93,7 +93,7 @@ bool qp_clear(painter_device_t device) { qp_dprintf("qp_clear: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_clear: fail (validation_ok == false)\n"); + qp_dprintf("qp_clear: fail (bad device handle)\n"); return false; } @@ -115,7 +115,7 @@ bool qp_flush(painter_device_t device) { qp_dprintf("qp_flush: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_flush: fail (validation_ok == false)\n"); + qp_dprintf("qp_flush: fail (bad device handle)\n"); return false; } @@ -138,7 +138,7 @@ void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height, painter_driver_t *driver = (painter_driver_t *)device; if (!driver) { - qp_dprintf("qp_get_geometry: fail (pointer to NULL)\n"); + qp_dprintf("qp_get_geometry: fail (un-initialized device handle)\n"); return; } @@ -187,7 +187,7 @@ void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_ painter_driver_t *driver = (painter_driver_t *)device; if (!driver) { - qp_dprintf("qp_set_viewport_offsets: fail (pointer to NULL)\n"); + qp_dprintf("qp_set_viewport_offsets: fail (un-initialized device handle)\n"); return; } @@ -204,7 +204,7 @@ bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t qp_dprintf("qp_viewport: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_viewport: fail (validation_ok == false)\n"); + qp_dprintf("qp_viewport: fail (bad device handle)\n"); return false; } @@ -227,7 +227,7 @@ bool qp_pixdata(painter_device_t device, const void *pixel_data, uint32_t native qp_dprintf("qp_pixdata: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_pixdata: fail (validation_ok == false)\n"); + qp_dprintf("qp_pixdata: fail (bad device handle)\n"); return false; } diff --git a/quantum/painter/qp_comms.c b/quantum/painter/qp_comms.c index 63667783e10d..13d6dda7d927 100644 --- a/quantum/painter/qp_comms.c +++ b/quantum/painter/qp_comms.c @@ -9,7 +9,7 @@ bool qp_comms_init(painter_device_t device) { painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_comms_init: fail (validation_ok == false)\n"); + qp_dprintf("qp_comms_init: fail (bad device handle)\n"); return false; } @@ -19,7 +19,7 @@ bool qp_comms_init(painter_device_t device) { bool qp_comms_start(painter_device_t device) { painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_comms_start: fail (validation_ok == false)\n"); + qp_dprintf("qp_comms_start: fail (bad device handle)\n"); return false; } @@ -29,7 +29,7 @@ bool qp_comms_start(painter_device_t device) { void qp_comms_stop(painter_device_t device) { painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_comms_stop: fail (validation_ok == false)\n"); + qp_dprintf("qp_comms_stop: fail (bad device handle)\n"); return; } @@ -39,7 +39,7 @@ void qp_comms_stop(painter_device_t device) { uint32_t qp_comms_send(painter_device_t device, const void *data, uint32_t byte_count) { painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_comms_send: fail (validation_ok == false)\n"); + qp_dprintf("qp_comms_send: fail (bad device handle)\n"); return false; } diff --git a/quantum/painter/qp_draw_circle.c b/quantum/painter/qp_draw_circle.c index 7f5a7ddfcd71..6a6938619eac 100644 --- a/quantum/painter/qp_draw_circle.c +++ b/quantum/painter/qp_draw_circle.c @@ -129,7 +129,7 @@ bool qp_circle(painter_device_t device, uint16_t x, uint16_t y, uint16_t radius, qp_dprintf("qp_circle: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_circle: fail (validation_ok == false)\n"); + qp_dprintf("qp_circle: fail (bad device handle)\n"); return false; } diff --git a/quantum/painter/qp_draw_core.c b/quantum/painter/qp_draw_core.c index aa5fa4aa761f..ea970e642830 100644 --- a/quantum/painter/qp_draw_core.c +++ b/quantum/painter/qp_draw_core.c @@ -146,7 +146,7 @@ bool qp_internal_load_qgf_palette(qp_stream_t *stream, uint8_t bpp) { bool qp_setpixel(painter_device_t device, uint16_t x, uint16_t y, uint8_t hue, uint8_t sat, uint8_t val) { painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_setpixel: fail (validation_ok == false)\n"); + qp_dprintf("qp_setpixel: fail (bad device handle)\n"); return false; } @@ -176,7 +176,7 @@ bool qp_line(painter_device_t device, uint16_t x0, uint16_t y0, uint16_t x1, uin qp_dprintf("qp_line(%d, %d, %d, %d): entry\n", (int)x0, (int)y0, (int)x1, (int)y1); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_line: fail (validation_ok == false)\n"); + qp_dprintf("qp_line: fail (bad device handle)\n"); return false; } @@ -254,7 +254,7 @@ bool qp_rect(painter_device_t device, uint16_t left, uint16_t top, uint16_t righ qp_dprintf("qp_rect(%d, %d, %d, %d): entry\n", (int)left, (int)top, (int)right, (int)bottom); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_rect: fail (validation_ok == false)\n"); + qp_dprintf("qp_rect: fail (bad device handle)\n"); return false; } diff --git a/quantum/painter/qp_draw_ellipse.c b/quantum/painter/qp_draw_ellipse.c index e912a3e91fe8..91a854614a60 100644 --- a/quantum/painter/qp_draw_ellipse.c +++ b/quantum/painter/qp_draw_ellipse.c @@ -63,7 +63,7 @@ bool qp_ellipse(painter_device_t device, uint16_t x, uint16_t y, uint16_t sizex, qp_dprintf("qp_ellipse: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_ellipse: fail (validation_ok == false)\n"); + qp_dprintf("qp_ellipse: fail (bad device handle)\n"); return false; } diff --git a/quantum/painter/qp_draw_image.c b/quantum/painter/qp_draw_image.c index fb17a05a1b61..bb8afd7b07f4 100644 --- a/quantum/painter/qp_draw_image.c +++ b/quantum/painter/qp_draw_image.c @@ -211,7 +211,7 @@ static bool qp_drawimage_recolor_impl(painter_device_t device, uint16_t x, uint1 qp_dprintf("qp_drawimage_recolor: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_drawimage_recolor: fail (validation_ok == false)\n"); + qp_dprintf("qp_drawimage_recolor: fail (bad device handle)\n"); return false; } diff --git a/quantum/painter/qp_draw_text.c b/quantum/painter/qp_draw_text.c index ff6fc01d11ef..771e3be3b1ee 100644 --- a/quantum/painter/qp_draw_text.c +++ b/quantum/painter/qp_draw_text.c @@ -407,7 +407,7 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai qp_dprintf("qp_drawtext_recolor: entry\n"); painter_driver_t *driver = (painter_driver_t *)device; if (!driver || !driver->validate_ok) { - qp_dprintf("qp_drawtext_recolor: fail (validation_ok == false)\n"); + qp_dprintf("qp_drawtext_recolor: fail (bad device handle)\n"); return 0; } From feda09161bb6ced4848d815847171a6e95dee896 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Sun, 1 Oct 2023 15:21:15 +0200 Subject: [PATCH 5/7] [FIX] broken dereferences --- docs/quantum_painter.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/quantum_painter.md b/docs/quantum_painter.md index 8cc48835e3fb..b91eca7d83b0 100644 --- a/docs/quantum_painter.md +++ b/docs/quantum_painter.md @@ -741,7 +741,9 @@ The `qp_drawimage` and `qp_drawimage_recolor` functions draw the supplied image static painter_image_handle_t my_image; void keyboard_post_init_kb(void) { my_image = qp_load_image_mem(gfx_my_image); - qp_drawimage(display, (239 - my_image->width), (319 - my_image->height), my_image); + if (my_image != NULL) { + qp_drawimage(display, (239 - my_image->width), (319 - my_image->height), my_image); + } } ``` @@ -764,7 +766,9 @@ static painter_image_handle_t my_image; static deferred_token my_anim; void keyboard_post_init_kb(void) { my_image = qp_load_image_mem(gfx_my_image); - my_anim = qp_animate(display, (239 - my_image->width), (319 - my_image->height), my_image); + if (my_image != NULL) { + my_anim = qp_animate(display, (239 - my_image->width), (319 - my_image->height), my_image); + } } ``` @@ -850,9 +854,11 @@ The `qp_drawtext` and `qp_drawtext_recolor` functions draw the supplied string t static painter_font_handle_t my_font; void keyboard_post_init_kb(void) { my_font = qp_load_font_mem(font_noto11); - static const char *text = "Hello from QMK!"; - int16_t width = qp_textwidth(my_font, text); - qp_drawtext(display, (239 - width), (319 - my_font->line_height), my_font, text); + if (my_font != NULL) { + static const char *text = "Hello from QMK!"; + int16_t width = qp_textwidth(my_font, text); + qp_drawtext(display, (239 - width), (319 - my_font->line_height), my_font, text); + } } ``` From 592c403139b45bfb1e01b8bcfcef7008dcccfc27 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Wed, 11 Oct 2023 22:58:41 +0200 Subject: [PATCH 6/7] Correct handling of comms --- drivers/painter/gc9a01/qp_gc9a01.c | 2 ++ drivers/painter/ili9xxx/qp_ili9xxx.c | 2 ++ drivers/painter/ssd1351/qp_ssd1351.c | 2 ++ drivers/painter/st77xx/qp_st77xx.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/drivers/painter/gc9a01/qp_gc9a01.c b/drivers/painter/gc9a01/qp_gc9a01.c index e314585d25ab..c12a793b8185 100644 --- a/drivers/painter/gc9a01/qp_gc9a01.c +++ b/drivers/painter/gc9a01/qp_gc9a01.c @@ -96,7 +96,9 @@ bool qp_gc9a01_set_inversion(painter_device_t device, bool invert) { return false; } + qp_comms_start(device); qp_comms_command(device, invert ? GC9A01_CMD_INVERT_ON : GC9A01_CMD_INVERT_OFF); + qp_comms_stop(device); qp_dprintf("qp_gc9a01_set_inversion: ok\n"); return true; diff --git a/drivers/painter/ili9xxx/qp_ili9xxx.c b/drivers/painter/ili9xxx/qp_ili9xxx.c index 867dfc170beb..88138290086d 100644 --- a/drivers/painter/ili9xxx/qp_ili9xxx.c +++ b/drivers/painter/ili9xxx/qp_ili9xxx.c @@ -10,7 +10,9 @@ bool qp_ili9xxx_set_inversion(painter_device_t device, bool invert) { return false; } + qp_comms_start(device); qp_comms_command(device, invert ? ILI9XXX_CMD_INVERT_ON : ILI9XXX_CMD_INVERT_OFF); + qp_comms_stop(device); qp_dprintf("qp_ili9xxx_set_inversion: ok\n"); return true; diff --git a/drivers/painter/ssd1351/qp_ssd1351.c b/drivers/painter/ssd1351/qp_ssd1351.c index ceb54fb8c62f..91ba0c10618d 100644 --- a/drivers/painter/ssd1351/qp_ssd1351.c +++ b/drivers/painter/ssd1351/qp_ssd1351.c @@ -65,7 +65,9 @@ bool qp_ssd1351_set_inversion(painter_device_t device, bool invert) { return false; } + qp_comms_start(device); qp_comms_command(device, invert ? SSD1351_INVERTDISPLAY : SSD1351_NORMALDISPLAY); + qp_comms_stop(device); qp_dprintf("qp_ssd1351_set_inversion: ok\n"); return true; diff --git a/drivers/painter/st77xx/qp_st77xx.c b/drivers/painter/st77xx/qp_st77xx.c index 926fcc446d06..82355b96cc66 100644 --- a/drivers/painter/st77xx/qp_st77xx.c +++ b/drivers/painter/st77xx/qp_st77xx.c @@ -10,7 +10,9 @@ bool qp_st77xx_set_inversion(painter_device_t device, bool invert) { return false; } + qp_comms_start(device); qp_comms_command(device, invert ? ST77XX_CMD_INVERT_ON : ST77XX_CMD_INVERT_OFF); + qp_comms_stop(device); qp_dprintf("qp_st77xx_set_inversion: ok\n"); return true; From 1bdb05ff17ea09f78809bf62abc799c401b396f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Sat, 11 Nov 2023 10:43:00 +0100 Subject: [PATCH 7/7] Fix merge issue --- quantum/painter/rules.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/quantum/painter/rules.mk b/quantum/painter/rules.mk index 0e0ceb5ec58f..c5abf25f516b 100644 --- a/quantum/painter/rules.mk +++ b/quantum/painter/rules.mk @@ -168,6 +168,7 @@ ifeq ($(strip $(QUANTUM_PAINTER_ST77XX)), yes) SRC += \ $(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \ $(DRIVER_PATH)/painter/st77xx/qp_st77xx.c +endif # If a surface is needed, set up the required files ifeq ($(strip $(QUANTUM_PAINTER_NEEDS_SURFACE)), yes)