From 7060cb7b267e78ba693a77a3346c77c2d4209b01 Mon Sep 17 00:00:00 2001 From: precondition <57645186+precondition@users.noreply.github.com> Date: Thu, 23 Jun 2022 20:43:24 +0200 Subject: Refactor steno and add `STENO_PROTOCOL = [all|txbolt|geminipr]` (#17065) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactor steno into STENO_ENABLE_[ALL|GEMINI|BOLT] * Update stenography documentation * STENO_ENABLE_TXBOLT → STENO_ENABLE_BOLT TXBOLT is a better name but BOLT is more consistent with the pre-existing TX Bolt related constants, which all drop the "TX " prefix * Comments * STENO_ENABLE_[GEMINI|BOLT|ALL] → STENO_PROTOCOL = [geminipr|txbolt|all] * Add note on lacking V-USB support * Clear chord at the end of the switch(mode){send_steno_chord} block * Return true if NOEVENT * update_chord_xxx → add_xxx_key_to_chord * Enable the defines for all the protocols if STENO_PROTOCOL = all * Mention how to use `steno_set_mode` * Set the default steno protocol to "all" This is done so that existing keymaps invoking `steno_set_mode` don't all suddenly break * Add data driver equivalents for stenography feature * Document format of serial steno packets (Thanks dnaq) * Add missing comma --- quantum/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/keyboard.c') diff --git a/quantum/keyboard.c b/quantum/keyboard.c index a65f9d6d18..8273299a9a 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -381,7 +381,7 @@ void keyboard_init(void) { #ifdef ENCODER_ENABLE encoder_init(); #endif -#ifdef STENO_ENABLE +#ifdef STENO_ENABLE_ALL steno_init(); #endif #ifdef POINTING_DEVICE_ENABLE -- cgit v1.2.3 From 5f32690cba8789c1ac98e71cb8ae8a4b6a5ee2d2 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 21 Jul 2022 10:16:44 -0700 Subject: Move Pointing Device Initialization (#17740) Move Pointing Device Initialization to after Split Post Initialization If both pointing device and split is enabled, the pointing device init needs to be called after the split post init, otherwise the connection (serial/etc) isn't initialized yet, and any commands that need to send data over (such as calling the set cpi command) never get sent over. --- quantum/keyboard.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'quantum/keyboard.c') diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 8273299a9a..2364e3167b 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -384,9 +384,6 @@ void keyboard_init(void) { #ifdef STENO_ENABLE_ALL steno_init(); #endif -#ifdef POINTING_DEVICE_ENABLE - pointing_device_init(); -#endif #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) keymap_config.nkro = 1; eeconfig_update_keymap(keymap_config.raw); @@ -403,6 +400,10 @@ void keyboard_init(void) { #ifdef SPLIT_KEYBOARD split_post_init(); #endif +#ifdef POINTING_DEVICE_ENABLE + // init after split init + pointing_device_init(); +#endif #if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE) debug_enable = true; -- cgit v1.2.3 From f27b617f36d55ac5469247016a1b79304f892366 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Sat, 6 Aug 2022 12:51:13 +0200 Subject: [Core] Process all changed keys in one scan loop, deprecate `QMK_KEYS_PER_SCAN` (#15292) --- quantum/keyboard.c | 138 ++++++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 64 deletions(-) (limited to 'quantum/keyboard.c') diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 2364e3167b..1c62a43d9d 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -212,6 +212,12 @@ static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) { return false; } +#else + +static inline bool has_ghost_in_row(uint8_t row, matrix_row_t rowdata) { + return false; +} + #endif /** \brief matrix_setup @@ -426,64 +432,74 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) { #endif } -/** \brief Perform scan of keyboard matrix +/** + * @brief Generates a tick event at a maximum rate of 1KHz that drives the + * internal QMK state machine. + */ +static inline void generate_tick_event(void) { + static uint16_t last_tick = 0; + const uint16_t now = timer_read(); + if (TIMER_DIFF_16(now, last_tick) != 0) { + action_exec(TICK_EVENT); + last_tick = now; + } +} + +/** + * @brief This task scans the keyboards matrix and processes any key presses + * that occur. * - * Any detected changes in state are sent out as part of the processing + * @return true Matrix did change + * @return false Matrix didn't change */ -bool matrix_scan_task(void) { - static matrix_row_t matrix_prev[MATRIX_ROWS]; - matrix_row_t matrix_row = 0; - matrix_row_t matrix_change = 0; -#ifdef QMK_KEYS_PER_SCAN - uint8_t keys_processed = 0; -#endif +static bool matrix_task(void) { + static matrix_row_t matrix_previous[MATRIX_ROWS]; - uint8_t matrix_changed = matrix_scan(); - if (matrix_changed) last_matrix_activity_trigger(); + matrix_scan(); - for (uint8_t r = 0; r < MATRIX_ROWS; r++) { - matrix_row = matrix_get_row(r); - matrix_change = matrix_row ^ matrix_prev[r]; - if (matrix_change) { -#ifdef MATRIX_HAS_GHOST - if (has_ghost_in_row(r, matrix_row)) { - continue; - } -#endif - if (debug_matrix) matrix_print(); - matrix_row_t col_mask = 1; - for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) { - if (matrix_change & col_mask) { - if (should_process_keypress()) { - action_exec((keyevent_t){ - .key = (keypos_t){.row = r, .col = c}, .pressed = (matrix_row & col_mask), .time = (timer_read() | 1) /* time should not be 0 */ - }); - } - // record a processed key - matrix_prev[r] ^= col_mask; - - switch_events(r, c, (matrix_row & col_mask)); - -#ifdef QMK_KEYS_PER_SCAN - // only jump out if we have processed "enough" keys. - if (++keys_processed >= QMK_KEYS_PER_SCAN) -#endif - // process a key per task call - goto MATRIX_LOOP_END; + bool matrix_changed = false; + for (uint8_t row = 0; row < MATRIX_ROWS && !matrix_changed; row++) { + matrix_changed |= matrix_previous[row] ^ matrix_get_row(row); + } + + matrix_scan_perf_task(); + + // Short-circuit the complete matrix processing if it is not necessary + if (!matrix_changed) { + generate_tick_event(); + return matrix_changed; + } + + if (debug_config.matrix) { + matrix_print(); + } + + const bool process_keypress = should_process_keypress(); + + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + const matrix_row_t current_row = matrix_get_row(row); + const matrix_row_t row_changes = current_row ^ matrix_previous[row]; + + if (!row_changes || has_ghost_in_row(row, current_row)) { + continue; + } + + matrix_row_t col_mask = 1; + for (uint8_t col = 0; col < MATRIX_COLS; col++, col_mask <<= 1) { + if (row_changes & col_mask) { + const bool key_pressed = current_row & col_mask; + + if (process_keypress) { + action_exec(MAKE_KEYEVENT(row, col, key_pressed)); } + + switch_events(row, col, key_pressed); } } - } - // call with pseudo tick event when no real key event. -#ifdef QMK_KEYS_PER_SCAN - // we can get here with some keys processed now. - if (!keys_processed) -#endif - action_exec(TICK_EVENT); -MATRIX_LOOP_END: + matrix_previous[row] = current_row; + } - matrix_scan_perf_task(); return matrix_changed; } @@ -562,20 +578,12 @@ void quantum_task(void) { #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. - */ +/** \brief Main task that is repeatedly called as fast as possible. */ void keyboard_task(void) { - bool matrix_changed = matrix_scan_task(); - (void)matrix_changed; + const bool matrix_changed = matrix_task(); + if (matrix_changed) { + last_matrix_activity_trigger(); + } quantum_task(); @@ -597,8 +605,10 @@ void keyboard_task(void) { #endif #ifdef ENCODER_ENABLE - bool encoders_changed = encoder_read(); - if (encoders_changed) last_encoder_activity_trigger(); + const bool encoders_changed = encoder_read(); + if (encoders_changed) { + last_encoder_activity_trigger(); + } #endif #ifdef OLED_ENABLE -- cgit v1.2.3