logo

qmk_firmware

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

display.c (6379B)


  1. // Copyright 2023 Dasky (@daskygit)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "display.h"
  4. #include "graphics/splash.qgf.h"
  5. #include "graphics/reverb.qgf.h"
  6. #include "graphics/robotomono20.qff.h"
  7. #include <stdio.h>
  8. #include <math.h>
  9. static painter_image_handle_t reverb_logo;
  10. static painter_image_handle_t splash_image;
  11. static deferred_token display_task_token;
  12. static uint32_t key_pressed_count = 0;
  13. static uint8_t reverb_surface_fb[SURFACE_REQUIRED_BUFFER_BYTE_SIZE(240, 240, 16)];
  14. painter_device_t reverb_surface;
  15. painter_device_t reverb_display;
  16. painter_font_handle_t roboto_font;
  17. uint32_t display_task_callback(uint32_t trigger_time, void *cb_arg) {
  18. display_task_kb();
  19. return 100;
  20. }
  21. void display_init_kb(void) {
  22. reverb_display = qp_gc9a01_make_spi_device(240, 240, DISPLAY_CS, DISPLAY_DC, DISPLAY_RST, 2, 0); // always init display
  23. qp_init(reverb_display, QP_ROTATION_0);
  24. roboto_font = qp_load_font_mem(font_robotomono20);
  25. reverb_surface = qp_make_rgb565_surface(240, 240, reverb_surface_fb);
  26. qp_init(reverb_surface, QP_ROTATION_0);
  27. if (!display_init_user()) {
  28. return;
  29. }
  30. splash_image = qp_load_image_mem(gfx_splash);
  31. reverb_logo = qp_load_image_mem(gfx_reverb);
  32. qp_drawimage(reverb_display, 0, 0, splash_image);
  33. qp_flush(reverb_display);
  34. qp_close_image(splash_image);
  35. display_task_token = defer_exec(2000, display_task_callback, NULL);
  36. }
  37. __attribute__((weak)) bool display_init_user(void) {
  38. return true;
  39. }
  40. void display_task_kb(void) {
  41. if (!display_task_user()) {
  42. return;
  43. }
  44. static bool first_draw = true;
  45. static uint32_t last_timer = 0;
  46. static uint32_t last_wpm = UINT32_MAX;
  47. static uint32_t last_scan_rate = 0;
  48. static uint32_t last_key_pressed_count = UINT32_MAX;
  49. static uint8_t last_hue = 0;
  50. static uint8_t last_sat = 0;
  51. static uint8_t last_val = 0;
  52. bool rgb_redraw = false;
  53. if (first_draw) {
  54. qp_rect(reverb_display, 0, 0, 239, 239, 0, 0, 0, true);
  55. first_draw = false;
  56. }
  57. char buffer[64] = {0};
  58. if (last_hue != rgb_matrix_get_hue() || last_sat != rgb_matrix_get_sat() || last_val != rgb_matrix_get_val()) {
  59. last_hue = rgb_matrix_get_hue();
  60. last_sat = rgb_matrix_get_sat();
  61. last_val = rgb_matrix_get_val();
  62. qp_drawimage_recolor(reverb_surface, 60, 40, reverb_logo, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128), 0, 0, 0);
  63. rgb_redraw = true;
  64. }
  65. if (rgb_redraw || last_scan_rate != get_matrix_scan_rate()) {
  66. snprintf(buffer, sizeof(buffer), "Scan Rate %ld", get_matrix_scan_rate());
  67. int16_t width = qp_textwidth(roboto_font, buffer);
  68. qp_line(reverb_surface, 17, 101, 220, 101, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128));
  69. qp_rect(reverb_surface, 16, 125 - roboto_font->line_height, 221, 125, 0, 0, 0, true);
  70. qp_drawtext_recolor(reverb_surface, (120 - (width / 2)), (125 - roboto_font->line_height), roboto_font, buffer, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128), 0, 0, 0);
  71. qp_line(reverb_surface, 16, 126, 221, 126, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128));
  72. last_scan_rate = get_matrix_scan_rate();
  73. }
  74. if (rgb_redraw || last_key_pressed_count != key_pressed_count) {
  75. snprintf(buffer, sizeof(buffer), "Keys Pressed");
  76. int16_t width = qp_textwidth(roboto_font, buffer);
  77. qp_rect(reverb_surface, 30, 150 - roboto_font->line_height, 209, 150, 0, 0, 0, true);
  78. qp_drawtext_recolor(reverb_surface, (120 - (width / 2)), (150 - roboto_font->line_height), roboto_font, buffer, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128), 0, 0, 0);
  79. snprintf(buffer, sizeof(buffer), "%ld", key_pressed_count);
  80. width = qp_textwidth(roboto_font, buffer);
  81. qp_rect(reverb_surface, 30, 172 - roboto_font->line_height, 173, 172, 0, 0, 0, true);
  82. qp_drawtext_recolor(reverb_surface, (120 - (width / 2)), (172 - roboto_font->line_height), roboto_font, buffer, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128), 0, 0, 0);
  83. qp_line(reverb_surface, 30, 173, 209, 173, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128));
  84. last_key_pressed_count = key_pressed_count;
  85. }
  86. if (rgb_redraw || last_wpm != get_current_wpm()) {
  87. snprintf(buffer, sizeof(buffer), "WPM %d", get_current_wpm());
  88. int16_t width = qp_textwidth(roboto_font, buffer);
  89. qp_rect(reverb_surface, 56, 200 - roboto_font->line_height, 184, 200, 0, 0, 0, true);
  90. qp_drawtext_recolor(reverb_surface, (120 - (width / 2)), (200 - roboto_font->line_height), roboto_font, buffer, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128), 0, 0, 0);
  91. qp_line(reverb_surface, 56, 201, 184, 201, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128));
  92. last_wpm = get_current_wpm();
  93. }
  94. if (rgb_redraw || timer_elapsed(last_timer) >= 1000) {
  95. static uint8_t seconds = 0;
  96. static uint8_t x = 0;
  97. static uint8_t y = 0;
  98. if (x && y) {
  99. qp_circle(reverb_surface, x, y, 4, 0, 0, 0, true);
  100. }
  101. double radians = 0.10471975511966 * seconds;
  102. x = (110 * cos(radians)) + 119;
  103. y = (110 * sin(radians)) + 119;
  104. qp_circle(reverb_surface, x, y, 4, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128), true);
  105. qp_circle(reverb_surface, 119, 119, 105, rgb_matrix_get_hue(), rgb_matrix_get_sat(), MAX(rgb_matrix_get_val(), 128), false);
  106. if (seconds == 59) {
  107. seconds = 0;
  108. } else if (timer_elapsed(last_timer) >= 1000) {
  109. last_timer = timer_read32();
  110. seconds++;
  111. }
  112. }
  113. qp_surface_draw(reverb_surface, reverb_display, 0, 0, rgb_redraw);
  114. }
  115. __attribute__((weak)) bool display_task_user(void) {
  116. return true;
  117. }
  118. void display_key_counter(void) {
  119. if (key_pressed_count == UINT32_MAX) {
  120. key_pressed_count = 0;
  121. }
  122. key_pressed_count++;
  123. }