logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

qp_surface_internal.h (7744B)


  1. // Copyright 2022 Nick Brassel (@tzarc)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #ifdef QUANTUM_PAINTER_SURFACE_ENABLE
  5. # include "qp_surface.h"
  6. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  7. // Internal declarations
  8. // Surface vtable
  9. typedef struct surface_painter_driver_vtable_t {
  10. painter_driver_vtable_t base; // must be first, so it can be cast to/from the painter_driver_vtable_t* type
  11. bool (*target_pixdata_transfer)(painter_driver_t *surface_driver, painter_driver_t *target_driver, uint16_t x, uint16_t y, bool entire_surface);
  12. } surface_painter_driver_vtable_t;
  13. typedef struct surface_dirty_data_t {
  14. bool is_dirty;
  15. uint16_t l;
  16. uint16_t t;
  17. uint16_t r;
  18. uint16_t b;
  19. } surface_dirty_data_t;
  20. typedef struct surface_viewport_data_t {
  21. // Manually manage the viewport for streaming pixel data to the display
  22. uint16_t viewport_l;
  23. uint16_t viewport_t;
  24. uint16_t viewport_r;
  25. uint16_t viewport_b;
  26. // Current write location to the display when streaming pixel data
  27. uint16_t pixdata_x;
  28. uint16_t pixdata_y;
  29. } surface_viewport_data_t;
  30. // Surface struct
  31. typedef struct surface_painter_device_t {
  32. painter_driver_t base; // must be first, so it can be cast to/from the painter_device_t* type
  33. // The target buffer
  34. union {
  35. void * buffer;
  36. uint8_t * u8buffer;
  37. uint16_t *u16buffer;
  38. };
  39. // Manually manage the viewport for streaming pixel data to the display
  40. surface_viewport_data_t viewport;
  41. // Maintain a dirty region so we can stream only what we need
  42. surface_dirty_data_t dirty;
  43. } surface_painter_device_t;
  44. /**
  45. * Factory method for an RGB565 surface (aka framebuffer). Accepts an external device table.
  46. *
  47. * @param device_table[in] the table of devices to use for instantiation
  48. * @param device_table_len[in] the length of the table of devices
  49. * @param panel_width[in] the width of the display panel
  50. * @param panel_height[in] the height of the display panel
  51. * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 16)`
  52. * @return the device handle used with all drawing routines in Quantum Painter
  53. */
  54. painter_device_t qp_make_rgb565_surface_advanced(surface_painter_device_t *device_table, size_t device_table_len, uint16_t panel_width, uint16_t panel_height, void *buffer);
  55. /**
  56. * Factory method for a 1bpp monochrome surface (aka framebuffer).
  57. *
  58. * @param device_table[in] the table of devices to use for instantiation
  59. * @param device_table_len[in] the length of the table of devices
  60. * @param panel_width[in] the width of the display panel
  61. * @param panel_height[in] the height of the display panel
  62. * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 16)`
  63. * @return the device handle used with all drawing routines in Quantum Painter
  64. */
  65. painter_device_t qp_make_mono1bpp_surface_advanced(surface_painter_device_t *device_table, size_t device_table_len, uint16_t panel_width, uint16_t panel_height, void *buffer);
  66. // Driver storage
  67. extern surface_painter_device_t surface_drivers[SURFACE_NUM_DEVICES];
  68. // Surface common APIs
  69. bool qp_surface_init(painter_device_t device, painter_rotation_t rotation);
  70. bool qp_surface_power(painter_device_t device, bool power_on);
  71. bool qp_surface_clear(painter_device_t device);
  72. bool qp_surface_flush(painter_device_t device);
  73. bool qp_surface_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom);
  74. void qp_surface_increment_pixdata_location(surface_viewport_data_t *viewport);
  75. void qp_surface_update_dirty(surface_dirty_data_t *dirty, uint16_t x, uint16_t y);
  76. #endif // QUANTUM_PAINTER_SURFACE_ENABLE
  77. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  78. // Factory functions for creating a handle to a surface
  79. #define SURFACE_FACTORY_FUNCTION_IMPL(function_name, vtable, bpp) \
  80. painter_device_t(function_name##_advanced)(surface_painter_device_t * device_table, size_t device_table_len, uint16_t panel_width, uint16_t panel_height, void *buffer) { \
  81. for (uint32_t i = 0; i < device_table_len; ++i) { \
  82. surface_painter_device_t *driver = &device_table[i]; \
  83. if (!driver->base.driver_vtable) { \
  84. driver->base.driver_vtable = (painter_driver_vtable_t *)&(vtable); \
  85. driver->base.native_bits_per_pixel = (bpp); \
  86. driver->base.comms_vtable = &dummy_comms_vtable; \
  87. driver->base.panel_width = panel_width; \
  88. driver->base.panel_height = panel_height; \
  89. driver->base.rotation = QP_ROTATION_0; \
  90. driver->base.offset_x = 0; \
  91. driver->base.offset_y = 0; \
  92. driver->buffer = buffer; \
  93. return (painter_device_t)driver; \
  94. } \
  95. } \
  96. return NULL; \
  97. } \
  98. painter_device_t(function_name)(uint16_t panel_width, uint16_t panel_height, void *buffer) { \
  99. return (function_name##_advanced)(surface_drivers, SURFACE_NUM_DEVICES, panel_width, panel_height, buffer); \
  100. }