logo

qmk_firmware

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

rev1.c (3186B)


  1. // Copyright 2022 QMK
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "quantum.h"
  4. #ifdef OLED_ENABLE
  5. #include <stdio.h>
  6. oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
  7. if (!is_keyboard_master()) {
  8. return OLED_ROTATION_180; // flips the display 180 degrees if offhand
  9. }
  10. return rotation;
  11. }
  12. void oled_render_layer_state(void) {
  13. oled_write_P(PSTR("Layer: "), false);
  14. switch (get_highest_layer(layer_state)) {
  15. case 0:
  16. oled_write_ln_P(PSTR("Default"), false);
  17. break;
  18. case 1:
  19. oled_write_ln_P(PSTR("Lower"), false);
  20. break;
  21. case 2:
  22. oled_write_ln_P(PSTR("Raise"), false);
  23. break;
  24. case 3:
  25. oled_write_ln_P(PSTR("Adjust"), false);
  26. break;
  27. default:
  28. oled_write_ln_P(PSTR("Undef"), false);
  29. }
  30. }
  31. char keylog_str[24] = {};
  32. const char code_to_name[60] = {
  33. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
  34. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
  35. 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  36. '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
  37. 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
  38. '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
  39. void set_keylog(uint16_t keycode, keyrecord_t *record) {
  40. char name = ' ';
  41. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
  42. keycode = keycode & 0xFF;
  43. }
  44. if (keycode < 60) {
  45. name = code_to_name[keycode];
  46. }
  47. // update keylog
  48. snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c", record->event.key.row, record->event.key.col, keycode, name);
  49. }
  50. void oled_render_keylog(void) {
  51. oled_write(keylog_str, false);
  52. }
  53. void render_bootmagic_status(bool status) {
  54. /* Show Ctrl-Gui Swap options */
  55. static const char PROGMEM logo[][2][3] = {
  56. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  57. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  58. };
  59. if (status) {
  60. oled_write_ln_P(logo[0][0], false);
  61. oled_write_ln_P(logo[0][1], false);
  62. } else {
  63. oled_write_ln_P(logo[1][0], false);
  64. oled_write_ln_P(logo[1][1], false);
  65. }
  66. }
  67. void oled_render_logo(void) {
  68. static const char PROGMEM crkbd_logo[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0};
  69. oled_write_P(crkbd_logo, false);
  70. }
  71. bool oled_task_kb(void) {
  72. if (!oled_task_user()) {
  73. return true;
  74. }
  75. if (is_keyboard_master()) {
  76. oled_render_layer_state();
  77. oled_render_keylog();
  78. } else {
  79. oled_render_logo();
  80. }
  81. return false;
  82. }
  83. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  84. if (record->event.pressed) {
  85. set_keylog(keycode, record);
  86. }
  87. return process_record_user(keycode, record);
  88. }
  89. #endif // OLED_ENABLE