qp_tft_panel.h 2.6 KB

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