logo

qmk_firmware

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

pi50.c (9654B)


  1. /* Copyright 2023 ziptyze
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "quantum.h"
  17. #include <ctype.h>
  18. #include <stdio.h>
  19. #if defined(RGB_MATRIX_EFFECT)
  20. # undef RGB_MATRIX_EFFECT
  21. #endif // defined(RGB_MATRIX_EFFECT)
  22. #define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x,
  23. enum {
  24. RGB_MATRIX_EFFECT_NONE,
  25. #include "rgb_matrix_effects.inc"
  26. #undef RGB_MATRIX_EFFECT
  27. #ifdef RGB_MATRIX_CUSTOM_KB
  28. # include "rgb_matrix_kb.inc"
  29. #endif
  30. #ifdef RGB_MATRIX_CUSTOM_USER
  31. # include "rgb_matrix_user.inc"
  32. #endif
  33. #if defined(COMMUNITY_MODULES_ENABLE) && __has_include("rgb_matrix_community_modules.inc")
  34. # include "rgb_matrix_community_modules.inc"
  35. #endif
  36. };
  37. #define RGB_MATRIX_EFFECT(x) \
  38. case RGB_MATRIX_EFFECT_##x: \
  39. return #x;
  40. const char* rgb_matrix_name(uint8_t effect) {
  41. switch (effect) {
  42. case RGB_MATRIX_EFFECT_NONE:
  43. return "NONE";
  44. #include "rgb_matrix_effects.inc"
  45. #undef RGB_MATRIX_EFFECT
  46. #ifdef RGB_MATRIX_CUSTOM_KB
  47. # include "rgb_matrix_kb.inc"
  48. #endif
  49. #ifdef RGB_MATRIX_CUSTOM_USER
  50. # include "rgb_matrix_user.inc"
  51. #endif
  52. #if defined(COMMUNITY_MODULES_ENABLE) && __has_include("rgb_matrix_community_modules.inc")
  53. # include "rgb_matrix_community_modules.inc"
  54. #endif
  55. default:
  56. return "UNKNOWN";
  57. }
  58. }
  59. #ifdef OLED_ENABLE
  60. static uint32_t oled_logo_timer = 0;
  61. static bool clear_logo = true;
  62. static const char PROGMEM my_logo[] = {
  63. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  64. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  65. 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
  66. 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f,
  67. 0x0f, 0x0f, 0x0f, 0x1f, 0xff, 0xff, 0xff, 0x1f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
  68. 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x00,
  69. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73. 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74. 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  75. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
  76. 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,
  77. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  78. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  79. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  80. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  81. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  82. 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
  83. 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
  84. 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 0x00,
  85. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  86. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  87. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  88. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  89. 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
  90. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xfb,
  91. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff,
  92. 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  93. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  94. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  95. };
  96. #endif
  97. #ifdef OLED_ENABLE
  98. void init_timer(void){
  99. oled_logo_timer = timer_read32();
  100. };
  101. void user_oled_magic(void) {
  102. // Host Keyboard Layer Status
  103. oled_write_P(PSTR("Layer: "), false);
  104. switch (get_highest_layer(layer_state)) {
  105. case 0:
  106. oled_write_P(PSTR("One\n"), false);
  107. break;
  108. case 1:
  109. oled_write_P(PSTR("Two\n"), false);
  110. break;
  111. case 2:
  112. oled_write_P(PSTR("Three\n"), false);
  113. break;
  114. case 3:
  115. oled_write_P(PSTR("Four\n"), false);
  116. break;
  117. case 4:
  118. oled_write_P(PSTR("Five\n"), false);
  119. break;
  120. case 5:
  121. oled_write_P(PSTR("Six\n"), false);
  122. break;
  123. case 6:
  124. oled_write_P(PSTR("Seven\n"), false);
  125. break;
  126. case 7:
  127. oled_write_P(PSTR("Eight\n"), false);
  128. break;
  129. case 8:
  130. oled_write_P(PSTR("Nine\n"), false);
  131. break;
  132. case 9:
  133. oled_write_P(PSTR("Ten\n"), false);
  134. break;
  135. default:
  136. // Or use the write_ln shortcut over adding '\n' to the end of your string
  137. oled_write_ln_P(PSTR("Undefined"), false);
  138. }
  139. // Host Keyboard LED Status
  140. led_t led_state = host_keyboard_led_state();
  141. oled_write_P(led_state.caps_lock ? PSTR("Cap(x) ") : PSTR("Cap( ) "), false);
  142. oled_write_P(led_state.num_lock ? PSTR("Num(x) ") : PSTR("Num( ) "), false);
  143. oled_write_P(led_state.scroll_lock ? PSTR("Scrl(x)") : PSTR("Scrl( )"), false);
  144. char *mode_name = strdup(rgb_matrix_name(rgb_matrix_get_mode()));
  145. if (mode_name != NULL) {
  146. int len = strlen(mode_name);
  147. bool capitalize_next = true;
  148. for (int i = 0; i < len; i++) {
  149. if (i == 21 && mode_name[i] == '_') {
  150. continue; // Skip the underscore if it's the 22nd character
  151. }
  152. if (mode_name[i] == '_') {
  153. mode_name[i] = ' ';
  154. capitalize_next = true;
  155. } else if (capitalize_next) {
  156. mode_name[i] = mode_name[i] >= 'a' && mode_name[i] <= 'z' ? mode_name[i] - 'a' + 'A' : mode_name[i];
  157. capitalize_next = false;
  158. } else {
  159. mode_name[i] = mode_name[i] >= 'A' && mode_name[i] <= 'Z' ? mode_name[i] - 'A' + 'a' : mode_name[i];
  160. }
  161. }
  162. // Add line break and spaces if necessary
  163. if (len < 19) {
  164. strcat(mode_name, "\n");
  165. for (int i = 0; i < 21; i++) {
  166. strcat(mode_name, " ");
  167. }
  168. } else {
  169. // Find the most recent ' ' before the 21st character and replace it with a line break
  170. int break_pos = -1;
  171. for (int i = 18; i >= 0; i--) {
  172. if (mode_name[i] == ' ') {
  173. break_pos = i;
  174. break;
  175. }
  176. }
  177. if (break_pos >= 0) {
  178. mode_name[break_pos] = '\n';
  179. for (int i = 0; i < (21 - (len - break_pos - 1)); i++) {
  180. strcat(mode_name, " ");
  181. }
  182. } else {
  183. // No '_' found, just add spaces
  184. for (int i = 0; i < (21 - len); i++) {
  185. strcat(mode_name, " ");
  186. }
  187. }
  188. }
  189. oled_write_P(PSTR(mode_name), false);
  190. free(mode_name);
  191. }
  192. }
  193. void render_logo(void) {
  194. oled_write_raw_P(my_logo, sizeof(my_logo));
  195. }
  196. void clear_screen(void) {
  197. if (clear_logo){
  198. for (uint8_t i = 0; i < OLED_DISPLAY_HEIGHT; ++i) {
  199. for (uint8_t j = 0; j < OLED_DISPLAY_WIDTH; ++j) {
  200. oled_write_raw_byte(0x0, i*OLED_DISPLAY_WIDTH + j);
  201. }
  202. }
  203. clear_logo = false;
  204. }
  205. }
  206. oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
  207. return OLED_ROTATION_180;
  208. }
  209. void keyboard_post_init_kb(void) {
  210. init_timer();
  211. keyboard_post_init_user();
  212. }
  213. # define SHOW_LOGO 5000
  214. bool oled_task_kb(void) {
  215. if (!oled_task_user()) { return false; }
  216. if ((timer_elapsed32(oled_logo_timer) < SHOW_LOGO)){
  217. render_logo();
  218. }else{
  219. clear_screen();
  220. user_oled_magic();
  221. }
  222. return false;
  223. }
  224. #endif