qmk_firmware

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

big_knob.c (2441B)


      1 // Copyright 2023 jpe230 (@jpe230)
      2 // SPDX-License-Identifier: GPL-2.0-or-later
      3 
      4 #include "qp.h"
      5 #include "qp_comms.h"
      6 #include "qp_st77xx_opcodes.h"
      7 #include "gfx/logo.qgf.h"
      8 
      9 painter_device_t lcd;
     10 
     11 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     12 // Init board:
     13 // - Draw logo
     14 
     15 void keyboard_post_init_kb(void) {
     16     backlight_set(BACKLIGHT_DEFAULT_LEVEL);
     17 
     18     wait_ms(LCD_WAIT_TIME);
     19 
     20     // Initialise the LCD
     21     lcd = qp_st7735_make_spi_device(LCD_HEIGHT, LCD_WIDTH, LCD_CS_PIN, LCD_DC_PIN, LCD_RST_PIN, LCD_SPI_DIVISOR, 0);
     22     qp_init(lcd, LCD_ROTATION);
     23 
     24     // Invert Colour
     25     #ifdef LCD_INVERT_COLOUR
     26     qp_comms_start(lcd);
     27     qp_comms_command(lcd, ST77XX_CMD_INVERT_ON);
     28     qp_comms_stop(lcd);
     29     #endif
     30 
     31     // Apply Offset
     32     qp_set_viewport_offsets(lcd, LCD_OFFSET_X, LCD_OFFSET_Y);
     33 
     34     // Turn on the LCD and clear the display
     35     qp_power(lcd, true);
     36     qp_rect(lcd, 0, 0, LCD_WIDTH, LCD_HEIGHT, HSV_BLACK, true);
     37 
     38     // Show logo
     39     painter_image_handle_t logo_image = qp_load_image_mem(gfx_logo);
     40     qp_drawimage(lcd, 0, 0, logo_image);
     41 
     42     keyboard_post_init_user();
     43 }
     44 
     45 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     46 // Lights handling:
     47 //  - Turn off backlight (screen) after timeout or suspend
     48 //  - Turn off rgblight after timeout or suspend
     49 
     50 bool lights_off = false;
     51 
     52 __attribute__((weak)) void lights_wakeup_user(void) {};
     53 __attribute__((weak)) void lights_suspend_user(void) {};
     54 
     55 void backlight_wakeup(void) {
     56     backlight_set(BACKLIGHT_DEFAULT_LEVEL);
     57 }
     58 
     59 void backlight_suspend(void) {
     60     backlight_set(0);
     61 }
     62 
     63 void lights_wakeup(void) {
     64     lights_off = false;
     65     rgblight_wakeup();
     66     backlight_wakeup();
     67     lights_wakeup_user();
     68 }
     69 
     70 void lights_suspend(void) {
     71     lights_off = true;
     72     lights_suspend_user();
     73     rgblight_suspend();
     74     backlight_suspend();
     75 }
     76 
     77 void housekeeping_task_kb(void) {
     78     if ( lights_off && last_input_activity_elapsed() <= LIGHTS_TIMEOUT)
     79     {
     80         lights_wakeup();
     81     }
     82     if (!lights_off && last_input_activity_elapsed() > LIGHTS_TIMEOUT) {
     83         lights_suspend();
     84     }
     85 }
     86 
     87 void suspend_power_down_kb(void) {
     88     lights_suspend();
     89     qp_power(lcd, false);
     90     suspend_power_down_user();
     91 }
     92 
     93 void suspend_wakeup_init_kb(void) {
     94     qp_power(lcd, true);
     95     lights_wakeup();
     96     suspend_wakeup_init_user();
     97 }