From 71b5341ee052aecbdc7f2f95b56f250c0ce8eb1a Mon Sep 17 00:00:00 2001 From: joseamirandavelez Date: Sun, 25 Oct 2026 02:49:05 -0400 Subject: [PATCH 1/6] Add Q5 Pro ANSI encoder host lighting keymap Num Lock and Caps Lock stay solid white while a host streams colors. VIA no longer echoes those frames. The board links with Keychron debounce only, and the keyboard EEPROM header is included the same way as on the V3 Max. Co-authored-by: Cursor --- .../q5_pro/ansi_encoder/keymaps/rgbj/keymap.c | 198 ++++++++++++++++++ .../keymaps/rgbj/rgb_matrix_user.inc | 11 + .../q5_pro/ansi_encoder/keymaps/rgbj/rules.mk | 3 + keyboards/keychron/q5_pro/config.h | 2 + keyboards/keychron/q5_pro/q5_pro.c | 13 ++ keyboards/keychron/q5_pro/rules.mk | 7 + 6 files changed, 234 insertions(+) create mode 100644 keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c create mode 100644 keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/rgb_matrix_user.inc create mode 100644 keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/rules.mk diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c new file mode 100644 index 000000000000..6eab4bc8b1b6 --- /dev/null +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c @@ -0,0 +1,198 @@ +/* Copyright 2023 @ Keychron (https://www.keychron.com) + * Copyright 2026 José A Miranda Velez + * + * 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. + */ + +#include QMK_KEYBOARD_H +#include "raw_hid.h" + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [MAC_BASE] = LAYOUT_102_ansi( + KC_ESC, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_DEL, KC_F13, KC_F14, KC_F15, KC_MUTE, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_PGUP, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGDN, KC_P7, KC_P8, KC_P9, KC_PPLS, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_HOME, KC_P4, KC_P5, KC_P6, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT, + KC_LCTL, KC_LOPTN, KC_LCMMD, KC_SPC, KC_RCMMD, MO(MAC_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT ), + [MAC_FN] = LAYOUT_102_ansi( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, RGB_TOG, + _______, BT_HST1, BT_HST2, BT_HST3, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), + [WIN_BASE] = LAYOUT_102_ansi( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_F13, KC_F14, KC_F15, KC_MUTE, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_PGUP, KC_NUM, KC_PSLS, KC_PAST, KC_PMNS, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_PGDN, KC_P7, KC_P8, KC_P9, KC_PPLS, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_HOME, KC_P4, KC_P5, KC_P6, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_P1, KC_P2, KC_P3, KC_PENT, + KC_LCTL, KC_LWIN, KC_LALT, KC_SPC, KC_RALT, MO(WIN_FN), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT, KC_P0, KC_PDOT ), + [WIN_FN] = LAYOUT_102_ansi( + _______, KC_BRID, KC_BRIU, KC_TASK, KC_FILE, RGB_VAD, RGB_VAI, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, _______, _______, RGB_TOG, + _______, BT_HST1, BT_HST2, BT_HST3, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, BAT_LVL, NK_TOGG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), +}; + +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { + [MAC_BASE] = {ENCODER_CCW_CW(KC_VOLD, KC_VOLU)}, + [MAC_FN] = {ENCODER_CCW_CW(RGB_VAD, RGB_VAI)}, + [WIN_BASE] = {ENCODER_CCW_CW(KC_VOLD, KC_VOLU)}, + [WIN_FN] = {ENCODER_CCW_CW(RGB_VAD, RGB_VAI)}, +}; +#endif // ENCODER_MAP_ENABLE +// clang-format on + +/* Host lighting commands. The report id is stripped before we see the packet, + * so byte 0 is the command. Replies put the command back in byte 0. The host + * read includes the report id, so our byte 0 lands in the host's byte 1. */ +enum { + HOST_GET_QMK_VERSION = 0x21, + HOST_GET_PROTOCOL_VERSION = 0x22, + HOST_GET_UNIQUE_IDENTIFIER = 0x23, + HOST_STREAM_RGB_DATA = 0x24, + HOST_MODE_ENABLE = 0x25, + HOST_MODE_DISABLE = 0x26, + HOST_GET_TOTAL_LEDS = 0x27, + HOST_GET_FIRMWARE_TYPE = 0x28, +}; + +enum { + HOST_DEVICE_ERROR_LED_BOUNDS = 253, + HOST_DEVICE_ERROR_LED_COUNT = 254, +}; + +static uint8_t host_packet[32]; + +static void host_reply(uint8_t command, uint8_t b1, uint8_t b2, uint8_t b3) { + memset(host_packet, 0, sizeof(host_packet)); + host_packet[0] = command; + host_packet[1] = b1; + host_packet[2] = b2; + host_packet[3] = b3; + raw_hid_send(host_packet, sizeof(host_packet)); +} + +/* Num Lock is LED 32, Caps Lock is LED 55. While that lock is on, both this + * packet and the indicator task must write the same white. If the packet + * writes the effect colour instead, it lands after the indicator and the key + * flickers. */ +static bool host_lock_led_is_lit(uint8_t led) { +#if defined(NUM_LOCK_INDEX) + if (led == NUM_LOCK_INDEX && host_keyboard_led_state().num_lock) { + return true; + } +#endif +#if defined(CAPS_LOCK_INDEX) && !defined(DIM_CAPS_LOCK) + if (led == CAPS_LOCK_INDEX && host_keyboard_led_state().caps_lock) { + return true; + } +#endif +#if defined(SCROLL_LOCK_INDEX) + if (led == SCROLL_LOCK_INDEX && host_keyboard_led_state().scroll_lock) { + return true; + } +#endif + return false; +} + +static void host_led_streaming(uint8_t *data) { + uint8_t index = data[1]; + uint8_t numberofleds = data[2]; + + if ((uint16_t)index + numberofleds > RGB_MATRIX_LED_COUNT) { + host_reply(HOST_STREAM_RGB_DATA, HOST_DEVICE_ERROR_LED_BOUNDS, 0, 0); + return; + } + if (numberofleds >= 10) { + host_reply(HOST_STREAM_RGB_DATA, HOST_DEVICE_ERROR_LED_COUNT, 0, 0); + return; + } + + for (uint8_t i = 0; i < numberofleds; i++) { + uint8_t led = index + i; + uint8_t offset = (i * 3) + 3; + if (host_lock_led_is_lit(led)) { + rgb_matrix_set_color(led, 255, 255, 255); + } else { + rgb_matrix_set_color(led, data[offset], data[offset + 1], data[offset + 2]); + } + } +} + +bool q5_pro_host_lighting_rx(uint8_t *data, uint8_t length) { + (void)length; + + switch (data[0]) { + case HOST_GET_QMK_VERSION: + host_reply(HOST_GET_QMK_VERSION, 0, 26, 0); + return true; + case HOST_GET_PROTOCOL_VERSION: + host_reply(HOST_GET_PROTOCOL_VERSION, 1, 0, 6); + return true; + case HOST_GET_UNIQUE_IDENTIFIER: + host_reply(HOST_GET_UNIQUE_IDENTIFIER, 0, 0, 0); + return true; + case HOST_STREAM_RGB_DATA: + /* No reply. A reply is just our own frame echoed back, and the host + * would answer that with another frame. */ + host_led_streaming(data); + return true; + case HOST_MODE_ENABLE: + rgb_matrix_enable_noeeprom(); + rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_HOSTLIGHT); + return true; + case HOST_MODE_DISABLE: + rgb_matrix_reload_from_eeprom(); + return true; + case HOST_GET_TOTAL_LEDS: + host_reply(HOST_GET_TOTAL_LEDS, RGB_MATRIX_LED_COUNT, 0, 0); + return true; + case HOST_GET_FIRMWARE_TYPE: + /* 2 is the VIA firmware type the host already accepts. */ + host_reply(HOST_GET_FIRMWARE_TYPE, 2, 0, 0); + return true; + default: + return false; + } +} + +/* Paint the lock keys white on every frame, including while the host is + * streaming. The packet writes the same white, so the key stays solid. */ +void os_state_indicate(void) { +#if defined(NUM_LOCK_INDEX) + if (host_keyboard_led_state().num_lock) { + rgb_matrix_set_color(NUM_LOCK_INDEX, 255, 255, 255); + } +#endif +#if defined(CAPS_LOCK_INDEX) + if (host_keyboard_led_state().caps_lock) { +# if defined(DIM_CAPS_LOCK) + rgb_matrix_set_color(CAPS_LOCK_INDEX, 0, 0, 0); +# else + rgb_matrix_set_color(CAPS_LOCK_INDEX, 255, 255, 255); +# endif + } +#endif +#if defined(SCROLL_LOCK_INDEX) + if (host_keyboard_led_state().scroll_lock) { + rgb_matrix_set_color(SCROLL_LOCK_INDEX, 255, 255, 255); + } +#endif +} diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/rgb_matrix_user.inc b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/rgb_matrix_user.inc new file mode 100644 index 000000000000..04f83bec77a3 --- /dev/null +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/rgb_matrix_user.inc @@ -0,0 +1,11 @@ +RGB_MATRIX_EFFECT(HOSTLIGHT) +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +/* Host frames call rgb_matrix_set_color() themselves. This effect must not + * repaint, or the next flush replaces the frame that just arrived. */ +bool HOSTLIGHT(effect_params_t *params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + return rgb_matrix_check_finished_leds(led_max); +} + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/rules.mk b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/rules.mk new file mode 100644 index 000000000000..8f95cac9f2eb --- /dev/null +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/rules.mk @@ -0,0 +1,3 @@ +VIA_ENABLE = yes +ENCODER_MAP_ENABLE = yes +RGB_MATRIX_CUSTOM_USER = yes diff --git a/keyboards/keychron/q5_pro/config.h b/keyboards/keychron/q5_pro/config.h index da0e1ba5b757..1abd15c4e4d9 100644 --- a/keyboards/keychron/q5_pro/config.h +++ b/keyboards/keychron/q5_pro/config.h @@ -16,6 +16,8 @@ #pragma once +#include "eeconfig_kb.h" + /* turn off effects when suspended */ #define RGB_DISABLE_WHEN_USB_SUSPENDED diff --git a/keyboards/keychron/q5_pro/q5_pro.c b/keyboards/keychron/q5_pro/q5_pro.c index 28c94399d1b4..e029574222b9 100644 --- a/keyboards/keychron/q5_pro/q5_pro.c +++ b/keyboards/keychron/q5_pro/q5_pro.c @@ -283,6 +283,14 @@ void battery_calculte_voltage(uint16_t value) { battery_set_voltage(voltage); } +/* Keymaps that speak the host lighting protocol override this. Stock maps leave it false + * so VIA still owns every other command. */ +__attribute__((weak)) bool q5_pro_host_lighting_rx(uint8_t *data, uint8_t length) { + (void)data; + (void)length; + return false; +} + bool via_command_kb(uint8_t *data, uint8_t length) { switch (data[0]) { #ifdef KC_BLUETOOTH_ENABLE @@ -296,6 +304,11 @@ bool via_command_kb(uint8_t *data, uint8_t length) { break; #endif default: + /* Claim host lighting commands here. If they fall through, VIA echoes the + * packet, and a colour frame (0x24) comes straight back. */ + if (q5_pro_host_lighting_rx(data, length)) { + return true; + } return false; } diff --git a/keyboards/keychron/q5_pro/rules.mk b/keyboards/keychron/q5_pro/rules.mk index f995372f9c4a..db9c4843aa1f 100644 --- a/keyboards/keychron/q5_pro/rules.mk +++ b/keyboards/keychron/q5_pro/rules.mk @@ -1,6 +1,13 @@ +# common.mk compiles Keychron's debounce. Tell QMK not to also link its own. +DEBOUNCE_TYPE = custom + # Enter lower-power sleep mode when on the ChibiOS idle thread OPT_DEFS += -DCORTEX_ENABLE_WFI_IDLE=TRUE OPT_DEFS += -DNO_USB_STARTUP_CHECK -DENABLE_FACTORY_TEST include keyboards/keychron/bluetooth/bluetooth.mk include keyboards/keychron/common/common.mk + +# eeconfig_kb.h includes this header. The language module is optional, but the +# header has to be on the include path or the keyboard does not compile. +VPATH += $(TOP_DIR)/keyboards/keychron/common/language From 87be8edf08cb611ca6cf23be9d70e43201657d01 Mon Sep 17 00:00:00 2001 From: joseamirandavelez Date: Sun, 25 Oct 2026 12:23:40 -0400 Subject: [PATCH 2/6] Keep host lighting selected and smooth onboard speed changes. A streaming host stays on its effect, and a bad color frame no longer replies. Onboard effects advance by elapsed time times speed, so Launcher sliders change the rate without restarting the pattern. Co-authored-by: Cursor --- keyboards/keychron/common/rgb/per_key_rgb.c | 4 +- .../q5_pro/ansi_encoder/keymaps/rgbj/keymap.c | 42 ++++++++---- .../rgb_matrix/animations/breathing_anim.h | 2 +- .../animations/flower_blooming_anim.h | 2 +- .../animations/hue_breathing_anim.h | 2 +- .../animations/jellybean_raindrops_anim.h | 2 +- .../rgb_matrix/animations/raindrops_anim.h | 2 +- .../rgb_matrix/animations/riverflow_anim.h | 3 +- .../animations/runners/effect_runner_dx_dy.h | 2 +- .../runners/effect_runner_dx_dy_dist.h | 2 +- .../animations/runners/effect_runner_i.h | 2 +- .../runners/effect_runner_reactive.h | 5 +- .../runners/effect_runner_reactive_splash.h | 2 +- .../runners/effect_runner_sin_cos_i.h | 2 +- .../animations/solid_reactive_anim.h | 2 +- .../animations/solid_reactive_cross.h | 2 +- .../animations/solid_reactive_nexus.h | 2 +- .../animations/solid_reactive_simple_anim.h | 2 +- .../animations/solid_reactive_wide.h | 2 +- .../rgb_matrix/animations/starlight_anim.h | 4 +- .../animations/starlight_dual_hue_anim.h | 4 +- .../animations/starlight_dual_sat_anim.h | 4 +- quantum/rgb_matrix/rgb_matrix.c | 65 ++++++++++++++----- quantum/rgb_matrix/rgb_matrix.h | 8 +++ 24 files changed, 116 insertions(+), 53 deletions(-) diff --git a/keyboards/keychron/common/rgb/per_key_rgb.c b/keyboards/keychron/common/rgb/per_key_rgb.c index 8cf18af82484..f16b15550442 100644 --- a/keyboards/keychron/common/rgb/per_key_rgb.c +++ b/keyboards/keychron/common/rgb/per_key_rgb.c @@ -42,7 +42,7 @@ bool per_key_rgb_solid(effect_params_t *params) { bool per_key_rgb_breahting(effect_params_t *params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); HSV hsv; - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + uint16_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 8); for (uint8_t i = led_min; i < led_max; i++) { hsv = per_key_led[i]; @@ -116,7 +116,7 @@ static HSV solid_reactive_wide_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dis uint16_t effect = tick + dist * 5; if (effect > 255) effect = 255; # ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE - hsv.h = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 8) >> 4); + hsv.h = rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 8) >> 4); # endif hsv.v = qadd8(hsv.v, 255 - effect); return hsv; diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c index 6eab4bc8b1b6..f786d921a612 100644 --- a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c @@ -73,12 +73,8 @@ enum { HOST_GET_FIRMWARE_TYPE = 0x28, }; -enum { - HOST_DEVICE_ERROR_LED_BOUNDS = 253, - HOST_DEVICE_ERROR_LED_COUNT = 254, -}; - static uint8_t host_packet[32]; +static bool host_lighting_active = false; static void host_reply(uint8_t command, uint8_t b1, uint8_t b2, uint8_t b3) { memset(host_packet, 0, sizeof(host_packet)); @@ -116,12 +112,9 @@ static void host_led_streaming(uint8_t *data) { uint8_t index = data[1]; uint8_t numberofleds = data[2]; - if ((uint16_t)index + numberofleds > RGB_MATRIX_LED_COUNT) { - host_reply(HOST_STREAM_RGB_DATA, HOST_DEVICE_ERROR_LED_BOUNDS, 0, 0); - return; - } - if (numberofleds >= 10) { - host_reply(HOST_STREAM_RGB_DATA, HOST_DEVICE_ERROR_LED_COUNT, 0, 0); + /* Stay silent on a bad frame. A reply uses the colour command, and the + * next handshake can read that leftover report as its answer. */ + if ((uint16_t)index + numberofleds > RGB_MATRIX_LED_COUNT || numberofleds >= 10) { return; } @@ -155,10 +148,12 @@ bool q5_pro_host_lighting_rx(uint8_t *data, uint8_t length) { host_led_streaming(data); return true; case HOST_MODE_ENABLE: + host_lighting_active = true; rgb_matrix_enable_noeeprom(); rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_HOSTLIGHT); return true; case HOST_MODE_DISABLE: + host_lighting_active = false; rgb_matrix_reload_from_eeprom(); return true; case HOST_GET_TOTAL_LEDS: @@ -196,3 +191,28 @@ void os_state_indicate(void) { } #endif } + +/* While a host is streaming, keep its effect selected. The lighting keys and + * the Launcher would otherwise load an onboard effect and the two painters + * flicker against each other. */ +bool rgb_matrix_effect_locked(uint8_t mode) { + return host_lighting_active && mode != RGB_MATRIX_CUSTOM_HOSTLIGHT; +} + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + (void)record; + if (host_lighting_active && IS_RGB_KEYCODE(keycode)) { + return false; + } + return true; +} + +void housekeeping_task_user(void) { + if (!host_lighting_active) { + return; + } + if (!rgb_matrix_is_enabled() || rgb_matrix_get_mode() != RGB_MATRIX_CUSTOM_HOSTLIGHT) { + rgb_matrix_enable_noeeprom(); + rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_HOSTLIGHT); + } +} diff --git a/quantum/rgb_matrix/animations/breathing_anim.h b/quantum/rgb_matrix/animations/breathing_anim.h index ac73a7cd839e..05e3257a8f6b 100644 --- a/quantum/rgb_matrix/animations/breathing_anim.h +++ b/quantum/rgb_matrix/animations/breathing_anim.h @@ -6,7 +6,7 @@ bool BREATHING(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); HSV hsv = rgb_matrix_config.hsv; - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + uint16_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 8); hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); RGB rgb = rgb_matrix_hsv_to_rgb(hsv); for (uint8_t i = led_min; i < led_max; i++) { diff --git a/quantum/rgb_matrix/animations/flower_blooming_anim.h b/quantum/rgb_matrix/animations/flower_blooming_anim.h index 135bff7e7096..4c383e61188f 100644 --- a/quantum/rgb_matrix/animations/flower_blooming_anim.h +++ b/quantum/rgb_matrix/animations/flower_blooming_anim.h @@ -23,7 +23,7 @@ typedef HSV (*flower_blooming_f)(HSV hsv, uint8_t i, uint8_t time); bool effect_runner_bloom(effect_params_t* params, flower_blooming_f effect_func) { RGB_MATRIX_USE_LIMITS(led_min, led_max); - uint8_t time = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed / 10, 1)); + uint8_t time = rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed / 10, 1)); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); if (g_led_config.point[i].y > k_rgb_matrix_center.y) { diff --git a/quantum/rgb_matrix/animations/hue_breathing_anim.h b/quantum/rgb_matrix/animations/hue_breathing_anim.h index 0d9c4d651c75..9e86efe4034f 100644 --- a/quantum/rgb_matrix/animations/hue_breathing_anim.h +++ b/quantum/rgb_matrix/animations/hue_breathing_anim.h @@ -8,7 +8,7 @@ bool HUE_BREATHING(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); uint8_t huedelta = 12; HSV hsv = rgb_matrix_config.hsv; - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + uint16_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 8); hsv.h = hsv.h + scale8(abs8(sin8(time) - 128) * 2, huedelta); RGB rgb = hsv_to_rgb(hsv); for (uint8_t i = led_min; i < led_max; i++) { diff --git a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h index 55ae931d4dec..f9975318cdd4 100644 --- a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h +++ b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h @@ -13,7 +13,7 @@ bool JELLYBEAN_RAINDROPS(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); if (!params->init) { // Change one LED every tick, make sure speed is not 0 - if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { + if (rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { jellybean_raindrops_set_color(random8_max(RGB_MATRIX_LED_COUNT), params); } } else { diff --git a/quantum/rgb_matrix/animations/raindrops_anim.h b/quantum/rgb_matrix/animations/raindrops_anim.h index 57b2219ddd76..acc0b11a42a7 100644 --- a/quantum/rgb_matrix/animations/raindrops_anim.h +++ b/quantum/rgb_matrix/animations/raindrops_anim.h @@ -23,7 +23,7 @@ bool RAINDROPS(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); if (!params->init) { // Change one LED every tick, make sure speed is not 0 - if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { + if (rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { raindrops_set_color(random8_max(RGB_MATRIX_LED_COUNT), params); } } else { diff --git a/quantum/rgb_matrix/animations/riverflow_anim.h b/quantum/rgb_matrix/animations/riverflow_anim.h index bd21e5823221..19a96d028b9c 100644 --- a/quantum/rgb_matrix/animations/riverflow_anim.h +++ b/quantum/rgb_matrix/animations/riverflow_anim.h @@ -8,7 +8,8 @@ bool RIVERFLOW(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); for (uint8_t i = led_min; i < led_max; i++) { HSV hsv = rgb_matrix_config.hsv; - uint16_t time = scale16by8(g_rgb_timer + (i * 315), rgb_matrix_config.speed / 8); + uint8_t scale = rgb_matrix_config.speed / 8; + uint16_t time = rgb_matrix_anim_time(scale) + scale16by8(i * 315, scale); hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); RGB rgb = rgb_matrix_hsv_to_rgb(hsv); RGB_MATRIX_TEST_LED_FLAGS(); diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h index 0469ed1c1ba4..277e9a165d1e 100644 --- a/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h +++ b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy.h @@ -5,7 +5,7 @@ typedef HSV (*dx_dy_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t time); bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) { RGB_MATRIX_USE_LIMITS(led_min, led_max); - uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 2); + uint8_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 2); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h index a5dd84f6401a..f78d30148792 100644 --- a/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h +++ b/quantum/rgb_matrix/animations/runners/effect_runner_dx_dy_dist.h @@ -5,7 +5,7 @@ typedef HSV (*dx_dy_dist_f)(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint8 bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func) { RGB_MATRIX_USE_LIMITS(led_min, led_max); - uint8_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 2); + uint8_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 2); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); int16_t dx = g_led_config.point[i].x - k_rgb_matrix_center.x; diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_i.h b/quantum/rgb_matrix/animations/runners/effect_runner_i.h index 49147149940c..34362ef356d7 100644 --- a/quantum/rgb_matrix/animations/runners/effect_runner_i.h +++ b/quantum/rgb_matrix/animations/runners/effect_runner_i.h @@ -5,7 +5,7 @@ typedef HSV (*i_f)(HSV hsv, uint8_t i, uint8_t time); bool effect_runner_i(effect_params_t* params, i_f effect_func) { RGB_MATRIX_USE_LIMITS(led_min, led_max); - uint8_t time = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed / 4, 1)); + uint8_t time = rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed / 4, 1)); for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time)); diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h b/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h index baca2fbc5490..b1eeb8f3cd71 100644 --- a/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h +++ b/quantum/rgb_matrix/animations/runners/effect_runner_reactive.h @@ -7,7 +7,7 @@ typedef HSV (*reactive_f)(HSV hsv, uint16_t offset); bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { RGB_MATRIX_USE_LIMITS(led_min, led_max); - uint16_t max_tick = 65535 / qadd8(rgb_matrix_config.speed, 1); + uint16_t max_tick = 255; for (uint8_t i = led_min; i < led_max; i++) { RGB_MATRIX_TEST_LED_FLAGS(); uint16_t tick = max_tick; @@ -19,8 +19,7 @@ bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) { } } - uint16_t offset = scale16by8(tick, qadd8(rgb_matrix_config.speed, 1)); - RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, offset)); + RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, tick)); rgb_matrix_region_set_color(params->region, i, rgb.r, rgb.g, rgb.b); } return rgb_matrix_check_finished_leds(led_max); diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h b/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h index 8e549e32fcdd..b2d5fdef8b13 100644 --- a/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h +++ b/quantum/rgb_matrix/animations/runners/effect_runner_reactive_splash.h @@ -16,7 +16,7 @@ bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, react int16_t dx = g_led_config.point[i].x - g_last_hit_tracker.x[j]; int16_t dy = g_led_config.point[i].y - g_last_hit_tracker.y[j]; uint8_t dist = sqrt16(dx * dx + dy * dy); - uint16_t tick = scale16by8(g_last_hit_tracker.tick[j], qadd8(rgb_matrix_config.speed, 1)); + uint16_t tick = g_last_hit_tracker.tick[j]; hsv = effect_func(hsv, dx, dy, dist, tick); } hsv.v = scale8(hsv.v, rgb_matrix_config.hsv.v); diff --git a/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h b/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h index 27cd9f4d022e..21b71bc1267f 100644 --- a/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h +++ b/quantum/rgb_matrix/animations/runners/effect_runner_sin_cos_i.h @@ -5,7 +5,7 @@ typedef HSV (*sin_cos_i_f)(HSV hsv, int8_t sin, int8_t cos, uint8_t i, uint8_t t bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) { RGB_MATRIX_USE_LIMITS(led_min, led_max); - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 4); + uint16_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 4); int8_t cos_value = cos8(time) - 128; int8_t sin_value = sin8(time) - 128; for (uint8_t i = led_min; i < led_max; i++) { diff --git a/quantum/rgb_matrix/animations/solid_reactive_anim.h b/quantum/rgb_matrix/animations/solid_reactive_anim.h index edf604135031..412bfe5e3314 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_anim.h +++ b/quantum/rgb_matrix/animations/solid_reactive_anim.h @@ -5,7 +5,7 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE) static HSV SOLID_REACTIVE_math(HSV hsv, uint16_t offset) { # ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE - hsv.h = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 8) >> 4); + hsv.h = rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 8) >> 4); # endif hsv.h += qsub8(130, offset); return hsv; diff --git a/quantum/rgb_matrix/animations/solid_reactive_cross.h b/quantum/rgb_matrix/animations/solid_reactive_cross.h index a18d6b03dd6b..f46b5d2f1046 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_cross.h +++ b/quantum/rgb_matrix/animations/solid_reactive_cross.h @@ -20,7 +20,7 @@ static HSV SOLID_REACTIVE_CROSS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t di effect += dx > dy ? dy : dx; if (effect > 255) effect = 255; # ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE - hsv.h = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 8) >> 4); + hsv.h = rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 8) >> 4); # endif hsv.v = qadd8(hsv.v, 255 - effect); return hsv; diff --git a/quantum/rgb_matrix/animations/solid_reactive_nexus.h b/quantum/rgb_matrix/animations/solid_reactive_nexus.h index 53cc008616de..46ccc23e8987 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_nexus.h +++ b/quantum/rgb_matrix/animations/solid_reactive_nexus.h @@ -17,7 +17,7 @@ static HSV SOLID_REACTIVE_NEXUS_math(HSV hsv, int16_t dx, int16_t dy, uint8_t di if (dist > 72) effect = 255; if ((dx > 8 || dx < -8) && (dy > 8 || dy < -8)) effect = 255; # ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE - hsv.h = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 8) >> 4) + dy / 4; + hsv.h = rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 8) >> 4) + dy / 4; # else hsv.h = rgb_matrix_config.hsv.h + dy / 4; # endif diff --git a/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h index 7f4e48747a6c..909f3ecf9bf4 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h +++ b/quantum/rgb_matrix/animations/solid_reactive_simple_anim.h @@ -5,7 +5,7 @@ RGB_MATRIX_EFFECT(SOLID_REACTIVE_SIMPLE) static HSV SOLID_REACTIVE_SIMPLE_math(HSV hsv, uint16_t offset) { # ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE - hsv.h = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 8) >> 4); + hsv.h = rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 8) >> 4); # endif hsv.v = scale8(255 - offset, hsv.v); return hsv; diff --git a/quantum/rgb_matrix/animations/solid_reactive_wide.h b/quantum/rgb_matrix/animations/solid_reactive_wide.h index feca1266483d..c71e66156931 100644 --- a/quantum/rgb_matrix/animations/solid_reactive_wide.h +++ b/quantum/rgb_matrix/animations/solid_reactive_wide.h @@ -15,7 +15,7 @@ static HSV SOLID_REACTIVE_WIDE_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dis uint16_t effect = tick + dist * 5; if (effect > 255) effect = 255; # ifdef RGB_MATRIX_SOLID_REACTIVE_GRADIENT_MODE - hsv.h = scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 8) >> 4); + hsv.h = rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 8) >> 4); # endif hsv.v = qadd8(hsv.v, 255 - effect); return hsv; diff --git a/quantum/rgb_matrix/animations/starlight_anim.h b/quantum/rgb_matrix/animations/starlight_anim.h index db94bb3f0b3d..64adcf5f8909 100644 --- a/quantum/rgb_matrix/animations/starlight_anim.h +++ b/quantum/rgb_matrix/animations/starlight_anim.h @@ -3,7 +3,7 @@ RGB_MATRIX_EFFECT(STARLIGHT) # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS void set_starlight_color(int i, effect_params_t* params) { - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + uint16_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 8); HSV hsv = rgb_matrix_config.hsv; hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); RGB rgb = hsv_to_rgb(hsv); @@ -12,7 +12,7 @@ void set_starlight_color(int i, effect_params_t* params) { bool STARLIGHT(effect_params_t* params) { if (!params->init) { - if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 5)) % 5 == 0) { + if (rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 5)) % 5 == 0) { int rand_led = rand() % RGB_MATRIX_LED_COUNT; set_starlight_color(rand_led, params); } diff --git a/quantum/rgb_matrix/animations/starlight_dual_hue_anim.h b/quantum/rgb_matrix/animations/starlight_dual_hue_anim.h index d9ccdfb7b093..9ab8e39d249b 100644 --- a/quantum/rgb_matrix/animations/starlight_dual_hue_anim.h +++ b/quantum/rgb_matrix/animations/starlight_dual_hue_anim.h @@ -3,7 +3,7 @@ RGB_MATRIX_EFFECT(STARLIGHT_DUAL_HUE) # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS void set_starlight_dual_hue_color(int i, effect_params_t* params) { - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + uint16_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 8); HSV hsv = rgb_matrix_config.hsv; hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); hsv.h = hsv.h + (rand() % (30 + 1 - -30) + -30); @@ -13,7 +13,7 @@ void set_starlight_dual_hue_color(int i, effect_params_t* params) { bool STARLIGHT_DUAL_HUE(effect_params_t* params) { if (!params->init) { - if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 5)) % 5 == 0) { + if (rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 5)) % 5 == 0) { int rand_led = rand() % RGB_MATRIX_LED_COUNT; set_starlight_dual_hue_color(rand_led, params); } diff --git a/quantum/rgb_matrix/animations/starlight_dual_sat_anim.h b/quantum/rgb_matrix/animations/starlight_dual_sat_anim.h index b01229b09abf..ff6250e24cb9 100644 --- a/quantum/rgb_matrix/animations/starlight_dual_sat_anim.h +++ b/quantum/rgb_matrix/animations/starlight_dual_sat_anim.h @@ -3,7 +3,7 @@ RGB_MATRIX_EFFECT(STARLIGHT_DUAL_SAT) # ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS void set_starlight_dual_sat_color(int i, effect_params_t* params) { - uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 8); + uint16_t time = rgb_matrix_anim_time(rgb_matrix_config.speed / 8); HSV hsv = rgb_matrix_config.hsv; hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); hsv.s = hsv.s + (rand() % (30 + 1 - -30) + -30); @@ -13,7 +13,7 @@ void set_starlight_dual_sat_color(int i, effect_params_t* params) { bool STARLIGHT_DUAL_SAT(effect_params_t* params) { if (!params->init) { - if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 5)) % 5 == 0) { + if (rgb_matrix_anim_time(qadd8(rgb_matrix_config.speed, 5)) % 5 == 0) { int rand_led = rand() % RGB_MATRIX_LED_COUNT; set_starlight_dual_sat_color(rand_led, params); } diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 4e8d2bacb567..43279a3b0d5b 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -66,6 +66,26 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { // globals rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr uint32_t g_rgb_timer; + +uint16_t rgb_matrix_anim_time(uint8_t scale) { + static uint32_t accum; + static uint32_t last_ms; + static uint32_t last_stamp; + + /* One phase for the running effect. The next frame adds real elapsed + * time times the current speed, so a slider does not jump the pattern. */ + if (g_rgb_timer != last_stamp) { + uint32_t now = sync_timer_read32(); + uint32_t delta = now - last_ms; + if (last_ms != 0 && delta <= 250) { + accum += delta * scale; + } + last_ms = now; + last_stamp = g_rgb_timer; + } + return (uint16_t)(accum >> 8); +} + #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; #endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS @@ -297,12 +317,16 @@ static void rgb_task_timers(void) { // Update double buffer last hit timers #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED uint8_t count = last_hit_buffer.count; + /* Age is stored already scaled by speed. A later speed change only + * affects the next step, so a splash does not jump. */ + uint16_t delta16 = deltaTime > 250 ? 16 : (uint16_t)deltaTime; + uint16_t step = scale16by8(delta16, qadd8(rgb_matrix_config.speed, 1)); for (uint8_t i = 0; i < count; ++i) { - if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) { + if (step > (uint16_t)(UINT16_MAX - last_hit_buffer.tick[i])) { last_hit_buffer.count--; continue; } - last_hit_buffer.tick[i] += deltaTime; + last_hit_buffer.tick[i] += step; } #endif // RGB_MATRIX_KEYREACTIVE_ENABLED } @@ -332,10 +356,6 @@ static void rgb_task_render(uint8_t effect) { rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); if (effect != rgb_last_effect) { memset(rgb_regions, 0, RGB_MATRIX_LED_COUNT); - rgb_config_t rgb_cfg; - eeprom_read_block(&rgb_cfg, EECONFIG_RGB_MATRIX, sizeof(rgb_cfg)); - rgb_matrix_config.hsv = rgb_cfg.hsv; - rgb_matrix_config.speed = rgb_cfg.speed; } if (rgb_effect_params.flags != rgb_matrix_config.flags) { @@ -608,6 +628,9 @@ void rgb_matrix_disable(void) { } void rgb_matrix_disable_noeeprom(void) { + if (rgb_matrix_effect_locked(0)) { + return; + } if (rgb_matrix_config.enable) rgb_task_state = STARTING; rgb_matrix_config.enable = 0; } @@ -616,22 +639,34 @@ uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } +__attribute__((weak)) bool rgb_matrix_effect_locked(uint8_t mode) { + (void)mode; + return false; +} + void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { if (!rgb_matrix_config.enable) { return; } - if (mode < 1) { - rgb_matrix_config.mode = 1; - } else if (mode >= RGB_MATRIX_EFFECT_MAX) { - rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; - } else { - rgb_matrix_config.mode = mode; + uint8_t next = mode; + if (next < 1) { + next = 1; + } else if (next >= RGB_MATRIX_EFFECT_MAX) { + next = RGB_MATRIX_EFFECT_MAX - 1; + } + if (rgb_matrix_effect_locked(next)) { + return; + } + /* Same effect again (the Launcher sends it with every slider tick) + * must not restart the animation. */ + if (rgb_matrix_config.mode != next) { + rgb_matrix_config.mode = next; + rgb_task_state = STARTING; } - rgb_task_state = STARTING; if (write_to_eeprom) { - uint8_t mode = (rgb_matrix_config.mode << 2) | rgb_matrix_config.enable; - eeprom_write_byte((uint8_t*)EECONFIG_RGB_MATRIX, mode); + uint8_t packed = (rgb_matrix_config.mode << 2) | rgb_matrix_config.enable; + eeprom_write_byte((uint8_t*)EECONFIG_RGB_MATRIX, packed); } dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); } diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index 824859815985..37619a56f33d 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -328,6 +328,14 @@ extern const rgb_matrix_driver_t rgb_matrix_driver; extern rgb_config_t rgb_matrix_config; extern uint32_t g_rgb_timer; + +/* Phase that advances with speed. Changing speed keeps the current frame + * and only changes how fast the next frames move. */ +uint16_t rgb_matrix_anim_time(uint8_t scale); + +/* Keymaps can hold the current effect. Return true to refuse `mode`. */ +bool rgb_matrix_effect_locked(uint8_t mode); + extern led_config_t g_led_config; #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED extern last_hit_t g_last_hit_tracker; From 5ebdaad64780a03f260727df76a07e3e236b51eb Mon Sep 17 00:00:00 2001 From: joseamirandavelez Date: Mon, 26 Oct 2026 12:04:27 -0400 Subject: [PATCH 3/6] Use asymmetric debounce so a bouncing key types once. Eager per-key accepted a new edge every 5ms, so contact bounce showed up as two or three of the same character. The press is still immediate, so holding a key still holds it. The release waits until the contact has been open for 10ms. Co-authored-by: Cursor --- .../q5_pro/ansi_encoder/keymaps/rgbj/config.h | 17 ++++++++++++++ .../q5_pro/ansi_encoder/keymaps/rgbj/keymap.c | 23 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h new file mode 100644 index 000000000000..d18368529504 --- /dev/null +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h @@ -0,0 +1,17 @@ +#pragma once + +/* One tap was sometimes coming out as two or three of the same character. + * The switch contact bounces, and the old eager per-key debounce only + * ignored those extra edges for 5ms. Bounce that lasted longer became + * another press. The count changed from tap to tap because the bounce + * is irregular. + * + * Asymmetric eager-defer still reports the press immediately, so a key + * you keep holding stays held and key repeat still works. The release is + * reported only after the contact has stayed open for this whole window, + * so a bounce cannot become a second character. 10ms covers the chatter + * we were seeing without making a normal tap feel held. + * + * The algorithm stores the time in 7 bits, so the window caps at 127ms. */ +#define DEFAULT_DEBOUNCE_TYPE DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY +#define DEBOUNCE 10 diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c index f786d921a612..84bcc2009d9d 100644 --- a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c @@ -8,8 +8,12 @@ */ #include QMK_KEYBOARD_H +#include "eeconfig_kb.h" +#include "keychron_debounce.h" #include "raw_hid.h" +extern void debounce_set(uint8_t new_debounce_type, uint8_t time, bool force); + enum layers { MAC_BASE, MAC_FN, @@ -199,6 +203,25 @@ bool rgb_matrix_effect_locked(uint8_t mode) { return host_lighting_active && mode != RGB_MATRIX_CUSTOM_HOSTLIGHT; } +/* The running debounce is stored on the keyboard. A flash does not replace + * it, so the first boot after this firmware moves the old eager setting + * over. A later change in the Launcher is left alone. */ +void keyboard_post_init_user(void) { + uint8_t *cfg = (uint8_t *)EECONFIG_BASE_DYNAMIC_DEBOUNCE; + uint8_t type = eeprom_read_byte(cfg); + + if (type == DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY) { + return; + } + if (type != DEBOUNCE_SYM_EAGER_PER_KEY && type < DEBOUNCE_MAX) { + return; + } + + debounce_set(DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY, DEBOUNCE, true); + eeprom_update_byte(cfg, DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY); + eeprom_update_byte(cfg + 1, DEBOUNCE); +} + bool process_record_user(uint16_t keycode, keyrecord_t *record) { (void)record; if (host_lighting_active && IS_RGB_KEYCODE(keycode)) { From db188d4ad93f0caa11542be634bb2c9a9a55f7d5 Mon Sep 17 00:00:00 2001 From: joseamirandavelez Date: Sun, 8 Nov 2026 21:20:27 -0400 Subject: [PATCH 4/6] Fix bounce doubles and host lighting flicker on Q5 Pro. Symmetric eager debounce locks out late bounce after release, host mode blacks the last onboard frame on enter, and Bluetooth NKRO stays off so wireless reports stay clean. Co-authored-by: Cursor --- .../q5_pro/ansi_encoder/keymaps/rgbj/config.h | 23 +++++---- .../q5_pro/ansi_encoder/keymaps/rgbj/keymap.c | 48 ++++++++++++++----- keyboards/keychron/q5_pro/config.h | 3 -- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h index d18368529504..2710ae8d3893 100644 --- a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h @@ -1,17 +1,16 @@ #pragma once /* One tap was sometimes coming out as two or three of the same character. - * The switch contact bounces, and the old eager per-key debounce only - * ignored those extra edges for 5ms. Bounce that lasted longer became - * another press. The count changed from tap to tap because the bounce - * is irregular. + * Contact bounce is irregular, so the count changed from tap to tap. * - * Asymmetric eager-defer still reports the press immediately, so a key - * you keep holding stays held and key repeat still works. The release is - * reported only after the contact has stayed open for this whole window, - * so a bounce cannot become a second character. 10ms covers the chatter - * we were seeing without making a normal tap feel held. + * Asymmetric eager-defer helped the release edge, but once a release was + * accepted there was no lockout. A late bounce closed again and became a + * second press. Symmetric eager per-key reports the press and the release + * immediately, then ignores every edge on that key for this whole window, + * so that late bounce cannot type again. 50ms matches what settles this + * board without blocking normal typing speed. * - * The algorithm stores the time in 7 bits, so the window caps at 127ms. */ -#define DEFAULT_DEBOUNCE_TYPE DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY -#define DEBOUNCE 10 + * Holding a key still works: the press is already accepted, and OS key + * repeat does not need the bounce window. */ +#define DEFAULT_DEBOUNCE_TYPE DEBOUNCE_SYM_EAGER_PER_KEY +#define DEBOUNCE 50 diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c index 84bcc2009d9d..c4b2695fb2af 100644 --- a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c @@ -11,6 +11,7 @@ #include "eeconfig_kb.h" #include "keychron_debounce.h" #include "raw_hid.h" +#include "transport.h" extern void debounce_set(uint8_t new_debounce_type, uint8_t time, bool force); @@ -89,6 +90,20 @@ static void host_reply(uint8_t command, uint8_t b1, uint8_t b2, uint8_t b3) { raw_hid_send(host_packet, sizeof(host_packet)); } +/* Switch to the host effect and clear the last onboard frame. Without the + * blackout, HOSTLIGHT keeps flushing the previous animation until the first + * colour packets arrive, so the board flickers between the two painters. */ +static void host_lighting_enter(void) { + bool already = host_lighting_active && rgb_matrix_is_enabled() && rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_HOSTLIGHT; + + host_lighting_active = true; + rgb_matrix_enable_noeeprom(); + rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_HOSTLIGHT); + if (!already) { + rgb_matrix_set_color_all(0, 0, 0); + } +} + /* Num Lock is LED 32, Caps Lock is LED 55. While that lock is on, both this * packet and the indicator task must write the same white. If the packet * writes the effect colour instead, it lands after the indicator and the key @@ -148,13 +163,14 @@ bool q5_pro_host_lighting_rx(uint8_t *data, uint8_t length) { return true; case HOST_STREAM_RGB_DATA: /* No reply. A reply is just our own frame echoed back, and the host - * would answer that with another frame. */ + * would answer that with another frame. Enter host mode on the + * first colour frame too: if enable is late, the onboard effect + * would keep repainting over these pixels and the board flickers. */ + host_lighting_enter(); host_led_streaming(data); return true; case HOST_MODE_ENABLE: - host_lighting_active = true; - rgb_matrix_enable_noeeprom(); - rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_HOSTLIGHT); + host_lighting_enter(); return true; case HOST_MODE_DISABLE: host_lighting_active = false; @@ -204,29 +220,39 @@ bool rgb_matrix_effect_locked(uint8_t mode) { } /* The running debounce is stored on the keyboard. A flash does not replace - * it, so the first boot after this firmware moves the old eager setting - * over. A later change in the Launcher is left alone. */ + * it, so boot moves an old asymmetric or shorter eager window up to this + * keymap's setting. A longer eager window set in the Launcher is left + * alone. */ void keyboard_post_init_user(void) { uint8_t *cfg = (uint8_t *)EECONFIG_BASE_DYNAMIC_DEBOUNCE; uint8_t type = eeprom_read_byte(cfg); + uint8_t time = eeprom_read_byte(cfg + 1); - if (type == DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY) { + if (type == DEBOUNCE_SYM_EAGER_PER_KEY && time >= DEBOUNCE && time <= 255) { return; } - if (type != DEBOUNCE_SYM_EAGER_PER_KEY && type < DEBOUNCE_MAX) { + if (type != DEBOUNCE_SYM_EAGER_PER_KEY && type != DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY && type < DEBOUNCE_MAX) { return; } - debounce_set(DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY, DEBOUNCE, true); - eeprom_update_byte(cfg, DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY); + debounce_set(DEBOUNCE_SYM_EAGER_PER_KEY, DEBOUNCE, true); + eeprom_update_byte(cfg, DEBOUNCE_SYM_EAGER_PER_KEY); eeprom_update_byte(cfg + 1, DEBOUNCE); } bool process_record_user(uint16_t keycode, keyrecord_t *record) { - (void)record; if (host_lighting_active && IS_RGB_KEYCODE(keycode)) { return false; } + /* Wireless NKRO scrambles reports on this board. Keep Bluetooth on 6KRO + * even if Fn+N is pressed. USB NKRO is unchanged. */ + if (record->event.pressed && get_transport() == TRANSPORT_BLUETOOTH) { + switch (keycode) { + case QK_MAGIC_TOGGLE_NKRO: + case QK_MAGIC_NKRO_ON: + return false; + } + } return true; } diff --git a/keyboards/keychron/q5_pro/config.h b/keyboards/keychron/q5_pro/config.h index 1abd15c4e4d9..e75c0c7ea32c 100644 --- a/keyboards/keychron/q5_pro/config.h +++ b/keyboards/keychron/q5_pro/config.h @@ -64,9 +64,6 @@ /* Keep USB connection in blueooth mode */ # define KEEP_USB_CONNECTION_IN_BLUETOOTH_MODE -/* Enable bluetooth NKRO */ -# define BLUETOOTH_NKRO_ENABLE - /* Raw hid command for factory test and bluetooth DFU */ # define RAW_HID_CMD 0xAA ... 0xAB #else From 4e56e994c2a093580c9dc86992bb825f5132b379 Mon Sep 17 00:00:00 2001 From: joseamirandavelez Date: Sun, 8 Nov 2026 21:30:30 -0400 Subject: [PATCH 5/6] Restore onboard RGB when host colour stream stops. If no colour frames arrive for a few seconds, leave host mode and reload the EEPROM effect so a quit or crashed app does not freeze the last frame. Co-authored-by: Cursor --- .../q5_pro/ansi_encoder/keymaps/rgbj/config.h | 5 ++++ .../q5_pro/ansi_encoder/keymaps/rgbj/keymap.c | 29 +++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h index 2710ae8d3893..84b4401f13a1 100644 --- a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h @@ -14,3 +14,8 @@ * repeat does not need the bounce window. */ #define DEFAULT_DEBOUNCE_TYPE DEBOUNCE_SYM_EAGER_PER_KEY #define DEBOUNCE 50 + +/* After this long with no host colour frames, leave host mode and restore + * the onboard effect from EEPROM. Long enough that a slow render tick does + * not bounce back to hardware mid-effect. */ +#define HOST_LIGHTING_TIMEOUT_MS 3000 diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c index c4b2695fb2af..f548eff6f094 100644 --- a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c @@ -78,8 +78,13 @@ enum { HOST_GET_FIRMWARE_TYPE = 0x28, }; -static uint8_t host_packet[32]; -static bool host_lighting_active = false; +static uint8_t host_packet[32]; +static bool host_lighting_active = false; +static uint32_t host_lighting_last_activity = 0; + +#ifndef HOST_LIGHTING_TIMEOUT_MS +# define HOST_LIGHTING_TIMEOUT_MS 3000 +#endif static void host_reply(uint8_t command, uint8_t b1, uint8_t b2, uint8_t b3) { memset(host_packet, 0, sizeof(host_packet)); @@ -90,13 +95,22 @@ static void host_reply(uint8_t command, uint8_t b1, uint8_t b2, uint8_t b3) { raw_hid_send(host_packet, sizeof(host_packet)); } +static void host_lighting_leave(void) { + if (!host_lighting_active) { + return; + } + host_lighting_active = false; + rgb_matrix_reload_from_eeprom(); +} + /* Switch to the host effect and clear the last onboard frame. Without the * blackout, HOSTLIGHT keeps flushing the previous animation until the first * colour packets arrive, so the board flickers between the two painters. */ static void host_lighting_enter(void) { bool already = host_lighting_active && rgb_matrix_is_enabled() && rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_HOSTLIGHT; - host_lighting_active = true; + host_lighting_active = true; + host_lighting_last_activity = timer_read32(); rgb_matrix_enable_noeeprom(); rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_HOSTLIGHT); if (!already) { @@ -173,8 +187,7 @@ bool q5_pro_host_lighting_rx(uint8_t *data, uint8_t length) { host_lighting_enter(); return true; case HOST_MODE_DISABLE: - host_lighting_active = false; - rgb_matrix_reload_from_eeprom(); + host_lighting_leave(); return true; case HOST_GET_TOTAL_LEDS: host_reply(HOST_GET_TOTAL_LEDS, RGB_MATRIX_LED_COUNT, 0, 0); @@ -260,6 +273,12 @@ void housekeeping_task_user(void) { if (!host_lighting_active) { return; } + /* App quit, crash, or sleep: colour frames stop, so give the onboard + * effect back instead of freezing on the last host frame. */ + if (timer_elapsed32(host_lighting_last_activity) > HOST_LIGHTING_TIMEOUT_MS) { + host_lighting_leave(); + return; + } if (!rgb_matrix_is_enabled() || rgb_matrix_get_mode() != RGB_MATRIX_CUSTOM_HOSTLIGHT) { rgb_matrix_enable_noeeprom(); rgb_matrix_mode_noeeprom(RGB_MATRIX_CUSTOM_HOSTLIGHT); From 850cf64581b7e7bfc63ad87bac25395a872e1b64 Mon Sep 17 00:00:00 2001 From: joseamirandavelez Date: Tue, 1 Dec 2026 20:32:11 -0400 Subject: [PATCH 6/6] Stop a later scan from typing the same key again. Defer debounce ignores a one-scan glitch, boot keeps that 46ms window, and Bluetooth sends each report once so the key-up is not stuck behind repeats of the key-down. Co-authored-by: Cursor --- keyboards/keychron/bluetooth/report_buffer.c | 10 ++++----- .../common/debounce/keychron_debounce.c | 4 +++- .../q5_pro/ansi_encoder/keymaps/rgbj/config.h | 22 +++++++++---------- .../q5_pro/ansi_encoder/keymaps/rgbj/keymap.c | 20 +++++------------ 4 files changed, 23 insertions(+), 33 deletions(-) diff --git a/keyboards/keychron/bluetooth/report_buffer.c b/keyboards/keychron/bluetooth/report_buffer.c index 7494c42b975f..7884090aafe1 100644 --- a/keyboards/keychron/bluetooth/report_buffer.c +++ b/keyboards/keychron/bluetooth/report_buffer.c @@ -108,13 +108,13 @@ void report_buffer_task(void) { if (bluetooth_get_state() == BLUETOOTH_CONNECTED && (!report_buffer_is_empty() || retry) && report_buffer_next_inverval()) { bool pending_data = false; + /* Send each report once. Arming a blind retry here repeated the + * key-down up to 30 times before the key-up could leave the queue, + * so the computer still had the key held and typed it again. A full + * module fifo still sets retry from the ack handler. */ if (!retry) { if (report_buffer_dequeue(&kb_rpt) && kb_rpt.type != REPORT_TYPE_NONE) { - if (sync_timer_read32() > 2) { - pending_data = true; - retry = RETPORT_RETRY_COUNT; - retry_time_buffer = sync_timer_read32(); - } + pending_data = true; } } else { if (sync_timer_elapsed32(retry_time_buffer) > 7) { diff --git a/keyboards/keychron/common/debounce/keychron_debounce.c b/keyboards/keychron/common/debounce/keychron_debounce.c index 6296d85b8171..8a94b4353998 100644 --- a/keyboards/keychron/common/debounce/keychron_debounce.c +++ b/keyboards/keychron/common/debounce/keychron_debounce.c @@ -89,7 +89,9 @@ void debounce_set(uint8_t new_debounce_type, uint8_t time, bool force); */ bool debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) { - if (debounce_func.debounce) debounce_func.debounce(raw, cooked, num_rows, changed); + if (debounce_func.debounce) { + return debounce_func.debounce(raw, cooked, num_rows, changed); + } return false; } diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h index 84b4401f13a1..fada1caf5461 100644 --- a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/config.h @@ -1,19 +1,17 @@ #pragma once -/* One tap was sometimes coming out as two or three of the same character. - * Contact bounce is irregular, so the count changed from tap to tap. +/* One tap was coming out as two of the same character, sometimes right + * away ("Thiss") and sometimes after later letters ("a acat", "cat a"). * - * Asymmetric eager-defer helped the release edge, but once a release was - * accepted there was no lockout. A late bounce closed again and became a - * second press. Symmetric eager per-key reports the press and the release - * immediately, then ignores every edge on that key for this whole window, - * so that late bounce cannot type again. 50ms matches what settles this - * board without blocking normal typing speed. + * Eager debounce reports the press on the first sample, then ignores that + * key only until the window ends. A later scan that sees the key again is + * a new character. A longer eager window just moves that hole. * - * Holding a key still works: the press is already accepted, and OS key - * repeat does not need the bounce window. */ -#define DEFAULT_DEBOUNCE_TYPE DEBOUNCE_SYM_EAGER_PER_KEY -#define DEBOUNCE 50 + * Defer waits until the contact has stayed in the new state for this whole + * window. A one-scan glitch never becomes a letter. 46ms still lets a + * normal tap through, including holding a key for OS repeat. */ +#define DEFAULT_DEBOUNCE_TYPE DEBOUNCE_SYM_DEFER_PER_KEY +#define DEBOUNCE 46 /* After this long with no host colour frames, leave host mode and restore * the onboard effect from EEPROM. Long enough that a slow render tick does diff --git a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c index f548eff6f094..48ede17d261c 100644 --- a/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c +++ b/keyboards/keychron/q5_pro/ansi_encoder/keymaps/rgbj/keymap.c @@ -233,23 +233,13 @@ bool rgb_matrix_effect_locked(uint8_t mode) { } /* The running debounce is stored on the keyboard. A flash does not replace - * it, so boot moves an old asymmetric or shorter eager window up to this - * keymap's setting. A longer eager window set in the Launcher is left - * alone. */ + * it, and a stored time of 0 turns debounce off. Boot always puts this + * keymap's defer window back, including over an eager window saved earlier. */ void keyboard_post_init_user(void) { - uint8_t *cfg = (uint8_t *)EECONFIG_BASE_DYNAMIC_DEBOUNCE; - uint8_t type = eeprom_read_byte(cfg); - uint8_t time = eeprom_read_byte(cfg + 1); + uint8_t *cfg = (uint8_t *)EECONFIG_BASE_DYNAMIC_DEBOUNCE; - if (type == DEBOUNCE_SYM_EAGER_PER_KEY && time >= DEBOUNCE && time <= 255) { - return; - } - if (type != DEBOUNCE_SYM_EAGER_PER_KEY && type != DEBOUNCE_ASYM_EAGER_DEFER_PER_KEY && type < DEBOUNCE_MAX) { - return; - } - - debounce_set(DEBOUNCE_SYM_EAGER_PER_KEY, DEBOUNCE, true); - eeprom_update_byte(cfg, DEBOUNCE_SYM_EAGER_PER_KEY); + debounce_set(DEBOUNCE_SYM_DEFER_PER_KEY, DEBOUNCE, true); + eeprom_update_byte(cfg, DEBOUNCE_SYM_DEFER_PER_KEY); eeprom_update_byte(cfg + 1, DEBOUNCE); }