aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-04-13 19:51:03 +1000
committerGitHub <noreply@github.com>2021-04-13 19:51:03 +1000
commitce99f98bb5217ede628cfbf7e20924346b4279da (patch)
tree20079e250b26339964ff3eb9c588d35474cbe8c5
parent15f7cc3bde0199afe3b49718fa7b73bc6771e04b (diff)
downloadqmk_firmware-ce99f98bb5217ede628cfbf7e20924346b4279da.tar.gz
qmk_firmware-ce99f98bb5217ede628cfbf7e20924346b4279da.zip
LED Matrix: suspend code (#12509)
-rw-r--r--quantum/led_matrix.c57
-rw-r--r--quantum/led_matrix.h7
-rw-r--r--tmk_core/common/avr/suspend.c3
-rw-r--r--tmk_core/common/chibios/suspend.c6
-rw-r--r--tmk_core/common/keyboard.c3
5 files changed, 49 insertions, 27 deletions
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c
index e13376455..5258b3acf 100644
--- a/quantum/led_matrix.c
+++ b/quantum/led_matrix.c
@@ -27,8 +27,6 @@
27 27
28#include <lib/lib8tion/lib8tion.h> 28#include <lib/lib8tion/lib8tion.h>
29 29
30led_eeconfig_t led_matrix_eeconfig;
31
32#ifndef MAX 30#ifndef MAX
33# define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) 31# define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
34#endif 32#endif
@@ -74,7 +72,9 @@ led_eeconfig_t led_matrix_eeconfig;
74# define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2 72# define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2
75#endif 73#endif
76 74
77bool g_suspend_state = false; 75// globals
76bool g_suspend_state = false;
77led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr
78 78
79// Global tick at 20 Hz 79// Global tick at 20 Hz
80uint32_t g_tick = 0; 80uint32_t g_tick = 0;
@@ -139,10 +139,10 @@ void led_matrix_set_value_all(uint8_t value) {
139#endif 139#endif
140} 140}
141 141
142bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { 142void process_led_matrix(uint8_t row, uint8_t col, bool pressed) {
143 if (record->event.pressed) { 143 if (pressed) {
144 uint8_t led[8]; 144 uint8_t led[8];
145 uint8_t led_count = led_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); 145 uint8_t led_count = led_matrix_map_row_column_to_led(row, col, led);
146 if (led_count > 0) { 146 if (led_count > 0) {
147 for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) { 147 for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) {
148 g_last_led_hit[i - 1] = g_last_led_hit[i - 2]; 148 g_last_led_hit[i - 1] = g_last_led_hit[i - 2];
@@ -155,35 +155,24 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
155 } else { 155 } else {
156#ifdef LED_MATRIX_KEYRELEASES 156#ifdef LED_MATRIX_KEYRELEASES
157 uint8_t led[8]; 157 uint8_t led[8];
158 uint8_t led_count = led_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); 158 uint8_t led_count = led_matrix_map_row_column_to_led(row, .col, led);
159 for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255; 159 for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255;
160 160
161 g_any_key_hit = 255; 161 g_any_key_hit = 255;
162#endif 162#endif
163 } 163 }
164 return true;
165} 164}
166 165
167void led_matrix_set_suspend_state(bool state) { 166static void led_matrix_none(void) { led_matrix_set_value_all(0); }
168 if (LED_DISABLE_WHEN_USB_SUSPENDED && state) {
169 led_matrix_set_value_all(0); // turn off all LEDs when suspending
170 }
171 g_suspend_state = state;
172}
173
174bool led_matrix_get_suspend_state(void) { return g_suspend_state; }
175
176// All LEDs off
177void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); }
178 167
179// Uniform brightness 168// Uniform brightness
180void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(led_matrix_eeconfig.val); } 169void led_matrix_uniform_brightness(void) { led_matrix_set_value_all(led_matrix_eeconfig.val); }
181 170
182void led_matrix_custom(void) {} 171void led_matrix_custom(void) {}
183 172
184void led_matrix_task(void) { 173void led_matrix_task(void) {
185 if (!led_matrix_eeconfig.enable) { 174 if (!led_matrix_eeconfig.enable) {
186 led_matrix_all_off(); 175 led_matrix_none();
187 led_matrix_indicators(); 176 led_matrix_indicators();
188 return; 177 return;
189 } 178 }
@@ -203,13 +192,23 @@ void led_matrix_task(void) {
203 192
204 // Ideally we would also stop sending zeros to the LED driver PWM buffers 193 // Ideally we would also stop sending zeros to the LED driver PWM buffers
205 // while suspended and just do a software shutdown. This is a cheap hack for now. 194 // while suspended and just do a software shutdown. This is a cheap hack for now.
206 bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || (LED_DISABLE_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_TIMEOUT)); 195 bool suspend_backlight =
207 uint8_t effect = suspend_backlight ? 0 : led_matrix_eeconfig.mode; 196#if LED_DISABLE_WHEN_USB_SUSPENDED == true
197 g_suspend_state ||
198#endif // LED_DISABLE_WHEN_USB_SUSPENDED == true
199#if LED_DISABLE_TIMEOUT > 0
200 (g_any_key_hit > (uint32_t)LED_DISABLE_TIMEOUT) ||
201#endif // LED_DISABLE_TIMEOUT > 0
202 false;
203
204 uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode;
208 205
209 // this gets ticked at 20 Hz. 206 // this gets ticked at 20 Hz.
210 // each effect can opt to do calculations 207 // each effect can opt to do calculations
211 // and/or request PWM buffer updates. 208 // and/or request PWM buffer updates.
212 switch (effect) { 209 switch (effect) {
210 case LED_MATRIX_NONE:
211 led_matrix_none();
213 case LED_MATRIX_UNIFORM_BRIGHTNESS: 212 case LED_MATRIX_UNIFORM_BRIGHTNESS:
214 led_matrix_uniform_brightness(); 213 led_matrix_uniform_brightness();
215 break; 214 break;
@@ -218,7 +217,7 @@ void led_matrix_task(void) {
218 break; 217 break;
219 } 218 }
220 219
221 if (!suspend_backlight) { 220 if (effect) {
222 led_matrix_indicators(); 221 led_matrix_indicators();
223 } 222 }
224 223
@@ -257,10 +256,18 @@ void led_matrix_init(void) {
257 dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); 256 dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n");
258 eeconfig_update_led_matrix_default(); 257 eeconfig_update_led_matrix_default();
259 } 258 }
260
261 eeconfig_debug_led_matrix(); // display current eeprom values 259 eeconfig_debug_led_matrix(); // display current eeprom values
262} 260}
263 261
262void led_matrix_set_suspend_state(bool state) {
263 if (LED_DISABLE_WHEN_USB_SUSPENDED && state) {
264 led_matrix_set_value_all(0); // turn off all LEDs when suspending
265 }
266 g_suspend_state = state;
267}
268
269bool led_matrix_get_suspend_state(void) { return g_suspend_state; }
270
264void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 271void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
265 led_matrix_eeconfig.enable ^= 1; 272 led_matrix_eeconfig.enable ^= 1;
266 if (write_to_eeprom) { 273 if (write_to_eeprom) {
diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h
index ba8f0279a..48c9483b2 100644
--- a/quantum/led_matrix.h
+++ b/quantum/led_matrix.h
@@ -48,8 +48,11 @@
48#endif 48#endif
49 49
50enum led_matrix_effects { 50enum led_matrix_effects {
51 LED_MATRIX_UNIFORM_BRIGHTNESS = 1, 51 LED_MATRIX_NONE = 0,
52
53 LED_MATRIX_UNIFORM_BRIGHTNESS,
52 // All new effects go above this line 54 // All new effects go above this line
55
53 LED_MATRIX_EFFECT_MAX 56 LED_MATRIX_EFFECT_MAX
54}; 57};
55 58
@@ -63,7 +66,7 @@ uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
63void led_matrix_set_value(int index, uint8_t value); 66void led_matrix_set_value(int index, uint8_t value);
64void led_matrix_set_value_all(uint8_t value); 67void led_matrix_set_value_all(uint8_t value);
65 68
66bool process_led_matrix(uint16_t keycode, keyrecord_t *record); 69void process_led_matrix(uint8_t row, uint8_t col, bool pressed);
67 70
68void led_matrix_task(void); 71void led_matrix_task(void);
69 72
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index d52c8ac41..96b19a77f 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -28,6 +28,9 @@
28# include "rgblight.h" 28# include "rgblight.h"
29#endif 29#endif
30 30
31#ifdef LED_MATRIX_ENABLE
32# include "led_matrix.h"
33#endif
31#ifdef RGB_MATRIX_ENABLE 34#ifdef RGB_MATRIX_ENABLE
32# include "rgb_matrix.h" 35# include "rgb_matrix.h"
33#endif 36#endif
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 17f024cab..b3949185e 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -24,6 +24,9 @@
24# include "rgblight.h" 24# include "rgblight.h"
25#endif 25#endif
26 26
27#ifdef LED_MATRIX_ENABLE
28# include "led_matrix.h"
29#endif
27#ifdef RGB_MATRIX_ENABLE 30#ifdef RGB_MATRIX_ENABLE
28# include "rgb_matrix.h" 31# include "rgb_matrix.h"
29#endif 32#endif
@@ -57,6 +60,9 @@ void suspend_power_down(void) {
57 backlight_set(0); 60 backlight_set(0);
58#endif 61#endif
59 62
63#ifdef LED_MATRIX_ENABLE
64 led_matrix_task();
65#endif
60#ifdef RGB_MATRIX_ENABLE 66#ifdef RGB_MATRIX_ENABLE
61 rgb_matrix_task(); 67 rgb_matrix_task();
62#endif 68#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index e473806b2..132affe7a 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -330,6 +330,9 @@ void keyboard_init(void) {
330 * This is differnet than keycode events as no layer processing, or filtering occurs. 330 * This is differnet than keycode events as no layer processing, or filtering occurs.
331 */ 331 */
332void switch_events(uint8_t row, uint8_t col, bool pressed) { 332void switch_events(uint8_t row, uint8_t col, bool pressed) {
333#if defined(LED_MATRIX_ENABLE)
334 process_led_matrix(row, col, pressed);
335#endif
333#if defined(RGB_MATRIX_ENABLE) 336#if defined(RGB_MATRIX_ENABLE)
334 process_rgb_matrix(row, col, pressed); 337 process_rgb_matrix(row, col, pressed);
335#endif 338#endif