qp_tft_panel.h (2828B)
1 // Copyright 2021 Nick Brassel (@tzarc) 2 // SPDX-License-Identifier: GPL-2.0-or-later 3 #pragma once 4 5 #include "color.h" 6 #include "qp_internal.h" 7 8 #ifdef QUANTUM_PAINTER_SPI_ENABLE 9 # include "qp_comms_spi.h" 10 #endif // QUANTUM_PAINTER_SPI_ENABLE 11 12 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 13 // Common TFT panel implementation using D/C, and RST pins. 14 15 // Driver vtable with extras 16 typedef struct tft_panel_dc_reset_painter_driver_vtable_t { 17 painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type 18 19 // Number of bytes for transmitting x/y coordinates 20 uint8_t num_window_bytes; 21 22 // Whether or not the x/y coords should be swapped on 90/270 rotation 23 bool swap_window_coords; 24 25 // Opcodes for normal display operation 26 struct { 27 uint8_t display_on; 28 uint8_t display_off; 29 uint8_t set_column_address; 30 uint8_t set_row_address; 31 uint8_t enable_writes; 32 } opcodes; 33 } tft_panel_dc_reset_painter_driver_vtable_t; 34 35 // Device definition 36 typedef struct tft_panel_dc_reset_painter_device_t { 37 painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type 38 39 union { 40 #ifdef QUANTUM_PAINTER_SPI_ENABLE 41 // SPI-based configurables 42 qp_comms_spi_dc_reset_config_t spi_dc_reset_config; 43 #endif // QUANTUM_PAINTER_SPI_ENABLE 44 45 // TODO: I2C/parallel etc. 46 }; 47 } tft_panel_dc_reset_painter_device_t; 48 49 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 50 // Forward declarations for injecting into concrete driver vtables 51 52 bool qp_tft_panel_power(painter_device_t device, bool power_on); 53 bool qp_tft_panel_clear(painter_device_t device); 54 bool qp_tft_panel_flush(painter_device_t device); 55 bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom); 56 bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count); 57 58 bool qp_tft_panel_palette_convert_rgb565_swapped(painter_device_t device, int16_t palette_size, qp_pixel_t *palette); 59 bool qp_tft_panel_palette_convert_rgb888(painter_device_t device, int16_t palette_size, qp_pixel_t *palette); 60 61 bool 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); 62 bool 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); 63 64 bool qp_tft_panel_append_pixdata(painter_device_t device, uint8_t *target_buffer, uint32_t pixdata_offset, uint8_t pixdata_byte);