logo

qmk_firmware

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

display.c (4295B)


  1. // Copyright 2023 zzeneg (@zzeneg)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "display.h"
  4. #include "qp.h"
  5. #include "lvgl_helpers.h"
  6. /* shared styles */
  7. lv_style_t style_screen;
  8. lv_style_t style_container;
  9. lv_style_t style_button;
  10. lv_style_t style_button_active;
  11. /* screens */
  12. static lv_obj_t *screen_home;
  13. /* home screen content */
  14. static lv_obj_t *label_shift;
  15. static lv_obj_t *label_ctrl;
  16. static lv_obj_t *label_alt;
  17. static lv_obj_t *label_gui;
  18. static lv_obj_t *label_caps;
  19. void init_styles(void) {
  20. lv_style_init(&style_screen);
  21. lv_style_set_bg_color(&style_screen, lv_color_black());
  22. lv_style_init(&style_container);
  23. lv_style_set_pad_top(&style_container, 0);
  24. lv_style_set_pad_bottom(&style_container, 0);
  25. lv_style_set_pad_left(&style_container, 0);
  26. lv_style_set_pad_right(&style_container, 0);
  27. lv_style_set_bg_opa(&style_container, 0);
  28. lv_style_set_border_width(&style_container, 0);
  29. lv_style_set_width(&style_container, lv_pct(100));
  30. lv_style_set_height(&style_container, LV_SIZE_CONTENT);
  31. lv_style_init(&style_button);
  32. lv_style_set_pad_top(&style_button, 4);
  33. lv_style_set_pad_bottom(&style_button, 4);
  34. lv_style_set_pad_left(&style_button, 4);
  35. lv_style_set_pad_right(&style_button, 4);
  36. lv_style_set_radius(&style_button, 6);
  37. lv_style_set_text_color(&style_button, lv_palette_main(LV_PALETTE_AMBER));
  38. lv_style_init(&style_button_active);
  39. lv_style_set_bg_color(&style_button_active, lv_palette_main(LV_PALETTE_AMBER));
  40. lv_style_set_bg_opa(&style_button_active, LV_OPA_100);
  41. lv_style_set_text_color(&style_button_active, lv_color_black());
  42. }
  43. void init_screen_home(void) {
  44. screen_home = lv_scr_act();
  45. lv_obj_add_style(screen_home, &style_screen, 0);
  46. use_flex_column(screen_home);
  47. lv_obj_t *mods = lv_obj_create(screen_home);
  48. lv_obj_add_style(mods, &style_container, 0);
  49. use_flex_column(mods);
  50. lv_obj_t *mods_row1 = lv_obj_create(mods);
  51. lv_obj_add_style(mods_row1, &style_container, 0);
  52. use_flex_row(mods_row1);
  53. label_gui = create_button(mods_row1, "GUI", &style_button, &style_button_active);
  54. label_alt = create_button(mods_row1, "ALT", &style_button, &style_button_active);
  55. lv_obj_t *mods_row2 = lv_obj_create(mods);
  56. lv_obj_add_style(mods_row2, &style_container, 0);
  57. use_flex_row(mods_row2);
  58. label_ctrl = create_button(mods_row2, "CTL", &style_button, &style_button_active);
  59. label_shift = create_button(mods_row2, "SFT", &style_button, &style_button_active);
  60. lv_obj_t *label_stront = lv_label_create(screen_home);
  61. lv_label_set_text(label_stront, "stront");
  62. #if LV_FONT_MONTSERRAT_48
  63. lv_obj_set_style_text_font(label_stront, &lv_font_montserrat_48, LV_PART_MAIN);
  64. #endif
  65. label_caps = create_button(screen_home, "CAPS", &style_button, &style_button_active);
  66. }
  67. bool display_init_kb(void) {
  68. dprint("display_init_kb - start\n");
  69. backlight_enable();
  70. painter_device_t display = qp_st7789_make_spi_device(240, 300, LCD_CS_PIN, LCD_DC_PIN, LCD_RST_PIN, 16, 3);
  71. qp_set_viewport_offsets(display, 0, 20);
  72. if (!qp_init(display, QP_ROTATION_180) || !qp_power(display, true) || !qp_lvgl_attach(display)) return false;
  73. dprint("display_init_kb - initialised\n");
  74. lv_disp_t *lv_display = lv_disp_get_default();
  75. lv_theme_t *lv_theme = lv_theme_default_init(lv_display, lv_palette_main(LV_PALETTE_AMBER), lv_palette_main(LV_PALETTE_BLUE), true, LV_FONT_DEFAULT);
  76. lv_disp_set_theme(lv_display, lv_theme);
  77. init_styles();
  78. bool res = display_init_user();
  79. if (res) {
  80. dprint("display_init_kb - adding default home screen\n");
  81. init_screen_home();
  82. }
  83. return true;
  84. }
  85. __attribute__((weak)) bool display_init_user(void) {
  86. return true;
  87. }
  88. __attribute__((weak)) void display_housekeeping_task(void) {
  89. dprint("display_housekeeping_task_kb\n");
  90. toggle_state(label_shift, LV_STATE_PRESSED, MODS_SHIFT);
  91. toggle_state(label_ctrl, LV_STATE_PRESSED, MODS_CTRL);
  92. toggle_state(label_alt, LV_STATE_PRESSED, MODS_ALT);
  93. toggle_state(label_gui, LV_STATE_PRESSED, MODS_GUI);
  94. }
  95. __attribute__((weak)) void display_process_caps(bool active) {
  96. dprint("display_process_caps\n");
  97. toggle_state(label_caps, LV_STATE_PRESSED, active);
  98. }