oled_stuff.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  2. * Copyright 2021 John Ezra - wpm graph
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "drashna.h"
  18. #ifdef UNICODE_COMMON_ENABLE
  19. # include "process_unicode_common.h"
  20. # include "keyrecords/unicode.h"
  21. #endif
  22. #ifdef AUDIO_CLICKY
  23. # include "process_clicky.h"
  24. #endif
  25. #include <string.h>
  26. bool is_oled_enabled = true, is_oled_locked = false;
  27. extern bool host_driver_disabled;
  28. uint32_t oled_timer = 0;
  29. char keylog_str[OLED_KEYLOGGER_LENGTH] = {0};
  30. static uint16_t log_timer = 0;
  31. #ifdef OLED_DISPLAY_VERBOSE
  32. const char PROGMEM display_border[3] = {0x0, 0xFF, 0x0};
  33. #endif
  34. deferred_token kittoken;
  35. // clang-format off
  36. static const char PROGMEM code_to_name[256] = {
  37. // 0 1 2 3 4 5 6 7 8 9 A B c D E F
  38. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', // 0x
  39. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', // 1x
  40. '3', '4', '5', '6', '7', '8', '9', '0', 20, 19, 27, 26, 22, '-', '=', '[', // 2x
  41. ']','\\', '#', ';','\'', '`', ',', '.', '/', 128,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA, // 3x
  42. 0xDB,0xDC,0xDD,0xDE,0XDF,0xFB,'P', 'S', 19, ' ', 17, 30, 16, 16, 31, 26, // 4x
  43. 27, 25, 24, 'N', '/', '*', '-', '+', 23, '1', '2', '3', '4', '5', '6', '7', // 5x
  44. '8', '9', '0', '.','\\', 'A', 0, '=', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 6x
  45. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 7x
  46. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 8x
  47. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 9x
  48. ' ', ' ', ' ', ' ', ' ', 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Ax
  49. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Bx
  50. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Cx
  51. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Dx
  52. 'C', 'S', 'A', 'C', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 24, 26, 24, // Ex
  53. 25,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D, 24, 25, 27, 26, ' ', ' ', ' ' // Fx
  54. };
  55. // clang-format on
  56. /**
  57. * @brief parses pressed keycodes and saves to buffer
  58. *
  59. * @param keycode Keycode pressed from switch matrix
  60. * @param record keyrecord_t data structure
  61. */
  62. void add_keylog(uint16_t keycode, keyrecord_t *record) {
  63. if (keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) {
  64. keycode = QK_MOD_TAP_GET_TAP_KEYCODE(keycode);
  65. } else if (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX) {
  66. keycode = QK_LAYER_TAP_GET_TAP_KEYCODE(keycode);
  67. } else if (keycode >= QK_MODS && keycode <= QK_MODS_MAX) {
  68. keycode = QK_MODS_GET_BASIC_KEYCODE(keycode);
  69. }
  70. if ((keycode == KC_BSPC) && mod_config(get_mods() | get_oneshot_mods()) & MOD_MASK_CTRL) {
  71. memset(keylog_str, ' ', OLED_KEYLOGGER_LENGTH);
  72. keylog_str[OLED_KEYLOGGER_LENGTH-1] = 0x00;
  73. return;
  74. }
  75. if (record->tap.count) {
  76. keycode &= 0xFF;
  77. } else if (keycode > 0xFF) {
  78. return;
  79. }
  80. memmove(keylog_str, keylog_str + 1, OLED_KEYLOGGER_LENGTH - 2);
  81. if (keycode < ARRAY_SIZE(code_to_name)) {
  82. keylog_str[(OLED_KEYLOGGER_LENGTH - 2)] = pgm_read_byte(&code_to_name[keycode]);
  83. }
  84. log_timer = timer_read();
  85. }
  86. /**
  87. * @brief Keycode handler for oled display.
  88. *
  89. * This adds pressed keys to buffer, but also resets the oled timer
  90. *
  91. * @param keycode Keycode from matrix
  92. * @param record keyrecord data struture
  93. * @return true
  94. * @return false
  95. */
  96. bool process_record_user_oled(uint16_t keycode, keyrecord_t *record) {
  97. if (record->event.pressed) {
  98. oled_timer_reset();
  99. add_keylog(keycode, record);
  100. }
  101. return true;
  102. }
  103. void oled_timer_reset(void) {
  104. oled_timer = timer_read32();
  105. }
  106. /**
  107. * @brief Renders keylogger buffer to oled
  108. *
  109. */
  110. void render_keylogger_status(uint8_t col, uint8_t line) {
  111. #ifdef OLED_DISPLAY_VERBOSE
  112. oled_set_cursor(col, line);
  113. #endif
  114. oled_write_P(PSTR(OLED_RENDER_KEYLOGGER), false);
  115. oled_write(keylog_str, false);
  116. #ifdef OLED_DISPLAY_VERBOSE
  117. oled_advance_page(true);
  118. #endif
  119. }
  120. /**
  121. * @brief Renders default layer state (aka layout) to oled
  122. *
  123. */
  124. void render_default_layer_state(uint8_t col, uint8_t line) {
  125. #ifdef OLED_DISPLAY_VERBOSE
  126. oled_set_cursor(col, line);
  127. #endif
  128. oled_write_P(PSTR(OLED_RENDER_LAYOUT_NAME), false);
  129. switch (get_highest_layer(default_layer_state)) {
  130. case _QWERTY:
  131. oled_write_P(PSTR(OLED_RENDER_LAYOUT_QWERTY), false);
  132. break;
  133. case _COLEMAK_DH:
  134. oled_write_P(PSTR(OLED_RENDER_LAYOUT_COLEMAK_DH), false);
  135. break;
  136. case _COLEMAK:
  137. oled_write_P(PSTR(OLED_RENDER_LAYOUT_COLEMAK), false);
  138. break;
  139. case _DVORAK:
  140. oled_write_P(PSTR(OLED_RENDER_LAYOUT_DVORAK), false);
  141. break;
  142. }
  143. #ifdef OLED_DISPLAY_VERBOSE
  144. oled_advance_page(true);
  145. #endif
  146. }
  147. /**
  148. * @brief Renders the active layers to the OLED
  149. *
  150. */
  151. void render_layer_state(uint8_t col, uint8_t line) {
  152. #ifdef OLED_DISPLAY_VERBOSE
  153. // clang-format off
  154. static const char PROGMEM tri_layer_image[][3][24] = {
  155. // base
  156. {
  157. {
  158. 0x00, 0x00, 0x00, 0x80, 0x80, 0x40,
  159. 0x40, 0x20, 0x20, 0x10, 0x10, 0x08,
  160. 0x08, 0x10, 0x10, 0x20, 0x20, 0x40,
  161. 0x40, 0x80, 0x80, 0x00, 0x00, 0x00
  162. },
  163. {
  164. 0x00, 0x00, 0x00, 0x88, 0x88, 0x5D,
  165. 0x5D, 0x3E, 0x3E, 0x7C, 0x7C, 0xF8,
  166. 0xF8, 0x7C, 0x7C, 0x3E, 0x3E, 0x5D,
  167. 0x5D, 0x88, 0x88, 0x00, 0x00, 0x00
  168. },
  169. {
  170. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  171. 0x01, 0x02, 0x02, 0x04, 0x04, 0x08,
  172. 0x08, 0x04, 0x04, 0x02, 0x02, 0x01,
  173. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
  174. }
  175. },
  176. // raise
  177. {
  178. {
  179. 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0,
  180. 0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF8,
  181. 0xF8, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0,
  182. 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00
  183. },
  184. {
  185. 0x00, 0x00, 0x00, 0x88, 0x88, 0x55,
  186. 0x55, 0x23, 0x23, 0x47, 0x47, 0x8F,
  187. 0x8F, 0x47, 0x47, 0x23, 0x23, 0x55,
  188. 0x55, 0x88, 0x88, 0x00, 0x00, 0x00
  189. },
  190. {
  191. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  192. 0x01, 0x02, 0x02, 0x04, 0x04, 0x08,
  193. 0x08, 0x04, 0x04, 0x02, 0x02, 0x01,
  194. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
  195. }
  196. },
  197. // lower
  198. {
  199. {
  200. 0x00, 0x00, 0x00, 0x80, 0x80, 0x40,
  201. 0x40, 0x20, 0x20, 0x10, 0x10, 0x08,
  202. 0x08, 0x10, 0x10, 0x20, 0x20, 0x40,
  203. 0x40, 0x80, 0x80, 0x00, 0x00, 0x00
  204. },
  205. {
  206. 0x00, 0x00, 0x00, 0x88, 0x88, 0xD5,
  207. 0xD5, 0xE2, 0xE2, 0xC4, 0xC4, 0x88,
  208. 0x88, 0xC4, 0xC4, 0xE2, 0xE2, 0xD5,
  209. 0xD5, 0x88, 0x88, 0x00, 0x00, 0x00
  210. },
  211. {
  212. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  213. 0x01, 0x03, 0x03, 0x07, 0x07, 0x0F,
  214. 0x0F, 0x07, 0x07, 0x03, 0x03, 0x01,
  215. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
  216. }
  217. },
  218. // adjust
  219. {
  220. {
  221. 0x00, 0x00, 0x00, 0x80, 0x80, 0x40,
  222. 0xC0, 0x60, 0xA0, 0x50, 0xB0, 0x58,
  223. 0xA8, 0x50, 0xB0, 0x60, 0xA0, 0x40,
  224. 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00
  225. },
  226. {
  227. 0x00, 0x00, 0x00, 0x88, 0x88, 0x5D,
  228. 0xD5, 0x6B, 0xB6, 0x6D, 0xD6, 0xAD,
  229. 0xDA, 0x6D, 0xD6, 0x6B, 0xB6, 0x5D,
  230. 0xD5, 0x88, 0x88, 0x00, 0x00, 0x00
  231. },
  232. {
  233. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  234. 0x01, 0x03, 0x02, 0x05, 0x06, 0x0D,
  235. 0x0A, 0x05, 0x06, 0x03, 0x02, 0x01,
  236. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
  237. }
  238. },
  239. // blank
  240. {
  241. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  242. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  243. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  244. },
  245. // better gamepad
  246. {
  247. { 0, 0, 0,192,224,224,112,240,240,240,240,144,144,240,240,240,240,112,224,224,192, 0, 0, 0 },
  248. { 128,248,255,255,255,254,252,230,195,195,230,255,255,254,247,227,246,253,254,255,255,255,248,128 },
  249. { 7, 15, 15, 15, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 15, 15, 7 }
  250. },
  251. // mouse
  252. {
  253. { 0, 0, 0, 0, 0, 0, 0, 0,192, 32, 32, 32,160, 32, 32, 32,192, 0, 0, 0, 0, 0, 0, 0 },
  254. { 0, 0, 0, 0, 0, 0, 0,240, 15, 0, 0, 0, 3, 0, 0, 0, 15,240, 0, 0, 0, 0, 0, 0 },
  255. { 0, 0, 0, 0, 0, 0, 0, 3, 6, 4, 4, 4, 4, 4, 4, 4, 6, 3, 0, 0, 0, 0, 0, 0 }
  256. }
  257. };
  258. // clang-format on
  259. uint8_t layer_is[4] = {0, 4, 4, 4};
  260. if (layer_state_is(_ADJUST)) {
  261. layer_is[0] = 3;
  262. } else if (layer_state_is(_RAISE)) {
  263. layer_is[0] = 1;
  264. } else if (layer_state_is(_LOWER)) {
  265. layer_is[0] = 2;
  266. }
  267. if (layer_state_is(_MOUSE)) {
  268. layer_is[1] = 6;
  269. }
  270. if (layer_state_is(_GAMEPAD)) {
  271. layer_is[2] = 5;
  272. }
  273. oled_set_cursor(col, line);
  274. oled_write_raw_P(tri_layer_image[layer_is[0]][0], sizeof(tri_layer_image[0][0]));
  275. oled_set_cursor(col + 4, line);
  276. oled_write_raw_P(tri_layer_image[layer_is[1]][0], sizeof(tri_layer_image[0][0]));
  277. oled_set_cursor(col + 8, line);
  278. oled_write_raw_P(tri_layer_image[layer_is[2]][0], sizeof(tri_layer_image[0][0]));
  279. oled_set_cursor(col + 13, line);
  280. oled_write_P(PSTR("Diablo2"), layer_state_is(_DIABLOII));
  281. oled_advance_page(true);
  282. oled_set_cursor(col, line + 1);
  283. oled_write_raw_P(tri_layer_image[layer_is[0]][1], sizeof(tri_layer_image[0][0]));
  284. oled_set_cursor(col + 4, line + 1);
  285. oled_write_raw_P(tri_layer_image[layer_is[1]][1], sizeof(tri_layer_image[0][0]));
  286. oled_set_cursor(col + 8, line + 1);
  287. oled_write_raw_P(tri_layer_image[layer_is[2]][1], sizeof(tri_layer_image[0][0]));
  288. oled_set_cursor(col + 13, line + 1);
  289. oled_write_P(PSTR("Diablo3"), layer_state_is(_DIABLO));
  290. oled_advance_page(true);
  291. oled_set_cursor(col, line + 2);
  292. oled_write_raw_P(tri_layer_image[layer_is[0]][2], sizeof(tri_layer_image[0][0]));
  293. oled_set_cursor(col + 4, line + 2);
  294. oled_write_raw_P(tri_layer_image[layer_is[1]][2], sizeof(tri_layer_image[0][0]));
  295. oled_set_cursor(col + 8, line + 2);
  296. oled_write_raw_P(tri_layer_image[layer_is[2]][2], sizeof(tri_layer_image[0][0]));
  297. oled_set_cursor(col + 13, line + 2);
  298. oled_write_P(PSTR("Media"), layer_state_is(_MEDIA));
  299. #else
  300. oled_write_P(PSTR(OLED_RENDER_LAYER_NAME), false);
  301. oled_write_P(PSTR(OLED_RENDER_LAYER_LOWER), layer_state_is(_LOWER));
  302. oled_write_P(PSTR(OLED_RENDER_LAYER_RAISE), layer_state_is(_RAISE));
  303. #endif
  304. oled_advance_page(true);
  305. }
  306. /**
  307. * @brief Renders the current lock status to oled
  308. *
  309. * @param led_usb_state Current keyboard led state
  310. */
  311. void render_keylock_status(led_t led_usb_state, uint8_t col, uint8_t line) {
  312. #if defined(OLED_DISPLAY_VERBOSE)
  313. oled_set_cursor(col, line);
  314. #endif
  315. #ifdef CAPS_WORD_ENABLE
  316. led_usb_state.caps_lock |= is_caps_word_on();
  317. #endif
  318. oled_write_P(PSTR(OLED_RENDER_LOCK_NAME), false);
  319. #if !defined(OLED_DISPLAY_VERBOSE)
  320. oled_write_P(PSTR(" "), false);
  321. #endif
  322. oled_write_P(PSTR(OLED_RENDER_LOCK_NUML), led_usb_state.num_lock);
  323. oled_write_P(PSTR(" "), false);
  324. oled_write_P(PSTR(OLED_RENDER_LOCK_CAPS), led_usb_state.caps_lock);
  325. #if defined(OLED_DISPLAY_VERBOSE)
  326. oled_write_P(PSTR(" "), false);
  327. oled_write_P(PSTR(OLED_RENDER_LOCK_SCLK), led_usb_state.scroll_lock);
  328. #endif
  329. }
  330. /**
  331. * @brief Renders the matrix scan rate to the host system
  332. *
  333. */
  334. void render_matrix_scan_rate(uint8_t padding, uint8_t col, uint8_t line) {
  335. #ifdef DEBUG_MATRIX_SCAN_RATE
  336. oled_set_cursor(col, line);
  337. oled_write_P(PSTR("MS:"), false);
  338. if (padding) {
  339. for (uint8_t n = padding; n > 0; n--) {
  340. oled_write_P(PSTR(" "), false);
  341. }
  342. }
  343. oled_write(get_u16_str(get_matrix_scan_rate(), ' '), false);
  344. #endif
  345. }
  346. /**
  347. * @brief Renders the modifier state
  348. *
  349. * @param modifiers Modifiers to check against (real, weak, onesheot, etc;)
  350. */
  351. void render_mod_status(uint8_t modifiers, uint8_t col, uint8_t line) {
  352. static const char PROGMEM mod_status[5][3] = {{0xE8, 0xE9, 0}, {0xE4, 0xE5, 0}, {0xE6, 0xE7, 0}, {0xEA, 0xEB, 0}, {0xEC, 0xED, 0}};
  353. #if defined(OLED_DISPLAY_VERBOSE)
  354. oled_set_cursor(col, line);
  355. #endif
  356. oled_write_P(PSTR(OLED_RENDER_MODS_NAME), false);
  357. #if defined(OLED_DISPLAY_VERBOSE)
  358. oled_write_P(mod_status[0], (modifiers & MOD_BIT(KC_LSFT)));
  359. oled_write_P(mod_status[!keymap_config.swap_lctl_lgui ? 3 : 4], (modifiers & MOD_BIT(KC_LGUI)));
  360. oled_write_P(mod_status[2], (modifiers & MOD_BIT(KC_LALT)));
  361. oled_write_P(mod_status[1], (modifiers & MOD_BIT(KC_LCTL)));
  362. oled_write_P(mod_status[1], (modifiers & MOD_BIT(KC_RCTL)));
  363. oled_write_P(mod_status[2], (modifiers & MOD_BIT(KC_RALT)));
  364. oled_write_P(mod_status[!keymap_config.swap_lctl_lgui ? 3 : 4], (modifiers & MOD_BIT(KC_RGUI)));
  365. oled_write_P(mod_status[0], (modifiers & MOD_BIT(KC_RSFT)));
  366. #else
  367. oled_write_P(mod_status[0], (modifiers & MOD_MASK_SHIFT));
  368. oled_write_P(mod_status[!keymap_config.swap_lctl_lgui ? 3 : 4], (modifiers & MOD_MASK_GUI));
  369. oled_write_P(PSTR(" "), false);
  370. oled_write_P(mod_status[2], (modifiers & MOD_MASK_ALT));
  371. oled_write_P(mod_status[1], (modifiers & MOD_MASK_CTRL));
  372. #endif
  373. }
  374. #ifdef SWAP_HANDS_ENABLE
  375. extern bool swap_hands;
  376. #endif
  377. void render_bootmagic_status(uint8_t col, uint8_t line) {
  378. /* Show Ctrl-Gui Swap options */
  379. static const char PROGMEM logo[][2][3] = {
  380. {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
  381. {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
  382. };
  383. bool is_bootmagic_on;
  384. #ifdef OLED_DISPLAY_VERBOSE
  385. oled_set_cursor(col, line);
  386. // oled_set_cursor(7, 3);
  387. is_bootmagic_on = !keymap_config.swap_lctl_lgui;
  388. #else
  389. is_bootmagic_on = keymap_config.swap_lctl_lgui;
  390. #endif
  391. #ifdef OLED_DISPLAY_VERBOSE
  392. if (keymap_config.swap_lctl_lgui)
  393. #else
  394. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_NAME), false);
  395. oled_write_P(PSTR(" "), false);
  396. #endif
  397. {
  398. oled_write_P(logo[1][0], is_bootmagic_on);
  399. #ifdef OLED_DISPLAY_VERBOSE
  400. } else {
  401. #endif
  402. oled_write_P(logo[0][0], !is_bootmagic_on);
  403. }
  404. #ifndef OLED_DISPLAY_VERBOSE
  405. oled_write_P(PSTR(" "), false);
  406. oled_write_P(logo[1][1], is_bootmagic_on);
  407. oled_write_P(logo[0][1], !is_bootmagic_on);
  408. #endif
  409. oled_write_P(PSTR(" "), false);
  410. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_NKRO), keymap_config.nkro);
  411. oled_write_P(PSTR(" "), false);
  412. #if defined(AUTOCORRECT_ENABLE)
  413. oled_write_P(PSTR("CRCT"), autocorrect_is_enabled());
  414. oled_write_P(PSTR(" "), false);
  415. #else
  416. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_NOGUI), keymap_config.no_gui);
  417. #endif
  418. #ifdef OLED_DISPLAY_VERBOSE
  419. oled_set_cursor(col, line + 1);
  420. if (keymap_config.swap_lctl_lgui) {
  421. oled_write_P(logo[1][1], is_bootmagic_on);
  422. } else {
  423. oled_write_P(logo[0][1], !is_bootmagic_on);
  424. }
  425. #endif
  426. oled_write_P(PSTR(" "), false);
  427. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_ONESHOT), is_oneshot_enabled());
  428. #ifdef SWAP_HANDS_ENABLE
  429. oled_write_P(PSTR(" "), false);
  430. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_SWAP), swap_hands);
  431. oled_write_P(PSTR(" "), false);
  432. #endif
  433. }
  434. void render_user_status(uint8_t col, uint8_t line) {
  435. #ifdef AUDIO_ENABLE
  436. bool is_audio_on = false, l_is_clicky_on = false;
  437. # ifdef SPLIT_KEYBOARD
  438. is_audio_on = user_state.audio_enable;
  439. # ifdef AUDIO_CLICKY
  440. l_is_clicky_on = user_state.audio_clicky_enable;
  441. # endif
  442. # else
  443. is_audio_on = is_audio_on();
  444. # ifdef AUDIO_CLICKY
  445. l_is_clicky_on = is_clicky_on();
  446. # endif
  447. # endif
  448. #endif
  449. #if defined(OLED_DISPLAY_VERBOSE)
  450. oled_set_cursor(col, line);
  451. #endif
  452. oled_write_P(PSTR(OLED_RENDER_USER_NAME), false);
  453. #if !defined(OLED_DISPLAY_VERBOSE)
  454. oled_write_P(PSTR(" "), false);
  455. #endif
  456. #if defined(RGB_MATRIX_ENABLE)
  457. oled_write_P(PSTR(OLED_RENDER_USER_ANIM), userspace_config.rgb_matrix_idle_anim);
  458. # if !defined(OLED_DISPLAY_VERBOSE)
  459. oled_write_P(PSTR(" "), false);
  460. # endif
  461. #elif defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
  462. static const char PROGMEM mouse_lock[3] = {0xF2, 0xF3, 0};
  463. oled_write_P(mouse_lock, get_auto_mouse_toggle());
  464. #endif
  465. #ifdef AUDIO_ENABLE
  466. static const char PROGMEM audio_status[2][3] = {{0xE0, 0xE1, 0}, {0xE2, 0xE3, 0}};
  467. oled_write_P(audio_status[is_audio_on], false);
  468. # ifdef AUDIO_CLICKY
  469. static const char PROGMEM audio_clicky_status[2][3] = {{0xF4, 0xF5, 0}, {0xF6, 0xF7, 0}};
  470. oled_write_P(audio_clicky_status[l_is_clicky_on && is_audio_on], false);
  471. # if !defined(OLED_DISPLAY_VERBOSE)
  472. oled_write_P(PSTR(" "), false);
  473. # endif
  474. # endif
  475. #endif
  476. static const char PROGMEM rgb_layer_status[2][3] = {{0xEE, 0xEF, 0}, {0xF0, 0xF1, 0}};
  477. oled_write_P(rgb_layer_status[userspace_config.rgb_layer_change], false);
  478. static const char PROGMEM cat_mode[2][3] = {{0xF8, 0xF9, 0}, {0xF6, 0xF7, 0}};
  479. oled_write_P(cat_mode[0], host_driver_disabled);
  480. #if defined(UNICODE_COMMON_ENABLE)
  481. static const char PROGMEM uc_mod_status[5][3] = {{0xEC, 0xED, 0}, {0x20, 0x20, 0}, {0x20, 0x20, 0}, {0x20, 0x20, 0}, {0xEA, 0xEB, 0}};
  482. oled_write_P(uc_mod_status[get_unicode_input_mode()], false);
  483. #endif
  484. if (userspace_config.nuke_switch) {
  485. #if !defined(OLED_DISPLAY_VERBOSE)
  486. oled_write_P(PSTR(" "), false);
  487. #endif
  488. static const char PROGMEM nukem_good[2] = {0xFA, 0};
  489. oled_write_P(nukem_good, false);
  490. #if !defined(OLED_DISPLAY_VERBOSE)
  491. oled_advance_page(true);
  492. #endif
  493. }
  494. #if defined(OLED_DISPLAY_VERBOSE)
  495. oled_advance_page(true);
  496. #endif
  497. }
  498. void render_rgb_hsv(uint8_t col, uint8_t line) {
  499. oled_set_cursor(col, line);
  500. oled_write_P(PSTR("HSV: "), false);
  501. #ifdef RGB_MATRIX_ENABLE
  502. oled_write(get_u8_str(rgb_matrix_get_hue(), ' '), false);
  503. oled_write_P(PSTR(", "), false);
  504. oled_write(get_u8_str(rgb_matrix_get_sat(), ' '), false);
  505. oled_write_P(PSTR(", "), false);
  506. oled_write(get_u8_str(rgb_matrix_get_val(), ' '), false);
  507. #elif RGBLIGHT_ENABLE
  508. oled_write(get_u8_str(rgblight_get_hue(), ' '), false);
  509. oled_write_P(PSTR(", "), false);
  510. oled_write(get_u8_str(rgblight_get_sat(), ' '), false);
  511. oled_write_P(PSTR(", "), false);
  512. oled_write(get_u8_str(rgblight_get_val(), ' '), false);
  513. #endif
  514. }
  515. void render_wpm(uint8_t padding, uint8_t col, uint8_t line) {
  516. #ifdef WPM_ENABLE
  517. oled_set_cursor(col, line);
  518. oled_write_P(PSTR(OLED_RENDER_WPM_COUNTER), false);
  519. if (padding) {
  520. for (uint8_t n = padding; n > 0; n--) {
  521. oled_write_P(PSTR(" "), false);
  522. }
  523. }
  524. oled_write(get_u8_str(get_current_wpm(), ' '), false);
  525. #endif
  526. }
  527. //============= USER CONFIG PARAMS ===============
  528. // wpm graph originally designed by john-ezra
  529. // for 128x128:
  530. // max_lines_graph = 54;
  531. // vertical_offset = 64;
  532. // for 128x64:
  533. // max_lines_graph = 64;
  534. // vertical_offset = 0;
  535. void render_wpm_graph(uint8_t max_lines_graph, uint8_t vertical_offset) {
  536. #ifdef WPM_ENABLE
  537. static uint16_t timer = 0;
  538. static uint8_t x = OLED_DISPLAY_HEIGHT - 1;
  539. uint8_t currwpm = get_current_wpm();
  540. float max_wpm = OLED_WPM_GRAPH_MAX_WPM;
  541. if (timer_elapsed(timer) > OLED_WPM_GRAPH_REFRESH_INTERVAL) { // check if it's been long enough before refreshing graph
  542. x = (max_lines_graph - 1) - ((currwpm / max_wpm) * (max_lines_graph - 1)); // main calculation to plot graph line
  543. for (uint8_t i = 0; i <= OLED_WPM_GRAPH_GRAPH_LINE_THICKNESS - 1; i++) { // first draw actual value line
  544. oled_write_pixel(3, x + i + vertical_offset, true);
  545. }
  546. # ifdef OLED_WPM_GRAPH_VERTICAL_LINE
  547. static uint8_t vert_count = 0;
  548. if (vert_count == OLED_WPM_GRAPH_VERTCAL_LINE_INTERVAL) {
  549. vert_count = 0;
  550. while (x <= (max_lines_graph - 1)) {
  551. oled_write_pixel(3, x + vertical_offset, true);
  552. x++;
  553. }
  554. } else {
  555. for (uint8_t i = (max_lines_graph - 1); i > x; i--) {
  556. if (i % OLED_WPM_GRAPH_AREA_FILL_INTERVAL == 0) {
  557. oled_write_pixel(3, i + vertical_offset, true);
  558. }
  559. }
  560. vert_count++;
  561. }
  562. # else
  563. for (int i = (max_lines_graph - 1); i > x; i--) {
  564. if (i % OLED_WPM_GRAPH_AREA_FILL_INTERVAL == 0) {
  565. oled_write_pixel(3, i + vertical_offset, true);
  566. }
  567. }
  568. # endif
  569. # include <math.h>
  570. uint8_t y_start = ceil(vertical_offset / 8);
  571. uint8_t y_length = y_start + ceil(max_lines_graph / 8);
  572. oled_pan_section(false, y_start, y_length, 3, 125); // then move the entire graph one pixel to the right
  573. timer = timer_read(); // refresh the timer for the next iteration
  574. }
  575. #endif
  576. }
  577. #if defined(POINTING_DEVICE_ENABLE)
  578. void render_pointing_dpi_status(uint16_t cpi, uint8_t padding, uint8_t col, uint8_t line) {
  579. oled_set_cursor(col, line);
  580. oled_write_P(PSTR("CPI:"), false);
  581. if (padding) {
  582. for (uint8_t n = padding - 1; n > 0; n--) {
  583. oled_write_P(PSTR(" "), false);
  584. }
  585. }
  586. oled_write(get_u16_str(cpi, ' '), false);
  587. }
  588. #endif
  589. // WPM-responsive animation stuff here
  590. #define OLED_SLEEP_FRAMES 2
  591. #define OLED_SLEEP_SPEED 10 // below this wpm value your animation will idle
  592. #define OLED_WAKE_FRAMES 2 // uncomment if >1
  593. #define OLED_WAKE_SPEED OLED_SLEEP_SPEED // below this wpm value your animation will idle
  594. #define OLED_KAKI_FRAMES 3
  595. #define OLED_KAKI_SPEED 40 // above this wpm value typing animation to triggere
  596. #define OLED_RTOGI_FRAMES 2
  597. // #define OLED_LTOGI_FRAMES 2
  598. // #define ANIM_FRAME_DURATION 500 // how long each frame lasts in ms
  599. // #define SLEEP_TIMER 60000 // should sleep after this period of 0 wpm, needs fixing
  600. #define OLED_ANIM_SIZE 36
  601. #define OLED_ANIM_ROWS 4
  602. #define OLED_ANIM_MAX_FRAMES 3
  603. #if (OLED_SLEEP_FRAMES > OLED_ANIM_MAX_FRAMES) || (OLED_WAKE_FRAMES > OLED_ANIM_MAX_FRAMES) || (OLED_KAKI_FRAMES > OLED_ANIM_MAX_FRAMES) || (OLED_RTOGI_FRAMES > OLED_ANIM_MAX_FRAMES)
  604. # error frame size too large
  605. #endif
  606. static uint8_t animation_frame = 0;
  607. static uint8_t animation_type = 0;
  608. void render_kitty(uint8_t col, uint8_t line) {
  609. // Images credit j-inc(/James Incandenza) and pixelbenny.
  610. // Credit to obosob for initial animation approach.
  611. // heavily modified by drashna because he's a glutton for punishment
  612. // clang-format off
  613. static const char PROGMEM animation[4][OLED_ANIM_MAX_FRAMES][OLED_ANIM_ROWS][OLED_ANIM_SIZE] = {
  614. // sleep frames
  615. {
  616. {
  617. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0xa8, 0x48, 0xa8, 0x18, 0x08, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  618. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x80, 0x44, 0x84, 0x06, 0x05, 0x04, 0x80, 0x40, 0x20, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  619. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x18, 0x04, 0x04, 0x02, 0x7a, 0x86, 0x01, 0x80, 0x80, 0x01, 0x03, 0x05, 0x07, 0x01, 0x00, 0x00, 0x80, 0x83, 0x45, 0xfa, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  620. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x33, 0x24, 0x28, 0x28, 0x29, 0x29, 0x29, 0x3a, 0x18, 0x1c, 0x39, 0x24, 0x24, 0x3a, 0x2d, 0x26, 0x31, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00 }
  621. },
  622. {
  623. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  624. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x3a, 0x2a, 0x26, 0x22, 0x80, 0xc0, 0x80, 0x00, 0x24, 0x34, 0x2c, 0xe4, 0x60, 0x10, 0x70, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  625. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x38, 0x04, 0x02, 0x02, 0x01, 0x79, 0x87, 0x01, 0x80, 0x81, 0x83, 0x05, 0x05, 0x03, 0x01, 0x00, 0x00, 0x80, 0x43, 0x05, 0xfa, 0x3c, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  626. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x33, 0x24, 0x28, 0x28, 0x28, 0x29, 0x29, 0x3a, 0x18, 0x1c, 0x39, 0x24, 0x24, 0x3a, 0x2d, 0x26, 0x31, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00 }
  627. }
  628. },
  629. // wake frames
  630. {
  631. {
  632. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x30, 0x08, 0x10, 0x60, 0x80, 0x00, 0x80, 0x60, 0x10, 0x08, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  633. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x80, 0x40, 0x40, 0x5c, 0x00, 0x01, 0x41, 0x01, 0x00, 0x5c, 0x40, 0x40, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  634. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x80, 0xe1, 0x12, 0x0a, 0x06, 0x00, 0x80, 0x00, 0x06, 0x0a, 0x12, 0xe1, 0x80, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  635. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1f, 0x14, 0x14, 0x10, 0x10, 0x11, 0x1f, 0x10, 0x10, 0x18, 0x0f, 0x18, 0x10, 0x10, 0x1f, 0x11, 0x10, 0x10, 0x14, 0x14, 0x1f, 0x1c, 0x14, 0x14, 0x14, 0x08, 0x00, 0x00, 0x00, 0x00 }
  636. },
  637. {
  638. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x30, 0x08, 0x10, 0x60, 0x80, 0x00, 0x80, 0x60, 0x10, 0x08, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  639. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x90, 0x12, 0x0a, 0x02, 0xf4, 0x09, 0x0d, 0xf1, 0x04, 0x02, 0x0a, 0x12, 0x90, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  640. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x80, 0xe1, 0x12, 0x0a, 0x06, 0x01, 0x81, 0x00, 0x06, 0x0a, 0x12, 0xe1, 0x80, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  641. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1f, 0x14, 0x14, 0x10, 0x10, 0x11, 0x1f, 0x10, 0x10, 0x18, 0x0f, 0x18, 0x10, 0x10, 0x1f, 0x11, 0x10, 0x10, 0x14, 0x14, 0x1f, 0x1c, 0x14, 0x14, 0x14, 0x08, 0x00, 0x00, 0x00, 0x00 }
  642. }
  643. },
  644. // kaki frames
  645. {
  646. {
  647. { 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x40, 0x40, 0x80, 0x80, 0x80, 0x00, 0xfc, 0x84, 0x08, 0x08, 0x10, 0x20, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  648. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x1e, 0x60, 0x80, 0x00, 0x00, 0x91, 0xa1, 0x80, 0x00, 0x00, 0x22, 0x84, 0x40, 0x50, 0x48, 0xc1, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  649. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x41, 0x82, 0xe2, 0x12, 0x0a, 0x06, 0x00, 0x80, 0x88, 0x4f, 0x02, 0x22, 0xe2, 0x9f, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  650. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1f, 0x14, 0x14, 0x10, 0x10, 0x11, 0x1f, 0x10, 0x10, 0x18, 0x0f, 0x18, 0x14, 0x10, 0x10, 0x10, 0x10, 0x10, 0x14, 0x14, 0x1f, 0x1a, 0x0a, 0x0a, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 }
  651. },
  652. {
  653. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  654. { 0x00, 0x00, 0x06, 0x1a, 0x22, 0xc2, 0x04, 0x04, 0x04, 0x07, 0x00, 0xc0, 0x20, 0x10, 0x80, 0x80, 0x01, 0x01, 0x02, 0xfc, 0xfe, 0x02, 0x3c, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  655. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0d, 0x8d, 0x55, 0x50, 0x94, 0xf0, 0x10, 0x09, 0x08, 0x00, 0x80, 0x00, 0x06, 0x09, 0x1b, 0xee, 0x00, 0x00, 0x00, 0x00, 0x81, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  656. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1f, 0x14, 0x14, 0x10, 0x10, 0x11, 0x1f, 0x10, 0x10, 0x18, 0x0f, 0x18, 0x10, 0x10, 0x1f, 0x19, 0x18, 0x1c, 0x14, 0x16, 0x15, 0x14, 0x14, 0x14, 0x14, 0x08, 0x00, 0x00, 0x00, 0x00 }
  657. },
  658. {
  659. { 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  660. { 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x01, 0x02, 0x04, 0x04, 0x03, 0x80, 0x40, 0x40, 0x20, 0x00, 0x01, 0x02, 0x8c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  661. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0d, 0x8d, 0x55, 0x50, 0x94, 0xf0, 0x10, 0x0a, 0x0e, 0x1d, 0x95, 0x24, 0x24, 0x27, 0x13, 0xe1, 0x01, 0x01, 0x01, 0x01, 0x02, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  662. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x1f, 0x14, 0x14, 0x10, 0x10, 0x11, 0x1f, 0x10, 0x10, 0x18, 0x0f, 0x18, 0x10, 0x10, 0x1f, 0x19, 0x18, 0x1c, 0x14, 0x14, 0x17, 0x14, 0x14, 0x14, 0x14, 0x08, 0x00, 0x00, 0x00, 0x00 }
  663. }
  664. },
  665. // rtogi frames
  666. {
  667. {
  668. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x0f, 0x90, 0x10, 0x20, 0xf0, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00 },
  669. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x48, 0x47, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x88, 0xc7, 0xc4, 0x62, 0x23, 0x11, 0x3f, 0x00, 0x00, 0x00, 0x00 },
  670. { 0x80, 0x40, 0x20, 0x10, 0x88, 0xcc, 0x43, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xc0, 0x80, 0x80, 0xc0, 0xe1, 0xfe, 0xb8, 0x88, 0x0c, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
  671. { 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x06, 0x04, 0x04, 0x04, 0x04, 0x05, 0x04, 0x04, 0x04, 0x07, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
  672. },
  673. {
  674. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x1f, 0xa0, 0x20, 0x40, 0x80, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00 },
  675. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x48, 0x47, 0x88, 0x00, 0x00, 0x00, 0x00, 0x24, 0x24, 0x28, 0x6b, 0x40, 0xa0, 0x99, 0x86, 0xff, 0x00, 0x00, 0x00, 0x00 },
  676. { 0x0f, 0x11, 0x22, 0x44, 0x48, 0x4c, 0x43, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xc0, 0x80, 0x80, 0xc0, 0xe1, 0xfe, 0xb8, 0x88, 0x0c, 0x04, 0x06, 0x06, 0x06, 0x0e, 0x0e, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00 },
  677. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x06, 0x04, 0x04, 0x04, 0x04, 0x05, 0x04, 0x04, 0x04, 0x07, 0x07, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
  678. }
  679. }
  680. };
  681. // clang-format on
  682. for (uint8_t i = 0; i < 4; i++) {
  683. oled_set_cursor(col, line + i);
  684. oled_write_raw_P(animation[animation_type][animation_frame][i], OLED_ANIM_SIZE);
  685. }
  686. }
  687. void render_unicode_mode(uint8_t col, uint8_t line) {
  688. #if defined(CUSTOM_UNICODE_ENABLE) && defined(UNICODE_COMMON_ENABLE)
  689. oled_set_cursor(col, line);
  690. oled_write_P(PSTR("Unicode:"), false);
  691. oled_write_P(unicode_mode_str[unicode_typing_mode], false);
  692. #endif
  693. }
  694. uint32_t kitty_animation_phases(uint32_t triger_time, void *cb_arg) {
  695. static uint32_t anim_frame_duration = 500;
  696. #if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
  697. if (get_auto_mouse_toggle()) {
  698. animation_frame = (animation_frame + 1) % OLED_RTOGI_FRAMES;
  699. animation_type = 3;
  700. anim_frame_duration = 300;
  701. } else
  702. #endif
  703. {
  704. #ifdef WPM_ENABLE
  705. if (get_current_wpm() <= OLED_SLEEP_SPEED) {
  706. #endif
  707. animation_frame = (animation_frame + 1) % OLED_SLEEP_FRAMES;
  708. animation_type = 0;
  709. anim_frame_duration = 500;
  710. #ifdef WPM_ENABLE
  711. } else if (get_current_wpm() > OLED_WAKE_SPEED) {
  712. animation_frame = (animation_frame + 1) % OLED_WAKE_FRAMES;
  713. animation_type = 1;
  714. anim_frame_duration = 800;
  715. } else if (get_current_wpm() >= OLED_KAKI_SPEED) {
  716. animation_frame = (animation_frame + 1) % OLED_KAKI_FRAMES;
  717. animation_type = 2;
  718. anim_frame_duration = 500;
  719. }
  720. #endif
  721. }
  722. return anim_frame_duration;
  723. }
  724. void render_mouse_mode(uint8_t col, uint8_t line) {
  725. #if (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && defined(POINTING_DEVICE_ENABLE)
  726. // credit and thanks to jaspertandy on discord for these images
  727. static const char PROGMEM mouse_logo[3][2][16] = {// mouse icon
  728. {{0, 0, 0, 252, 2, 2, 2, 58, 2, 2, 2, 252, 0, 0, 0, 0}, {0, 0, 63, 96, 64, 64, 64, 64, 64, 64, 64, 96, 63, 0, 0, 0}},
  729. // crosshair icon
  730. {{128, 240, 136, 228, 146, 138, 202, 127, 202, 138, 146, 228, 136, 240, 128, 0}, {0, 7, 8, 19, 36, 40, 41, 127, 41, 40, 36, 19, 8, 7, 0, 0}},
  731. // dragscroll icon
  732. {{0, 0, 112, 136, 156, 2, 15, 1, 15, 2, 140, 68, 56, 0, 0, 0}, {0, 0, 2, 6, 15, 28, 60, 124, 60, 28, 15, 6, 2, 0, 0, 0}}};
  733. uint8_t image_index = 0;
  734. # ifdef OLED_DISPLAY_TEST
  735. image_index = animation_frame;
  736. # else
  737. if (charybdis_get_pointer_sniping_enabled()) {
  738. image_index = 1;
  739. } else if (charybdis_get_pointer_dragscroll_enabled()) {
  740. image_index = 2;
  741. }
  742. # endif
  743. oled_set_cursor(col, line);
  744. oled_write_raw_P(mouse_logo[image_index][0], 16);
  745. oled_set_cursor(col, line + 1);
  746. oled_write_raw_P(mouse_logo[image_index][1], 16);
  747. #endif
  748. }
  749. void render_status_right(void) {
  750. #if defined(OLED_DISPLAY_VERBOSE)
  751. render_default_layer_state(1, 1);
  752. #else
  753. render_default_layer_state(0, 0);
  754. #endif
  755. /* Show Keyboard Layout */
  756. render_layer_state(1, 2);
  757. render_mod_status(get_mods() | get_oneshot_mods(), 1, 5);
  758. #if !defined(OLED_DISPLAY_VERBOSE) && defined(WPM_ENABLE) && !defined(STM32F303xC)
  759. render_wpm(2, 7, 1);
  760. #endif
  761. render_keylock_status(host_keyboard_led_state(), 1, 6);
  762. }
  763. void render_status_left(void) {
  764. #if defined(OLED_DISPLAY_VERBOSE)
  765. render_kitty(0, 1);
  766. # if defined(WPM_ENABLE)
  767. render_wpm(1, 7, 1);
  768. # elif defined(DEBUG_MATRIX_SCAN_RATE)
  769. render_matrix_scan_rate(1, 7, 1);
  770. # endif
  771. # if (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && defined(POINTING_DEVICE_ENABLE)
  772. render_pointing_dpi_status(charybdis_get_pointer_sniping_enabled() ? charybdis_get_pointer_sniping_dpi() : charybdis_get_pointer_default_dpi(), 1, 7, 2);
  773. render_mouse_mode(17, 1);
  774. # elif defined(WPM_ENABLE) && defined(DEBUG_MATRIX_SCAN_RATE)
  775. render_matrix_scan_rate(1, 7, 2);
  776. # endif
  777. /* Show Keyboard Layout */
  778. render_bootmagic_status(7, 3);
  779. render_user_status(1, 5);
  780. render_keylogger_status(1, 6);
  781. #else
  782. render_default_layer_state(0, 0);
  783. /* Show Keyboard Layout */
  784. render_bootmagic_status(7, 3);
  785. render_user_status(1, 5);
  786. render_keylogger_status(1, 6);
  787. #endif
  788. }
  789. __attribute__((weak)) void oled_render_large_display(bool side) {
  790. if (!side) {
  791. render_unicode_mode(1, 14);
  792. }
  793. }
  794. __attribute__((weak)) void render_oled_title(bool side) {
  795. oled_write_P(side ? PSTR(" Left ") : PSTR(" Right "), true);
  796. // oled_write_P(PSTR( "1234567890123" "1234567890123"), true);
  797. }
  798. __attribute__((weak)) oled_rotation_t oled_init_keymap(oled_rotation_t rotation) {
  799. return rotation;
  800. }
  801. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  802. if (is_keyboard_master()) {
  803. memset(keylog_str, ' ', OLED_KEYLOGGER_LENGTH);
  804. }
  805. kittoken = defer_exec(3000, kitty_animation_phases, NULL);
  806. oled_clear();
  807. oled_render();
  808. return oled_init_keymap(rotation);
  809. }
  810. __attribute__((weak)) bool oled_task_keymap(void) {
  811. return true;
  812. }
  813. bool oled_task_user(void) {
  814. #ifndef OLED_DISPLAY_TEST
  815. if (!is_oled_enabled) {
  816. oled_off();
  817. return false;
  818. } else
  819. #endif
  820. {
  821. oled_on();
  822. }
  823. if (!oled_task_keymap()) {
  824. return false;
  825. }
  826. #if defined(OLED_DISPLAY_VERBOSE)
  827. static const char PROGMEM header_image[] = {
  828. 0, 192, 32, 16, 8, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 7, 15, 31, 63, 127, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 63, 31, 15, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 8, 16, 32, 192, 0,
  829. // 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 7, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 7, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0
  830. };
  831. oled_write_raw_P(header_image, sizeof(header_image));
  832. oled_set_cursor(4, 0);
  833. render_oled_title(is_keyboard_left());
  834. #endif
  835. #ifndef OLED_DISPLAY_TEST
  836. if (is_keyboard_left()) {
  837. #endif
  838. render_status_left();
  839. #if defined(OLED_DISPLAY_128X128)
  840. oled_render_large_display(true);
  841. #endif
  842. #ifndef OLED_DISPLAY_TEST
  843. } else {
  844. render_status_right();
  845. # if defined(OLED_DISPLAY_128X128)
  846. oled_render_large_display(false);
  847. # endif
  848. }
  849. #endif
  850. #if defined(OLED_DISPLAY_VERBOSE)
  851. uint8_t num_of_rows;
  852. # if defined(OLED_DISPLAY_128X128)
  853. num_of_rows = 15;
  854. # else
  855. num_of_rows = 7;
  856. # endif
  857. for (uint8_t i = 1; i < num_of_rows; i++) {
  858. oled_set_cursor(0, i);
  859. oled_write_raw_P(display_border, sizeof(display_border));
  860. oled_set_cursor(21, i);
  861. oled_write_raw_P(display_border, sizeof(display_border));
  862. }
  863. static const char PROGMEM footer_image[] = {0, 3, 4, 8, 16, 32, 64, 128, 128, 128, 128, 128, 128, 128, 192, 224, 240, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 240, 224, 192, 128, 128, 128, 128, 128, 128, 128, 64, 32, 16, 8, 4, 3, 0};
  864. oled_set_cursor(0, num_of_rows);
  865. oled_write_raw_P(footer_image, sizeof(footer_image));
  866. #endif
  867. return false;
  868. }
  869. extern bool oled_initialized;
  870. __attribute__((weak)) void housekeeping_task_oled(void) {
  871. is_oled_enabled = is_oled_locked ? true : !(timer_elapsed32(oled_timer) > 60000);
  872. }