logo

qmk_firmware

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

qp_internal.c (4129B)


  1. // Copyright 2023 Nick Brassel (@tzarc)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "qp_internal.h"
  4. #include "compiler_support.h"
  5. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6. // Quantum Painter Core API: device registration
  7. enum {
  8. // Work out how many devices we're actually going to be instantiating
  9. // NOTE: We intentionally do not include surfaces here, despite them conforming to the same API.
  10. QP_NUM_DEVICES = (ILI9163_NUM_DEVICES) // ILI9163
  11. + (ILI9341_NUM_DEVICES) // ILI9341
  12. + (ILI9486_NUM_DEVICES) // ILI9486
  13. + (ILI9488_NUM_DEVICES) // ILI9488
  14. + (ST7789_NUM_DEVICES) // ST7789
  15. + (ST7735_NUM_DEVICES) // ST7735
  16. + (GC9A01_NUM_DEVICES) // GC9A01
  17. + (GC9107_NUM_DEVICES) // GC9107
  18. + (SSD1351_NUM_DEVICES) // SSD1351
  19. + (SH1106_NUM_DEVICES) // SH1106
  20. + (SH1107_NUM_DEVICES) // SH1107
  21. + (LD7032_NUM_DEVICES) // LD7032
  22. };
  23. static painter_device_t qp_devices[QP_NUM_DEVICES] = {NULL};
  24. bool qp_internal_register_device(painter_device_t driver) {
  25. for (uint8_t i = 0; i < QP_NUM_DEVICES; i++) {
  26. if (qp_devices[i] == NULL) {
  27. qp_devices[i] = driver;
  28. return true;
  29. }
  30. }
  31. // We should never get here -- someone has screwed up their device counts during config
  32. qp_dprintf("qp_internal_register_device: no more space for devices!\n");
  33. return false;
  34. }
  35. #if (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0
  36. static void qp_internal_display_timeout_task(void) {
  37. // Handle power on/off state
  38. static bool display_on = true;
  39. bool should_change_display_state = false;
  40. bool target_display_state = false;
  41. if (last_input_activity_elapsed() < (QUANTUM_PAINTER_DISPLAY_TIMEOUT)) {
  42. should_change_display_state = display_on == false;
  43. target_display_state = true;
  44. } else {
  45. should_change_display_state = display_on == true;
  46. target_display_state = false;
  47. }
  48. if (should_change_display_state) {
  49. for (uint8_t i = 0; i < QP_NUM_DEVICES; i++) {
  50. if (qp_devices[i] != NULL) {
  51. qp_power(qp_devices[i], target_display_state);
  52. }
  53. }
  54. display_on = target_display_state;
  55. }
  56. }
  57. #endif // (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0
  58. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  59. // Quantum Painter Core API: qp_internal_task
  60. STATIC_ASSERT((QUANTUM_PAINTER_TASK_THROTTLE) > 0 && (QUANTUM_PAINTER_TASK_THROTTLE) < 1000, "QUANTUM_PAINTER_TASK_THROTTLE must be between 1 and 999");
  61. void qp_internal_task(void) {
  62. // Perform throttling of the internal processing of Quantum Painter
  63. static uint32_t last_tick = 0;
  64. uint32_t now = timer_read32();
  65. if (TIMER_DIFF_32(now, last_tick) < (QUANTUM_PAINTER_TASK_THROTTLE)) {
  66. return;
  67. }
  68. last_tick = now;
  69. #if (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0
  70. qp_internal_display_timeout_task();
  71. #endif // (QUANTUM_PAINTER_DISPLAY_TIMEOUT) > 0
  72. // Handle animations
  73. void qp_internal_animation_tick(void);
  74. qp_internal_animation_tick();
  75. #ifdef QUANTUM_PAINTER_LVGL_INTEGRATION_ENABLE
  76. // Run LVGL ticks
  77. void qp_lvgl_internal_tick(void);
  78. qp_lvgl_internal_tick();
  79. #endif
  80. // Flush (render) dirty regions to corresponding displays
  81. #if !defined(QUANTUM_PAINTER_DEBUG_ENABLE_FLUSH_TASK_OUTPUT)
  82. bool old_debug_state = debug_enable;
  83. debug_enable = false;
  84. #endif // defined(QUANTUM_PAINTER_DEBUG_ENABLE_FLUSH_TASK_OUTPUT)
  85. for (uint8_t i = 0; i < QP_NUM_DEVICES; i++) {
  86. if (qp_devices[i] != NULL) {
  87. qp_flush(qp_devices[i]);
  88. }
  89. }
  90. #if !defined(QUANTUM_PAINTER_DEBUG_ENABLE_FLUSH_TASK_OUTPUT)
  91. debug_enable = old_debug_state;
  92. #endif // defined(QUANTUM_PAINTER_DEBUG_ENABLE_FLUSH_TASK_OUTPUT)
  93. }