logo

qmk_firmware

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

big_knob.c (2441B)


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