quantum.c 18 KB

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