Change RGB/LED Matrix to use a simple define for USB suspend (#12697)

This commit is contained in:
Drashna Jaelre 2021-04-28 19:39:54 -07:00 committed by GitHub
parent 7409f03cbf
commit d8167779cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 53 deletions

View file

@ -437,7 +437,7 @@ These are defined in [`rgblight_list.h`](https://github.com/qmk/qmk_firmware/blo
#define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (instead of keypresses) #define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (instead of keypresses)
#define RGB_DISABLE_TIMEOUT 0 // number of milliseconds to wait until rgb automatically turns off #define RGB_DISABLE_TIMEOUT 0 // number of milliseconds to wait until rgb automatically turns off
#define RGB_DISABLE_AFTER_TIMEOUT 0 // OBSOLETE: number of ticks to wait until disabling effects #define RGB_DISABLE_AFTER_TIMEOUT 0 // OBSOLETE: number of ticks to wait until disabling effects
#define RGB_DISABLE_WHEN_USB_SUSPENDED false // turn off effects when suspended #define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended
#define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 // limits the number of LEDs to process in an animation per task run (increases keyboard responsiveness) #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 // limits the number of LEDs to process in an animation per task run (increases keyboard responsiveness)
#define RGB_MATRIX_LED_FLUSH_LIMIT 16 // limits in milliseconds how frequently an animation will update the LEDs. 16 (16ms) is equivalent to limiting to 60fps (increases keyboard responsiveness) #define RGB_MATRIX_LED_FLUSH_LIMIT 16 // limits in milliseconds how frequently an animation will update the LEDs. 16 (16ms) is equivalent to limiting to 60fps (increases keyboard responsiveness)
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 200 // limits maximum brightness of LEDs to 200 out of 255. If not defined maximum brightness is set to 255 #define RGB_MATRIX_MAXIMUM_BRIGHTNESS 200 // limits maximum brightness of LEDs to 200 out of 255. If not defined maximum brightness is set to 255

View file

@ -37,7 +37,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
}; };
void rgb_matrix_indicators_user(void) { void rgb_matrix_indicators_user(void) {
if (!g_suspend_state && layer_state_is(1)) { if (layer_state_is(1)) {
rgb_matrix_set_color(77,0xFF, 0x80, 0x00); rgb_matrix_set_color(77,0xFF, 0x80, 0x00);
} }
if (host_keyboard_led_state().caps_lock) { if (host_keyboard_led_state().caps_lock) {

View file

@ -44,13 +44,11 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
void rgb_matrix_indicators_user(void) { void rgb_matrix_indicators_user(void) {
led_t led_state = host_keyboard_led_state(); led_t led_state = host_keyboard_led_state();
if (!g_suspend_state) {
switch (get_highest_layer(layer_state)) { switch (get_highest_layer(layer_state)) {
case _FN: case _FN:
rgb_matrix_set_color(77,0xFF, 0x80, 0x00); rgb_matrix_set_color(77,0xFF, 0x80, 0x00);
break; break;
} }
}
if (led_state.caps_lock) { if (led_state.caps_lock) {
rgb_matrix_set_color(46, 0xFF, 0xFF, 0xFF); rgb_matrix_set_color(46, 0xFF, 0xFF, 0xFF);
} }

View file

@ -35,8 +35,8 @@
# define LED_DISABLE_TIMEOUT 0 # define LED_DISABLE_TIMEOUT 0
#endif #endif
#ifndef LED_DISABLE_WHEN_USB_SUSPENDED #if LED_DISABLE_WHEN_USB_SUSPENDED == false
# define LED_DISABLE_WHEN_USB_SUSPENDED false # undef LED_DISABLE_WHEN_USB_SUSPENDED
#endif #endif
#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
@ -65,7 +65,6 @@
#endif #endif
// globals // 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 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; uint32_t g_led_timer;
#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
@ -76,6 +75,7 @@ last_hit_t g_last_hit_tracker;
#endif // LED_MATRIX_KEYREACTIVE_ENABLED #endif // LED_MATRIX_KEYREACTIVE_ENABLED
// internals // internals
static bool suspend_state = false;
static uint8_t led_last_enable = UINT8_MAX; static uint8_t led_last_enable = UINT8_MAX;
static uint8_t led_last_effect = UINT8_MAX; static uint8_t led_last_effect = UINT8_MAX;
static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; 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 // 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. // while suspended and just do a software shutdown. This is a cheap hack for now.
bool suspend_backlight = bool suspend_backlight =
#if LED_DISABLE_WHEN_USB_SUSPENDED == true suspend_state ||
g_suspend_state ||
#endif // LED_DISABLE_WHEN_USB_SUSPENDED == true
#if LED_DISABLE_TIMEOUT > 0 #if LED_DISABLE_TIMEOUT > 0
(led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) || (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) ||
#endif // LED_DISABLE_TIMEOUT > 0 #endif // LED_DISABLE_TIMEOUT > 0
@ -416,13 +414,15 @@ void led_matrix_init(void) {
} }
void led_matrix_set_suspend_state(bool state) { 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 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) { void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
led_matrix_eeconfig.enable ^= 1; led_matrix_eeconfig.enable ^= 1;

View file

@ -134,7 +134,6 @@ extern const led_matrix_driver_t led_matrix_driver;
extern led_eeconfig_t led_matrix_eeconfig; extern led_eeconfig_t led_matrix_eeconfig;
extern bool g_suspend_state;
extern uint32_t g_led_timer; extern uint32_t g_led_timer;
extern led_config_t g_led_config; extern led_config_t g_led_config;
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED #ifdef LED_MATRIX_KEYREACTIVE_ENABLED

View file

@ -67,8 +67,8 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv
# define RGB_DISABLE_TIMEOUT 0 # define RGB_DISABLE_TIMEOUT 0
#endif #endif
#ifndef RGB_DISABLE_WHEN_USB_SUSPENDED #if RGB_DISABLE_WHEN_USB_SUSPENDED == false
# define RGB_DISABLE_WHEN_USB_SUSPENDED false # undef RGB_DISABLE_WHEN_USB_SUSPENDED
#endif #endif
#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX #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 #endif
// globals // 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 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; uint32_t g_rgb_timer;
#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
@ -129,6 +128,7 @@ last_hit_t g_last_hit_tracker;
#endif // RGB_MATRIX_KEYREACTIVE_ENABLED #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
// internals // internals
static bool suspend_state = false;
static uint8_t rgb_last_enable = UINT8_MAX; static uint8_t rgb_last_enable = UINT8_MAX;
static uint8_t rgb_last_effect = UINT8_MAX; static uint8_t rgb_last_effect = UINT8_MAX;
static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; 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 // 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. // while suspended and just do a software shutdown. This is a cheap hack for now.
bool suspend_backlight = bool suspend_backlight =
#if RGB_DISABLE_WHEN_USB_SUSPENDED == true suspend_state ||
g_suspend_state ||
#endif // RGB_DISABLE_WHEN_USB_SUSPENDED == true
#if RGB_DISABLE_TIMEOUT > 0 #if RGB_DISABLE_TIMEOUT > 0
(rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) ||
#endif // RGB_DISABLE_TIMEOUT > 0 #endif // RGB_DISABLE_TIMEOUT > 0
@ -501,13 +499,15 @@ void rgb_matrix_init(void) {
} }
void rgb_matrix_set_suspend_state(bool state) { 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 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) { void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
rgb_matrix_config.enable ^= 1; rgb_matrix_config.enable ^= 1;

View file

@ -216,7 +216,6 @@ extern const rgb_matrix_driver_t rgb_matrix_driver;
extern rgb_config_t rgb_matrix_config; extern rgb_config_t rgb_matrix_config;
extern bool g_suspend_state;
extern uint32_t g_rgb_timer; extern uint32_t g_rgb_timer;
extern led_config_t g_led_config; extern led_config_t g_led_config;
#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED

View file

@ -163,6 +163,10 @@ void suspend_power_down(void) {
rgblight_suspend(); rgblight_suspend();
# endif # endif
# if defined(RGB_MATRIX_ENABLE)
rgb_matrix_set_suspend_state(true);
# endif
// Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt) // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt)
# if defined(WDT_vect) # if defined(WDT_vect)
power_down(WDTO_15MS); power_down(WDTO_15MS);
@ -214,6 +218,9 @@ void suspend_wakeup_init(void) {
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
rgblight_wakeup(); rgblight_wakeup();
#endif #endif
# if defined(RGB_MATRIX_ENABLE)
rgb_matrix_set_suspend_state(false);
# endif
suspend_wakeup_init_kb(); suspend_wakeup_init_kb();
} }

View file

@ -83,6 +83,9 @@ void suspend_power_down(void) {
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
rgblight_suspend(); rgblight_suspend();
#endif #endif
# if defined(RGB_MATRIX_ENABLE)
rgb_matrix_set_suspend_state(true);
# endif
#ifdef AUDIO_ENABLE #ifdef AUDIO_ENABLE
stop_all_notes(); stop_all_notes();
#endif /* AUDIO_ENABLE */ #endif /* AUDIO_ENABLE */
@ -151,5 +154,8 @@ void suspend_wakeup_init(void) {
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) #if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
rgblight_wakeup(); rgblight_wakeup();
#endif #endif
# if defined(RGB_MATRIX_ENABLE)
rgb_matrix_set_suspend_state(false);
# endif
suspend_wakeup_init_kb(); suspend_wakeup_init_kb();
} }