aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-04-28 19:39:54 -0700
committerGitHub <noreply@github.com>2021-04-29 12:39:54 +1000
commitd8167779cdfb243cb140782210d2cc6a7cb9b123 (patch)
tree52a05a41568f5dbb0d3ba931c0d401ad03504410
parent7409f03cbf7a863e0c2c949de2a5a276f5661c04 (diff)
downloadqmk_firmware-d8167779cdfb243cb140782210d2cc6a7cb9b123.tar.gz
qmk_firmware-d8167779cdfb243cb140782210d2cc6a7cb9b123.zip
Change RGB/LED Matrix to use a simple define for USB suspend (#12697)
-rw-r--r--docs/feature_rgb_matrix.md2
-rw-r--r--keyboards/mt64rgb/keymaps/default/keymap.c32
-rw-r--r--keyboards/mt84/keymaps/default/keymap.c30
-rw-r--r--quantum/led_matrix.c18
-rw-r--r--quantum/led_matrix.h1
-rw-r--r--quantum/rgb_matrix.c18
-rw-r--r--quantum/rgb_matrix.h1
-rw-r--r--tmk_core/common/avr/suspend.c7
-rw-r--r--tmk_core/common/chibios/suspend.c6
9 files changed, 62 insertions, 53 deletions
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index 046b1f17f..63ff7d6ad 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -437,7 +437,7 @@ These are defined in [`rgblight_list.h`](https://github.com/qmk/qmk_firmware/blo
437#define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (instead of keypresses) 437#define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (instead of keypresses)
438#define RGB_DISABLE_TIMEOUT 0 // number of milliseconds to wait until rgb automatically turns off 438#define RGB_DISABLE_TIMEOUT 0 // number of milliseconds to wait until rgb automatically turns off
439#define RGB_DISABLE_AFTER_TIMEOUT 0 // OBSOLETE: number of ticks to wait until disabling effects 439#define RGB_DISABLE_AFTER_TIMEOUT 0 // OBSOLETE: number of ticks to wait until disabling effects
440#define RGB_DISABLE_WHEN_USB_SUSPENDED false // turn off effects when suspended 440#define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended
441#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) 441#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)
442#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) 442#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)
443#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 443#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
diff --git a/keyboards/mt64rgb/keymaps/default/keymap.c b/keyboards/mt64rgb/keymaps/default/keymap.c
index c7e027ba7..84f3b1d35 100644
--- a/keyboards/mt64rgb/keymaps/default/keymap.c
+++ b/keyboards/mt64rgb/keymaps/default/keymap.c
@@ -1,18 +1,18 @@
1/* Copyright 2020 MT 1/* Copyright 2020 MT
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or 5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version. 6 * (at your option) any later version.
7 * 7 *
8 * This program is distributed in the hope that it will be useful, 8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License 13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16#include QMK_KEYBOARD_H 16#include QMK_KEYBOARD_H
17 17
18 18
@@ -37,7 +37,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
37}; 37};
38 38
39void rgb_matrix_indicators_user(void) { 39void rgb_matrix_indicators_user(void) {
40 if (!g_suspend_state && layer_state_is(1)) { 40 if (layer_state_is(1)) {
41 rgb_matrix_set_color(77,0xFF, 0x80, 0x00); 41 rgb_matrix_set_color(77,0xFF, 0x80, 0x00);
42 } 42 }
43 if (host_keyboard_led_state().caps_lock) { 43 if (host_keyboard_led_state().caps_lock) {
diff --git a/keyboards/mt84/keymaps/default/keymap.c b/keyboards/mt84/keymaps/default/keymap.c
index fc8481da9..bb7d5b447 100644
--- a/keyboards/mt84/keymaps/default/keymap.c
+++ b/keyboards/mt84/keymaps/default/keymap.c
@@ -1,18 +1,18 @@
1 /* Copyright 2020 mt<704340378@qq.com> 1 /* Copyright 2020 mt<704340378@qq.com>
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or 5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version. 6 * (at your option) any later version.
7 * 7 *
8 * This program is distributed in the hope that it will be useful, 8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 * 12 *
13 * You should have received a copy of the GNU General Public License 13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16#include QMK_KEYBOARD_H 16#include QMK_KEYBOARD_H
17 17
18 18
@@ -44,12 +44,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
44 44
45void rgb_matrix_indicators_user(void) { 45void rgb_matrix_indicators_user(void) {
46 led_t led_state = host_keyboard_led_state(); 46 led_t led_state = host_keyboard_led_state();
47 if (!g_suspend_state) {
48 switch (get_highest_layer(layer_state)) { 47 switch (get_highest_layer(layer_state)) {
49 case _FN: 48 case _FN:
50 rgb_matrix_set_color(77,0xFF, 0x80, 0x00); 49 rgb_matrix_set_color(77,0xFF, 0x80, 0x00);
51 break; 50 break;
52 }
53 } 51 }
54 if (led_state.caps_lock) { 52 if (led_state.caps_lock) {
55 rgb_matrix_set_color(46, 0xFF, 0xFF, 0xFF); 53 rgb_matrix_set_color(46, 0xFF, 0xFF, 0xFF);
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c
index 72eb5190b..5dd37dff1 100644
--- a/quantum/led_matrix.c
+++ b/quantum/led_matrix.c
@@ -35,8 +35,8 @@
35# define LED_DISABLE_TIMEOUT 0 35# define LED_DISABLE_TIMEOUT 0
36#endif 36#endif
37 37
38#ifndef LED_DISABLE_WHEN_USB_SUSPENDED 38#if LED_DISABLE_WHEN_USB_SUSPENDED == false
39# define LED_DISABLE_WHEN_USB_SUSPENDED false 39# undef LED_DISABLE_WHEN_USB_SUSPENDED
40#endif 40#endif
41 41
42#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX 42#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
@@ -65,7 +65,6 @@
65#endif 65#endif
66 66
67// globals 67// globals
68bool g_suspend_state = false;
69led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr 68led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr
70uint32_t g_led_timer; 69uint32_t g_led_timer;
71#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS 70#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
@@ -76,6 +75,7 @@ last_hit_t g_last_hit_tracker;
76#endif // LED_MATRIX_KEYREACTIVE_ENABLED 75#endif // LED_MATRIX_KEYREACTIVE_ENABLED
77 76
78// internals 77// internals
78static bool suspend_state = false;
79static uint8_t led_last_enable = UINT8_MAX; 79static uint8_t led_last_enable = UINT8_MAX;
80static uint8_t led_last_effect = UINT8_MAX; 80static uint8_t led_last_effect = UINT8_MAX;
81static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; 81static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false};
@@ -325,9 +325,7 @@ void led_matrix_task(void) {
325 // Ideally we would also stop sending zeros to the LED driver PWM buffers 325 // Ideally we would also stop sending zeros to the LED driver PWM buffers
326 // while suspended and just do a software shutdown. This is a cheap hack for now. 326 // while suspended and just do a software shutdown. This is a cheap hack for now.
327 bool suspend_backlight = 327 bool suspend_backlight =
328#if LED_DISABLE_WHEN_USB_SUSPENDED == true 328 suspend_state ||
329 g_suspend_state ||
330#endif // LED_DISABLE_WHEN_USB_SUSPENDED == true
331#if LED_DISABLE_TIMEOUT > 0 329#if LED_DISABLE_TIMEOUT > 0
332 (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) || 330 (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) ||
333#endif // LED_DISABLE_TIMEOUT > 0 331#endif // LED_DISABLE_TIMEOUT > 0
@@ -416,13 +414,15 @@ void led_matrix_init(void) {
416} 414}
417 415
418void led_matrix_set_suspend_state(bool state) { 416void led_matrix_set_suspend_state(bool state) {
419 if (LED_DISABLE_WHEN_USB_SUSPENDED && state) { 417#ifdef LED_DISABLE_WHEN_USB_SUSPENDED
418 if (state) {
420 led_matrix_set_value_all(0); // turn off all LEDs when suspending 419 led_matrix_set_value_all(0); // turn off all LEDs when suspending
421 } 420 }
422 g_suspend_state = state; 421 suspend_state = state;
422#endif
423} 423}
424 424
425bool led_matrix_get_suspend_state(void) { return g_suspend_state; } 425bool led_matrix_get_suspend_state(void) { return suspend_state; }
426 426
427void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 427void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
428 led_matrix_eeconfig.enable ^= 1; 428 led_matrix_eeconfig.enable ^= 1;
diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h
index f35bbe209..a3fa552b0 100644
--- a/quantum/led_matrix.h
+++ b/quantum/led_matrix.h
@@ -134,7 +134,6 @@ extern const led_matrix_driver_t led_matrix_driver;
134 134
135extern led_eeconfig_t led_matrix_eeconfig; 135extern led_eeconfig_t led_matrix_eeconfig;
136 136
137extern bool g_suspend_state;
138extern uint32_t g_led_timer; 137extern uint32_t g_led_timer;
139extern led_config_t g_led_config; 138extern led_config_t g_led_config;
140#ifdef LED_MATRIX_KEYREACTIVE_ENABLED 139#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 8aae48603..1f7604943 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
67# define RGB_DISABLE_TIMEOUT 0 67# define RGB_DISABLE_TIMEOUT 0
68#endif 68#endif
69 69
70#ifndef RGB_DISABLE_WHEN_USB_SUSPENDED 70#if RGB_DISABLE_WHEN_USB_SUSPENDED == false
71# define RGB_DISABLE_WHEN_USB_SUSPENDED false 71# undef RGB_DISABLE_WHEN_USB_SUSPENDED
72#endif 72#endif
73 73
74#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX 74#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
118#endif 118#endif
119 119
120// globals 120// globals
121bool g_suspend_state = false;
122rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr 121rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr
123uint32_t g_rgb_timer; 122uint32_t g_rgb_timer;
124#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS 123#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
@@ -129,6 +128,7 @@ last_hit_t g_last_hit_tracker;
129#endif // RGB_MATRIX_KEYREACTIVE_ENABLED 128#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
130 129
131// internals 130// internals
131static bool suspend_state = false;
132static uint8_t rgb_last_enable = UINT8_MAX; 132static uint8_t rgb_last_enable = UINT8_MAX;
133static uint8_t rgb_last_effect = UINT8_MAX; 133static uint8_t rgb_last_effect = UINT8_MAX;
134static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; 134static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false};
@@ -410,9 +410,7 @@ void rgb_matrix_task(void) {
410 // Ideally we would also stop sending zeros to the LED driver PWM buffers 410 // Ideally we would also stop sending zeros to the LED driver PWM buffers
411 // while suspended and just do a software shutdown. This is a cheap hack for now. 411 // while suspended and just do a software shutdown. This is a cheap hack for now.
412 bool suspend_backlight = 412 bool suspend_backlight =
413#if RGB_DISABLE_WHEN_USB_SUSPENDED == true 413 suspend_state ||
414 g_suspend_state ||
415#endif // RGB_DISABLE_WHEN_USB_SUSPENDED == true
416#if RGB_DISABLE_TIMEOUT > 0 414#if RGB_DISABLE_TIMEOUT > 0
417 (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || 415 (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) ||
418#endif // RGB_DISABLE_TIMEOUT > 0 416#endif // RGB_DISABLE_TIMEOUT > 0
@@ -501,13 +499,15 @@ void rgb_matrix_init(void) {
501} 499}
502 500
503void rgb_matrix_set_suspend_state(bool state) { 501void rgb_matrix_set_suspend_state(bool state) {
504 if (RGB_DISABLE_WHEN_USB_SUSPENDED && state) { 502#ifdef RGB_DISABLE_WHEN_USB_SUSPENDED
503 if (state) {
505 rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending 504 rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending
506 } 505 }
507 g_suspend_state = state; 506 suspend_state = state;
507#endif
508} 508}
509 509
510bool rgb_matrix_get_suspend_state(void) { return g_suspend_state; } 510bool rgb_matrix_get_suspend_state(void) { return suspend_state; }
511 511
512void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 512void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
513 rgb_matrix_config.enable ^= 1; 513 rgb_matrix_config.enable ^= 1;
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index bb8bcfab6..a615b8422 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -216,7 +216,6 @@ extern const rgb_matrix_driver_t rgb_matrix_driver;
216 216
217extern rgb_config_t rgb_matrix_config; 217extern rgb_config_t rgb_matrix_config;
218 218
219extern bool g_suspend_state;
220extern uint32_t g_rgb_timer; 219extern uint32_t g_rgb_timer;
221extern led_config_t g_led_config; 220extern led_config_t g_led_config;
222#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED 221#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index 96b19a77f..1c2bf9cb4 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -163,6 +163,10 @@ void suspend_power_down(void) {
163 rgblight_suspend(); 163 rgblight_suspend();
164# endif 164# endif
165 165
166# if defined(RGB_MATRIX_ENABLE)
167 rgb_matrix_set_suspend_state(true);
168# endif
169
166 // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt) 170 // Enter sleep state if possible (ie, the MCU has a watchdog timeout interrupt)
167# if defined(WDT_vect) 171# if defined(WDT_vect)
168 power_down(WDTO_15MS); 172 power_down(WDTO_15MS);
@@ -214,6 +218,9 @@ void suspend_wakeup_init(void) {
214#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) 218#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
215 rgblight_wakeup(); 219 rgblight_wakeup();
216#endif 220#endif
221# if defined(RGB_MATRIX_ENABLE)
222 rgb_matrix_set_suspend_state(false);
223# endif
217 224
218 suspend_wakeup_init_kb(); 225 suspend_wakeup_init_kb();
219} 226}
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index b3949185e..1f4f93c45 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -83,6 +83,9 @@ void suspend_power_down(void) {
83#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) 83#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
84 rgblight_suspend(); 84 rgblight_suspend();
85#endif 85#endif
86# if defined(RGB_MATRIX_ENABLE)
87 rgb_matrix_set_suspend_state(true);
88# endif
86#ifdef AUDIO_ENABLE 89#ifdef AUDIO_ENABLE
87 stop_all_notes(); 90 stop_all_notes();
88#endif /* AUDIO_ENABLE */ 91#endif /* AUDIO_ENABLE */
@@ -151,5 +154,8 @@ void suspend_wakeup_init(void) {
151#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE) 154#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
152 rgblight_wakeup(); 155 rgblight_wakeup();
153#endif 156#endif
157# if defined(RGB_MATRIX_ENABLE)
158 rgb_matrix_set_suspend_state(false);
159# endif
154 suspend_wakeup_init_kb(); 160 suspend_wakeup_init_kb();
155} 161}