From 04719c774d895d0cec3bcbe69291d32916280b08 Mon Sep 17 00:00:00 2001 From: Evgenii Vilkov Date: Wed, 31 May 2023 20:46:03 +0200 Subject: Fix backlight sync on suspend_power_down for split keyboards (#21079) --- quantum/quantum.c | 2 +- quantum/split_common/transactions.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum') diff --git a/quantum/quantum.c b/quantum/quantum.c index 091cf298f7..fe3e85720d 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -468,7 +468,7 @@ void suspend_power_down_quantum(void) { #ifndef NO_SUSPEND_POWER_DOWN // Turn off backlight # ifdef BACKLIGHT_ENABLE - backlight_set(0); + backlight_level_noeeprom(0); # endif # ifdef LED_MATRIX_ENABLE diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c index b3c80f1194..8cd018a6ec 100644 --- a/quantum/split_common/transactions.c +++ b/quantum/split_common/transactions.c @@ -412,7 +412,7 @@ static void backlight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t uint8_t backlight_level = split_shmem->backlight_level; split_shared_memory_unlock(); - backlight_set(backlight_level); + backlight_level_noeeprom(backlight_level); } # define TRANSACTIONS_BACKLIGHT_MASTER() TRANSACTION_HANDLER_MASTER(backlight) -- cgit v1.2.3 From a4ed6ad0f5ccbbf1b497dc03ba64820bdaaa8957 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 2 Jun 2023 02:25:08 +1000 Subject: Unicodemap keycodes rename (#21092) --- quantum/quantum_keycodes.h | 4 ++-- quantum/quantum_keycodes_legacy.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'quantum') diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index f931b7e4c7..d3249bd455 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -179,10 +179,10 @@ #define QK_UNICODE_GET_CODE_POINT(kc) ((kc)&0x7FFF) // UNICODEMAP_ENABLE - Allows Unicode input up to 0x10FFFF, requires unicode_map -#define X(i) (QK_UNICODEMAP | ((i)&0x3FFF)) +#define UM(i) (QK_UNICODEMAP | ((i)&0x3FFF)) #define QK_UNICODEMAP_GET_INDEX(kc) ((kc)&0x3FFF) -#define XP(i, j) (QK_UNICODEMAP_PAIR | ((i)&0x7F) | (((j)&0x7F) << 7)) // 127 max i and j +#define UP(i, j) (QK_UNICODEMAP_PAIR | ((i)&0x7F) | (((j)&0x7F) << 7)) // 127 max i and j #define QK_UNICODEMAP_PAIR_GET_UNSHIFTED_INDEX(kc) ((kc)&0x7F) #define QK_UNICODEMAP_PAIR_GET_SHIFTED_INDEX(kc) (((kc) >> 7) & 0x7F) diff --git a/quantum/quantum_keycodes_legacy.h b/quantum/quantum_keycodes_legacy.h index 120c98bc62..ad078cdad5 100644 --- a/quantum/quantum_keycodes_legacy.h +++ b/quantum/quantum_keycodes_legacy.h @@ -53,3 +53,6 @@ #define GUI_ON QK_MAGIC_GUI_ON #define GUI_OFF QK_MAGIC_GUI_OFF #define GUI_TOG QK_MAGIC_TOGGLE_GUI + +#define X(i) UM(i) +#define XP(i, j) UM(i, j) -- cgit v1.2.3 From c754f644dcccc44e09a3e6f9986ad70ec2fc3b54 Mon Sep 17 00:00:00 2001 From: Ariane Emory <97994360+ariane-emory@users.noreply.github.com> Date: Fri, 2 Jun 2023 17:46:04 -0400 Subject: [Core] Move dynamic macro "stop recording" logic to a function (#21108) --- quantum/process_keycode/process_dynamic_macro.c | 117 +++++++++++++----------- quantum/process_keycode/process_dynamic_macro.h | 1 + 2 files changed, 63 insertions(+), 55 deletions(-) (limited to 'quantum') diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c index bf6af566e2..a022949d3d 100644 --- a/quantum/process_keycode/process_dynamic_macro.c +++ b/quantum/process_keycode/process_dynamic_macro.c @@ -151,6 +151,67 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin *macro_end = macro_pointer; } +/* Both macros use the same buffer but read/write on different + * ends of it. + * + * Macro1 is written left-to-right starting from the beginning of + * the buffer. + * + * Macro2 is written right-to-left starting from the end of the + * buffer. + * + * ¯o_buffer macro_end + * v v + * +------------------------------------------------------------+ + * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| + * +------------------------------------------------------------+ + * ^ ^ + * r_macro_end r_macro_buffer + * + * During the recording when one macro encounters the end of the + * other macro, the recording is stopped. Apart from this, there + * are no arbitrary limits for the macros' length in relation to + * each other: for example one can either have two medium sized + * macros or one long macro and one short macro. Or even one empty + * and one using the whole buffer. + */ +static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; + +/* Pointer to the first buffer element after the first macro. + * Initially points to the very beginning of the buffer since the + * macro is empty. */ +static keyrecord_t *macro_end = macro_buffer; + +/* The other end of the macro buffer. Serves as the beginning of + * the second macro. */ +static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; + +/* Like macro_end but for the second macro. */ +static keyrecord_t *r_macro_end = r_macro_buffer; + +/* A persistent pointer to the current macro position (iterator) + * used during the recording. */ +static keyrecord_t *macro_pointer = NULL; + +/* 0 - no macro is being recorded right now + * 1,2 - either macro 1 or 2 is being recorded */ +static uint8_t macro_id = 0; + +/** + * If a dynamic macro is currently being recorded, stop recording. + */ +void dynamic_macro_stop_recording(void) { + switch (macro_id) { + case 1: + dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); + break; + case 2: + dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); + break; + } + macro_id = 0; +} + /* Handle the key events related to the dynamic macros. Should be * called from process_record_user() like this: * @@ -162,52 +223,6 @@ void dynamic_macro_record_end(keyrecord_t *macro_buffer, keyrecord_t *macro_poin * } */ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { - /* Both macros use the same buffer but read/write on different - * ends of it. - * - * Macro1 is written left-to-right starting from the beginning of - * the buffer. - * - * Macro2 is written right-to-left starting from the end of the - * buffer. - * - * ¯o_buffer macro_end - * v v - * +------------------------------------------------------------+ - * |>>>>>> MACRO1 >>>>>> <<<<<<<<<<<<< MACRO2 <<<<<<<<<<<<<| - * +------------------------------------------------------------+ - * ^ ^ - * r_macro_end r_macro_buffer - * - * During the recording when one macro encounters the end of the - * other macro, the recording is stopped. Apart from this, there - * are no arbitrary limits for the macros' length in relation to - * each other: for example one can either have two medium sized - * macros or one long macro and one short macro. Or even one empty - * and one using the whole buffer. - */ - static keyrecord_t macro_buffer[DYNAMIC_MACRO_SIZE]; - - /* Pointer to the first buffer element after the first macro. - * Initially points to the very beginning of the buffer since the - * macro is empty. */ - static keyrecord_t *macro_end = macro_buffer; - - /* The other end of the macro buffer. Serves as the beginning of - * the second macro. */ - static keyrecord_t *const r_macro_buffer = macro_buffer + DYNAMIC_MACRO_SIZE - 1; - - /* Like macro_end but for the second macro. */ - static keyrecord_t *r_macro_end = r_macro_buffer; - - /* A persistent pointer to the current macro position (iterator) - * used during the recording. */ - static keyrecord_t *macro_pointer = NULL; - - /* 0 - no macro is being recorded right now - * 1,2 - either macro 1 or 2 is being recorded */ - static uint8_t macro_id = 0; - if (macro_id == 0) { /* No macro recording in progress. */ if (!record->event.pressed) { @@ -238,15 +253,7 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed ^ (keycode != QK_DYNAMIC_MACRO_RECORD_STOP)) { /* Ignore the initial release * just after the recording * starts for DM_RSTP. */ - switch (macro_id) { - case 1: - dynamic_macro_record_end(macro_buffer, macro_pointer, +1, ¯o_end); - break; - case 2: - dynamic_macro_record_end(r_macro_buffer, macro_pointer, -1, &r_macro_end); - break; - } - macro_id = 0; + dynamic_macro_stop_recording(); } return false; #ifdef DYNAMIC_MACRO_NO_NESTING diff --git a/quantum/process_keycode/process_dynamic_macro.h b/quantum/process_keycode/process_dynamic_macro.h index ab70726897..9841254af4 100644 --- a/quantum/process_keycode/process_dynamic_macro.h +++ b/quantum/process_keycode/process_dynamic_macro.h @@ -39,3 +39,4 @@ void dynamic_macro_record_start_user(int8_t direction); void dynamic_macro_play_user(int8_t direction); void dynamic_macro_record_key_user(int8_t direction, keyrecord_t *record); void dynamic_macro_record_end_user(int8_t direction); +void dynamic_macro_stop_recording(void); -- cgit v1.2.3 From edaf6654143fdd2dffaaa9c3ba8db1c9b282b5d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Sun, 4 Jun 2023 03:11:54 +0200 Subject: [Enhancement] Decouple autocorrect logic (#21116) --- quantum/process_keycode/process_autocorrect.c | 19 ++++++++++++++++++- quantum/process_keycode/process_autocorrect.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'quantum') diff --git a/quantum/process_keycode/process_autocorrect.c b/quantum/process_keycode/process_autocorrect.c index 1376788266..7c9cb814e5 100644 --- a/quantum/process_keycode/process_autocorrect.c +++ b/quantum/process_keycode/process_autocorrect.c @@ -57,7 +57,7 @@ void autocorrect_toggle(void) { } /** - * @brief handler for determining if autocorrect should process keypress + * @brief handler for user to override whether autocorrect should process this keypress * * @param keycode Keycode registered by matrix press, per keymap * @param record keyrecord_t structure @@ -67,6 +67,23 @@ void autocorrect_toggle(void) { * @return false Stop processing and escape from autocorrect. */ __attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) { + return process_autocorrect_default_handler(keycode, record, typo_buffer_size, mods); +} + +/** + * @brief fallback handler for determining if autocorrect should process this keypress + * can be used by user callback to get the basic keycode being "wrapped" + * + * NOTE: These values may have been edited by user callback before getting here + * + * @param keycode Keycode registered by matrix press, per keymap + * @param record keyrecord_t structure + * @param typo_buffer_size passed along to allow resetting of autocorrect buffer + * @param mods allow processing of mod status + * @return true Allow autocorection + * @return false Stop processing and escape from autocorrect. + */ +bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) { // See quantum_keycodes.h for reference on these matched ranges. switch (*keycode) { // Exclude these keycodes from processing. diff --git a/quantum/process_keycode/process_autocorrect.h b/quantum/process_keycode/process_autocorrect.h index c7596107e5..00dacbf958 100644 --- a/quantum/process_keycode/process_autocorrect.h +++ b/quantum/process_keycode/process_autocorrect.h @@ -9,6 +9,7 @@ bool process_autocorrect(uint16_t keycode, keyrecord_t *record); bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods); +bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods); bool apply_autocorrect(uint8_t backspaces, const char *str); bool autocorrect_is_enabled(void); -- cgit v1.2.3 From 0c0cabe3f5a27f62aa5c93a2e88e322114fc75b9 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Mon, 5 Jun 2023 06:17:38 +0100 Subject: Remove quantum/keymap.h (#21086) --- quantum/keymap.h | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 quantum/keymap.h (limited to 'quantum') diff --git a/quantum/keymap.h b/quantum/keymap.h deleted file mode 100644 index a067e1aa36..0000000000 --- a/quantum/keymap.h +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2012-2016 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#pragma once - -#pragma message("'keymap.h' should no longer be included!") -- cgit v1.2.3 From fd1e638c28128601725e84eb4739128301ecfb3c Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Thu, 8 Jun 2023 04:12:49 +0800 Subject: Use unsigned integer for mousekey kinetic speed (#21151) --- quantum/mousekey.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'quantum') diff --git a/quantum/mousekey.c b/quantum/mousekey.c index df8aa613be..ede055dc8f 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -74,7 +74,7 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX; uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10; /* milliseconds between repeated motion events (0-255) */ # ifdef MK_KINETIC_SPEED -float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; +uint16_t mk_wheel_interval = 1000U / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; # else uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL; # endif @@ -190,37 +190,37 @@ const uint16_t mk_decelerated_speed = MOUSEKEY_DECELERATED_SPEED; const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED; static uint8_t move_unit(void) { - float speed = mk_initial_speed; + uint16_t speed = mk_initial_speed; if (mousekey_accel & ((1 << 0) | (1 << 2))) { speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed; } else if (mousekey_repeat && mouse_timer) { - const float time_elapsed = timer_elapsed(mouse_timer) / 50; - speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed; + const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50; + speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed; speed = speed > mk_base_speed ? mk_base_speed : speed; } /* convert speed to USB mouse speed 1 to 127 */ - speed = (uint8_t)(speed / (1000.0f / mk_interval)); + speed = (uint8_t)(speed / (1000U / mk_interval)); speed = speed < 1 ? 1 : speed; return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed; } static uint8_t wheel_unit(void) { - float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; + uint16_t speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; if (mousekey_accel & ((1 << 0) | (1 << 2))) { speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS; } else if (mousekey_wheel_repeat && mouse_timer) { if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) { - const float time_elapsed = timer_elapsed(mouse_timer) / 50; - speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed; + const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50; + speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed; } speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed; } - mk_wheel_interval = 1000.0f / speed; + mk_wheel_interval = 1000U / speed; return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1; } -- cgit v1.2.3 From 90ea9e447adb16151974c8d29c18bbb140bde9dc Mon Sep 17 00:00:00 2001 From: dexter93 Date: Thu, 8 Jun 2023 04:01:45 +0300 Subject: Reset `matrix_need_update` properly in eager debouncing algorithms (#21154) The `matrix_need_update` variable needs to be reset to `false` in `transfer_matrix_values()`, otherwise that function continues to be invoked for every scanning loop (forever with `sym_eager_pk` and `sym_eager_pk`, or until some key gets released with `asym_eager_defer_pk`), and the scanning rate gets much lower because of all that useless work. Co-authored-by: Sergey Vlasov --- quantum/debounce/asym_eager_defer_pk.c | 2 ++ quantum/debounce/sym_eager_pk.c | 1 + quantum/debounce/sym_eager_pr.c | 1 + 3 files changed, 4 insertions(+) (limited to 'quantum') diff --git a/quantum/debounce/asym_eager_defer_pk.c b/quantum/debounce/asym_eager_defer_pk.c index 4745c6f465..0f7640a80c 100644 --- a/quantum/debounce/asym_eager_defer_pk.c +++ b/quantum/debounce/asym_eager_defer_pk.c @@ -144,6 +144,8 @@ static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { debounce_counter_t *debounce_pointer = debounce_counters; + matrix_need_update = false; + for (uint8_t row = 0; row < num_rows; row++) { matrix_row_t delta = raw[row] ^ cooked[row]; for (uint8_t col = 0; col < MATRIX_COLS; col++) { diff --git a/quantum/debounce/sym_eager_pk.c b/quantum/debounce/sym_eager_pk.c index f736d1645c..15360441de 100644 --- a/quantum/debounce/sym_eager_pk.c +++ b/quantum/debounce/sym_eager_pk.c @@ -125,6 +125,7 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { // upload from raw_matrix to final matrix; static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + matrix_need_update = false; debounce_counter_t *debounce_pointer = debounce_counters; for (uint8_t row = 0; row < num_rows; row++) { matrix_row_t delta = raw[row] ^ cooked[row]; diff --git a/quantum/debounce/sym_eager_pr.c b/quantum/debounce/sym_eager_pr.c index aad5ca351b..84f897d674 100644 --- a/quantum/debounce/sym_eager_pr.c +++ b/quantum/debounce/sym_eager_pr.c @@ -119,6 +119,7 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) { // upload from raw_matrix to final matrix; static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) { + matrix_need_update = false; debounce_counter_t *debounce_pointer = debounce_counters; for (uint8_t row = 0; row < num_rows; row++) { matrix_row_t existing_row = cooked[row]; -- cgit v1.2.3 From 806b61c2f71c085de73a93493a6624b5699d63cc Mon Sep 17 00:00:00 2001 From: Xelus22 <17491233+Xelus22@users.noreply.github.com> Date: Fri, 9 Jun 2023 10:00:22 +1000 Subject: [Core] RGB matrix ws2812 update (#21135) * ws2812_update boolean to stop update every single cycle * lint1 Co-authored-by: Joel Challis * lint2 Co-authored-by: Joel Challis * Update quantum/rgb_matrix/rgb_matrix_drivers.c --------- Co-authored-by: Joel Challis --- quantum/rgb_matrix/rgb_matrix_drivers.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'quantum') diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index d66fc801dd..6de20ac8a5 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -426,11 +426,17 @@ const rgb_matrix_driver_t rgb_matrix_driver = { // LED color buffer LED_TYPE rgb_matrix_ws2812_array[RGB_MATRIX_LED_COUNT]; +bool ws2812_dirty = false; -static void init(void) {} +static void init(void) { + ws2812_dirty = false; +} static void flush(void) { - ws2812_setleds(rgb_matrix_ws2812_array, RGB_MATRIX_LED_COUNT); + if (ws2812_dirty) { + ws2812_setleds(rgb_matrix_ws2812_array, RGB_MATRIX_LED_COUNT); + ws2812_dirty = false; + } } // Set an led in the buffer to a color @@ -448,6 +454,11 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { } # endif + if (rgb_matrix_ws2812_array[i].r == r && rgb_matrix_ws2812_array[i].g == g && rgb_matrix_ws2812_array[i].b == b) { + return; + } + + ws2812_dirty = true; rgb_matrix_ws2812_array[i].r = r; rgb_matrix_ws2812_array[i].g = g; rgb_matrix_ws2812_array[i].b = b; -- cgit v1.2.3 From 3444e9656d031bf23d78b0a4ab56d84ed0f10757 Mon Sep 17 00:00:00 2001 From: Albert Y <76888457+filterpaper@users.noreply.github.com> Date: Sun, 11 Jun 2023 14:55:03 +0800 Subject: Refactor the rain lighting decision operator (#21139) --- quantum/rgb_matrix/animations/pixel_rain_anim.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'quantum') diff --git a/quantum/rgb_matrix/animations/pixel_rain_anim.h b/quantum/rgb_matrix/animations/pixel_rain_anim.h index 9d63f451e2..26cd73b578 100644 --- a/quantum/rgb_matrix/animations/pixel_rain_anim.h +++ b/quantum/rgb_matrix/animations/pixel_rain_anim.h @@ -16,13 +16,9 @@ static bool PIXEL_RAIN(effect_params_t* params) { if (!HAS_ANY_FLAGS(g_led_config.flags[led_index], params->flags)) { return; } - if (random8() & 2) { - rgb_matrix_set_color(led_index, 0, 0, 0); - } else { - HSV hsv = {random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v}; - RGB rgb = rgb_matrix_hsv_to_rgb(hsv); - rgb_matrix_set_color(led_index, rgb.r, rgb.g, rgb.b); - } + HSV hsv = (random8() & 2) ? (HSV){0, 0, 0} : (HSV){random8(), random8_min_max(127, 255), rgb_matrix_config.hsv.v}; + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(led_index, rgb.r, rgb.g, rgb.b); wait_timer = g_rgb_timer + interval(); } -- cgit v1.2.3 From 6c7c5889ca04959c3ce2448d6ca07545b9811e4d Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 15 Jun 2023 13:48:19 +1000 Subject: Rely on introspection to handle OOB access. (#21247) --- quantum/dynamic_keymap.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'quantum') diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index 90a0f20838..2030c82a1b 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -152,22 +152,13 @@ void dynamic_keymap_reset(void) { for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) { for (int row = 0; row < MATRIX_ROWS; row++) { for (int column = 0; column < MATRIX_COLS; column++) { - if (layer < keymap_layer_count()) { - dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column)); - } else { - dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT); - } + dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column)); } } #ifdef ENCODER_MAP_ENABLE for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) { - if (layer < encodermap_layer_count()) { - dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true)); - dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false)); - } else { - dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT); - dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT); - } + dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true)); + dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false)); } #endif // ENCODER_MAP_ENABLE } -- cgit v1.2.3 From 5542f5ede1356df387dfb10587f2d74e40fa62a8 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 27 Jun 2023 09:15:33 +1000 Subject: Get rid of `USB_LED_KANA` and `USB_LED_COMPOSE` (#21366) --- quantum/led.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'quantum') diff --git a/quantum/led.h b/quantum/led.h index b9ad7ed9ae..d9a132bbaa 100644 --- a/quantum/led.h +++ b/quantum/led.h @@ -26,8 +26,6 @@ along with this program. If not, see . #define USB_LED_NUM_LOCK 0 #define USB_LED_CAPS_LOCK 1 #define USB_LED_SCROLL_LOCK 2 -#define USB_LED_COMPOSE 3 -#define USB_LED_KANA 4 #ifdef __cplusplus extern "C" { -- cgit v1.2.3 From 7ff80a57cbe57e888646c3b90e2f4f9dea977156 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 3 Jul 2023 04:24:22 +1000 Subject: Get rid of `USB_LED_SCROLL_LOCK` (#21405) --- quantum/action.c | 12 ++++++------ quantum/led.h | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'quantum') diff --git a/quantum/action.c b/quantum/action.c index a45e70c557..84ecf6da9a 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -882,7 +882,7 @@ __attribute__((weak)) void register_code(uint8_t code) { } else if (KC_LOCKING_CAPS_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE // Resync: ignore if caps lock already is on - if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return; + if (host_keyboard_led_state().caps_lock) return; # endif add_key(KC_CAPS_LOCK); send_keyboard_report(); @@ -892,7 +892,7 @@ __attribute__((weak)) void register_code(uint8_t code) { } else if (KC_LOCKING_NUM_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE - if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return; + if (host_keyboard_led_state().num_lock) return; # endif add_key(KC_NUM_LOCK); send_keyboard_report(); @@ -902,7 +902,7 @@ __attribute__((weak)) void register_code(uint8_t code) { } else if (KC_LOCKING_SCROLL_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE - if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return; + if (host_keyboard_led_state().scroll_lock) return; # endif add_key(KC_SCROLL_LOCK); send_keyboard_report(); @@ -952,7 +952,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) { } else if (KC_LOCKING_CAPS_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE // Resync: ignore if caps lock already is off - if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return; + if (!host_keyboard_led_state().caps_lock) return; # endif add_key(KC_CAPS_LOCK); send_keyboard_report(); @@ -961,7 +961,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) { } else if (KC_LOCKING_NUM_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE - if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return; + if (!host_keyboard_led_state().num_lock) return; # endif add_key(KC_NUM_LOCK); send_keyboard_report(); @@ -970,7 +970,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) { } else if (KC_LOCKING_SCROLL_LOCK == code) { # ifdef LOCKING_RESYNC_ENABLE - if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return; + if (!host_keyboard_led_state().scroll_lock) return; # endif add_key(KC_SCROLL_LOCK); send_keyboard_report(); diff --git a/quantum/led.h b/quantum/led.h index d9a132bbaa..197f2618be 100644 --- a/quantum/led.h +++ b/quantum/led.h @@ -25,7 +25,6 @@ along with this program. If not, see . /* keyboard LEDs */ #define USB_LED_NUM_LOCK 0 #define USB_LED_CAPS_LOCK 1 -#define USB_LED_SCROLL_LOCK 2 #ifdef __cplusplus extern "C" { -- cgit v1.2.3 From 9ab16e62f75dc6228549ec0aba00ec0704bbc779 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 3 Jul 2023 04:35:41 +1000 Subject: Get rid of `USB_LED_NUM_LOCK` (#21424) --- quantum/led.h | 1 - 1 file changed, 1 deletion(-) (limited to 'quantum') diff --git a/quantum/led.h b/quantum/led.h index 197f2618be..679e743396 100644 --- a/quantum/led.h +++ b/quantum/led.h @@ -23,7 +23,6 @@ along with this program. If not, see . /* FIXME: Add doxygen comments here. */ /* keyboard LEDs */ -#define USB_LED_NUM_LOCK 0 #define USB_LED_CAPS_LOCK 1 #ifdef __cplusplus -- cgit v1.2.3 From c4f66e5d6e57d2100a8d3a08758075c470f04767 Mon Sep 17 00:00:00 2001 From: Xelus22 <17491233+Xelus22@users.noreply.github.com> Date: Mon, 3 Jul 2023 08:56:48 +1000 Subject: [Core] RGB Matrix limit basic indicators to the last render (#21169) Co-authored-by: Joel Challis --- quantum/led_matrix/led_matrix.c | 5 ++++- quantum/led_matrix/led_matrix.h | 3 ++- quantum/rgb_matrix/rgb_matrix.c | 5 ++++- quantum/rgb_matrix/rgb_matrix.h | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) (limited to 'quantum') diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index 828d61641a..4b692d1904 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -366,7 +366,10 @@ void led_matrix_task(void) { case RENDERING: led_task_render(effect); if (effect) { - led_matrix_indicators(); + // Only run the basic indicators in the last render iteration (default there are 5 iterations) + if (led_effect_params.iter == LED_MATRIX_LED_PROCESS_MAX_ITERATIONS) { + led_matrix_indicators(); + } led_matrix_indicators_advanced(&led_effect_params); } break; diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h index c7d360f366..9091f6890b 100644 --- a/quantum/led_matrix/led_matrix.h +++ b/quantum/led_matrix/led_matrix.h @@ -42,8 +42,9 @@ #endif #ifndef LED_MATRIX_LED_PROCESS_LIMIT -# define LED_MATRIX_LED_PROCESS_LIMIT (LED_MATRIX_LED_COUNT + 4) / 5 +# define LED_MATRIX_LED_PROCESS_LIMIT ((LED_MATRIX_LED_COUNT + 4) / 5) #endif +#define LED_MATRIX_LED_PROCESS_MAX_ITERATIONS ((LED_MATRIX_LED_COUNT + LED_MATRIX_LED_PROCESS_LIMIT - 1) / LED_MATRIX_LED_PROCESS_LIMIT) #if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < LED_MATRIX_LED_COUNT # if defined(LED_MATRIX_SPLIT) diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 1f3912cf7e..1680389793 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -428,7 +428,10 @@ void rgb_matrix_task(void) { case RENDERING: rgb_task_render(effect); if (effect) { - rgb_matrix_indicators(); + // Only run the basic indicators in the last render iteration (default there are 5 iterations) + if (rgb_effect_params.iter == RGB_MATRIX_LED_PROCESS_MAX_ITERATIONS) { + rgb_matrix_indicators(); + } rgb_matrix_indicators_advanced(&rgb_effect_params); } break; diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index 9ea248b66d..83851d8995 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -49,8 +49,9 @@ #endif #ifndef RGB_MATRIX_LED_PROCESS_LIMIT -# define RGB_MATRIX_LED_PROCESS_LIMIT (RGB_MATRIX_LED_COUNT + 4) / 5 +# define RGB_MATRIX_LED_PROCESS_LIMIT ((RGB_MATRIX_LED_COUNT + 4) / 5) #endif +#define RGB_MATRIX_LED_PROCESS_MAX_ITERATIONS ((RGB_MATRIX_LED_COUNT + RGB_MATRIX_LED_PROCESS_LIMIT - 1) / RGB_MATRIX_LED_PROCESS_LIMIT) #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT # if defined(RGB_MATRIX_SPLIT) -- cgit v1.2.3 From 87b11345a55d076966846d87b60d0f315b8bb984 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 6 Jul 2023 18:48:02 +1000 Subject: Get rid of `USB_LED_CAPS_LOCK` (#21436) --- quantum/led.c | 6 +++--- quantum/led.h | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'quantum') diff --git a/quantum/led.c b/quantum/led.c index 42144566fd..8d86374a6f 100644 --- a/quantum/led.c +++ b/quantum/led.c @@ -153,14 +153,14 @@ __attribute__((weak)) void led_set(uint8_t usb_led) { /** \brief Trigger behaviour on transition to suspend */ void led_suspend(void) { - uint8_t leds_off = 0; + led_t leds_off = {0}; #ifdef BACKLIGHT_CAPS_LOCK if (is_backlight_enabled()) { // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off - leds_off |= (1 << USB_LED_CAPS_LOCK); + leds_off.caps_lock = true; } #endif - led_set(leds_off); + led_set(leds_off.raw); } /** \brief Trigger behaviour on transition from suspend diff --git a/quantum/led.h b/quantum/led.h index 679e743396..b9fad670ae 100644 --- a/quantum/led.h +++ b/quantum/led.h @@ -22,9 +22,6 @@ along with this program. If not, see . /* FIXME: Add doxygen comments here. */ -/* keyboard LEDs */ -#define USB_LED_CAPS_LOCK 1 - #ifdef __cplusplus extern "C" { #endif -- cgit v1.2.3 From e9ff66d8ad341917ff270c9f33b83d86fe0fb6c4 Mon Sep 17 00:00:00 2001 From: Chris Salch Date: Fri, 7 Jul 2023 06:52:24 -0500 Subject: Adds a way to separate tab from AUTO_SHIFT_SPECIAL. (#20996) --- quantum/process_keycode/process_auto_shift.c | 10 +++++++++- quantum/process_keycode/process_auto_shift.h | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'quantum') diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c index 62c347ae0c..63e893fc18 100644 --- a/quantum/process_keycode/process_auto_shift.c +++ b/quantum/process_keycode/process_auto_shift.c @@ -75,7 +75,15 @@ __attribute__((weak)) bool get_auto_shifted_key(uint16_t keycode, keyrecord_t *r case AUTO_SHIFT_NUMERIC: # endif # ifndef NO_AUTO_SHIFT_SPECIAL - case AUTO_SHIFT_SPECIAL: +# ifndef NO_AUTO_SHIFT_TAB + case KC_TAB: +# endif +# ifndef NO_AUTO_SHIFT_SYMBOLS + case AUTO_SHIFT_SYMBOLS: +# endif +# endif +# ifdef AUTO_SHIFT_ENTER + case KC_ENT: # endif return true; } diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h index 66a4b3138a..780177d2ff 100644 --- a/quantum/process_keycode/process_auto_shift.h +++ b/quantum/process_keycode/process_auto_shift.h @@ -28,10 +28,14 @@ // clang-format off #define AUTO_SHIFT_ALPHA KC_A ... KC_Z #define AUTO_SHIFT_NUMERIC KC_1 ... KC_0 +#define AUTO_SHIFT_SYMBOLS \ + KC_MINUS ... KC_SLASH: \ + case KC_NONUS_BACKSLASH + +// Kept to avoid breaking existing keymaps. #define AUTO_SHIFT_SPECIAL \ KC_TAB: \ - case KC_MINUS ... KC_SLASH: \ - case KC_NONUS_BACKSLASH + case AUTO_SHIFT_SYMBOLS // clang-format on bool process_auto_shift(uint16_t keycode, keyrecord_t *record); -- cgit v1.2.3 From 55295ed3dc5000d4c9937602624060c168753434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Fri, 7 Jul 2023 16:13:15 +0200 Subject: [Enhancement] More info on `apply_autocorrect` (#21056) Co-authored-by: Drashna Jaelre --- quantum/process_keycode/process_autocorrect.c | 55 +++++++++++++++++++++++++-- quantum/process_keycode/process_autocorrect.h | 3 +- 2 files changed, 54 insertions(+), 4 deletions(-) (limited to 'quantum') diff --git a/quantum/process_keycode/process_autocorrect.c b/quantum/process_keycode/process_autocorrect.c index 7c9cb814e5..cc1f19e4f9 100644 --- a/quantum/process_keycode/process_autocorrect.c +++ b/quantum/process_keycode/process_autocorrect.c @@ -1,5 +1,6 @@ // Copyright 2021 Google LLC // Copyright 2021 @filterpaper +// Copyright 2023 Pablo Martinez (@elpekenin) // SPDX-License-Identifier: Apache-2.0 // Original source: https://getreuer.info/posts/keyboards/autocorrection @@ -174,10 +175,12 @@ bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, * * @param backspaces number of characters to remove * @param str pointer to PROGMEM string to replace mistyped seletion with + * @param typo the wrong string that triggered a correction + * @param correct what it would become after the changes * @return true apply correction * @return false user handled replacement */ -__attribute__((weak)) bool apply_autocorrect(uint8_t backspaces, const char *str) { +__attribute__((weak)) bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct) { return true; } @@ -301,11 +304,57 @@ bool process_autocorrect(uint16_t keycode, keyrecord_t *record) { if (code & 128) { // A typo was found! Apply autocorrect. const uint8_t backspaces = (code & 63) + !record->event.pressed; - if (apply_autocorrect(backspaces, (char const *)(autocorrect_data + state + 1))) { + const char * changes = (const char *)(autocorrect_data + state + 1); + + /* Gather info about the typo'd word + * + * Since buffer may contain several words, delimited by spaces, we + * iterate from the end to find the start and length of the typo + */ + char typo[AUTOCORRECT_MAX_LENGTH + 1] = {0}; // extra char for null terminator + + uint8_t typo_len = 0; + uint8_t typo_start = 0; + bool space_last = typo_buffer[typo_buffer_size - 1] == KC_SPC; + for (uint8_t i = typo_buffer_size; i > 0; --i) { + // stop counting after finding space (unless it is the last thing) + if (typo_buffer[i - 1] == KC_SPC && i != typo_buffer_size) { + typo_start = i; + break; + } + + ++typo_len; + } + + // when detecting 'typo:', reduce the length of the string by one + if (space_last) { + --typo_len; + } + + // convert buffer of keycodes into a string + for (uint8_t i = 0; i < typo_len; ++i) { + typo[i] = typo_buffer[typo_start + i] - KC_A + 'a'; + } + + /* Gather the corrected word + * + * A) Correction of 'typo:' -- Code takes into account + * an extra backspace to delete the space (which we dont copy) + * for this reason the offset is correct to "skip" the null terminator + * + * B) When correcting 'typo' -- Need extra offset for terminator + */ + char correct[AUTOCORRECT_MAX_LENGTH + 10] = {0}; // let's hope this is big enough + + uint8_t offset = space_last ? backspaces : backspaces + 1; + strcpy(correct, typo); + strcpy_P(correct + typo_len - offset, changes); + + if (apply_autocorrect(backspaces, changes, typo, correct)) { for (uint8_t i = 0; i < backspaces; ++i) { tap_code(KC_BSPC); } - send_string_P((char const *)(autocorrect_data + state + 1)); + send_string_P(changes); } if (keycode == KC_SPC) { diff --git a/quantum/process_keycode/process_autocorrect.h b/quantum/process_keycode/process_autocorrect.h index 00dacbf958..9cc7d46a8b 100644 --- a/quantum/process_keycode/process_autocorrect.h +++ b/quantum/process_keycode/process_autocorrect.h @@ -1,5 +1,6 @@ // Copyright 2021 Google LLC // Copyright 2021 @filterpaper +// Copyright 2023 Pablo Martinez (@elpekenin) // SPDX-License-Identifier: Apache-2.0 // Original source: https://getreuer.info/posts/keyboards/autocorrection @@ -10,7 +11,7 @@ bool process_autocorrect(uint16_t keycode, keyrecord_t *record); bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods); bool process_autocorrect_default_handler(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods); -bool apply_autocorrect(uint8_t backspaces, const char *str); +bool apply_autocorrect(uint8_t backspaces, const char *str, char *typo, char *correct); bool autocorrect_is_enabled(void); void autocorrect_enable(void); -- cgit v1.2.3 From 1abf8f3e8b8a9b358be3c27867f9bee7422507f3 Mon Sep 17 00:00:00 2001 From: precondition <57645186+precondition@users.noreply.github.com> Date: Fri, 7 Jul 2023 16:18:02 +0200 Subject: [Feature] Send a dummy keycode to neutralize flashing modifiers in retro tap and key overrides (#20992) --- quantum/action.c | 7 +++++++ quantum/action_util.c | 25 +++++++++++++++++++++++++ quantum/action_util.h | 13 +++++++++++++ quantum/process_keycode/process_key_override.c | 9 +++++++++ 4 files changed, 54 insertions(+) (limited to 'quantum') diff --git a/quantum/action.c b/quantum/action.c index 84ecf6da9a..6368f7398c 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -528,6 +528,13 @@ void process_action(keyrecord_t *record, action_t action) { unregister_code(action.key.code); } else { ac_dprintf("MODS_TAP: No tap: add_mods\n"); +# if defined(RETRO_TAPPING) && defined(DUMMY_MOD_NEUTRALIZER_KEYCODE) + // Send a dummy keycode to neutralize flashing modifiers + // if the key was held and then released with no interruptions. + if (retro_tapping_counter == 2) { + neutralize_flashing_modifiers(get_mods()); + } +# endif unregister_mods(mods); } } diff --git a/quantum/action_util.c b/quantum/action_util.c index 361f410d2d..909dea0595 100644 --- a/quantum/action_util.c +++ b/quantum/action_util.c @@ -500,3 +500,28 @@ __attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) { uint8_t has_anymod(void) { return bitpop(real_mods); } + +#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE +/** \brief Send a dummy keycode in between the register and unregister event of a modifier key, to neutralize the "flashing modifiers" phenomenon. + * + * \param active_mods 8-bit packed bit-array describing the currently active modifiers (in the format GASCGASC). + * + * Certain QMK features like key overrides or retro tap must unregister a previously + * registered modifier before sending another keycode but this can trigger undesired + * keyboard shortcuts if the clean tap of a single modifier key is bound to an action + * on the host OS, as is for example the case for the left GUI key on Windows, which + * opens the Start Menu when tapped. + */ +void neutralize_flashing_modifiers(uint8_t active_mods) { + // In most scenarios, the flashing modifiers phenomenon is a problem + // only for a subset of modifier masks. + const static uint8_t mods_to_neutralize[] = MODS_TO_NEUTRALIZE; + const static uint8_t n_mods = ARRAY_SIZE(mods_to_neutralize); + for (uint8_t i = 0; i < n_mods; ++i) { + if (active_mods == mods_to_neutralize[i]) { + tap_code(DUMMY_MOD_NEUTRALIZER_KEYCODE); + break; + } + } +} +#endif diff --git a/quantum/action_util.h b/quantum/action_util.h index 02f6e9e6df..831caf3c0a 100644 --- a/quantum/action_util.h +++ b/quantum/action_util.h @@ -102,6 +102,19 @@ void use_oneshot_swaphands(void); void clear_oneshot_swaphands(void); #endif +#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE +// KC_A is used as the lowerbound instead of QK_BASIC because the range QK_BASIC...KC_A includes +// internal keycodes like KC_NO and KC_TRANSPARENT which are unsuitable for use with `tap_code(kc)`. +# if !(KC_A <= DUMMY_MOD_NEUTRALIZER_KEYCODE && DUMMY_MOD_NEUTRALIZER_KEYCODE <= QK_BASIC_MAX) +# error "DUMMY_MOD_NEUTRALIZER_KEYCODE must be a basic, unmodified, HID keycode!" +# endif +void neutralize_flashing_modifiers(uint8_t active_mods); +#endif +#ifndef MODS_TO_NEUTRALIZE +# define MODS_TO_NEUTRALIZE \ + { MOD_BIT(KC_LEFT_ALT), MOD_BIT(KC_LEFT_GUI) } +#endif + #ifdef __cplusplus } #endif diff --git a/quantum/process_keycode/process_key_override.c b/quantum/process_keycode/process_key_override.c index 17e490e67a..de628d3fec 100644 --- a/quantum/process_keycode/process_key_override.c +++ b/quantum/process_keycode/process_key_override.c @@ -322,6 +322,15 @@ static bool try_activating_override(const uint16_t keycode, const uint8_t layer, clear_active_override(false); +#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE + // Send a dummy keycode before unregistering the modifier(s) + // so that suppressing the modifier(s) doesn't falsely get interpreted + // by the host OS as a tap of a modifier key. + // For example, unintended activations of the start menu on Windows when + // using a GUI+ key override with suppressed mods. + neutralize_flashing_modifiers(active_mods); +#endif + active_override = override; active_override_trigger_is_down = true; -- cgit v1.2.3 From 2264e6d26b17dccd511d29e06c00cc4c193abd95 Mon Sep 17 00:00:00 2001 From: mechlovin <57231893+mechlovin@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:24:29 +0700 Subject: add VIA support for LED Matrix (#21281) --- quantum/via.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- quantum/via.h | 14 +++++++++ 2 files changed, 111 insertions(+), 2 deletions(-) (limited to 'quantum') diff --git a/quantum/via.c b/quantum/via.c index c54e37a175..f4293dacd4 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -31,7 +31,7 @@ #include "eeprom.h" #include "version.h" // for QMK_BUILDDATE used in EEPROM magic -#if defined(RGB_MATRIX_ENABLE) +#if (defined(RGB_MATRIX_ENABLE) || defined(LED_MATRIX_ENABLE)) # include #endif @@ -141,6 +141,9 @@ __attribute__((weak)) void via_set_device_indication(uint8_t value) { #if defined(RGB_MATRIX_ENABLE) rgb_matrix_toggle_noeeprom(); #endif // RGB_MATRIX_ENABLE +#if defined(LED_MATRIX_ENABLE) + led_matrix_toggle_noeeprom(); +#endif // LED_MATRIX_ENABLE #if defined(AUDIO_ENABLE) if (value == 0) { wait_ms(10); @@ -194,6 +197,7 @@ __attribute__((weak)) void via_custom_value_command_kb(uint8_t *data, uint8_t le // id_qmk_backlight_channel -> via_qmk_backlight_command() // id_qmk_rgblight_channel -> via_qmk_rgblight_command() // id_qmk_rgb_matrix_channel -> via_qmk_rgb_matrix_command() +// id_qmk_led_matrix_channel -> via_qmk_led_matrix_command() // id_qmk_audio_channel -> via_qmk_audio_command() // __attribute__((weak)) void via_custom_value_command(uint8_t *data, uint8_t length) { @@ -219,7 +223,14 @@ __attribute__((weak)) void via_custom_value_command(uint8_t *data, uint8_t lengt via_qmk_rgb_matrix_command(data, length); return; } -#endif // RGBLIGHT_ENABLE +#endif // RGB_MATRIX_ENABLE + +#if defined(LED_MATRIX_ENABLE) + if (*channel_id == id_qmk_led_matrix_channel) { + via_qmk_led_matrix_command(data, length); + return; + } +#endif // LED_MATRIX_ENABLE #if defined(AUDIO_ENABLE) if (*channel_id == id_qmk_audio_channel) { @@ -692,6 +703,90 @@ void via_qmk_rgb_matrix_save(void) { #endif // RGB_MATRIX_ENABLE +#if defined(LED_MATRIX_ENABLE) + +# if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX +# undef LED_MATRIX_MAXIMUM_BRIGHTNESS +# define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX +# endif + +void via_qmk_led_matrix_command(uint8_t *data, uint8_t length) { + // data = [ command_id, channel_id, value_id, value_data ] + uint8_t *command_id = &(data[0]); + uint8_t *value_id_and_data = &(data[2]); + + switch (*command_id) { + case id_custom_set_value: { + via_qmk_led_matrix_set_value(value_id_and_data); + break; + } + case id_custom_get_value: { + via_qmk_led_matrix_get_value(value_id_and_data); + break; + } + case id_custom_save: { + via_qmk_led_matrix_save(); + break; + } + default: { + *command_id = id_unhandled; + break; + } + } +} + +void via_qmk_led_matrix_get_value(uint8_t *data) { + // data = [ value_id, value_data ] + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + + switch (*value_id) { + case id_qmk_led_matrix_brightness: { + value_data[0] = ((uint16_t)led_matrix_get_val() * UINT8_MAX) / LED_MATRIX_MAXIMUM_BRIGHTNESS; + break; + } + case id_qmk_led_matrix_effect: { + value_data[0] = led_matrix_is_enabled() ? led_matrix_get_mode() : 0; + break; + } + case id_qmk_led_matrix_effect_speed: { + value_data[0] = led_matrix_get_speed(); + break; + } + } +} + +void via_qmk_led_matrix_set_value(uint8_t *data) { + // data = [ value_id, value_data ] + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + switch (*value_id) { + case id_qmk_led_matrix_brightness: { + led_matrix_set_val_noeeprom(scale8(value_data[0], LED_MATRIX_MAXIMUM_BRIGHTNESS)); + break; + } + case id_qmk_led_matrix_effect: { + if (value_data[0] == 0) { + led_matrix_disable_noeeprom(); + } else { + led_matrix_enable_noeeprom(); + led_matrix_mode_noeeprom(value_data[0]); + } + break; + } + case id_qmk_led_matrix_effect_speed: { + led_matrix_set_speed_noeeprom(value_data[0]); + break; + } + } +} + +void via_qmk_led_matrix_save(void) { + eeconfig_update_led_matrix(); +} + +#endif // LED_MATRIX_ENABLE + #if defined(AUDIO_ENABLE) extern audio_config_t audio_config; diff --git a/quantum/via.h b/quantum/via.h index ab4eb05028..6c8465b81e 100644 --- a/quantum/via.h +++ b/quantum/via.h @@ -109,6 +109,7 @@ enum via_channel_id { id_qmk_rgblight_channel = 2, id_qmk_rgb_matrix_channel = 3, id_qmk_audio_channel = 4, + id_qmk_led_matrix_channel = 5, }; enum via_qmk_backlight_value { @@ -130,6 +131,12 @@ enum via_qmk_rgb_matrix_value { id_qmk_rgb_matrix_color = 4, }; +enum via_qmk_led_matrix_value { + id_qmk_led_matrix_brightness = 1, + id_qmk_led_matrix_effect = 2, + id_qmk_led_matrix_effect_speed = 3, +}; + enum via_qmk_audio_value { id_qmk_audio_enable = 1, id_qmk_audio_clicky_enable = 2, @@ -182,6 +189,13 @@ void via_qmk_rgb_matrix_get_value(uint8_t *data); void via_qmk_rgb_matrix_save(void); #endif +#if defined(LED_MATRIX_ENABLE) +void via_qmk_led_matrix_command(uint8_t *data, uint8_t length); +void via_qmk_led_matrix_set_value(uint8_t *data); +void via_qmk_led_matrix_get_value(uint8_t *data); +void via_qmk_led_matrix_save(void); +#endif + #if defined(AUDIO_ENABLE) void via_qmk_audio_command(uint8_t *data, uint8_t length); void via_qmk_audio_set_value(uint8_t *data); -- cgit v1.2.3 From df5984022faf248c4fc4d05fcc4c50304baaab97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Fri, 7 Jul 2023 22:26:06 +0800 Subject: Refactor kinetic mouse key feature (#21164) --- quantum/mousekey.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'quantum') diff --git a/quantum/mousekey.c b/quantum/mousekey.c index ede055dc8f..aaaf7fff22 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -175,7 +175,7 @@ static uint8_t wheel_unit(void) { /* * Kinetic movement acceleration algorithm * - * current speed = I + A * T/50 + A * 0.5 * T^2 | maximum B + * current speed = I + A * T/50 + A * (T/50)^2 * 1/2 | maximum B * * T: time since the mouse movement started * E: mouse events per second (set through MOUSEKEY_INTERVAL, UHK sends 250, the @@ -192,37 +192,46 @@ const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED; static uint8_t move_unit(void) { uint16_t speed = mk_initial_speed; - if (mousekey_accel & ((1 << 0) | (1 << 2))) { - speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed; + if (mousekey_accel & (1 << 0)) { + speed = mk_decelerated_speed; + } else if (mousekey_accel & (1 << 2)) { + speed = mk_accelerated_speed; } else if (mousekey_repeat && mouse_timer) { const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50; - speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed; - - speed = speed > mk_base_speed ? mk_base_speed : speed; + speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + (MOUSEKEY_MOVE_DELTA * time_elapsed * time_elapsed) / 2; + if (speed > mk_base_speed) { + speed = mk_base_speed; + } } - /* convert speed to USB mouse speed 1 to 127 */ speed = (uint8_t)(speed / (1000U / mk_interval)); - speed = speed < 1 ? 1 : speed; - return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed; + if (speed > MOUSEKEY_MOVE_MAX) { + speed = MOUSEKEY_MOVE_MAX; + } else if (speed < 1) { + speed = 1; + } + return speed; } static uint8_t wheel_unit(void) { uint16_t speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS; - if (mousekey_accel & ((1 << 0) | (1 << 2))) { - speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS; + if (mousekey_accel & (1 << 0)) { + speed = MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS; + } else if (mousekey_accel & (1 << 2)) { + speed = MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS; } else if (mousekey_wheel_repeat && mouse_timer) { if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) { const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50; - speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed; + speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + (1 * time_elapsed * time_elapsed) / 2; + } + if (speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS) { + speed = MOUSEKEY_WHEEL_BASE_MOVEMENTS; } - speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed; } mk_wheel_interval = 1000U / speed; - - return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1; + return 1; } # endif /* #ifndef MK_KINETIC_SPEED */ -- cgit v1.2.3 From 0035ed67627919ac332b096afa97469bd8e73756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Fri, 7 Jul 2023 22:35:22 +0800 Subject: Set minimum middle column value (#21365) --- quantum/rgb_matrix/animations/pixel_fractal_anim.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'quantum') diff --git a/quantum/rgb_matrix/animations/pixel_fractal_anim.h b/quantum/rgb_matrix/animations/pixel_fractal_anim.h index 875b4ceb3d..4cd1d9b861 100644 --- a/quantum/rgb_matrix/animations/pixel_fractal_anim.h +++ b/quantum/rgb_matrix/animations/pixel_fractal_anim.h @@ -7,7 +7,11 @@ RGB_MATRIX_EFFECT(PIXEL_FRACTAL) # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS static bool PIXEL_FRACTAL(effect_params_t* params) { -# define MID_COL MATRIX_COLS / 2 +# if MATRIX_COLS < 2 +# define MID_COL 1 +# else +# define MID_COL MATRIX_COLS / 2 +# endif static bool led[MATRIX_ROWS][MID_COL]; static uint32_t wait_timer = 0; -- cgit v1.2.3 From e648b84da3db022ba308163f21c3cf8165c45e09 Mon Sep 17 00:00:00 2001 From: Jake Grossman Date: Fri, 7 Jul 2023 09:40:09 -0500 Subject: Allow key override to respect weak mods caused by caps word (#21434) --- quantum/quantum.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'quantum') diff --git a/quantum/quantum.c b/quantum/quantum.c index fe3e85720d..c6a40a4baa 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -310,15 +310,15 @@ bool process_record_quantum(keyrecord_t *record) { #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) process_music(keycode, record) && #endif +#ifdef CAPS_WORD_ENABLE + process_caps_word(keycode, record) && +#endif #ifdef KEY_OVERRIDE_ENABLE process_key_override(keycode, record) && #endif #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif -#ifdef CAPS_WORD_ENABLE - process_caps_word(keycode, record) && -#endif #if defined(UNICODE_COMMON_ENABLE) process_unicode_common(keycode, record) && #endif -- cgit v1.2.3 From a8a87a0922a33d38ed80165ee62f9dc35bd08a3d Mon Sep 17 00:00:00 2001 From: Pascal Getreuer <50221757+getreuer@users.noreply.github.com> Date: Fri, 7 Jul 2023 08:47:16 -0600 Subject: [Core] Simplify audio_duration_to_ms() and audio_ms_to_duration(), reduce firmware size by a few bytes. (#21427) --- quantum/audio/audio.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'quantum') diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index 2570ad9cd1..0300483a93 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -547,20 +547,39 @@ void audio_decrease_tempo(uint8_t tempo_change) { note_tempo -= tempo_change; } -// TODO in the int-math version are some bugs; songs sometimes abruptly end - maybe an issue with the timer/system-tick wrapping around? +/** + * Converts from units of 1/64ths of a beat to milliseconds. + * + * Round-off error is at most 1 millisecond. + * + * Conversion will never overflow for duration_bpm <= 699, provided that + * note_tempo is at least 10. This is quite a long duration, over ten beats. + * + * Beware that for duration_bpm > 699, the result may overflow uint16_t range + * when duration_bpm is large compared to note_tempo: + * + * duration_bpm * 60 * 1000 / (64 * note_tempo) > UINT16_MAX + * + * duration_bpm > (2 * 65535 / 1875) * note_tempo + * = 69.904 * note_tempo. + */ uint16_t audio_duration_to_ms(uint16_t duration_bpm) { -#if defined(__AVR__) - // doing int-math saves us some bytes in the overall firmware size, but the intermediate result is less accurate before being cast to/returned as uint - return ((uint32_t)duration_bpm * 60 * 1000) / (64 * note_tempo); - // NOTE: beware of uint16_t overflows when note_tempo is low and/or the duration is long -#else - return ((float)duration_bpm * 60) / (64 * note_tempo) * 1000; -#endif + return ((uint32_t)duration_bpm * 1875) / ((uint_fast16_t)note_tempo * 2); } + +/** + * Converts from units of milliseconds to 1/64ths of a beat. + * + * Round-off error is at most 1/64th of a beat. + * + * This conversion never overflows: since duration_ms <= UINT16_MAX = 65535 + * and note_tempo <= 255, the result is always in uint16_t range: + * + * duration_ms * 64 * note_tempo / 60 / 1000 + * <= 65535 * 2 * 255 / 1875 + * = 17825.52 + * <= UINT16_MAX. + */ uint16_t audio_ms_to_duration(uint16_t duration_ms) { -#if defined(__AVR__) - return ((uint32_t)duration_ms * 64 * note_tempo) / 60 / 1000; -#else - return ((float)duration_ms * 64 * note_tempo) / 60 / 1000; -#endif + return ((uint32_t)duration_ms * 2 * note_tempo) / 1875; } -- cgit v1.2.3 From 9b3ac793bca14dc5efd424ba28324937b7bed40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=BC=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=83=91=E3=83=BC?= <76888457+filterpaper@users.noreply.github.com> Date: Fri, 7 Jul 2023 22:50:21 +0800 Subject: Refactor times inverse of sqrt 2 calculation (#21293) --- quantum/mousekey.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'quantum') diff --git a/quantum/mousekey.c b/quantum/mousekey.c index aaaf7fff22..c982a2f40b 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -25,11 +25,16 @@ #include "mousekey.h" static inline int8_t times_inv_sqrt2(int8_t x) { - // 181/256 is pretty close to 1/sqrt(2) - // 0.70703125 0.707106781 - // 1 too small for x=99 and x=198 - // This ends up being a mult and discard lower 8 bits - return (x * 181) >> 8; + // 181/256 (0.70703125) is used as an approximation for 1/sqrt(2) + // because it is close to the exact value which is 0.707106781 + const int16_t n = x * 181; + const uint16_t d = 256; + + // To ensure that the integer result is rounded accurately after + // division, check the sign of the numerator: + // If negative, subtract half of the denominator before dividing + // Otherwise, add half of the denominator before dividing + return n < 0 ? (n - d / 2) / d : (n + d / 2) / d; } static report_mouse_t mouse_report = {0}; -- cgit v1.2.3 From d13925be9abe02438f3c74ffcbc65ce74dde3de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Mart=C3=ADnez?= <58857054+elpekenin@users.noreply.github.com> Date: Fri, 7 Jul 2023 16:51:19 +0200 Subject: [Bugfix] Check `NULL` pointers on QP (#20481) --- quantum/painter/lvgl/qp_lvgl.c | 2 +- quantum/painter/qp.c | 29 ++++++++++++++++++++++------- quantum/painter/qp_comms.c | 8 ++++---- quantum/painter/qp_draw_circle.c | 2 +- quantum/painter/qp_draw_core.c | 6 +++--- quantum/painter/qp_draw_ellipse.c | 2 +- quantum/painter/qp_draw_image.c | 6 +++--- quantum/painter/qp_draw_text.c | 8 ++++---- 8 files changed, 39 insertions(+), 24 deletions(-) (limited to 'quantum') diff --git a/quantum/painter/lvgl/qp_lvgl.c b/quantum/painter/lvgl/qp_lvgl.c index 6cc0061d73..280aeaf91f 100644 --- a/quantum/painter/lvgl/qp_lvgl.c +++ b/quantum/painter/lvgl/qp_lvgl.c @@ -61,7 +61,7 @@ bool qp_lvgl_attach(painter_device_t device) { qp_lvgl_detach(); painter_driver_t *driver = (painter_driver_t *)device; - if (!driver->validate_ok) { + if (!driver || !driver->validate_ok) { qp_dprintf("qp_lvgl_attach: fail (validation_ok == false)\n"); qp_lvgl_detach(); return false; diff --git a/quantum/paint