From d8167779cdfb243cb140782210d2cc6a7cb9b123 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Wed, 28 Apr 2021 19:39:54 -0700 Subject: Change RGB/LED Matrix to use a simple define for USB suspend (#12697) --- quantum/led_matrix.c | 18 +++++++++--------- quantum/led_matrix.h | 1 - quantum/rgb_matrix.c | 18 +++++++++--------- quantum/rgb_matrix.h | 1 - 4 files changed, 18 insertions(+), 20 deletions(-) (limited to 'quantum') diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 72eb5190b3..5dd37dff14 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c @@ -35,8 +35,8 @@ # define LED_DISABLE_TIMEOUT 0 #endif -#ifndef LED_DISABLE_WHEN_USB_SUSPENDED -# define LED_DISABLE_WHEN_USB_SUSPENDED false +#if LED_DISABLE_WHEN_USB_SUSPENDED == false +# undef LED_DISABLE_WHEN_USB_SUSPENDED #endif #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX @@ -65,7 +65,6 @@ #endif // globals -bool g_suspend_state = false; led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr uint32_t g_led_timer; #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS @@ -76,6 +75,7 @@ last_hit_t g_last_hit_tracker; #endif // LED_MATRIX_KEYREACTIVE_ENABLED // internals +static bool suspend_state = false; 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}; @@ -325,9 +325,7 @@ void led_matrix_task(void) { // Ideally we would also stop sending zeros to the LED driver PWM buffers // while suspended and just do a software shutdown. This is a cheap hack for now. bool suspend_backlight = -#if LED_DISABLE_WHEN_USB_SUSPENDED == true - g_suspend_state || -#endif // LED_DISABLE_WHEN_USB_SUSPENDED == true + suspend_state || #if LED_DISABLE_TIMEOUT > 0 (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) || #endif // LED_DISABLE_TIMEOUT > 0 @@ -416,13 +414,15 @@ void led_matrix_init(void) { } void led_matrix_set_suspend_state(bool state) { - if (LED_DISABLE_WHEN_USB_SUSPENDED && state) { +#ifdef LED_DISABLE_WHEN_USB_SUSPENDED + if (state) { led_matrix_set_value_all(0); // turn off all LEDs when suspending } - g_suspend_state = state; + suspend_state = state; +#endif } -bool led_matrix_get_suspend_state(void) { return g_suspend_state; } +bool led_matrix_get_suspend_state(void) { return suspend_state; } void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { led_matrix_eeconfig.enable ^= 1; diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h index f35bbe2096..a3fa552b0a 100644 --- a/quantum/led_matrix.h +++ b/quantum/led_matrix.h @@ -134,7 +134,6 @@ extern const led_matrix_driver_t led_matrix_driver; extern led_eeconfig_t led_matrix_eeconfig; -extern bool g_suspend_state; extern uint32_t g_led_timer; extern led_config_t g_led_config; #ifdef LED_MATRIX_KEYREACTIVE_ENABLED diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 8aae486034..1f76049430 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -67,8 +67,8 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv # define RGB_DISABLE_TIMEOUT 0 #endif -#ifndef RGB_DISABLE_WHEN_USB_SUSPENDED -# define RGB_DISABLE_WHEN_USB_SUSPENDED false +#if RGB_DISABLE_WHEN_USB_SUSPENDED == false +# undef RGB_DISABLE_WHEN_USB_SUSPENDED #endif #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX @@ -118,7 +118,6 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv #endif // globals -bool g_suspend_state = false; 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; #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS @@ -129,6 +128,7 @@ last_hit_t g_last_hit_tracker; #endif // RGB_MATRIX_KEYREACTIVE_ENABLED // internals +static bool suspend_state = false; 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}; @@ -410,9 +410,7 @@ void rgb_matrix_task(void) { // Ideally we would also stop sending zeros to the LED driver PWM buffers // while suspended and just do a software shutdown. This is a cheap hack for now. bool suspend_backlight = -#if RGB_DISABLE_WHEN_USB_SUSPENDED == true - g_suspend_state || -#endif // RGB_DISABLE_WHEN_USB_SUSPENDED == true + suspend_state || #if RGB_DISABLE_TIMEOUT > 0 (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || #endif // RGB_DISABLE_TIMEOUT > 0 @@ -501,13 +499,15 @@ void rgb_matrix_init(void) { } void rgb_matrix_set_suspend_state(bool state) { - if (RGB_DISABLE_WHEN_USB_SUSPENDED && state) { +#ifdef RGB_DISABLE_WHEN_USB_SUSPENDED + if (state) { rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending } - g_suspend_state = state; + suspend_state = state; +#endif } -bool rgb_matrix_get_suspend_state(void) { return g_suspend_state; } +bool rgb_matrix_get_suspend_state(void) { return suspend_state; } void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { rgb_matrix_config.enable ^= 1; diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index bb8bcfab68..a615b8422c 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -216,7 +216,6 @@ extern const rgb_matrix_driver_t rgb_matrix_driver; extern rgb_config_t rgb_matrix_config; -extern bool g_suspend_state; extern uint32_t g_rgb_timer; extern led_config_t g_led_config; #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED -- cgit v1.2.3