From fcb72434885a1ca8d4f93c7d96f72db55ee25406 Mon Sep 17 00:00:00 2001 From: Pete Neisen Date: Thu, 3 Aug 2023 08:37:04 -0600 Subject: [PATCH 1/3] Converted RGB matrix to use last_input_activity_elapsed(). After setting RGB_MATRIX_TIMEOUT to a value on my macro pad (winry315), the timeout worked as expected, but I was frustrated that turning my encoder knobs would not turn the LEDs back on and would not prevent them from turning off. This solution was suggested by @drashna. It removes the special timer used by RGB matrix in favor of using the last_input_activity timer. Since this timer is reset by encoder activity, it fixes the issue I was seeing. --- quantum/rgb_matrix/rgb_matrix.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 1f3912cf7e0c..5342487208bd 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -121,9 +121,6 @@ static uint8_t rgb_last_enable = UINT8_MAX; static uint8_t rgb_last_effect = UINT8_MAX; static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; static rgb_task_states rgb_task_state = SYNCING; -#if RGB_MATRIX_TIMEOUT > 0 -static uint32_t rgb_anykey_timer; -#endif // RGB_MATRIX_TIMEOUT > 0 // double buffers static uint32_t rgb_timer_buffer; @@ -208,9 +205,6 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { #ifndef RGB_MATRIX_SPLIT if (!is_keyboard_master()) return; #endif -#if RGB_MATRIX_TIMEOUT > 0 - rgb_anykey_timer = 0; -#endif // RGB_MATRIX_TIMEOUT > 0 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED uint8_t led[LED_HITS_TO_REMEMBER]; @@ -296,13 +290,6 @@ static void rgb_task_timers(void) { #endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_MATRIX_TIMEOUT > 0 rgb_timer_buffer = sync_timer_read32(); - // Update double buffer timers -#if RGB_MATRIX_TIMEOUT > 0 - if (rgb_anykey_timer + deltaTime <= UINT32_MAX) { - rgb_anykey_timer += deltaTime; - } -#endif // RGB_MATRIX_TIMEOUT > 0 - // Update double buffer last hit timers #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED uint8_t count = last_hit_buffer.count; @@ -415,7 +402,7 @@ void rgb_matrix_task(void) { // while suspended and just do a software shutdown. This is a cheap hack for now. bool suspend_backlight = suspend_state || #if RGB_MATRIX_TIMEOUT > 0 - (rgb_anykey_timer > (uint32_t)RGB_MATRIX_TIMEOUT) || + (last_input_activity_elapsed() > (uint32_t)RGB_MATRIX_TIMEOUT) || #endif // RGB_MATRIX_TIMEOUT > 0 false; From 6a07625730025a1d4ee5d14d6095a5f1e84d194a Mon Sep 17 00:00:00 2001 From: Pete Neisen Date: Thu, 3 Aug 2023 16:42:48 -0600 Subject: [PATCH 2/3] Converted LED matrix to use last_input_activity_elapsed(). I made a identical change to RGB matrix and it was pointed out that this feature is nearly identical and should have the changes as well. --- quantum/led_matrix/led_matrix.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index 828d61641a1b..dd64e6457b0b 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -98,9 +98,6 @@ static uint8_t led_last_enable = UINT8_MAX; static uint8_t led_last_effect = UINT8_MAX; static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; static led_task_states led_task_state = SYNCING; -#if LED_MATRIX_TIMEOUT > 0 -static uint32_t led_anykey_timer; -#endif // LED_MATRIX_TIMEOUT > 0 // double buffers static uint32_t led_timer_buffer; @@ -180,9 +177,6 @@ void process_led_matrix(uint8_t row, uint8_t col, bool pressed) { #ifndef LED_MATRIX_SPLIT if (!is_keyboard_master()) return; #endif -#if LED_MATRIX_TIMEOUT > 0 - led_anykey_timer = 0; -#endif // LED_MATRIX_TIMEOUT > 0 #ifdef LED_MATRIX_KEYREACTIVE_ENABLED uint8_t led[LED_HITS_TO_REMEMBER]; @@ -237,17 +231,6 @@ static void led_task_timers(void) { #endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_MATRIX_TIMEOUT > 0 led_timer_buffer = sync_timer_read32(); - // Update double buffer timers -#if LED_MATRIX_TIMEOUT > 0 - if (led_anykey_timer < UINT32_MAX) { - if (UINT32_MAX - deltaTime < led_anykey_timer) { - led_anykey_timer = UINT32_MAX; - } else { - led_anykey_timer += deltaTime; - } - } -#endif // LED_MATRIX_TIMEOUT > 0 - // Update double buffer last hit timers #ifdef LED_MATRIX_KEYREACTIVE_ENABLED uint8_t count = last_hit_buffer.count; @@ -353,7 +336,7 @@ void led_matrix_task(void) { // while suspended and just do a software shutdown. This is a cheap hack for now. bool suspend_backlight = suspend_state || #if LED_MATRIX_TIMEOUT > 0 - (led_anykey_timer > (uint32_t)LED_MATRIX_TIMEOUT) || + (last_input_activity_elapsed() > (uint32_t)LED_MATRIX_TIMEOUT) || #endif // LED_MATRIX_TIMEOUT > 0 false; From 30382056cb5434ca5776b8fdf6e5d98415aca6d3 Mon Sep 17 00:00:00 2001 From: Pete Neisen Date: Wed, 30 Aug 2023 06:24:25 -0600 Subject: [PATCH 3/3] Fixed compilation issue found in review --- quantum/led_matrix/led_matrix.c | 4 ++-- quantum/rgb_matrix/rgb_matrix.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index dd64e6457b0b..4cf1b5e4aaff 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -226,9 +226,9 @@ static bool led_matrix_none(effect_params_t *params) { } static void led_task_timers(void) { -#if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_MATRIX_TIMEOUT > 0 +#if defined(LED_MATRIX_KEYREACTIVE_ENABLED) uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer); -#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_MATRIX_TIMEOUT > 0 +#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) led_timer_buffer = sync_timer_read32(); // Update double buffer last hit timers diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 5342487208bd..fa8509aeaed1 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -285,9 +285,9 @@ static bool rgb_matrix_none(effect_params_t *params) { } static void rgb_task_timers(void) { -#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_MATRIX_TIMEOUT > 0 +#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) uint32_t deltaTime = sync_timer_elapsed32(rgb_timer_buffer); -#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_MATRIX_TIMEOUT > 0 +#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) rgb_timer_buffer = sync_timer_read32(); // Update double buffer last hit timers