diff options
| author | Pablo MartÃnez <58857054+elpekenin@users.noreply.github.com> | 2025-10-08 04:10:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-07 19:10:38 -0700 |
| commit | 0550830909e854d2ac0203905c861a868e82b289 (patch) | |
| tree | 67e5a1ce8e82d1be81f1ee89f175856e1c149aff /drivers | |
| parent | 8f86f9794e13b6a2078f07d01ca7529d54dd676e (diff) | |
[QP] Minor cleanup and support for RGB888 surface (#25706)
Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/painter/comms/qp_comms_spi.c | 2 | ||||
| -rw-r--r-- | drivers/painter/generic/qp_surface.h | 10 | ||||
| -rw-r--r-- | drivers/painter/generic/qp_surface_internal.h | 1 | ||||
| -rw-r--r-- | drivers/painter/generic/qp_surface_rgb565.c | 2 | ||||
| -rw-r--r-- | drivers/painter/generic/qp_surface_rgb888.c | 143 | ||||
| -rw-r--r-- | drivers/painter/ili9xxx/qp_ili9486.c | 2 | ||||
| -rw-r--r-- | drivers/painter/tft_panel/qp_tft_panel.c | 7 |
7 files changed, 159 insertions, 8 deletions
diff --git a/drivers/painter/comms/qp_comms_spi.c b/drivers/painter/comms/qp_comms_spi.c index 4e6067394b..8f4fc12a3c 100644 --- a/drivers/painter/comms/qp_comms_spi.c +++ b/drivers/painter/comms/qp_comms_spi.c | |||
| @@ -36,7 +36,7 @@ uint32_t qp_comms_spi_send_data(painter_device_t device, const void *data, uint3 | |||
| 36 | const uint32_t max_msg_length = 1024; | 36 | const uint32_t max_msg_length = 1024; |
| 37 | 37 | ||
| 38 | while (bytes_remaining > 0) { | 38 | while (bytes_remaining > 0) { |
| 39 | uint32_t bytes_this_loop = QP_MIN(bytes_remaining, max_msg_length); | 39 | uint32_t bytes_this_loop = MIN(bytes_remaining, max_msg_length); |
| 40 | spi_transmit(p, bytes_this_loop); | 40 | spi_transmit(p, bytes_this_loop); |
| 41 | p += bytes_this_loop; | 41 | p += bytes_this_loop; |
| 42 | bytes_remaining -= bytes_this_loop; | 42 | bytes_remaining -= bytes_this_loop; |
diff --git a/drivers/painter/generic/qp_surface.h b/drivers/painter/generic/qp_surface.h index a291793649..f602a8770b 100644 --- a/drivers/painter/generic/qp_surface.h +++ b/drivers/painter/generic/qp_surface.h | |||
| @@ -51,6 +51,16 @@ painter_device_t qp_make_rgb565_surface(uint16_t panel_width, uint16_t panel_hei | |||
| 51 | painter_device_t qp_make_mono1bpp_surface(uint16_t panel_width, uint16_t panel_height, void *buffer); | 51 | painter_device_t qp_make_mono1bpp_surface(uint16_t panel_width, uint16_t panel_height, void *buffer); |
| 52 | 52 | ||
| 53 | /** | 53 | /** |
| 54 | * Factory method for an RGB888 surface (aka framebuffer). | ||
| 55 | * | ||
| 56 | * @param panel_width[in] the width of the display panel | ||
| 57 | * @param panel_height[in] the height of the display panel | ||
| 58 | * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 16)` | ||
| 59 | * @return the device handle used with all drawing routines in Quantum Painter | ||
| 60 | */ | ||
| 61 | painter_device_t qp_make_rgb888_surface(uint16_t panel_width, uint16_t panel_height, void *buffer); | ||
| 62 | |||
| 63 | /** | ||
| 54 | * Helper method to draw the contents of the framebuffer to the target device. | 64 | * Helper method to draw the contents of the framebuffer to the target device. |
| 55 | * | 65 | * |
| 56 | * After successful completion, the dirty area is reset. | 66 | * After successful completion, the dirty area is reset. |
diff --git a/drivers/painter/generic/qp_surface_internal.h b/drivers/painter/generic/qp_surface_internal.h index 71f82e924d..e05a58594b 100644 --- a/drivers/painter/generic/qp_surface_internal.h +++ b/drivers/painter/generic/qp_surface_internal.h | |||
| @@ -45,6 +45,7 @@ typedef struct surface_painter_device_t { | |||
| 45 | void * buffer; | 45 | void * buffer; |
| 46 | uint8_t * u8buffer; | 46 | uint8_t * u8buffer; |
| 47 | uint16_t *u16buffer; | 47 | uint16_t *u16buffer; |
| 48 | rgb_t * rgbbuffer; | ||
| 48 | }; | 49 | }; |
| 49 | 50 | ||
| 50 | // Manually manage the viewport for streaming pixel data to the display | 51 | // Manually manage the viewport for streaming pixel data to the display |
diff --git a/drivers/painter/generic/qp_surface_rgb565.c b/drivers/painter/generic/qp_surface_rgb565.c index c5b351311a..2426d53c0c 100644 --- a/drivers/painter/generic/qp_surface_rgb565.c +++ b/drivers/painter/generic/qp_surface_rgb565.c | |||
| @@ -52,7 +52,7 @@ static bool qp_surface_pixdata_rgb565(painter_device_t device, const void *pixel | |||
| 52 | // Pixel colour conversion | 52 | // Pixel colour conversion |
| 53 | static bool qp_surface_palette_convert_rgb565_swapped(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) { | 53 | static bool qp_surface_palette_convert_rgb565_swapped(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) { |
| 54 | for (int16_t i = 0; i < palette_size; ++i) { | 54 | for (int16_t i = 0; i < palette_size; ++i) { |
| 55 | rgb_t rgb = hsv_to_rgb_nocie((hsv_t){palette[i].hsv888.h, palette[i].hsv888.s, palette[i].hsv888.v}); | 55 | rgb_t rgb = hsv_to_rgb_nocie(palette[i].hsv888); |
| 56 | uint16_t rgb565 = (((uint16_t)rgb.r) >> 3) << 11 | (((uint16_t)rgb.g) >> 2) << 5 | (((uint16_t)rgb.b) >> 3); | 56 | uint16_t rgb565 = (((uint16_t)rgb.r) >> 3) << 11 | (((uint16_t)rgb.g) >> 2) << 5 | (((uint16_t)rgb.b) >> 3); |
| 57 | palette[i].rgb565 = __builtin_bswap16(rgb565); | 57 | palette[i].rgb565 = __builtin_bswap16(rgb565); |
| 58 | } | 58 | } |
diff --git a/drivers/painter/generic/qp_surface_rgb888.c b/drivers/painter/generic/qp_surface_rgb888.c new file mode 100644 index 0000000000..68c824b0e4 --- /dev/null +++ b/drivers/painter/generic/qp_surface_rgb888.c | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | // Copyright 2022 Nick Brassel (@tzarc) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #ifdef QUANTUM_PAINTER_SURFACE_ENABLE | ||
| 5 | |||
| 6 | # include "color.h" | ||
| 7 | # include "qp_draw.h" | ||
| 8 | # include "qp_surface_internal.h" | ||
| 9 | # include "qp_comms_dummy.h" | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 12 | // Surface driver impl: rgb888 | ||
| 13 | |||
| 14 | static inline void setpixel_rgb888(surface_painter_device_t *surface, uint16_t x, uint16_t y, rgb_t rgb888) { | ||
| 15 | uint16_t w = surface->base.panel_width; | ||
| 16 | uint16_t h = surface->base.panel_height; | ||
| 17 | |||
| 18 | // Drop out if it's off-screen | ||
| 19 | if (x >= w || y >= h) { | ||
| 20 | return; | ||
| 21 | } | ||
| 22 | |||
| 23 | // Skip messing with the dirty info if the original value already matches | ||
| 24 | if (memcmp(&surface->rgbbuffer[y * w + x], &rgb888, sizeof(rgb_t)) != 0) { | ||
| 25 | // Update the dirty region | ||
| 26 | qp_surface_update_dirty(&surface->dirty, x, y); | ||
| 27 | |||
| 28 | // Update the pixel data in the buffer | ||
| 29 | surface->rgbbuffer[y * w + x] = rgb888; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | static inline void append_pixel_rgb888(surface_painter_device_t *surface, rgb_t rgb888) { | ||
| 34 | setpixel_rgb888(surface, surface->viewport.pixdata_x, surface->viewport.pixdata_y, rgb888); | ||
| 35 | qp_surface_increment_pixdata_location(&surface->viewport); | ||
| 36 | } | ||
| 37 | |||
| 38 | static inline void stream_pixdata_rgb888(surface_painter_device_t *surface, const rgb_t *data, uint32_t native_pixel_count) { | ||
| 39 | for (uint32_t pixel_counter = 0; pixel_counter < native_pixel_count; ++pixel_counter) { | ||
| 40 | append_pixel_rgb888(surface, data[pixel_counter]); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | // Stream pixel data to the current write position in GRAM | ||
| 45 | static bool qp_surface_pixdata_rgb888(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) { | ||
| 46 | painter_driver_t * driver = (painter_driver_t *)device; | ||
| 47 | surface_painter_device_t *surface = (surface_painter_device_t *)driver; | ||
| 48 | stream_pixdata_rgb888(surface, (const rgb_t *)pixel_data, native_pixel_count); | ||
| 49 | return true; | ||
| 50 | } | ||
| 51 | |||
| 52 | // Pixel colour conversion | ||
| 53 | static bool qp_surface_palette_convert_rgb888(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) { | ||
| 54 | for (int16_t i = 0; i < palette_size; ++i) { | ||
| 55 | palette[i].rgb888 = hsv_to_rgb_nocie(palette[i].hsv888); | ||
| 56 | } | ||
| 57 | return true; | ||
| 58 | } | ||
| 59 | |||
| 60 | // Append pixels to the target location, keyed by the pixel index | ||
| 61 | static bool qp_surface_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) { | ||
| 62 | rgb_t *buf = (rgb_t *)target_buffer; | ||
| 63 | for (uint32_t i = 0; i < pixel_count; ++i) { | ||
| 64 | buf[pixel_offset + i] = palette[palette_indices[i]].rgb888; | ||
| 65 | } | ||
| 66 | return true; | ||
| 67 | } | ||
| 68 | |||
| 69 | static bool rgb888_target_pixdata_transfer(painter_driver_t *surface_driver, painter_driver_t *target_driver, uint16_t x, uint16_t y, bool entire_surface) { | ||
| 70 | surface_painter_device_t *surface_handle = (surface_painter_device_t *)surface_driver; | ||
| 71 | |||
| 72 | uint16_t l = entire_surface ? 0 : surface_handle->dirty.l; | ||
| 73 | uint16_t t = entire_surface ? 0 : surface_handle->dirty.t; | ||
| 74 | uint16_t r = entire_surface ? (surface_handle->base.panel_width - 1) : surface_handle->dirty.r; | ||
| 75 | uint16_t b = entire_surface ? (surface_handle->base.panel_height - 1) : surface_handle->dirty.b; | ||
| 76 | |||
| 77 | // Set the target drawing area | ||
| 78 | bool ok = qp_viewport((painter_device_t)target_driver, x + l, y + t, x + r, y + b); | ||
| 79 | if (!ok) { | ||
| 80 | qp_dprintf("rgb888_target_pixdata_transfer: fail (could not set target viewport)\n"); | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | |||
| 84 | // Housekeeping of the amount of pixels to transfer | ||
| 85 | uint32_t total_pixel_count = (8 * QUANTUM_PAINTER_PIXDATA_BUFFER_SIZE) / surface_driver->native_bits_per_pixel; | ||
| 86 | uint32_t pixel_counter = 0; | ||
| 87 | rgb_t * target_buffer = (rgb_t *)qp_internal_global_pixdata_buffer; | ||
| 88 | |||
| 89 | // Fill the global pixdata area so that we can start transferring to the panel | ||
| 90 | for (uint16_t y = t; y <= b; ++y) { | ||
| 91 | for (uint16_t x = l; x <= r; ++x) { | ||
| 92 | // Update the target buffer | ||
| 93 | target_buffer[pixel_counter++] = surface_handle->rgbbuffer[y * surface_handle->base.panel_width + x]; | ||
| 94 | |||
| 95 | // If we've accumulated enough data, send it | ||
| 96 | if (pixel_counter == total_pixel_count) { | ||
| 97 | ok = qp_pixdata((painter_device_t)target_driver, qp_internal_global_pixdata_buffer, pixel_counter); | ||
| 98 | if (!ok) { | ||
| 99 | qp_dprintf("rgb888_target_pixdata_transfer: fail (could not stream pixdata to target)\n"); | ||
| 100 | return false; | ||
| 101 | } | ||
| 102 | // Reset the counter | ||
| 103 | pixel_counter = 0; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | // If there's any leftover data, send it | ||
| 109 | if (pixel_counter > 0) { | ||
| 110 | ok = qp_pixdata((painter_device_t)target_driver, qp_internal_global_pixdata_buffer, pixel_counter); | ||
| 111 | if (!ok) { | ||
| 112 | qp_dprintf("rgb888_target_pixdata_transfer: fail (could not stream pixdata to target)\n"); | ||
| 113 | return false; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | return true; | ||
| 118 | } | ||
| 119 | |||
| 120 | static bool qp_surface_append_pixdata_rgb888(painter_device_t device, uint8_t *target_buffer, uint32_t pixdata_offset, uint8_t pixdata_byte) { | ||
| 121 | target_buffer[pixdata_offset] = pixdata_byte; | ||
| 122 | return true; | ||
| 123 | } | ||
| 124 | |||
| 125 | const surface_painter_driver_vtable_t rgb888_surface_driver_vtable = { | ||
| 126 | .base = | ||
| 127 | { | ||
| 128 | .init = qp_surface_init, | ||
| 129 | .power = qp_surface_power, | ||
| 130 | .clear = qp_surface_clear, | ||
| 131 | .flush = qp_surface_flush, | ||
| 132 | .pixdata = qp_surface_pixdata_rgb888, | ||
| 133 | .viewport = qp_surface_viewport, | ||
| 134 | .palette_convert = qp_surface_palette_convert_rgb888, | ||
| 135 | .append_pixels = qp_surface_append_pixels_rgb888, | ||
| 136 | .append_pixdata = qp_surface_append_pixdata_rgb888, | ||
| 137 | }, | ||
| 138 | .target_pixdata_transfer = rgb888_target_pixdata_transfer, | ||
| 139 | }; | ||
| 140 | |||
| 141 | SURFACE_FACTORY_FUNCTION_IMPL(qp_make_rgb888_surface, rgb888_surface_driver_vtable, 24); | ||
| 142 | |||
| 143 | #endif // QUANTUM_PAINTER_SURFACE_ENABLE | ||
diff --git a/drivers/painter/ili9xxx/qp_ili9486.c b/drivers/painter/ili9xxx/qp_ili9486.c index 48db779c04..5a2e226668 100644 --- a/drivers/painter/ili9xxx/qp_ili9486.c +++ b/drivers/painter/ili9xxx/qp_ili9486.c | |||
| @@ -90,7 +90,7 @@ static uint32_t qp_comms_spi_send_data_odd_cs_pulse(painter_device_t device, con | |||
| 90 | 90 | ||
| 91 | gpio_write_pin_high(comms_config->dc_pin); | 91 | gpio_write_pin_high(comms_config->dc_pin); |
| 92 | while (bytes_remaining > 0) { | 92 | while (bytes_remaining > 0) { |
| 93 | uint32_t bytes_this_loop = QP_MIN(bytes_remaining, max_msg_length); | 93 | uint32_t bytes_this_loop = MIN(bytes_remaining, max_msg_length); |
| 94 | bool odd_bytes = bytes_this_loop & 1; | 94 | bool odd_bytes = bytes_this_loop & 1; |
| 95 | 95 | ||
| 96 | // send data | 96 | // send data |
diff --git a/drivers/painter/tft_panel/qp_tft_panel.c b/drivers/painter/tft_panel/qp_tft_panel.c index c8e33343d4..a6c72b4f6f 100644 --- a/drivers/painter/tft_panel/qp_tft_panel.c +++ b/drivers/painter/tft_panel/qp_tft_panel.c | |||
| @@ -90,7 +90,7 @@ bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint3 | |||
| 90 | 90 | ||
| 91 | bool qp_tft_panel_palette_convert_rgb565_swapped(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) { | 91 | bool qp_tft_panel_palette_convert_rgb565_swapped(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) { |
| 92 | for (int16_t i = 0; i < palette_size; ++i) { | 92 | for (int16_t i = 0; i < palette_size; ++i) { |
| 93 | rgb_t rgb = hsv_to_rgb_nocie((hsv_t){palette[i].hsv888.h, palette[i].hsv888.s, palette[i].hsv888.v}); | 93 | rgb_t rgb = hsv_to_rgb_nocie(palette[i].hsv888); |
| 94 | uint16_t rgb565 = (((uint16_t)rgb.r) >> 3) << 11 | (((uint16_t)rgb.g) >> 2) << 5 | (((uint16_t)rgb.b) >> 3); | 94 | uint16_t rgb565 = (((uint16_t)rgb.r) >> 3) << 11 | (((uint16_t)rgb.g) >> 2) << 5 | (((uint16_t)rgb.b) >> 3); |
| 95 | palette[i].rgb565 = __builtin_bswap16(rgb565); | 95 | palette[i].rgb565 = __builtin_bswap16(rgb565); |
| 96 | } | 96 | } |
| @@ -99,10 +99,7 @@ bool qp_tft_panel_palette_convert_rgb565_swapped(painter_device_t device, int16_ | |||
| 99 | 99 | ||
| 100 | bool qp_tft_panel_palette_convert_rgb888(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) { | 100 | bool qp_tft_panel_palette_convert_rgb888(painter_device_t device, int16_t palette_size, qp_pixel_t *palette) { |
| 101 | for (int16_t i = 0; i < palette_size; ++i) { | 101 | for (int16_t i = 0; i < palette_size; ++i) { |
| 102 | rgb_t rgb = hsv_to_rgb_nocie((hsv_t){palette[i].hsv888.h, palette[i].hsv888.s, palette[i].hsv888.v}); | 102 | palette[i].rgb888 = hsv_to_rgb_nocie(palette[i].hsv888); |
| 103 | palette[i].rgb888.r = rgb.r; | ||
| 104 | palette[i].rgb888.g = rgb.g; | ||
| 105 | palette[i].rgb888.b = rgb.b; | ||
| 106 | } | 103 | } |
| 107 | return true; | 104 | return true; |
| 108 | } | 105 | } |
