qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

qp_internal.c (4129B)


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