quantum.c 18 KB

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