summaryrefslogtreecommitdiff
path: root/quantum/keyboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/keyboard.c')
-rw-r--r--quantum/keyboard.c151
1 files changed, 117 insertions, 34 deletions
diff --git a/quantum/keyboard.c b/quantum/keyboard.c
index 3bca05aab7..fa20c675c3 100644
--- a/quantum/keyboard.c
+++ b/quantum/keyboard.c
@@ -16,6 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
+#include "quantum.h"
#include "keyboard.h"
#include "matrix.h"
#include "keymap.h"
@@ -349,6 +350,32 @@ void keyboard_init(void) {
keyboard_post_init_kb(); /* Always keep this last */
}
+/** \brief keyboard set leds
+ *
+ * FIXME: needs doc
+ */
+void keyboard_set_leds(uint8_t leds) {
+ if (debug_keyboard) {
+ debug("keyboard_set_led: ");
+ debug_hex8(leds);
+ debug("\n");
+ }
+ led_set(leds);
+}
+
+/** \brief set host led state
+ *
+ * Only sets state if change detected
+ */
+void led_task(void) {
+ static uint8_t led_status = 0;
+ // update LED
+ if (led_status != host_keyboard_leds()) {
+ led_status = host_keyboard_leds();
+ keyboard_set_leds(led_status);
+ }
+}
+
/** \brief key_event_task
*
* This function is responsible for calling into other systems when they need to respond to electrical switch press events.
@@ -363,28 +390,17 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) {
#endif
}
-/** \brief Keyboard task: Do keyboard routine jobs
+/** \brief Perform scan of keyboard matrix
*
- * Do routine keyboard jobs:
- *
- * * scan matrix
- * * handle mouse movements
- * * handle midi commands
- * * light LEDs
- *
- * This is repeatedly called as fast as possible.
+ * Any detected changes in state are sent out as part of the processing
*/
-void keyboard_task(void) {
+bool matrix_scan_task(void) {
static matrix_row_t matrix_prev[MATRIX_ROWS];
- static uint8_t led_status = 0;
matrix_row_t matrix_row = 0;
matrix_row_t matrix_change = 0;
#ifdef QMK_KEYS_PER_SCAN
uint8_t keys_processed = 0;
#endif
-#ifdef ENCODER_ENABLE
- bool encoders_changed = false;
-#endif
uint8_t matrix_changed = matrix_scan();
if (matrix_changed) last_matrix_activity_trigger();
@@ -431,10 +447,94 @@ void keyboard_task(void) {
MATRIX_LOOP_END:
-#ifdef DEBUG_MATRIX_SCAN_RATE
matrix_scan_perf_task();
+ return matrix_changed;
+}
+
+/** \brief Tasks previously located in matrix_scan_quantum
+ *
+ * TODO: rationalise against keyboard_task and current split role
+ */
+void quantum_task(void) {
+#ifdef SPLIT_KEYBOARD
+ // some tasks should only run on master
+ if (!is_keyboard_master()) return;
+#endif
+
+#if defined(AUDIO_ENABLE) && defined(AUDIO_INIT_DELAY)
+ // There are some tasks that need to be run a little bit
+ // after keyboard startup, or else they will not work correctly
+ // because of interaction with the USB device state, which
+ // may still be in flux...
+ //
+ // At the moment the only feature that needs this is the
+ // startup song.
+ static bool delayed_tasks_run = false;
+ static uint16_t delayed_task_timer = 0;
+ if (!delayed_tasks_run) {
+ if (!delayed_task_timer) {
+ delayed_task_timer = timer_read();
+ } else if (timer_elapsed(delayed_task_timer) > 300) {
+ audio_startup();
+ delayed_tasks_run = true;
+ }
+ }
+#endif
+
+#if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
+ music_task();
+#endif
+
+#ifdef KEY_OVERRIDE_ENABLE
+ key_override_task();
+#endif
+
+#ifdef SEQUENCER_ENABLE
+ sequencer_task();
#endif
+#ifdef TAP_DANCE_ENABLE
+ tap_dance_task();
+#endif
+
+#ifdef COMBO_ENABLE
+ combo_task();
+#endif
+
+#ifdef WPM_ENABLE
+ decay_wpm();
+#endif
+
+#ifdef HAPTIC_ENABLE
+ haptic_task();
+#endif
+
+#ifdef DIP_SWITCH_ENABLE
+ dip_switch_read(false);
+#endif
+
+#ifdef AUTO_SHIFT_ENABLE
+ autoshift_matrix_scan();
+#endif
+}
+
+/** \brief Keyboard task: Do keyboard routine jobs
+ *
+ * Do routine keyboard jobs:
+ *
+ * * scan matrix
+ * * handle mouse movements
+ * * handle midi commands
+ * * light LEDs
+ *
+ * This is repeatedly called as fast as possible.
+ */
+void keyboard_task(void) {
+ bool matrix_changed = matrix_scan_task();
+ (void)matrix_changed;
+
+ quantum_task();
+
#if defined(RGBLIGHT_ENABLE)
rgblight_task();
#endif
@@ -453,7 +553,7 @@ MATRIX_LOOP_END:
#endif
#ifdef ENCODER_ENABLE
- encoders_changed = encoder_read();
+ bool encoders_changed = encoder_read();
if (encoders_changed) last_encoder_activity_trigger();
#endif
@@ -516,22 +616,5 @@ MATRIX_LOOP_END:
programmable_button_send();
#endif
- // update LED
- if (led_status != host_keyboard_leds()) {
- led_status = host_keyboard_leds();
- keyboard_set_leds(led_status);
- }
-}
-
-/** \brief keyboard set leds
- *
- * FIXME: needs doc
- */
-void keyboard_set_leds(uint8_t leds) {
- if (debug_keyboard) {
- debug("keyboard_set_led: ");
- debug_hex8(leds);
- debug("\n");
- }
- led_set(leds);
+ led_task();
}