quantum.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /* Copyright 2016-2017 Jack Humbert
  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. #ifdef BACKLIGHT_ENABLE
  18. # include "process_backlight.h"
  19. #endif
  20. #ifdef BLUETOOTH_ENABLE
  21. # include "process_connection.h"
  22. #endif
  23. #ifdef GRAVE_ESC_ENABLE
  24. # include "process_grave_esc.h"
  25. #endif
  26. #ifdef HAPTIC_ENABLE
  27. # include "process_haptic.h"
  28. #endif
  29. #ifdef JOYSTICK_ENABLE
  30. # include "process_joystick.h"
  31. #endif
  32. #ifdef LEADER_ENABLE
  33. # include "process_leader.h"
  34. #endif
  35. #ifdef LED_MATRIX_ENABLE
  36. # include "process_led_matrix.h"
  37. #endif
  38. #ifdef MAGIC_ENABLE
  39. # include "process_magic.h"
  40. #endif
  41. #ifdef MIDI_ENABLE
  42. # include "process_midi.h"
  43. #endif
  44. #if !defined(NO_ACTION_LAYER)
  45. # include "process_default_layer.h"
  46. #endif
  47. #ifdef PROGRAMMABLE_BUTTON_ENABLE
  48. # include "process_programmable_button.h"
  49. #endif
  50. #if defined(RGB_MATRIX_ENABLE)
  51. # include "process_rgb_matrix.h"
  52. #endif
  53. #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
  54. # include "process_underglow.h"
  55. #endif
  56. #ifdef SECURE_ENABLE
  57. # include "process_secure.h"
  58. #endif
  59. #ifdef TRI_LAYER_ENABLE
  60. # include "process_tri_layer.h"
  61. #endif
  62. #ifdef UNICODE_COMMON_ENABLE
  63. # include "process_unicode_common.h"
  64. #endif
  65. #ifdef LAYER_LOCK_ENABLE
  66. # include "process_layer_lock.h"
  67. #endif
  68. #ifdef AUDIO_ENABLE
  69. # ifndef GOODBYE_SONG
  70. # define GOODBYE_SONG SONG(GOODBYE_SOUND)
  71. # endif
  72. float goodbye_song[][2] = GOODBYE_SONG;
  73. # ifdef DEFAULT_LAYER_SONGS
  74. float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
  75. # endif
  76. #endif
  77. uint8_t extract_mod_bits(uint16_t code) {
  78. switch (code) {
  79. case QK_MODS ... QK_MODS_MAX:
  80. break;
  81. default:
  82. return 0;
  83. }
  84. uint8_t mods_to_send = 0;
  85. if (code & QK_RMODS_MIN) { // Right mod flag is set
  86. if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RIGHT_CTRL);
  87. if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RIGHT_SHIFT);
  88. if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RIGHT_ALT);
  89. if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RIGHT_GUI);
  90. } else {
  91. if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LEFT_CTRL);
  92. if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LEFT_SHIFT);
  93. if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LEFT_ALT);
  94. if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LEFT_GUI);
  95. }
  96. return mods_to_send;
  97. }
  98. void do_code16(uint16_t code, void (*f)(uint8_t)) {
  99. f(extract_mod_bits(code));
  100. }
  101. __attribute__((weak)) void register_code16(uint16_t code) {
  102. if (IS_MODIFIER_KEYCODE(code) || code == KC_NO) {
  103. do_code16(code, register_mods);
  104. } else {
  105. do_code16(code, register_weak_mods);
  106. }
  107. register_code(code);
  108. }
  109. __attribute__((weak)) void unregister_code16(uint16_t code) {
  110. unregister_code(code);
  111. if (IS_MODIFIER_KEYCODE(code) || code == KC_NO) {
  112. do_code16(code, unregister_mods);
  113. } else {
  114. do_code16(code, unregister_weak_mods);
  115. }
  116. }
  117. /** \brief Tap a keycode with a delay.
  118. *
  119. * \param code The modded keycode to tap.
  120. * \param delay The amount of time in milliseconds to leave the keycode registered, before unregistering it.
  121. */
  122. __attribute__((weak)) void tap_code16_delay(uint16_t code, uint16_t delay) {
  123. register_code16(code);
  124. for (uint16_t i = delay; i > 0; i--) {
  125. wait_ms(1);
  126. }
  127. unregister_code16(code);
  128. }
  129. /** \brief Tap a keycode with the default delay.
  130. *
  131. * \param code The modded keycode to tap. If `code` is `KC_CAPS_LOCK`, the delay will be `TAP_HOLD_CAPS_DELAY`, otherwise `TAP_CODE_DELAY`, if defined.
  132. */
  133. __attribute__((weak)) void tap_code16(uint16_t code) {
  134. tap_code16_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY);
  135. }
  136. __attribute__((weak)) bool pre_process_record_kb(uint16_t keycode, keyrecord_t *record) {
  137. return pre_process_record_user(keycode, record);
  138. }
  139. __attribute__((weak)) bool pre_process_record_user(uint16_t keycode, keyrecord_t *record) {
  140. return true;
  141. }
  142. __attribute__((weak)) bool process_action_kb(keyrecord_t *record) {
  143. return true;
  144. }
  145. __attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  146. return process_record_user(keycode, record);
  147. }
  148. __attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  149. return true;
  150. }
  151. __attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t *record) {
  152. post_process_record_user(keycode, record);
  153. }
  154. __attribute__((weak)) void post_process_record_user(uint16_t keycode, keyrecord_t *record) {}
  155. void shutdown_quantum(bool jump_to_bootloader) {
  156. clear_keyboard();
  157. #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
  158. process_midi_all_notes_off();
  159. #endif
  160. #ifdef AUDIO_ENABLE
  161. # ifndef NO_MUSIC_MODE
  162. music_all_notes_off();
  163. # endif
  164. uint16_t timer_start = timer_read();
  165. PLAY_SONG(goodbye_song);
  166. shutdown_kb(jump_to_bootloader);
  167. while (timer_elapsed(timer_start) < 250)
  168. wait_ms(1);
  169. stop_all_notes();
  170. #else
  171. shutdown_kb(jump_to_bootloader);
  172. wait_ms(250);
  173. #endif
  174. #ifdef HAPTIC_ENABLE
  175. haptic_shutdown();
  176. #endif
  177. }
  178. void reset_keyboard(void) {
  179. shutdown_quantum(true);
  180. bootloader_jump();
  181. }
  182. void soft_reset_keyboard(void) {
  183. shutdown_quantum(false);
  184. mcu_reset();
  185. }
  186. /* Convert record into usable keycode via the contained event. */
  187. uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) {
  188. #if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE)
  189. if (record->keycode) {
  190. return record->keycode;
  191. }
  192. #endif
  193. return get_event_keycode(record->event, update_layer_cache);
  194. }
  195. /* Convert event into usable keycode. Checks the layer cache to ensure that it
  196. * retains the correct keycode after a layer change, if the key is still pressed.
  197. * "update_layer_cache" is to ensure that it only updates the layer cache when
  198. * appropriate, otherwise, it will update it and cause layer tap (and other keys)
  199. * from triggering properly.
  200. */
  201. uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {
  202. #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
  203. /* TODO: Use store_or_get_action() or a similar function. */
  204. if (!disable_action_cache) {
  205. uint8_t layer;
  206. if (event.pressed && update_layer_cache) {
  207. layer = layer_switch_get_layer(event.key);
  208. update_source_layers_cache(event.key, layer);
  209. } else {
  210. layer = read_source_layers_cache(event.key);
  211. }
  212. return keymap_key_to_keycode(layer, event.key);
  213. } else
  214. #endif
  215. return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
  216. }
  217. /* Get keycode, and then process pre tapping functionality */
  218. bool pre_process_record_quantum(keyrecord_t *record) {
  219. return pre_process_record_kb(get_record_keycode(record, true), record) &&
  220. #ifdef COMBO_ENABLE
  221. process_combo(get_record_keycode(record, true), record) &&
  222. #endif
  223. true;
  224. }
  225. /* Get keycode, and then call keyboard function */
  226. void post_process_record_quantum(keyrecord_t *record) {
  227. uint16_t keycode = get_record_keycode(record, false);
  228. post_process_record_kb(keycode, record);
  229. }
  230. /* Core keycode function, hands off handling to other functions,
  231. then processes internal quantum keycodes, and then processes
  232. ACTIONs. */
  233. bool process_record_quantum(keyrecord_t *record) {
  234. uint16_t keycode = get_record_keycode(record, true);
  235. // This is how you use actions here
  236. // if (keycode == QK_LEADER) {
  237. // action_t action;
  238. // action.code = ACTION_DEFAULT_LAYER_SET(0);
  239. // process_action(record, action);
  240. // return false;
  241. // }
  242. #if defined(SECURE_ENABLE)
  243. if (!preprocess_secure(keycode, record)) {
  244. return false;
  245. }
  246. #endif
  247. #ifdef TAP_DANCE_ENABLE
  248. if (preprocess_tap_dance(keycode, record)) {
  249. // The tap dance might have updated the layer state, therefore the
  250. // result of the keycode lookup might change.
  251. keycode = get_record_keycode(record, true);
  252. }
  253. #endif
  254. #ifdef RGBLIGHT_ENABLE
  255. if (record->event.pressed) {
  256. preprocess_rgblight();
  257. }
  258. #endif
  259. #ifdef WPM_ENABLE
  260. if (record->event.pressed) {
  261. update_wpm(keycode);
  262. }
  263. #endif
  264. if (!(
  265. #if defined(KEY_LOCK_ENABLE)
  266. // Must run first to be able to mask key_up events.
  267. process_key_lock(&keycode, record) &&
  268. #endif
  269. #if defined(DYNAMIC_MACRO_ENABLE) && !defined(DYNAMIC_MACRO_USER_CALL)
  270. // Must run asap to ensure all keypresses are recorded.
  271. process_dynamic_macro(keycode, record) &&
  272. #endif
  273. #ifdef REPEAT_KEY_ENABLE
  274. process_last_key(keycode, record) && process_repeat_key(keycode, record) &&
  275. #endif
  276. #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
  277. process_clicky(keycode, record) &&
  278. #endif
  279. #ifdef HAPTIC_ENABLE
  280. process_haptic(keycode, record) &&
  281. #endif
  282. #if defined(VIA_ENABLE)
  283. process_record_via(keycode, record) &&
  284. #endif
  285. #if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
  286. process_auto_mouse(keycode, record) &&
  287. #endif
  288. process_record_kb(keycode, record) &&
  289. #if defined(SECURE_ENABLE)
  290. process_secure(keycode, record) &&
  291. #endif
  292. #if defined(SEQUENCER_ENABLE)
  293. process_sequencer(keycode, record) &&
  294. #endif
  295. #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
  296. process_midi(keycode, record) &&
  297. #endif
  298. #ifdef AUDIO_ENABLE
  299. process_audio(keycode, record) &&
  300. #endif
  301. #if defined(BACKLIGHT_ENABLE)
  302. process_backlight(keycode, record) &&
  303. #endif
  304. #if defined(LED_MATRIX_ENABLE)
  305. process_led_matrix(keycode, record) &&
  306. #endif
  307. #ifdef STENO_ENABLE
  308. process_steno(keycode, record) &&
  309. #endif
  310. #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
  311. process_music(keycode, record) &&
  312. #endif
  313. #ifdef CAPS_WORD_ENABLE
  314. process_caps_word(keycode, record) &&
  315. #endif
  316. #ifdef KEY_OVERRIDE_ENABLE
  317. process_key_override(keycode, record) &&
  318. #endif
  319. #ifdef TAP_DANCE_ENABLE
  320. process_tap_dance(keycode, record) &&
  321. #endif
  322. #if defined(UNICODE_COMMON_ENABLE)
  323. process_unicode_common(keycode, record) &&
  324. #endif
  325. #ifdef LEADER_ENABLE
  326. process_leader(keycode, record) &&
  327. #endif
  328. #ifdef AUTO_SHIFT_ENABLE
  329. process_auto_shift(keycode, record) &&
  330. #endif
  331. #ifdef DYNAMIC_TAPPING_TERM_ENABLE
  332. process_dynamic_tapping_term(keycode, record) &&
  333. #endif
  334. #ifdef SPACE_CADET_ENABLE
  335. process_space_cadet(keycode, record) &&
  336. #endif
  337. #ifdef MAGIC_ENABLE
  338. process_magic(keycode, record) &&
  339. #endif
  340. #ifdef GRAVE_ESC_ENABLE
  341. process_grave_esc(keycode, record) &&
  342. #endif
  343. #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
  344. process_underglow(keycode, record) &&
  345. #endif
  346. #if defined(RGB_MATRIX_ENABLE)
  347. process_rgb_matrix(keycode, record) &&
  348. #endif
  349. #ifdef JOYSTICK_ENABLE
  350. process_joystick(keycode, record) &&
  351. #endif
  352. #ifdef PROGRAMMABLE_BUTTON_ENABLE
  353. process_programmable_button(keycode, record) &&
  354. #endif
  355. #ifdef AUTOCORRECT_ENABLE
  356. process_autocorrect(keycode, record) &&
  357. #endif
  358. #ifdef TRI_LAYER_ENABLE
  359. process_tri_layer(keycode, record) &&
  360. #endif
  361. #if !defined(NO_ACTION_LAYER)
  362. process_default_layer(keycode, record) &&
  363. #endif
  364. #ifdef LAYER_LOCK_ENABLE
  365. process_layer_lock(keycode, record) &&
  366. #endif
  367. #ifdef BLUETOOTH_ENABLE
  368. process_connection(keycode, record) &&
  369. #endif
  370. true)) {
  371. return false;
  372. }
  373. if (record->event.pressed) {
  374. switch (keycode) {
  375. #ifndef NO_RESET
  376. case QK_BOOTLOADER:
  377. reset_keyboard();
  378. return false;
  379. case QK_REBOOT:
  380. soft_reset_keyboard();
  381. return false;
  382. #endif
  383. #ifndef NO_DEBUG
  384. case QK_DEBUG_TOGGLE:
  385. debug_enable ^= 1;
  386. if (debug_enable) {
  387. print("DEBUG: enabled.\n");
  388. } else {
  389. print("DEBUG: disabled.\n");
  390. }
  391. #endif
  392. return false;
  393. case QK_CLEAR_EEPROM:
  394. #ifdef NO_RESET
  395. eeconfig_init();
  396. #else
  397. eeconfig_disable();
  398. soft_reset_keyboard();
  399. #endif
  400. return false;
  401. #ifdef VELOCIKEY_ENABLE
  402. case QK_VELOCIKEY_TOGGLE:
  403. velocikey_toggle();
  404. return false;
  405. #endif
  406. #ifndef NO_ACTION_ONESHOT
  407. case QK_ONE_SHOT_TOGGLE:
  408. oneshot_toggle();
  409. break;
  410. case QK_ONE_SHOT_ON:
  411. oneshot_enable();
  412. break;
  413. case QK_ONE_SHOT_OFF:
  414. oneshot_disable();
  415. break;
  416. #endif
  417. #ifdef ENABLE_COMPILE_KEYCODE
  418. case QK_MAKE: // Compiles the firmware, and adds the flash command based on keyboard bootloader
  419. {
  420. # ifdef NO_ACTION_ONESHOT
  421. const uint8_t temp_mod = mod_config(get_mods());
  422. # else
  423. const uint8_t temp_mod = mod_config(get_mods() | get_oneshot_mods());
  424. clear_oneshot_mods();
  425. # endif
  426. clear_mods();
  427. SEND_STRING_DELAY("qmk", TAP_CODE_DELAY);
  428. if (temp_mod & MOD_MASK_SHIFT) { // if shift is held, flash rather than compile
  429. SEND_STRING_DELAY(" flash ", TAP_CODE_DELAY);
  430. } else {
  431. SEND_STRING_DELAY(" compile ", TAP_CODE_DELAY);
  432. }
  433. # if defined(CONVERTER_ENABLED)
  434. SEND_STRING_DELAY("-kb " QMK_KEYBOARD " -km " QMK_KEYMAP " -e CONVERT_TO=" CONVERTER_TARGET SS_TAP(X_ENTER), TAP_CODE_DELAY);
  435. # else
  436. SEND_STRING_DELAY("-kb " QMK_KEYBOARD " -km " QMK_KEYMAP SS_TAP(X_ENTER), TAP_CODE_DELAY);
  437. # endif
  438. if (temp_mod & MOD_MASK_SHIFT && temp_mod & MOD_MASK_CTRL) {
  439. reset_keyboard();
  440. }
  441. }
  442. #endif
  443. }
  444. }
  445. return process_action_kb(record);
  446. }
  447. void set_single_default_layer(uint8_t default_layer) {
  448. #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
  449. PLAY_SONG(default_layer_songs[default_layer]);
  450. #endif
  451. default_layer_set((layer_state_t)1 << default_layer);
  452. }
  453. void set_single_persistent_default_layer(uint8_t default_layer) {
  454. eeconfig_update_default_layer((layer_state_t)1 << default_layer);
  455. set_single_default_layer(default_layer);
  456. }
  457. //------------------------------------------------------------------------------
  458. // Override these functions in your keymap file to play different tunes on
  459. // different events such as startup and bootloader jump
  460. __attribute__((weak)) bool shutdown_user(bool jump_to_bootloader) {
  461. return true;
  462. }
  463. __attribute__((weak)) bool shutdown_kb(bool jump_to_bootloader) {
  464. if (!shutdown_user(jump_to_bootloader)) {
  465. return false;
  466. }
  467. return true;
  468. }
  469. void suspend_power_down_quantum(void) {
  470. suspend_power_down_kb();
  471. #ifndef NO_SUSPEND_POWER_DOWN
  472. // Turn off backlight
  473. # ifdef BACKLIGHT_ENABLE
  474. backlight_level_noeeprom(0);
  475. # endif
  476. # ifdef LED_MATRIX_ENABLE
  477. led_matrix_task();
  478. # endif
  479. # ifdef RGB_MATRIX_ENABLE
  480. rgb_matrix_task();
  481. # endif
  482. // Turn off LED indicators
  483. led_suspend();
  484. // Turn off audio
  485. # ifdef AUDIO_ENABLE
  486. stop_all_notes();
  487. # endif
  488. // Turn off underglow
  489. # if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
  490. rgblight_suspend();
  491. # endif
  492. # if defined(LED_MATRIX_ENABLE)
  493. led_matrix_set_suspend_state(true);
  494. # endif
  495. # if defined(RGB_MATRIX_ENABLE)
  496. rgb_matrix_set_suspend_state(true);
  497. # endif
  498. # ifdef OLED_ENABLE
  499. oled_off();
  500. # endif
  501. # ifdef ST7565_ENABLE
  502. st7565_off();
  503. # endif
  504. # if defined(POINTING_DEVICE_ENABLE)
  505. // run to ensure scanning occurs while suspended
  506. pointing_device_task();
  507. # endif
  508. #endif
  509. }
  510. __attribute__((weak)) void suspend_wakeup_init_quantum(void) {
  511. // Turn on backlight
  512. #ifdef BACKLIGHT_ENABLE
  513. backlight_init();
  514. #endif
  515. // Restore LED indicators
  516. led_wakeup();
  517. // Wake up underglow
  518. #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
  519. rgblight_wakeup();
  520. #endif
  521. #if defined(LED_MATRIX_ENABLE)
  522. led_matrix_set_suspend_state(false);
  523. #endif
  524. #if defined(RGB_MATRIX_ENABLE)
  525. rgb_matrix_set_suspend_state(false);
  526. #endif
  527. suspend_wakeup_init_kb();
  528. }
  529. /** \brief converts unsigned integers into char arrays
  530. *
  531. * Takes an unsigned integer and converts that value into an equivalent char array
  532. * A padding character may be specified, ' ' for leading spaces, '0' for leading zeros.
  533. */
  534. const char *get_numeric_str(char *buf, size_t buf_len, uint32_t curr_num, char curr_pad) {
  535. buf[buf_len - 1] = '\0';
  536. for (size_t i = 0; i < buf_len - 1; ++i) {
  537. char c = '0' + curr_num % 10;
  538. buf[buf_len - 2 - i] = (c == '0' && i == 0) ? '0' : (curr_num > 0 ? c : curr_pad);
  539. curr_num /= 10;
  540. }
  541. return buf;
  542. }
  543. /** \brief converts uint8_t into char array
  544. *
  545. * Takes an uint8_t, and uses an internal static buffer to render that value into a char array
  546. * A padding character may be specified, ' ' for leading spaces, '0' for leading zeros.
  547. *
  548. * NOTE: Subsequent invocations will reuse the same static buffer and overwrite the previous
  549. * contents. Use the result immediately, instead of caching it.
  550. */
  551. const char *get_u8_str(uint8_t curr_num, char curr_pad) {
  552. static char buf[4] = {0};
  553. static uint8_t last_num = 0xFF;
  554. static char last_pad = '\0';
  555. if (last_num == curr_num && last_pad == curr_pad) {
  556. return buf;
  557. }
  558. last_num = curr_num;
  559. last_pad = curr_pad;
  560. return get_numeric_str(buf, sizeof(buf), curr_num, curr_pad);
  561. }
  562. /** \brief converts uint16_t into char array
  563. *
  564. * Takes an uint16_t, and uses an internal static buffer to render that value into a char array
  565. * A padding character may be specified, ' ' for leading spaces, '0' for leading zeros.
  566. *
  567. * NOTE: Subsequent invocations will reuse the same static buffer and overwrite the previous
  568. * contents. Use the result immediately, instead of caching it.
  569. */
  570. const char *get_u16_str(uint16_t curr_num, char curr_pad) {
  571. static char buf[6] = {0};
  572. static uint16_t last_num = 0xFF;
  573. static char last_pad = '\0';
  574. if (last_num == curr_num && last_pad == curr_pad) {
  575. return buf;
  576. }
  577. last_num = curr_num;
  578. last_pad = curr_pad;
  579. return get_numeric_str(buf, sizeof(buf), curr_num, curr_pad);
  580. }
  581. #if defined(SECURE_ENABLE)
  582. void secure_hook_quantum(secure_status_t secure_status) {
  583. // If keys are being held when this is triggered, they may not be released properly
  584. // this can result in stuck keys, mods and layers. To prevent that, manually
  585. // clear these, when it is triggered.
  586. if (secure_status == SECURE_PENDING) {
  587. clear_keyboard();
  588. layer_clear();
  589. }
  590. }
  591. #endif