oled_stuff.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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. #if defined(AUTOCORRECTION_ENABLE)
  26. # include "keyrecords/autocorrection/autocorrection.h"
  27. #endif
  28. #include <string.h>
  29. bool is_oled_enabled = true;
  30. extern bool host_driver_disabled;
  31. uint32_t oled_timer = 0;
  32. char keylog_str[OLED_KEYLOGGER_LENGTH] = {0};
  33. static uint16_t log_timer = 0;
  34. #ifdef OLED_DISPLAY_VERBOSE
  35. const char PROGMEM display_border[3] = {0x0, 0xFF, 0x0};
  36. #endif
  37. deferred_token kittoken;
  38. // clang-format off
  39. static const char PROGMEM code_to_name[256] = {
  40. // 0 1 2 3 4 5 6 7 8 9 A B c D E F
  41. ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', // 0x
  42. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', // 1x
  43. '3', '4', '5', '6', '7', '8', '9', '0', 20, 19, 27, 26, 22, '-', '=', '[', // 2x
  44. ']','\\', '#', ';','\'', '`', ',', '.', '/', 128,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA, // 3x
  45. 0xDB,0xDC,0xDD,0xDE,0XDF,0xFB,'P', 'S', 19, ' ', 17, 30, 16, 16, 31, 26, // 4x
  46. 27, 25, 24, 'N', '/', '*', '-', '+', 23, '1', '2', '3', '4', '5', '6', '7', // 5x
  47. '8', '9', '0', '.','\\', 'A', 0, '=', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 6x
  48. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 7x
  49. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 8x
  50. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 9x
  51. ' ', ' ', ' ', ' ', ' ', 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Ax
  52. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Bx
  53. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Cx
  54. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // Dx
  55. 'C', 'S', 'A', 'C', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 24, 26, 24, // Ex
  56. 25,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D, 24, 25, 27, 26, ' ', ' ', ' ' // Fx
  57. };
  58. // clang-format on
  59. /**
  60. * @brief parses pressed keycodes and saves to buffer
  61. *
  62. * @param keycode Keycode pressed from switch matrix
  63. * @param record keyrecord_t data structure
  64. */
  65. void add_keylog(uint16_t keycode, keyrecord_t *record) {
  66. if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX) || (keycode >= QK_MODS && keycode <= QK_MODS_MAX)) {
  67. if (((keycode & 0xFF) == KC_BSPC) && mod_config(get_mods() | get_oneshot_mods()) & MOD_MASK_CTRL) {
  68. memset(keylog_str, ' ', OLED_KEYLOGGER_LENGTH);
  69. return;
  70. }
  71. if (record->tap.count) {
  72. keycode &= 0xFF;
  73. } else if (keycode > 0xFF) {
  74. return;
  75. }
  76. }
  77. if (keycode > 0xFF) {
  78. return;
  79. }
  80. memmove(keylog_str, keylog_str + 1, OLED_KEYLOGGER_LENGTH - 1);
  81. if (keycode < (sizeof(code_to_name) / sizeof(char))) {
  82. keylog_str[(OLED_KEYLOGGER_LENGTH - 1)] = 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_LSHIFT)));
  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_RSHIFT)));
  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(logo[1][1], is_bootmagic_on);
  406. oled_write_P(logo[0][1], !is_bootmagic_on);
  407. #endif
  408. oled_write_P(PSTR(" "), false);
  409. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_NKRO), keymap_config.nkro);
  410. oled_write_P(PSTR(" "), false);
  411. #if defined(AUTOCORRECTION_ENABLE) || defined(AUTOCORRECT_ENABLE)
  412. oled_write_P(PSTR("CRCT"), autocorrect_is_enabled());
  413. oled_write_P(PSTR(" "), false);
  414. #else
  415. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_NOGUI), keymap_config.no_gui);
  416. #endif
  417. #ifdef OLED_DISPLAY_VERBOSE
  418. oled_set_cursor(col, line + 1);
  419. if (keymap_config.swap_lctl_lgui) {
  420. oled_write_P(logo[1][1], is_bootmagic_on);
  421. } else {
  422. oled_write_P(logo[0][1], !is_bootmagic_on);
  423. }
  424. #endif
  425. oled_write_P(PSTR(" "), false);
  426. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_ONESHOT), is_oneshot_enabled());
  427. #ifdef SWAP_HANDS_ENABLE
  428. oled_write_P(PSTR(" "), false);
  429. oled_write_P(PSTR(OLED_RENDER_BOOTMAGIC_SWAP), swap_hands);
  430. oled_write_P(PSTR(" "), false);
  431. #endif
  432. }
  433. #if defined(CUSTOM_POINTING_DEVICE)
  434. extern bool tap_toggling;
  435. #endif
  436. void render_user_status(uint8_t col, uint8_t line) {
  437. #ifdef AUDIO_ENABLE
  438. bool is_audio_on = false, l_is_clicky_on = false;
  439. # ifdef SPLIT_KEYBOARD
  440. is_audio_on = user_state.audio_enable;
  441. # ifdef AUDIO_CLICKY
  442. l_is_clicky_on = user_state.audio_clicky_enable;
  443. # endif
  444. # else
  445. is_audio_on = is_audio_on();
  446. # ifdef AUDIO_CLICKY
  447. l_is_clicky_on = is_clicky_on();
  448. # endif
  449. # endif
  450. #endif
  451. #if defined(OLED_DISPLAY_VERBOSE)
  452. oled_set_cursor(col, line);
  453. #endif
  454. oled_write_P(PSTR(OLED_RENDER_USER_NAME), false);
  455. #if !defined(OLED_DISPLAY_VERBOSE)
  456. oled_write_P(PSTR(" "), false);
  457. #endif
  458. #if defined(RGB_MATRIX_ENABLE)
  459. oled_write_P(PSTR(OLED_RENDER_USER_ANIM), userspace_config.rgb_matrix_idle_anim);
  460. # if !defined(OLED_DISPLAY_VERBOSE)
  461. oled_write_P(PSTR(" "), false);
  462. # endif
  463. #elif defined(CUSTOM_POINTING_DEVICE)
  464. static const char PROGMEM mouse_lock[3] = {0xF2, 0xF3, 0};
  465. oled_write_P(mouse_lock, tap_toggling);
  466. #endif
  467. #ifdef AUDIO_ENABLE
  468. static const char PROGMEM audio_status[2][3] = {{0xE0, 0xE1, 0}, {0xE2, 0xE3, 0}};
  469. oled_write_P(audio_status[is_audio_on], false);
  470. # ifdef AUDIO_CLICKY
  471. static const char PROGMEM audio_clicky_status[2][3] = {{0xF4, 0xF5, 0}, {0xF6, 0xF7, 0}};
  472. oled_write_P(audio_clicky_status[l_is_clicky_on && is_audio_on], false);
  473. # if !defined(OLED_DISPLAY_VERBOSE)
  474. oled_write_P(PSTR(" "), false);
  475. # endif
  476. # endif
  477. #endif
  478. static const char PROGMEM rgb_layer_status[2][3] = {{0xEE, 0xEF, 0}, {0xF0, 0xF1, 0}};
  479. oled_write_P(rgb_layer_status[userspace_config.rgb_layer_change], false);
  480. static const char PROGMEM cat_mode[2][3] = {{0xF8, 0xF9, 0}, {0xF6, 0xF7, 0}};
  481. oled_write_P(cat_mode[0], host_driver_disabled);
  482. #if defined(UNICODE_COMMON_ENABLE)
  483. static const char PROGMEM uc_mod_status[5][3] = {{0xEC, 0xED, 0}, {0x20, 0x20, 0}, {0x20, 0x20, 0}, {0x20, 0x20, 0}, {0xEA, 0xEB, 0}};
  484. oled_write_P(uc_mod_status[get_unicode_input_mode()], false);
  485. #endif
  486. if (userspace_config.nuke_switch) {
  487. #if !defined(OLED_DISPLAY_VERBOSE)
  488. oled_write_P(PSTR(" "), false);
  489. #endif
  490. static const char PROGMEM nukem_good[2] = {0xFA, 0};
  491. oled_write_P(nukem_good, false);
  492. #if !defined(OLED_DISPLAY_VERBOSE)
  493. oled_advance_page(true);
  494. #endif
  495. }
  496. #if defined(OLED_DISPLAY_VERBOSE)
  497. oled_advance_page(true);
  498. #endif
  499. }
  500. void render_rgb_hsv(uint8_t col, uint8_t line) {
  501. oled_set_cursor(col, line);
  502. oled_write_P(PSTR("HSV: "), false);
  503. #ifdef RGB_MATRIX_ENABLE
  504. oled_write(get_u8_str(rgb_matrix_get_hue(), ' '), false);
  505. oled_write_P(PSTR(", "), false);
  506. oled_write(get_u8_str(rgb_matrix_get_sat(), ' '), false);
  507. oled_write_P(PSTR(", "), false);
  508. oled_write(get_u8_str(rgb_matrix_get_val(), ' '), false);
  509. #elif RGBLIGHT_ENABLE
  510. oled_write(get_u8_str(rgblight_get_hue(), ' '), false);
  511. oled_write_P(PSTR(", "), false);
  512. oled_write(get_u8_str(rgblight_get_sat(), ' '), false);
  513. oled_write_P(PSTR(", "), false);
  514. oled_write(get_u8_str(rgblight_get_val(), ' '), false);
  515. #endif
  516. }
  517. void render_wpm(uint8_t padding, uint8_t col, uint8_t line) {
  518. #ifdef WPM_ENABLE
  519. oled_set_cursor(col, line);
  520. oled_write_P(PSTR(OLED_RENDER_WPM_COUNTER), false);
  521. if (padding) {
  522. for (uint8_t n = padding; n > 0; n--) {
  523. oled_write_P(PSTR(" "), false);
  524. }
  525. }
  526. oled_write(get_u8_str(get_current_wpm(), ' '), false);
  527. #endif
  528. }
  529. //============= USER CONFIG PARAMS ===============
  530. // wpm graph originally designed by john-ezra
  531. // for 128x128:
  532. // max_lines_graph = 54;
  533. // vertical_offset = 64;
  534. // for 128x64:
  535. // max_lines_graph = 64;
  536. // vertical_offset = 0;
  537. void render_wpm_graph(uint8_t max_lines_graph, uint8_t vertical_offset) {
  538. #ifdef WPM_ENABLE
  539. static uint16_t timer = 0;
  540. static uint8_t x = OLED_DISPLAY_HEIGHT - 1;
  541. uint8_t currwpm = get_current_wpm();
  542. float max_wpm = OLED_WPM_GRAPH_MAX_WPM;
  543. if (timer_elapsed(timer) > OLED_WPM_GRAPH_REFRESH_INTERVAL) { // check if it's been long enough before refreshing graph
  544. x = (max_lines_graph - 1) - ((currwpm / max_wpm) * (max_lines_graph - 1)); // main calculation to plot graph line
  545. for (uint8_t i = 0; i <= OLED_WPM_GRAPH_GRAPH_LINE_THICKNESS - 1; i++) { // first draw actual value line
  546. oled_write_pixel(3, x + i + vertical_offset, true);
  547. }
  548. # ifdef OLED_WPM_GRAPH_VERTICAL_LINE
  549. static uint8_t vert_count = 0;
  550. if (vert_count == OLED_WPM_GRAPH_VERTCAL_LINE_INTERVAL) {
  551. vert_count = 0;
  552. while (x <= (max_lines_graph - 1)) {
  553. oled_write_pixel(3, x + vertical_offset, true);
  554. x++;
  555. }
  556. } else {
  557. for (uint8_t i = (max_lines_graph - 1); i > x; i--) {
  558. if (i % OLED_WPM_GRAPH_AREA_FILL_INTERVAL == 0) {
  559. oled_write_pixel(3, i + vertical_offset, true);
  560. }
  561. }
  562. vert_count++;
  563. }
  564. # else
  565. for (int i = (max_lines_graph - 1); i > x; i--) {
  566. if (i % OLED_WPM_GRAPH_AREA_FILL_INTERVAL == 0) {
  567. oled_write_pixel(3, i + vertical_offset, true);
  568. }
  569. }
  570. # endif
  571. # include <math.h>
  572. uint8_t y_start = ceil(vertical_offset / 8);
  573. uint8_t y_length = y_start + ceil(max_lines_graph / 8);
  574. oled_pan_section(false, y_start, y_length, 3, 125); // then move the entire graph one pixel to the right
  575. timer = timer_read(); // refresh the timer for the next iteration
  576. }
  577. #endif
  578. }
  579. #if defined(POINTING_DEVICE_ENABLE)
  580. void render_pointing_dpi_status(uint16_t cpi, uint8_t padding, uint8_t col, uint8_t line) {
  581. oled_set_cursor(col, line);
  582. oled_write_P(PSTR("CPI:"), false);
  583. if (padding) {
  584. for (uint8_t n = padding - 1; n > 0; n--) {
  585. oled_write_P(PSTR(" "), false);
  586. }
  587. }
  588. oled_write(get_u16_str(cpi, ' '), false);
  589. }
  590. #endif
  591. // WPM-responsive animation stuff here
  592. #define OLED_SLEEP_FRAMES 2
  593. #define OLED_SLEEP_SPEED 10 // below this wpm value your animation will idle
  594. #define OLED_WAKE_FRAMES 2 // uncomment if >1
  595. #define OLED_WAKE_SPEED OLED_SLEEP_SPEED // below this wpm value your animation will idle
  596. #define OLED_KAKI_FRAMES 3
  597. #define OLED_KAKI_SPEED 40 // above this wpm value typing animation to triggere
  598. #define OLED_RTOGI_FRAMES 2
  599. //#define OLED_LTOGI_FRAMES 2
  600. //#define ANIM_FRAME_DURATION 500 // how long each frame lasts in ms
  601. // #define SLEEP_TIMER 60000 // should sleep after this period of 0 wpm, needs fixing
  602. #define OLED_ANIM_SIZE 36
  603. #define OLED_ANIM_ROWS 4
  604. #define OLED_ANIM_MAX_FRAMES 3
  605. #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)
  606. # error frame size too large
  607. #endif
  608. static uint8_t animation_frame = 0;
  609. static uint8_t animation_type = 0;
  610. void render_kitty(uint8_t col, uint8_t line) {
  611. // Images credit j-inc(/James Incandenza) and pixelbenny.
  612. // Credit to obosob for initial animation approach.
  613. // heavily modified by drashna because he's a glutton for punishment
  614. // clang-format off
  615. static const char PROGMEM animation[4][OLED_ANIM_MAX_FRAMES][OLED_ANIM_ROWS][OLED_ANIM_SIZE] = {
  616. // sleep frames
  617. {
  618. {
  619. { 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 },
  620. { 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 },
  621. { 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 },
  622. { 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 }
  623. },
  624. {
  625. { 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 },
  626. { 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 },
  627. { 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 },
  628. { 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 }
  629. }
  630. },
  631. // wake frames
  632. {
  633. {
  634. { 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 },
  635. { 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 },
  636. { 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 },
  637. { 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 }
  638. },
  639. {
  640. { 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 },
  641. { 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 },
  642. { 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 },
  643. { 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 }
  644. }
  645. },
  646. // kaki frames
  647. {
  648. {
  649. { 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 },
  650. { 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 },
  651. { 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 },
  652. { 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 }
  653. },
  654. {
  655. { 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 },
  656. { 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 },
  657. { 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 },
  658. { 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 }
  659. },
  660. {
  661. { 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 },
  662. { 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 },
  663. { 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 },
  664. { 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 }
  665. }
  666. },
  667. // rtogi frames
  668. {
  669. {
  670. { 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 },
  671. { 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 },
  672. { 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 },
  673. { 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 }
  674. },
  675. {
  676. { 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 },
  677. { 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 },
  678. { 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 },
  679. { 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 }
  680. }
  681. }
  682. };
  683. // clang-format on
  684. for (uint8_t i = 0; i < 4; i++) {
  685. oled_set_cursor(col, line + i);
  686. oled_write_raw_P(animation[animation_type][animation_frame][i], OLED_ANIM_SIZE);
  687. }
  688. }
  689. void render_unicode_mode(uint8_t col, uint8_t line) {
  690. #ifdef CUSTOM_UNICODE_ENABLE
  691. oled_set_cursor(col, line);
  692. oled_write_ln_P(PSTR("Unicode:"), false);
  693. switch (typing_mode) {
  694. case UCTM_WIDE:
  695. oled_write_P(PSTR(" Wide"), false);
  696. break;
  697. case UCTM_SCRIPT:
  698. oled_write_P(PSTR(" Script"), false);
  699. break;
  700. case UCTM_BLOCKS:
  701. oled_write_P(PSTR(" Blocks"), false);
  702. break;
  703. case UCTM_REGIONAL:
  704. oled_write_P(PSTR(" Regional"), false);
  705. break;
  706. case UCTM_AUSSIE:
  707. oled_write_P(PSTR(" Aussie"), false);
  708. break;
  709. case UCTM_ZALGO:
  710. oled_write_P(PSTR(" Zalgo"), false);
  711. break;
  712. case UCTM_NO_MODE:
  713. oled_write_P(PSTR(" Normal"), false);
  714. break;
  715. default:
  716. oled_write_P(PSTR(" Unknown"), false);
  717. break;
  718. }
  719. #endif
  720. }
  721. uint32_t kitty_animation_phases(uint32_t triger_time, void *cb_arg) {
  722. static uint32_t anim_frame_duration = 500;
  723. #ifdef CUSTOM_POINTING_DEVICE
  724. if (tap_toggling) {
  725. animation_frame = (animation_frame + 1) % OLED_RTOGI_FRAMES;
  726. animation_type = 3;
  727. anim_frame_duration = 300;
  728. } else
  729. #endif
  730. {
  731. #ifdef WPM_ENABLE
  732. if (get_current_wpm() <= OLED_SLEEP_SPEED) {
  733. #endif
  734. animation_frame = (animation_frame + 1) % OLED_SLEEP_FRAMES;
  735. animation_type = 0;
  736. anim_frame_duration = 500;
  737. #ifdef WPM_ENABLE
  738. } else if (get_current_wpm() > OLED_WAKE_SPEED) {
  739. animation_frame = (animation_frame + 1) % OLED_WAKE_FRAMES;
  740. animation_type = 1;
  741. anim_frame_duration = 800;
  742. } else if (get_current_wpm() >= OLED_KAKI_SPEED) {
  743. animation_frame = (animation_frame + 1) % OLED_KAKI_FRAMES;
  744. animation_type = 2;
  745. anim_frame_duration = 500;
  746. }
  747. #endif
  748. }
  749. return anim_frame_duration;
  750. }
  751. void render_mouse_mode(uint8_t col, uint8_t line) {
  752. #if (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && defined(POINTING_DEVICE_ENABLE)
  753. // credit and thanks to jaspertandy on discord for these images
  754. static const char PROGMEM mouse_logo[3][2][16] = {// mouse icon
  755. {{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}},
  756. // crosshair icon
  757. {{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}},
  758. // dragscroll icon
  759. {{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}}};
  760. uint8_t image_index = 0;
  761. # ifdef OLED_DISPLAY_TEST
  762. image_index = animation_frame;
  763. # else
  764. if (charybdis_get_pointer_sniping_enabled()) {
  765. image_index = 1;
  766. } else if (charybdis_get_pointer_dragscroll_enabled()) {
  767. image_index = 2;
  768. }
  769. # endif
  770. oled_set_cursor(col, line);
  771. oled_write_raw_P(mouse_logo[image_index][0], 16);
  772. oled_set_cursor(col, line + 1);
  773. oled_write_raw_P(mouse_logo[image_index][1], 16);
  774. #endif
  775. }
  776. void render_status_right(void) {
  777. #if defined(KEYBOARD_handwired_tractyl_manuform)
  778. oled_set_cursor(7, 0);
  779. oled_write_P(PSTR("Manuform"), true);
  780. #elif defined(KEYBOARD_bastardkb_charybdis)
  781. oled_set_cursor(6, 0);
  782. oled_write_P(PSTR("Charybdis"), true);
  783. #elif defined(KEYBOARD_splitkb_kyria)
  784. oled_set_cursor(8, 0);
  785. oled_write_P(PSTR("Kyria"), true);
  786. #else
  787. oled_set_cursor(8, 0);
  788. oled_write_P(PSTR("Right"), true);
  789. #endif
  790. #if defined(OLED_DISPLAY_VERBOSE)
  791. render_default_layer_state(1, 1);
  792. #else
  793. render_default_layer_state(0, 0);
  794. #endif
  795. /* Show Keyboard Layout */
  796. render_layer_state(1, 2);
  797. render_mod_status(get_mods() | get_oneshot_mods(), 1, 5);
  798. #if !defined(OLED_DISPLAY_VERBOSE) && defined(WPM_ENABLE) && !defined(STM32F303xC)
  799. render_wpm(2, 7, 1);
  800. #endif
  801. render_keylock_status(host_keyboard_led_state(), 1, 6);
  802. }
  803. void render_status_left(void) {
  804. #if defined(OLED_DISPLAY_VERBOSE)
  805. render_kitty(0, 1);
  806. # if defined(KEYBOARD_handwired_tractyl_manuform)
  807. oled_set_cursor(7, 0);
  808. oled_write_P(PSTR("Tractyl"), true);
  809. # elif defined(KEYBOARD_bastardkb_charybdis)
  810. oled_set_cursor(6, 0);
  811. oled_write_P(PSTR("Charybdis"), true);
  812. # elif defined(KEYBOARD_splitkb_kyria)
  813. oled_set_cursor(7, 0);
  814. oled_write_P(PSTR("SplitKB"), true);
  815. # elif defined(KEYBOARD_handwired_fingerpunch_rockon)
  816. oled_set_cursor(7, 0);
  817. oled_write_P(PSTR("Rock On"), true);
  818. # else
  819. oled_set_cursor(8, 0);
  820. oled_write_P(PSTR("Left"), true);
  821. # endif
  822. # if defined(WPM_ENABLE)
  823. render_wpm(1, 7, 1);
  824. # elif defined(DEBUG_MATRIX_SCAN_RATE)
  825. render_matrix_scan_rate(1, 7, 1);
  826. # endif
  827. # if (defined(KEYBOARD_bastardkb_charybdis) || defined(KEYBOARD_handwired_tractyl_manuform)) && defined(POINTING_DEVICE_ENABLE)
  828. render_pointing_dpi_status(charybdis_get_pointer_sniping_enabled() ? charybdis_get_pointer_sniping_dpi() : charybdis_get_pointer_default_dpi(), 1, 7, 2);
  829. render_mouse_mode(17, 1);
  830. # elif defined(WPM_ENABLE) && defined(DEBUG_MATRIX_SCAN_RATE)
  831. render_matrix_scan_rate(1, 7, 2);
  832. # endif
  833. /* Show Keyboard Layout */
  834. render_bootmagic_status(7, 3);
  835. render_user_status(1, 5);
  836. render_keylogger_status(1, 6);
  837. #else
  838. render_default_layer_state(0, 0);
  839. /* Show Keyboard Layout */
  840. render_bootmagic_status(7, 3);
  841. render_user_status(1, 5);
  842. render_keylogger_status(1, 6);
  843. #endif
  844. }
  845. __attribute__((weak)) void oled_render_large_display(bool side) {
  846. if (!side) {
  847. render_unicode_mode(1, 14);
  848. }
  849. }
  850. __attribute__((weak)) oled_rotation_t oled_init_keymap(oled_rotation_t rotation) {
  851. return rotation;
  852. }
  853. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  854. if (is_keyboard_master()) {
  855. memset(keylog_str, ' ', OLED_KEYLOGGER_LENGTH);
  856. }
  857. kittoken = defer_exec(3000, kitty_animation_phases, NULL);
  858. oled_clear();
  859. oled_render();
  860. return oled_init_keymap(rotation);
  861. }
  862. __attribute__((weak)) bool oled_task_keymap(void) {
  863. return true;
  864. }
  865. bool oled_task_user(void) {
  866. #ifndef OLED_DISPLAY_TEST
  867. if (!is_oled_enabled) {
  868. oled_off();
  869. return false;
  870. } else
  871. #endif
  872. {
  873. oled_on();
  874. }
  875. if (!oled_task_keymap()) {
  876. return false;
  877. }
  878. #if defined(OLED_DISPLAY_VERBOSE)
  879. static const char PROGMEM header_image[] = {
  880. 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,
  881. // 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
  882. };
  883. oled_write_raw_P(header_image, sizeof(header_image));
  884. #endif
  885. #ifndef OLED_DISPLAY_TEST
  886. if (is_keyboard_left()) {
  887. #endif
  888. render_status_left();
  889. #if defined(OLED_DISPLAY_128X128)
  890. oled_render_large_display(true);
  891. #endif
  892. #ifndef OLED_DISPLAY_TEST
  893. } else {
  894. render_status_right();
  895. # if defined(OLED_DISPLAY_128X128)
  896. oled_render_large_display(false);
  897. # endif
  898. }
  899. #endif
  900. #if defined(OLED_DISPLAY_VERBOSE)
  901. uint8_t num_of_rows;
  902. # if defined(OLED_DISPLAY_128X128)
  903. num_of_rows = 15;
  904. # else
  905. num_of_rows = 7;
  906. # endif
  907. for (uint8_t i = 1; i < num_of_rows; i++) {
  908. oled_set_cursor(0, i);
  909. oled_write_raw_P(display_border, sizeof(display_border));
  910. oled_set_cursor(21, i);
  911. oled_write_raw_P(display_border, sizeof(display_border));
  912. }
  913. 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};
  914. oled_set_cursor(0, num_of_rows);
  915. oled_write_raw_P(footer_image, sizeof(footer_image));
  916. #endif
  917. return false;
  918. }
  919. extern bool oled_initialized;
  920. __attribute__((weak)) void matrix_scan_oled(void) {
  921. is_oled_enabled = !(timer_elapsed32(oled_timer) > 60000);
  922. }