summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2022-07-02 13:20:45 +1000
committerGitHub <noreply@github.com>2022-07-02 13:20:45 +1000
commitb67ae67687b00ffb11ef9c4652e7f7f77b0c7b6d (patch)
treea2ba13597a00ed95e8b10a2371f08bf65f1e4942 /drivers
parentd6c39490df2aa114b4fb0fba00b4c03b5ff3a405 (diff)
[QP] Add ILI9488 support. (#17438)
Diffstat (limited to 'drivers')
-rw-r--r--drivers/painter/gc9a01/qp_gc9a01.c9
-rw-r--r--drivers/painter/ili9xxx/qp_ili9163.c9
-rw-r--r--drivers/painter/ili9xxx/qp_ili9341.c9
-rw-r--r--drivers/painter/ili9xxx/qp_ili9488.c120
-rw-r--r--drivers/painter/ili9xxx/qp_ili9488.h37
-rw-r--r--drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h1
-rw-r--r--drivers/painter/ssd1351/qp_ssd1351.c4
-rw-r--r--drivers/painter/st77xx/qp_st7789.c9
-rw-r--r--drivers/painter/tft_panel/qp_tft_panel.c60
-rw-r--r--drivers/painter/tft_panel/qp_tft_panel.h16
10 files changed, 211 insertions, 63 deletions
diff --git a/drivers/painter/gc9a01/qp_gc9a01.c b/drivers/painter/gc9a01/qp_gc9a01.c
index ad76d58b07..37700a28a4 100644
--- a/drivers/painter/gc9a01/qp_gc9a01.c
+++ b/drivers/painter/gc9a01/qp_gc9a01.c
@@ -102,12 +102,11 @@ const struct tft_panel_dc_reset_painter_driver_vtable_t gc9a01_driver_vtable = {
102 .flush = qp_tft_panel_flush, 102 .flush = qp_tft_panel_flush,
103 .pixdata = qp_tft_panel_pixdata, 103 .pixdata = qp_tft_panel_pixdata,
104 .viewport = qp_tft_panel_viewport, 104 .viewport = qp_tft_panel_viewport,
105 .palette_convert = qp_tft_panel_palette_convert, 105 .palette_convert = qp_tft_panel_palette_convert_rgb565_swapped,
106 .append_pixels = qp_tft_panel_append_pixels, 106 .append_pixels = qp_tft_panel_append_pixels_rgb565,
107 }, 107 },
108 .rgb888_to_native16bit = qp_rgb888_to_rgb565_swapped, 108 .num_window_bytes = 2,
109 .num_window_bytes = 2, 109 .swap_window_coords = false,
110 .swap_window_coords = false,
111 .opcodes = 110 .opcodes =
112 { 111 {
113 .display_on = GC9A01_CMD_DISPLAY_ON, 112 .display_on = GC9A01_CMD_DISPLAY_ON,
diff --git a/drivers/painter/ili9xxx/qp_ili9163.c b/drivers/painter/ili9xxx/qp_ili9163.c
index beaac0fbb5..14363c7d04 100644
--- a/drivers/painter/ili9xxx/qp_ili9163.c
+++ b/drivers/painter/ili9xxx/qp_ili9163.c
@@ -67,12 +67,11 @@ const struct tft_panel_dc_reset_painter_driver_vtable_t ili9163_driver_vtable =
67 .flush = qp_tft_panel_flush, 67 .flush = qp_tft_panel_flush,
68 .pixdata = qp_tft_panel_pixdata, 68 .pixdata = qp_tft_panel_pixdata,
69 .viewport = qp_tft_panel_viewport, 69 .viewport = qp_tft_panel_viewport,
70 .palette_convert = qp_tft_panel_palette_convert, 70 .palette_convert = qp_tft_panel_palette_convert_rgb565_swapped,
71 .append_pixels = qp_tft_panel_append_pixels, 71 .append_pixels = qp_tft_panel_append_pixels_rgb565,
72 }, 72 },
73 .rgb888_to_native16bit = qp_rgb888_to_rgb565_swapped, 73 .num_window_bytes = 2,
74 .num_window_bytes = 2, 74 .swap_window_coords = false,
75 .swap_window_coords = false,
76 .opcodes = 75 .opcodes =
77 { 76 {
78 .display_on = ILI9XXX_CMD_DISPLAY_ON, 77 .display_on = ILI9XXX_CMD_DISPLAY_ON,
diff --git a/drivers/painter/ili9xxx/qp_ili9341.c b/drivers/painter/ili9xxx/qp_ili9341.c
index 1f41dcfc0b..9608f109bd 100644
--- a/drivers/painter/ili9xxx/qp_ili9341.c
+++ b/drivers/painter/ili9xxx/qp_ili9341.c
@@ -74,12 +74,11 @@ const struct tft_panel_dc_reset_painter_driver_vtable_t ili9341_driver_vtable =
74 .flush = qp_tft_panel_flush, 74 .flush = qp_tft_panel_flush,
75 .pixdata = qp_tft_panel_pixdata, 75 .pixdata = qp_tft_panel_pixdata,
76 .viewport = qp_tft_panel_viewport, 76 .viewport = qp_tft_panel_viewport,
77 .palette_convert = qp_tft_panel_palette_convert, 77 .palette_convert = qp_tft_panel_palette_convert_rgb565_swapped,
78 .append_pixels = qp_tft_panel_append_pixels, 78 .append_pixels = qp_tft_panel_append_pixels_rgb565,
79 }, 79 },
80 .rgb888_to_native16bit = qp_rgb888_to_rgb565_swapped, 80 .num_window_bytes = 2,
81 .num_window_bytes = 2, 81 .swap_window_coords = false,
82 .swap_window_coords = false,
83 .opcodes = 82 .opcodes =
84 { 83 {
85 .display_on = ILI9XXX_CMD_DISPLAY_ON, 84 .display_on = ILI9XXX_CMD_DISPLAY_ON,
diff --git a/drivers/painter/ili9xxx/qp_ili9488.c b/drivers/painter/ili9xxx/qp_ili9488.c
new file mode 100644
index 0000000000..55cf9f896f
--- /dev/null
+++ b/drivers/painter/ili9xxx/qp_ili9488.c
@@ -0,0 +1,120 @@
1// Copyright 2021 Nick Brassel (@tzarc)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "qp_internal.h"
5#include "qp_comms.h"
6#include "qp_ili9488.h"
7#include "qp_ili9xxx_opcodes.h"
8#include "qp_tft_panel.h"
9
10#ifdef QUANTUM_PAINTER_ILI9488_SPI_ENABLE
11# include <qp_comms_spi.h>
12#endif // QUANTUM_PAINTER_ILI9488_SPI_ENABLE
13
14////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15// Common
16
17// Driver storage
18tft_panel_dc_reset_painter_device_t ili9488_drivers[ILI9488_NUM_DEVICES] = {0};
19
20////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
21// Initialization
22
23bool qp_ili9488_init(painter_device_t device, painter_rotation_t rotation) {
24 // clang-format off
25 const uint8_t ili9488_init_sequence[] = {
26 // Command, Delay, N, Data[N]
27 ILI9XXX_CMD_RESET, 120, 0,
28 ILI9XXX_SET_PGAMMA, 0, 15, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F,
29 ILI9XXX_SET_NGAMMA, 0, 15, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F,
30 ILI9XXX_SET_POWER_CTL_1, 0, 2, 0x17, 0x15,
31 ILI9XXX_SET_POWER_CTL_2, 0, 1, 0x41,
32 ILI9XXX_SET_VCOM_CTL_1, 0, 3, 0x00, 0x12, 0x80,
33 ILI9XXX_SET_PIX_FMT, 0, 1, 0x66,
34 ILI9XXX_SET_RGB_IF_SIG_CTL, 0, 1, 0x80,
35 ILI9XXX_SET_FRAME_CTL_NORMAL, 0, 1, 0xA0,
36 ILI9XXX_SET_INVERSION_CTL, 0, 1, 0x02,
37 ILI9XXX_SET_FUNCTION_CTL, 0, 2, 0x02, 0x02,
38 ILI9XXX_SET_IMAGE_FUNCTION, 0, 1, 0x00,
39 ILI9XXX_SET_PUMP_RATIO_CTL, 0, 4, 0xA9, 0x51, 0x2C, 0x82,
40 ILI9XXX_CMD_SLEEP_OFF, 5, 0,
41 ILI9XXX_CMD_DISPLAY_ON, 20, 0
42 };
43 // clang-format on
44 qp_comms_bulk_command_sequence(device, ili9488_init_sequence, sizeof(ili9488_init_sequence));
45
46 // Configure the rotation (i.e. the ordering and direction of memory writes in GRAM)
47 const uint8_t madctl[] = {
48 [QP_ROTATION_0] = ILI9XXX_MADCTL_BGR | ILI9XXX_MADCTL_MY,
49 [QP_ROTATION_90] = ILI9XXX_MADCTL_BGR | ILI9XXX_MADCTL_MX | ILI9XXX_MADCTL_MV | ILI9XXX_MADCTL_MY,
50 [QP_ROTATION_180] = ILI9XXX_MADCTL_BGR | ILI9XXX_MADCTL_MX,
51 [QP_ROTATION_270] = ILI9XXX_MADCTL_BGR | ILI9XXX_MADCTL_MV,
52 };
53 qp_comms_command_databyte(device, ILI9XXX_SET_MEM_ACS_CTL, madctl[rotation]);
54
55 return true;
56}
57
58////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59// Driver vtable
60
61const struct tft_panel_dc_reset_painter_driver_vtable_t ili9488_driver_vtable = {
62 .base =
63 {
64 .init = qp_ili9488_init,
65 .power = qp_tft_panel_power,
66 .clear = qp_tft_panel_clear,
67 .flush = qp_tft_panel_flush,
68 .pixdata = qp_tft_panel_pixdata,
69 .viewport = qp_tft_panel_viewport,
70 .palette_convert = qp_tft_panel_palette_convert_rgb888,
71 .append_pixels = qp_tft_panel_append_pixels_rgb888,
72 },
73 .num_window_bytes = 2,
74 .swap_window_coords = false,
75 .opcodes =
76 {
77 .display_on = ILI9XXX_CMD_DISPLAY_ON,
78 .display_off = ILI9XXX_CMD_DISPLAY_OFF,
79 .set_column_address = ILI9XXX_SET_COL_ADDR,
80 .set_row_address = ILI9XXX_SET_PAGE_ADDR,
81 .enable_writes = ILI9XXX_SET_MEM,
82 },
83};
84
85////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86// SPI
87
88#ifdef QUANTUM_PAINTER_ILI9488_SPI_ENABLE
89
90// Factory function for creating a handle to the ILI9488 device
91painter_device_t qp_ili9488_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) {
92 for (uint32_t i = 0; i < ILI9488_NUM_DEVICES; ++i) {
93 tft_panel_dc_reset_painter_device_t *driver = &ili9488_drivers[i];
94 if (!driver->base.driver_vtable) {
95 driver->base.driver_vtable = (const struct painter_driver_vtable_t *)&ili9488_driver_vtable;
96 driver->base.comms_vtable = (const struct painter_comms_vtable_t *)&spi_comms_with_dc_vtable;
97 driver->base.native_bits_per_pixel = 24; // RGB888
98 driver->base.panel_width = panel_width;
99 driver->base.panel_height = panel_height;
100 driver->base.rotation = QP_ROTATION_0;
101 driver->base.offset_x = 0;
102 driver->base.offset_y = 0;
103
104 // SPI and other pin configuration
105 driver->base.comms_config = &driver->spi_dc_reset_config;
106 driver->spi_dc_reset_config.spi_config.chip_select_pin = chip_select_pin;
107 driver->spi_dc_reset_config.spi_config.divisor = spi_divisor;
108 driver->spi_dc_reset_config.spi_config.lsb_first = false;
109 driver->spi_dc_reset_config.spi_config.mode = spi_mode;
110 driver->spi_dc_reset_config.dc_pin = dc_pin;
111 driver->spi_dc_reset_config.reset_pin = reset_pin;
112 return (painter_device_t)driver;
113 }
114 }
115 return NULL;
116}
117
118#endif // QUANTUM_PAINTER_ILI9488_SPI_ENABLE
119
120////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/drivers/painter/ili9xxx/qp_ili9488.h b/drivers/painter/ili9xxx/qp_ili9488.h
new file mode 100644
index 0000000000..21b8f03322
--- /dev/null
+++ b/drivers/painter/ili9xxx/qp_ili9488.h
@@ -0,0 +1,37 @@
1// Copyright 2021 Nick Brassel (@tzarc)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "gpio.h"
7#include "qp_internal.h"
8
9////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10// Quantum Painter ILI9488 configurables (add to your keyboard's config.h)
11
12#ifndef ILI9488_NUM_DEVICES
13/**
14 * @def This controls the maximum number of ILI9488 devices that Quantum Painter can communicate with at any one time.
15 * Increasing this number allows for multiple displays to be used.
16 */
17# define ILI9488_NUM_DEVICES 1
18#endif
19
20////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
21// Quantum Painter ILI9488 device factories
22
23#ifdef QUANTUM_PAINTER_ILI9488_SPI_ENABLE
24/**
25 * Factory method for an ILI9488 SPI LCD device.
26 *
27 * @param panel_width[in] the width of the display panel
28 * @param panel_height[in] the height of the display panel
29 * @param chip_select_pin[in] the GPIO pin used for SPI chip select
30 * @param dc_pin[in] the GPIO pin used for D/C control
31 * @param reset_pin[in] the GPIO pin used for RST
32 * @param spi_divisor[in] the SPI divisor to use when communicating with the display
33 * @param spi_mode[in] the SPI mode to use when communicating with the display
34 * @return the device handle used with all drawing routines in Quantum Painter
35 */
36painter_device_t qp_ili9488_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);
37#endif // QUANTUM_PAINTER_ILI9488_SPI_ENABLE
diff --git a/drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h b/drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h
index 1fa395cb89..47bb703648 100644
--- a/drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h
+++ b/drivers/painter/ili9xxx/qp_ili9xxx_opcodes.h
@@ -85,6 +85,7 @@
85#define ILI9XXX_SET_NGAMMA 0xE1 // Set negative gamma 85#define ILI9XXX_SET_NGAMMA 0xE1 // Set negative gamma
86#define ILI9XXX_SET_DGAMMA_CTL_1 0xE2 // Set digital gamma ctl 1 86#define ILI9XXX_SET_DGAMMA_CTL_1 0xE2 // Set digital gamma ctl 1
87#define ILI9XXX_SET_DGAMMA_CTL_2 0xE3 // Set digital gamma ctl 2 87#define ILI9XXX_SET_DGAMMA_CTL_2 0xE3 // Set digital gamma ctl 2
88#define ILI9XXX_SET_IMAGE_FUNCTION 0xE9 // Set image function
88#define ILI9XXX_ENABLE_3_GAMMA 0xF2 // Enable 3 gamma 89#define ILI9XXX_ENABLE_3_GAMMA 0xF2 // Enable 3 gamma
89#define ILI9XXX_SET_IF_CTL 0xF6 // Set interface control 90#define ILI9XXX_SET_IF_CTL 0xF6 // Set interface control
90#define ILI9XXX_SET_PUMP_RATIO_CTL 0xF7 // Set pump ratio control 91#define ILI9XXX_SET_PUMP_RATIO_CTL 0xF7 // Set pump ratio control
diff --git a/drivers/painter/ssd1351/qp_ssd1351.c b/drivers/painter/ssd1351/qp_ssd1351.c
index 970e7e67f3..67854133aa 100644
--- a/drivers/painter/ssd1351/qp_ssd1351.c
+++ b/drivers/painter/ssd1351/qp_ssd1351.c
@@ -71,8 +71,8 @@ const struct tft_panel_dc_reset_painter_driver_vtable_t ssd1351_driver_vtable =
71 .flush = qp_tft_panel_flush, 71 .flush = qp_tft_panel_flush,
72 .pixdata = qp_tft_panel_pixdata, 72 .pixdata = qp_tft_panel_pixdata,
73 .viewport = qp_tft_panel_viewport, 73 .viewport = qp_tft_panel_viewport,
74 .palette_convert = qp_tft_panel_palette_convert, 74 .palette_convert = qp_tft_panel_palette_convert_rgb565_swapped,
75 .append_pixels = qp_tft_panel_append_pixels, 75 .append_pixels = qp_tft_panel_append_pixels_rgb565,
76 }, 76 },
77 .rgb888_to_native16bit = qp_rgb888_to_rgb565_swapped, 77 .rgb888_to_native16bit = qp_rgb888_to_rgb565_swapped,
78 .num_window_bytes = 1, 78 .num_window_bytes = 1,
diff --git a/drivers/painter/st77xx/qp_st7789.c b/drivers/painter/st77xx/qp_st7789.c
index d005ece050..49e8436c29 100644
--- a/drivers/painter/st77xx/qp_st7789.c
+++ b/drivers/painter/st77xx/qp_st7789.c
@@ -90,12 +90,11 @@ const struct tft_panel_dc_reset_painter_driver_vtable_t st7789_driver_vtable = {
90 .flush = qp_tft_panel_flush, 90 .flush = qp_tft_panel_flush,
91 .pixdata = qp_tft_panel_pixdata, 91 .pixdata = qp_tft_panel_pixdata,
92 .viewport = qp_tft_panel_viewport, 92 .viewport = qp_tft_panel_viewport,
93 .palette_convert = qp_tft_panel_palette_convert, 93 .palette_convert = qp_tft_panel_palette_convert_rgb565_swapped,
94 .append_pixels = qp_tft_panel_append_pixels, 94 .append_pixels = qp_tft_panel_append_pixels_rgb565,
95 }, 95 },
96 .rgb888_to_native16bit = qp_rgb888_to_rgb565_swapped, 96 .num_window_bytes = 2,
97 .num_window_bytes = 2, 97 .swap_window_coords = false,
98 .swap_window_coords = false,
99 .opcodes = 98 .opcodes =
100 { 99 {
101 .display_on = ST77XX_CMD_DISPLAY_ON, 100 .display_on = ST77XX_CMD_DISPLAY_ON,
diff --git a/drivers/painter/tft_panel/qp_tft_panel.c b/drivers/painter/tft_panel/qp_tft_panel.c
index 4d636c9509..ad83b6c792 100644
--- a/drivers/painter/tft_panel/qp_tft_panel.c
+++ b/drivers/painter/tft_panel/qp_tft_panel.c
@@ -10,29 +10,6 @@
10#define BYTE_SWAP(x) (((((uint16_t)(x)) >> 8) & 0x00FF) | ((((uint16_t)(x)) << 8) & 0xFF00)) 10#define BYTE_SWAP(x) (((((uint16_t)(x)) >> 8) & 0x00FF) | ((((uint16_t)(x)) << 8) & 0xFF00))
11 11
12//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
13// Native pixel format conversion
14
15uint16_t qp_rgb888_to_rgb565(uint8_t r, uint8_t g, uint8_t b) {
16 uint16_t rgb565 = (((uint16_t)r) >> 3) << 11 | (((uint16_t)g) >> 2) << 5 | (((uint16_t)b) >> 3);
17 return rgb565;
18}
19
20uint16_t qp_rgb888_to_rgb565_swapped(uint8_t r, uint8_t g, uint8_t b) {
21 uint16_t rgb565 = (((uint16_t)r) >> 3) << 11 | (((uint16_t)g) >> 2) << 5 | (((uint16_t)b) >> 3);
22 return BYTE_SWAP(rgb565);
23}
24
25uint16_t qp_rgb888_to_bgr565(uint8_t r, uint8_t g, uint8_t b) {
26 uint16_t bgr565 = (((uint16_t)b) >> 3) << 11 | (((uint16_t)g) >> 2) << 5 | (((uint16_t)r) >> 3);
27 return bgr565;
28}
29
30uint16_t qp_rgb888_to_bgr565_swapped(uint8_t r, uint8_t g, uint8_t b) {
31 uint16_t bgr565 = (((uint16_t)b) >> 3) << 11 | (((uint16_t)g) >> 2) << 5 | (((uint16_t)r) >> 3);
32 return BYTE_SWAP(bgr565);
33}
34
35////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
36// Quantum Painter API implementations 13// Quantum Painter API implementations
37 14
38// Power control 15// Power control
@@ -105,26 +82,49 @@ bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top,
105 82
106// Stream pixel data to the current write position in GRAM 83// Stream pixel data to the current write position in GRAM
107bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) { 84bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) {
108 qp_comms_send(device, pixel_data, native_pixel_count * sizeof(uint16_t)); 85 struct painter_driver_t *driver = (struct painter_driver_t *)device;
86 qp_comms_send(device, pixel_data, native_pixel_count * driver->native_bits_per_pixel / 8);
109 return true; 87 return true;
110} 88}
111 89
90////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
112// Convert supplied palette entries into their native equivalents 91// Convert supplied palette entries into their native equivalents
113bool qp_tft_panel_palette_convert(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) { 92
114 struct painter_driver_t * driver = (struct painter_driver_t *)device; 93bool qp_tft_panel_palette_convert_rgb565_swapped(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) {
115 struct tft_panel_dc_reset_painter_driver_vtable_t *vtable = (struct tft_panel_dc_reset_painter_driver_vtable_t *)driver->driver_vtable;
116 for (int16_t i = 0; i < palette_size; ++i) { 94 for (int16_t i = 0; i < palette_size; ++i) {
117 RGB rgb = hsv_to_rgb_nocie((HSV){palette[i].hsv888.h, palette[i].hsv888.s, palette[i].hsv888.v}); 95 RGB rgb = hsv_to_rgb_nocie((HSV){palette[i].hsv888.h, palette[i].hsv888.s, palette[i].hsv888.v});
118 palette[i].rgb565 = vtable->rgb888_to_native16bit(rgb.r, rgb.g, rgb.b); 96 uint16_t rgb565 = (((uint16_t)rgb.r) >> 3) << 11 | (((uint16_t)rgb.g) >> 2) << 5 | (((uint16_t)rgb.b) >> 3);
97 palette[i].rgb565 = BYTE_SWAP(rgb565);
119 } 98 }
120 return true; 99 return true;
121} 100}
122 101
102bool qp_tft_panel_palette_convert_rgb888(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) {
103 for (int16_t i = 0; i < palette_size; ++i) {
104 RGB rgb = hsv_to_rgb_nocie((HSV){palette[i].hsv888.h, palette[i].hsv888.s, palette[i].hsv888.v});
105 palette[i].rgb888.r = rgb.r;
106 palette[i].rgb888.g = rgb.g;
107 palette[i].rgb888.b = rgb.b;
108 }
109 return true;
110}
111
112////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123// Append pixels to the target location, keyed by the pixel index 113// Append pixels to the target location, keyed by the pixel index
124bool qp_tft_panel_append_pixels(painter_device_t device, uint8_t *target_buffer, qp_pixel_t *palette, uint32_t pixel_offset, uint32_t pixel_count, uint8_t *palette_indices) { 114
115bool qp_tft_panel_append_pixels_rgb565(painter_device_t device, uint8_t *target_buffer, qp_pixel_t *palette, uint32_t pixel_offset, uint32_t pixel_count, uint8_t *palette_indices) {
125 uint16_t *buf = (uint16_t *)target_buffer; 116 uint16_t *buf = (uint16_t *)target_buffer;
126 for (uint32_t i = 0; i < pixel_count; ++i) { 117 for (uint32_t i = 0; i < pixel_count; ++i) {
127 buf[pixel_offset + i] = palette[palette_indices[i]].rgb565; 118 buf[pixel_offset + i] = palette[palette_indices[i]].rgb565;
128 } 119 }
129 return true; 120 return true;
130} 121}
122
123bool qp_tft_panel_append_pixels_rgb888(painter_device_t device, uint8_t *target_buffer, qp_pixel_t *palette, uint32_t pixel_offset, uint32_t pixel_count, uint8_t *palette_indices) {
124 for (uint32_t i = 0; i < pixel_count; ++i) {
125 target_buffer[(pixel_offset + i) * 3 + 0] = palette[palette_indices[i]].rgb888.r;
126 target_buffer[(pixel_offset + i) * 3 + 1] = palette[palette_indices[i]].rgb888.g;
127 target_buffer[(pixel_offset + i) * 3 + 2] = palette[palette_indices[i]].rgb888.b;
128 }
129 return true;
130}
diff --git a/drivers/painter/tft_panel/qp_tft_panel.h b/drivers/painter/tft_panel/qp_tft_panel.h
index 6eddfc503d..3cb015891b 100644
--- a/drivers/painter/tft_panel/qp_tft_panel.h
+++ b/drivers/painter/tft_panel/qp_tft_panel.h
@@ -11,15 +11,10 @@
11//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 11////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12// Common TFT panel implementation using D/C, and RST pins. 12// Common TFT panel implementation using D/C, and RST pins.
13 13
14typedef uint16_t (*rgb888_to_native_uint16_t)(uint8_t r, uint8_t g, uint8_t b);
15
16// Driver vtable with extras 14// Driver vtable with extras
17struct tft_panel_dc_reset_painter_driver_vtable_t { 15struct tft_panel_dc_reset_painter_driver_vtable_t {
18 struct painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type 16 struct painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type
19 17
20 // Conversion function for palette entries
21 rgb888_to_native_uint16_t rgb888_to_native16bit;
22
23 // Number of bytes for transmitting x/y coordinates 18 // Number of bytes for transmitting x/y coordinates
24 uint8_t num_window_bytes; 19 uint8_t num_window_bytes;
25 20
@@ -58,10 +53,9 @@ bool qp_tft_panel_clear(painter_device_t device);
58bool qp_tft_panel_flush(painter_device_t device); 53bool qp_tft_panel_flush(painter_device_t device);
59bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom); 54bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom);
60bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count); 55bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count);
61bool qp_tft_panel_palette_convert(painter_device_t device, int16_t palette_size, qp_pixel_t *palette);
62bool qp_tft_panel_append_pixels(painter_device_t device, uint8_t *target_buffer, qp_pixel_t *palette, uint32_t pixel_offset, uint32_t pixel_count, uint8_t *palette_indices);
63 56
64uint16_t qp_rgb888_to_rgb565(uint8_t r, uint8_t g, uint8_t b); 57bool qp_tft_panel_palette_convert_rgb565_swapped(painter_device_t device, int16_t palette_size, qp_pixel_t *palette);
65uint16_t qp_rgb888_to_rgb565_swapped(uint8_t r, uint8_t g, uint8_t b); 58bool qp_tft_panel_palette_convert_rgb888(painter_device_t device, int16_t palette_size, qp_pixel_t *palette);
66uint16_t qp_rgb888_to_bgr565(uint8_t r, uint8_t g, uint8_t b); 59
67uint16_t qp_rgb888_to_bgr565_swapped(uint8_t r, uint8_t g, uint8_t b); 60bool qp_tft_panel_append_pixels_rgb565(painter_device_t device, uint8_t *target_buffer, qp_pixel_t *palette, uint32_t pixel_offset, uint32_t pixel_count, uint8_t *palette_indices);
61bool qp_tft_panel_append_pixels_rgb888(painter_device_t device, uint8_t *target_buffer, qp_pixel_t *palette, uint32_t pixel_offset, uint32_t pixel_count, uint8_t *palette_indices);