keyboard.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. Copyright 2011, 2012, 2013 Jun Wako <wakojun@gmail.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdint.h>
  15. #include "keyboard.h"
  16. #include "keycode_config.h"
  17. #include "matrix.h"
  18. #include "keymap_introspection.h"
  19. #include "host.h"
  20. #include "led.h"
  21. #include "keycode.h"
  22. #include "timer.h"
  23. #include "sync_timer.h"
  24. #include "print.h"
  25. #include "debug.h"
  26. #include "command.h"
  27. #include "util.h"
  28. #include "host.h"
  29. #include "sendchar.h"
  30. #include "eeconfig.h"
  31. #include "action_layer.h"
  32. #include "suspend.h"
  33. #ifdef BOOTMAGIC_ENABLE
  34. # include "bootmagic.h"
  35. #endif
  36. #ifdef AUDIO_ENABLE
  37. # include "audio.h"
  38. #endif
  39. #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
  40. # include "process_music.h"
  41. #endif
  42. #ifdef BACKLIGHT_ENABLE
  43. # include "backlight.h"
  44. #endif
  45. #ifdef MOUSEKEY_ENABLE
  46. # include "mousekey.h"
  47. #endif
  48. #ifdef PS2_MOUSE_ENABLE
  49. # include "ps2_mouse.h"
  50. #endif
  51. #ifdef RGBLIGHT_ENABLE
  52. # include "rgblight.h"
  53. #endif
  54. #ifdef LED_MATRIX_ENABLE
  55. # include "led_matrix.h"
  56. #endif
  57. #ifdef RGB_MATRIX_ENABLE
  58. # include "rgb_matrix.h"
  59. #endif
  60. #ifdef ENCODER_ENABLE
  61. # include "encoder.h"
  62. #endif
  63. #ifdef HAPTIC_ENABLE
  64. # include "haptic.h"
  65. #endif
  66. #ifdef AUTO_SHIFT_ENABLE
  67. # include "process_auto_shift.h"
  68. #endif
  69. #ifdef COMBO_ENABLE
  70. # include "process_combo.h"
  71. #endif
  72. #ifdef TAP_DANCE_ENABLE
  73. # include "process_tap_dance.h"
  74. #endif
  75. #ifdef STENO_ENABLE
  76. # include "process_steno.h"
  77. #endif
  78. #ifdef KEY_OVERRIDE_ENABLE
  79. # include "process_key_override.h"
  80. #endif
  81. #ifdef SECURE_ENABLE
  82. # include "secure.h"
  83. #endif
  84. #ifdef POINTING_DEVICE_ENABLE
  85. # include "pointing_device.h"
  86. #endif
  87. #ifdef MIDI_ENABLE
  88. # include "process_midi.h"
  89. #endif
  90. #ifdef JOYSTICK_ENABLE
  91. # include "joystick.h"
  92. #endif
  93. #ifdef HD44780_ENABLE
  94. # include "hd44780.h"
  95. #endif
  96. #ifdef OLED_ENABLE
  97. # include "oled_driver.h"
  98. #endif
  99. #ifdef ST7565_ENABLE
  100. # include "st7565.h"
  101. #endif
  102. #ifdef VIA_ENABLE
  103. # include "via.h"
  104. #endif
  105. #ifdef DIP_SWITCH_ENABLE
  106. # include "dip_switch.h"
  107. #endif
  108. #ifdef EEPROM_DRIVER
  109. # include "eeprom_driver.h"
  110. #endif
  111. #if defined(CRC_ENABLE)
  112. # include "crc.h"
  113. #endif
  114. #ifdef VIRTSER_ENABLE
  115. # include "virtser.h"
  116. #endif
  117. #ifdef SLEEP_LED_ENABLE
  118. # include "sleep_led.h"
  119. #endif
  120. #ifdef SPLIT_KEYBOARD
  121. # include "split_util.h"
  122. #endif
  123. #ifdef BATTERY_ENABLE
  124. # include "battery.h"
  125. #endif
  126. #ifdef BLUETOOTH_ENABLE
  127. # include "bluetooth.h"
  128. #endif
  129. #ifdef CAPS_WORD_ENABLE
  130. # include "caps_word.h"
  131. #endif
  132. #ifdef LEADER_ENABLE
  133. # include "leader.h"
  134. #endif
  135. #ifdef UNICODE_COMMON_ENABLE
  136. # include "unicode.h"
  137. #endif
  138. #ifdef WPM_ENABLE
  139. # include "wpm.h"
  140. #endif
  141. #ifdef OS_DETECTION_ENABLE
  142. # include "os_detection.h"
  143. #endif
  144. #ifdef LAYER_LOCK_ENABLE
  145. # include "layer_lock.h"
  146. #endif
  147. #ifdef CONNECTION_ENABLE
  148. # include "connection.h"
  149. #endif
  150. static uint32_t last_input_modification_time = 0;
  151. uint32_t last_input_activity_time(void) {
  152. return last_input_modification_time;
  153. }
  154. uint32_t last_input_activity_elapsed(void) {
  155. return sync_timer_elapsed32(last_input_modification_time);
  156. }
  157. static uint32_t last_matrix_modification_time = 0;
  158. uint32_t last_matrix_activity_time(void) {
  159. return last_matrix_modification_time;
  160. }
  161. uint32_t last_matrix_activity_elapsed(void) {
  162. return sync_timer_elapsed32(last_matrix_modification_time);
  163. }
  164. void last_matrix_activity_trigger(void) {
  165. last_matrix_modification_time = last_input_modification_time = sync_timer_read32();
  166. }
  167. static uint32_t last_encoder_modification_time = 0;
  168. uint32_t last_encoder_activity_time(void) {
  169. return last_encoder_modification_time;
  170. }
  171. uint32_t last_encoder_activity_elapsed(void) {
  172. return sync_timer_elapsed32(last_encoder_modification_time);
  173. }
  174. void last_encoder_activity_trigger(void) {
  175. last_encoder_modification_time = last_input_modification_time = sync_timer_read32();
  176. }
  177. static uint32_t last_pointing_device_modification_time = 0;
  178. uint32_t last_pointing_device_activity_time(void) {
  179. return last_pointing_device_modification_time;
  180. }
  181. uint32_t last_pointing_device_activity_elapsed(void) {
  182. return sync_timer_elapsed32(last_pointing_device_modification_time);
  183. }
  184. void last_pointing_device_activity_trigger(void) {
  185. last_pointing_device_modification_time = last_input_modification_time = sync_timer_read32();
  186. }
  187. void set_activity_timestamps(uint32_t matrix_timestamp, uint32_t encoder_timestamp, uint32_t pointing_device_timestamp) {
  188. last_matrix_modification_time = matrix_timestamp;
  189. last_encoder_modification_time = encoder_timestamp;
  190. last_pointing_device_modification_time = pointing_device_timestamp;
  191. last_input_modification_time = MAX(matrix_timestamp, MAX(encoder_timestamp, pointing_device_timestamp));
  192. }
  193. // Only enable this if console is enabled to print to
  194. #if defined(DEBUG_MATRIX_SCAN_RATE)
  195. static uint32_t matrix_timer = 0;
  196. static uint32_t matrix_scan_count = 0;
  197. static uint32_t last_matrix_scan_count = 0;
  198. void matrix_scan_perf_task(void) {
  199. matrix_scan_count++;
  200. uint32_t timer_now = timer_read32();
  201. if (TIMER_DIFF_32(timer_now, matrix_timer) >= 1000) {
  202. # if defined(CONSOLE_ENABLE)
  203. dprintf("matrix scan frequency: %lu\n", matrix_scan_count);
  204. # endif
  205. last_matrix_scan_count = matrix_scan_count;
  206. matrix_timer = timer_now;
  207. matrix_scan_count = 0;
  208. }
  209. }
  210. uint32_t get_matrix_scan_rate(void) {
  211. return last_matrix_scan_count;
  212. }
  213. #else
  214. # define matrix_scan_perf_task()
  215. #endif
  216. #ifdef MATRIX_HAS_GHOST
  217. static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata) {
  218. matrix_row_t out = 0;
  219. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  220. // read each key in the row data and check if the keymap defines it as a real key
  221. if (keycode_at_keymap_location(0, row, col) && (rowdata & (((matrix_row_t)1) << col))) {
  222. // this creates new row data, if a key is defined in the keymap, it will be set here
  223. out |= ((matrix_row_t)1) << col;
  224. }
  225. }
  226. return out;
  227. }
  228. static inline bool popcount_more_than_one(matrix_row_t rowdata) {
  229. rowdata &= rowdata - 1; // if there are less than two bits (keys) set, rowdata will become zero
  230. return rowdata;
  231. }
  232. static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) {
  233. /* No ghost exists when less than 2 keys are down on the row.
  234. If there are "active" blanks in the matrix, the key can't be pressed by the user,
  235. there is no doubt as to which keys are really being pressed.
  236. The ghosts will be ignored, they are KC_NO. */
  237. rowdata = get_real_keys(row, rowdata);
  238. if ((popcount_more_than_one(rowdata)) == 0) {
  239. return false;
  240. }
  241. /* Ghost occurs when the row shares a column line with other row,
  242. and two columns are read on each row. Blanks in the matrix don't matter,
  243. so they are filtered out.
  244. If there are two or more real keys pressed and they match columns with
  245. at least two of another row's real keys, the row will be ignored. Keep in mind,
  246. we are checking one row at a time, not all of them at once.
  247. */
  248. for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
  249. if (i != row && popcount_more_than_one(get_real_keys(i, matrix_get_row(i)) & rowdata)) {
  250. return true;
  251. }
  252. }
  253. return false;
  254. }
  255. #else
  256. static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) {
  257. return false;
  258. }
  259. #endif
  260. /** \brief matrix_setup
  261. *
  262. * FIXME: needs doc
  263. */
  264. __attribute__((weak)) void matrix_setup(void) {}
  265. /** \brief keyboard_pre_init_user
  266. *
  267. * FIXME: needs doc
  268. */
  269. __attribute__((weak)) void keyboard_pre_init_user(void) {}
  270. /** \brief keyboard_pre_init_kb
  271. *
  272. * FIXME: needs doc
  273. */
  274. __attribute__((weak)) void keyboard_pre_init_kb(void) {
  275. keyboard_pre_init_user();
  276. }
  277. /** \brief keyboard_pre_init_modules
  278. *
  279. * FIXME: needs doc
  280. */
  281. __attribute__((weak)) void keyboard_pre_init_modules(void) {}
  282. /** \brief keyboard_pre_init_quantum
  283. *
  284. * FIXME: needs doc
  285. */
  286. void keyboard_pre_init_quantum(void) {
  287. keyboard_pre_init_modules();
  288. keyboard_pre_init_kb();
  289. }
  290. /** \brief keyboard_post_init_user
  291. *
  292. * FIXME: needs doc
  293. */
  294. __attribute__((weak)) void keyboard_post_init_user(void) {}
  295. /** \brief keyboard_post_init_kb
  296. *
  297. * FIXME: needs doc
  298. */
  299. __attribute__((weak)) void keyboard_post_init_kb(void) {
  300. keyboard_post_init_user();
  301. }
  302. /** \brief keyboard_post_init_modules
  303. *
  304. * FIXME: needs doc
  305. */
  306. __attribute__((weak)) void keyboard_post_init_modules(void) {}
  307. /** \brief keyboard_post_init_quantum
  308. *
  309. * FIXME: needs doc
  310. */
  311. void keyboard_post_init_quantum(void) {
  312. keyboard_post_init_modules();
  313. keyboard_post_init_kb();
  314. }
  315. /** \brief matrix_can_read
  316. *
  317. * Allows overriding when matrix scanning operations should be executed.
  318. */
  319. __attribute__((weak)) bool matrix_can_read(void) {
  320. return true;
  321. }
  322. /** \brief keyboard_setup
  323. *
  324. * FIXME: needs doc
  325. */
  326. void keyboard_setup(void) {
  327. print_set_sendchar(sendchar);
  328. #ifdef EEPROM_DRIVER
  329. eeprom_driver_init();
  330. #endif
  331. matrix_setup();
  332. keyboard_pre_init_quantum();
  333. }
  334. #ifndef SPLIT_KEYBOARD
  335. /** \brief is_keyboard_master
  336. *
  337. * FIXME: needs doc
  338. */
  339. __attribute__((weak)) bool is_keyboard_master(void) {
  340. return true;
  341. }
  342. /** \brief is_keyboard_left
  343. *
  344. * FIXME: needs doc
  345. */
  346. __attribute__((weak)) bool is_keyboard_left(void) {
  347. return true;
  348. }
  349. #endif
  350. /** \brief should_process_keypress
  351. *
  352. * Override this function if you have a condition where keypresses processing should change:
  353. * - splits where the slave side needs to process for rgb/oled functionality
  354. */
  355. __attribute__((weak)) bool should_process_keypress(void) {
  356. return is_keyboard_master();
  357. }
  358. /** \brief housekeeping_task_modules
  359. *
  360. * Codegen will override this if community modules are enabled.
  361. * This is specific to keyboard-level functionality.
  362. */
  363. __attribute__((weak)) void housekeeping_task_modules(void) {}
  364. /** \brief housekeeping_task_kb
  365. *
  366. * Override this function if you have a need to execute code for every keyboard main loop iteration.
  367. * This is specific to keyboard-level functionality.
  368. */
  369. __attribute__((weak)) void housekeeping_task_kb(void) {}
  370. /** \brief housekeeping_task_user
  371. *
  372. * Override this function if you have a need to execute code for every keyboard main loop iteration.
  373. * This is specific to user/keymap-level functionality.
  374. */
  375. __attribute__((weak)) void housekeeping_task_user(void) {}
  376. /** \brief housekeeping_task
  377. *
  378. * Invokes hooks for executing code after QMK is done after each loop iteration.
  379. */
  380. void housekeeping_task(void) {
  381. housekeeping_task_modules();
  382. housekeeping_task_kb();
  383. housekeeping_task_user();
  384. }
  385. /** \brief quantum_init
  386. *
  387. * Init global state
  388. */
  389. void quantum_init(void) {
  390. /* check signature */
  391. if (!eeconfig_is_enabled()) {
  392. eeconfig_init();
  393. }
  394. /* init globals */
  395. eeconfig_read_debug(&debug_config);
  396. eeconfig_read_keymap(&keymap_config);
  397. #ifdef BOOTMAGIC_ENABLE
  398. bootmagic();
  399. #endif
  400. /* read here just incase bootmagic process changed its value */
  401. layer_state_t default_layer = (layer_state_t)eeconfig_read_default_layer();
  402. default_layer_set(default_layer);
  403. /* Also initialize layer state to trigger callback functions for layer_state */
  404. layer_state_set_kb((layer_state_t)layer_state);
  405. }
  406. /** \brief keyboard_init
  407. *
  408. * FIXME: needs doc
  409. */
  410. void keyboard_init(void) {
  411. timer_init();
  412. sync_timer_init();
  413. #ifdef VIA_ENABLE
  414. via_init();
  415. #endif
  416. #ifdef SPLIT_KEYBOARD
  417. split_pre_init();
  418. #endif
  419. #ifdef ENCODER_ENABLE
  420. encoder_init();
  421. #endif
  422. matrix_init();
  423. quantum_init();
  424. #ifdef CONNECTION_ENABLE
  425. connection_init();
  426. #endif
  427. host_init();
  428. led_init_ports();
  429. #ifdef BACKLIGHT_ENABLE
  430. backlight_init_ports();
  431. #endif
  432. #ifdef AUDIO_ENABLE
  433. audio_init();
  434. #endif
  435. #ifdef LED_MATRIX_ENABLE
  436. led_matrix_init();
  437. #endif
  438. #ifdef RGB_MATRIX_ENABLE
  439. rgb_matrix_init();
  440. #endif
  441. #if defined(UNICODE_COMMON_ENABLE)
  442. unicode_input_mode_init();
  443. #endif
  444. #if defined(CRC_ENABLE)
  445. crc_init();
  446. #endif
  447. #ifdef OLED_ENABLE
  448. oled_init(OLED_ROTATION_0);
  449. #endif
  450. #ifdef ST7565_ENABLE
  451. st7565_init(DISPLAY_ROTATION_0);
  452. #endif
  453. #ifdef PS2_MOUSE_ENABLE
  454. ps2_mouse_init();
  455. #endif
  456. #ifdef BACKLIGHT_ENABLE
  457. backlight_init();
  458. #endif
  459. #ifdef RGBLIGHT_ENABLE
  460. rgblight_init();
  461. #endif
  462. #ifdef STENO_ENABLE_ALL
  463. steno_init();
  464. #endif
  465. #if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
  466. # pragma message "FORCE_NKRO option is now deprecated - Please migrate to NKRO_DEFAULT_ON instead."
  467. keymap_config.nkro = 1;
  468. eeconfig_update_keymap(&keymap_config);
  469. #endif
  470. #ifdef DIP_SWITCH_ENABLE
  471. dip_switch_init();
  472. #endif
  473. #ifdef JOYSTICK_ENABLE
  474. joystick_init();
  475. #endif
  476. #ifdef SLEEP_LED_ENABLE
  477. sleep_led_init();
  478. #endif
  479. #ifdef VIRTSER_ENABLE
  480. virtser_init();
  481. #endif
  482. #ifdef SPLIT_KEYBOARD
  483. split_post_init();
  484. #endif
  485. #ifdef POINTING_DEVICE_ENABLE
  486. // init after split init
  487. pointing_device_init();
  488. #endif
  489. #ifdef BATTERY_ENABLE
  490. battery_init();
  491. #endif
  492. #ifdef BLUETOOTH_ENABLE
  493. bluetooth_init();
  494. #endif
  495. #ifdef HAPTIC_ENABLE
  496. haptic_init();
  497. #endif
  498. #if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE)
  499. debug_enable = true;
  500. #endif
  501. keyboard_post_init_quantum(); /* Always keep this last */
  502. }
  503. /** \brief key_event_task
  504. *
  505. * This function is responsible for calling into other systems when they need to respond to electrical switch press events.
  506. * This is differnet than keycode events as no layer processing, or filtering occurs.
  507. */
  508. void switch_events(uint8_t row, uint8_t col, bool pressed) {
  509. #if defined(LED_MATRIX_ENABLE)
  510. led_matrix_handle_key_event(row, col, pressed);
  511. #endif
  512. #if defined(RGB_MATRIX_ENABLE)
  513. rgb_matrix_handle_key_event(row, col, pressed);
  514. #endif
  515. wakeup_matrix_handle_key_event(row, col, pressed);
  516. }
  517. /**
  518. * @brief Generates a tick event at a maximum rate of 1KHz that drives the
  519. * internal QMK state machine.
  520. */
  521. static inline void generate_tick_event(void) {
  522. static uint16_t last_tick = 0;
  523. const uint16_t now = timer_read();
  524. if (TIMER_DIFF_16(now, last_tick) != 0) {
  525. action_exec(MAKE_TICK_EVENT);
  526. last_tick = now;
  527. }
  528. }
  529. matrix_row_t matrix_previous[MATRIX_ROWS];
  530. /**
  531. * @brief This task scans the keyboards matrix and processes any key presses
  532. * that occur.
  533. *
  534. * @return true Matrix did change
  535. * @return false Matrix didn't change
  536. */
  537. static bool matrix_task(void) {
  538. if (!matrix_can_read()) {
  539. generate_tick_event();
  540. return false;
  541. }
  542. matrix_scan();
  543. bool matrix_changed = false;
  544. for (uint8_t row = 0; row < MATRIX_ROWS && !matrix_changed; row++) {
  545. matrix_changed |= matrix_previous[row] ^ matrix_get_row(row);
  546. }
  547. matrix_scan_perf_task();
  548. // Short-circuit the complete matrix processing if it is not necessary
  549. if (!matrix_changed) {
  550. generate_tick_event();
  551. return matrix_changed;
  552. }
  553. if (debug_config.matrix) {
  554. matrix_print();
  555. }
  556. const bool process_keypress = should_process_keypress();
  557. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  558. const matrix_row_t current_row = matrix_get_row(row);
  559. const matrix_row_t row_changes = current_row ^ matrix_previous[row];
  560. if (!row_changes || has_ghost_in_row(row, current_row)) {
  561. continue;
  562. }
  563. matrix_row_t col_mask = 1;
  564. for (uint8_t col = 0; col < MATRIX_COLS; col++, col_mask <<= 1) {
  565. if (row_changes & col_mask) {
  566. const bool key_pressed = current_row & col_mask;
  567. if (process_keypress && !keypress_is_wakeup_key(row, col)) {
  568. action_exec(MAKE_KEYEVENT(row, col, key_pressed));
  569. }
  570. switch_events(row, col, key_pressed);
  571. }
  572. }
  573. matrix_previous[row] = current_row;
  574. }
  575. return matrix_changed;
  576. }
  577. /** \brief Tasks previously located in matrix_scan_quantum
  578. *
  579. * TODO: rationalise against keyboard_task and current split role
  580. */
  581. void quantum_task(void) {
  582. #ifdef SPLIT_KEYBOARD
  583. // some tasks should only run on master
  584. if (!is_keyboard_master()) return;
  585. #endif
  586. #ifdef AUDIO_ENABLE
  587. audio_task();
  588. #endif
  589. #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
  590. music_task();
  591. #endif
  592. #ifdef KEY_OVERRIDE_ENABLE
  593. key_override_task();
  594. #endif
  595. #ifdef SEQUENCER_ENABLE
  596. sequencer_task();
  597. #endif
  598. #ifdef TAP_DANCE_ENABLE
  599. tap_dance_task();
  600. #endif
  601. #ifdef COMBO_ENABLE
  602. combo_task();
  603. #endif
  604. #ifdef LEADER_ENABLE
  605. leader_task();
  606. #endif
  607. #ifdef WPM_ENABLE
  608. decay_wpm();
  609. #endif
  610. #ifdef DIP_SWITCH_ENABLE
  611. dip_switch_task();
  612. #endif
  613. #ifdef AUTO_SHIFT_ENABLE
  614. autoshift_matrix_scan();
  615. #endif
  616. #ifdef CAPS_WORD_ENABLE
  617. caps_word_task();
  618. #endif
  619. #ifdef SECURE_ENABLE
  620. secure_task();
  621. #endif
  622. #ifdef LAYER_LOCK_ENABLE
  623. layer_lock_task();
  624. #endif
  625. host_task();
  626. }
  627. /** \brief Main task that is repeatedly called as fast as possible. */
  628. void keyboard_task(void) {
  629. __attribute__((unused)) bool activity_has_occurred = false;
  630. if (matrix_task()) {
  631. last_matrix_activity_trigger();
  632. activity_has_occurred = true;
  633. }
  634. quantum_task();
  635. #if defined(SPLIT_WATCHDOG_ENABLE)
  636. split_watchdog_task();
  637. #endif
  638. #if defined(RGBLIGHT_ENABLE)
  639. rgblight_task();
  640. #endif
  641. #ifdef LED_MATRIX_ENABLE
  642. led_matrix_task();
  643. #endif
  644. #ifdef RGB_MATRIX_ENABLE
  645. rgb_matrix_task();
  646. #endif
  647. #if defined(BACKLIGHT_ENABLE)
  648. # if defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS)
  649. backlight_task();
  650. # endif
  651. #endif
  652. #ifdef ENCODER_ENABLE
  653. if (encoder_task()) {
  654. last_encoder_activity_trigger();
  655. activity_has_occurred = true;
  656. }
  657. #endif
  658. #ifdef POINTING_DEVICE_ENABLE
  659. if (pointing_device_task()) {
  660. last_pointing_device_activity_trigger();
  661. activity_has_occurred = true;
  662. }
  663. #endif
  664. #ifdef OLED_ENABLE
  665. oled_task();
  666. # if OLED_TIMEOUT > 0
  667. // Wake up oled if user is using those fabulous keys or spinning those encoders!
  668. if (activity_has_occurred) oled_on();
  669. # endif
  670. #endif
  671. #ifdef ST7565_ENABLE
  672. st7565_task();
  673. # if ST7565_TIMEOUT > 0
  674. // Wake up display if user is using those fabulous keys or spinning those encoders!
  675. if (activity_has_occurred) st7565_on();
  676. # endif
  677. #endif
  678. #ifdef MOUSEKEY_ENABLE
  679. // mousekey repeat & acceleration
  680. mousekey_task();
  681. #endif
  682. #ifdef PS2_MOUSE_ENABLE
  683. ps2_mouse_task();
  684. #endif
  685. #ifdef MIDI_ENABLE
  686. midi_task();
  687. #endif
  688. #ifdef JOYSTICK_ENABLE
  689. joystick_task();
  690. #endif
  691. #ifdef BATTERY_ENABLE
  692. battery_task();
  693. #endif
  694. #ifdef BLUETOOTH_ENABLE
  695. bluetooth_task();
  696. #endif
  697. #ifdef HAPTIC_ENABLE
  698. haptic_task();
  699. #endif
  700. led_task();
  701. #ifdef OS_DETECTION_ENABLE
  702. os_detection_task();
  703. #endif
  704. }