diff options
| author | Ryan <fauxpark@gmail.com> | 2021-04-13 19:51:03 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-13 19:51:03 +1000 |
| commit | ce99f98bb5217ede628cfbf7e20924346b4279da (patch) | |
| tree | 20079e250b26339964ff3eb9c588d35474cbe8c5 /quantum/led_matrix.c | |
| parent | 15f7cc3bde0199afe3b49718fa7b73bc6771e04b (diff) | |
| download | qmk_firmware-ce99f98bb5217ede628cfbf7e20924346b4279da.tar.gz qmk_firmware-ce99f98bb5217ede628cfbf7e20924346b4279da.zip | |
LED Matrix: suspend code (#12509)
Diffstat (limited to 'quantum/led_matrix.c')
| -rw-r--r-- | quantum/led_matrix.c | 57 |
1 files changed, 32 insertions, 25 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 | ||
| 30 | led_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 | ||
| 77 | bool g_suspend_state = false; | 75 | // globals |
| 76 | bool g_suspend_state = false; | ||
| 77 | led_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 |
| 80 | uint32_t g_tick = 0; | 80 | uint32_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 | ||
| 142 | bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { | 142 | void 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 | ||
| 167 | void led_matrix_set_suspend_state(bool state) { | 166 | static 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 | |||
| 174 | bool led_matrix_get_suspend_state(void) { return g_suspend_state; } | ||
| 175 | |||
| 176 | // All LEDs off | ||
| 177 | void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } | ||
| 178 | 167 | ||
| 179 | // Uniform brightness | 168 | // Uniform brightness |
| 180 | void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(led_matrix_eeconfig.val); } | 169 | void led_matrix_uniform_brightness(void) { led_matrix_set_value_all(led_matrix_eeconfig.val); } |
| 181 | 170 | ||
| 182 | void led_matrix_custom(void) {} | 171 | void led_matrix_custom(void) {} |
| 183 | 172 | ||
| 184 | void led_matrix_task(void) { | 173 | void 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 | ||
| 262 | void 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 | |||
| 269 | bool led_matrix_get_suspend_state(void) { return g_suspend_state; } | ||
| 270 | |||
| 264 | void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { | 271 | void 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) { |
