logo

qmk_firmware

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

quantum.c (20548B)


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