You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.7 KiB

  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. typedef uint16_t (*rgb888_to_native_uint16_t)(uint8_t r, uint8_t g, uint8_t b);
  11. // Driver vtable with extras
  12. struct tft_panel_dc_reset_painter_driver_vtable_t {
  13. struct painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type
  14. // Conversion function for palette entries
  15. rgb888_to_native_uint16_t rgb888_to_native16bit;
  16. // Number of bytes for transmitting x/y coordinates
  17. uint8_t num_window_bytes;
  18. // Whether or not the x/y coords should be swapped on 90/270 rotation
  19. bool swap_window_coords;
  20. // Opcodes for normal display operation
  21. struct {
  22. uint8_t display_on;
  23. uint8_t display_off;
  24. uint8_t set_column_address;
  25. uint8_t set_row_address;
  26. uint8_t enable_writes;
  27. } opcodes;
  28. };
  29. // Device definition
  30. typedef struct tft_panel_dc_reset_painter_device_t {
  31. struct painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type
  32. union {
  33. #ifdef QUANTUM_PAINTER_SPI_ENABLE
  34. // SPI-based configurables
  35. struct qp_comms_spi_dc_reset_config_t spi_dc_reset_config;
  36. #endif // QUANTUM_PAINTER_SPI_ENABLE
  37. // TODO: I2C/parallel etc.
  38. };
  39. } tft_panel_dc_reset_painter_device_t;
  40. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. // Forward declarations for injecting into concrete driver vtables
  42. bool qp_tft_panel_power(painter_device_t device, bool power_on);
  43. bool qp_tft_panel_clear(painter_device_t device);
  44. bool qp_tft_panel_flush(painter_device_t device);
  45. bool qp_tft_panel_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom);
  46. bool qp_tft_panel_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count);
  47. bool qp_tft_panel_palette_convert(painter_device_t device, int16_t palette_size, qp_pixel_t *palette);
  48. bool 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);
  49. uint16_t qp_rgb888_to_rgb565(uint8_t r, uint8_t g, uint8_t b);
  50. uint16_t qp_rgb888_to_rgb565_swapped(uint8_t r, uint8_t g, uint8_t b);
  51. uint16_t qp_rgb888_to_bgr565(uint8_t r, uint8_t g, uint8_t b);
  52. uint16_t qp_rgb888_to_bgr565_swapped(uint8_t r, uint8_t g, uint8_t b);