diff options
| author | James Young <18669334+noroadsleft@users.noreply.github.com> | 2020-05-30 13:14:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-30 13:14:59 -0700 |
| commit | fced377ac007d27f2650ccffbe0b18abcdcfe23d (patch) | |
| tree | bd5b141987394a5a16cfc416bfe2b9efdb14d067 /quantum/rgb_matrix.c | |
| parent | 7b8a013826ad90714a05ea522de53adf964ab3b9 (diff) | |
| download | qmk_firmware-fced377ac007d27f2650ccffbe0b18abcdcfe23d.tar.gz qmk_firmware-fced377ac007d27f2650ccffbe0b18abcdcfe23d.zip | |
2020 May 30 Breaking Changes Update (#9215)
* Branch point for 2020 May 30 Breaking Change
* Migrate `ACTION_LAYER_TOGGLE` to `TG()` (#8954)
* Migrate `ACTION_MODS_ONESHOT` to `OSM()` (#8957)
* Migrate `ACTION_DEFAULT_LAYER_SET` to `DF()` (#8958)
* Migrate `ACTION_LAYER_MODS` to `LM()` (#8959)
* Migrate `ACTION_MODS_TAP_KEY` to `MT()` (#8968)
* Convert V-USB usbdrv to a submodule (#8321)
* Unify Tap Hold functions and documentation (#8348)
* Changing board names to prevent confusion (#8412)
* Move the Keyboardio Model01 to a keyboardio/ subdir (#8499)
* Move spaceman keyboards (#8830)
* Migrate miscellaneous `fn_actions` entries (#8977)
* Migrate `ACTION_MODS_KEY` to chained mod keycodes (#8979)
* Organizing my keyboards (plaid, tartan, ergoinu) (#8537)
* Refactor Lily58 to use split_common (#6260)
* Refactor zinc to use split_common (#7114)
* Add a message if bin/qmk doesn't work (#9000)
* Fix conflicting types for 'tfp_printf' (#8269)
* Fixed RGB_DISABLE_AFTER_TIMEOUT to be seconds based & small internals cleanup (#6480)
* Refactor and updates to TKC1800 code (#8472)
* Switch to qmk forks for everything (#9019)
* audio refactor: replace deprecated PLAY_NOTE_ARRAY (#8484)
* Audio enable corrections (2/3) (#8903)
* Split HHKB to ANSI and JP layouts and Add VIA support for each (#8582)
* Audio enable corrections (Part 4) (#8974)
* Fix typo from PR7114 (#9171)
* Augment future branch Changelogs (#8978)
* Revert "Branch point for 2020 May 30 Breaking Change"
Diffstat (limited to 'quantum/rgb_matrix.c')
| -rw-r--r-- | quantum/rgb_matrix.c | 106 |
1 files changed, 63 insertions, 43 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 91032b656..f3da0ab0f 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
| @@ -57,8 +57,12 @@ const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; | |||
| 57 | // -----End rgb effect includes macros------- | 57 | // -----End rgb effect includes macros------- |
| 58 | // ------------------------------------------ | 58 | // ------------------------------------------ |
| 59 | 59 | ||
| 60 | #ifndef RGB_DISABLE_AFTER_TIMEOUT | 60 | #if defined(RGB_DISABLE_AFTER_TIMEOUT) && !defined(RGB_DISABLE_TIMEOUT) |
| 61 | # define RGB_DISABLE_AFTER_TIMEOUT 0 | 61 | # define RGB_DISABLE_TIMEOUT (RGB_DISABLE_AFTER_TIMEOUT * 1200) |
| 62 | #endif | ||
| 63 | |||
| 64 | #ifndef RGB_DISABLE_TIMEOUT | ||
| 65 | # define RGB_DISABLE_TIMEOUT 0 | ||
| 62 | #endif | 66 | #endif |
| 63 | 67 | ||
| 64 | #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED | 68 | #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED |
| @@ -111,19 +115,29 @@ const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; | |||
| 111 | # define RGB_MATRIX_STARTUP_SPD UINT8_MAX / 2 | 115 | # define RGB_MATRIX_STARTUP_SPD UINT8_MAX / 2 |
| 112 | #endif | 116 | #endif |
| 113 | 117 | ||
| 114 | bool g_suspend_state = false; | 118 | // globals |
| 115 | 119 | bool g_suspend_state = false; | |
| 116 | rgb_config_t rgb_matrix_config; | 120 | rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr |
| 117 | 121 | uint32_t g_rgb_timer; | |
| 118 | rgb_counters_t g_rgb_counters; | ||
| 119 | static uint32_t rgb_counters_buffer; | ||
| 120 | |||
| 121 | #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS | 122 | #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS |
| 122 | uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; | 123 | uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}}; |
| 123 | #endif | 124 | #endif // RGB_MATRIX_FRAMEBUFFER_EFFECTS |
| 125 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 126 | last_hit_t g_last_hit_tracker; | ||
| 127 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | ||
| 124 | 128 | ||
| 129 | // internals | ||
| 130 | static uint8_t rgb_last_enable = UINT8_MAX; | ||
| 131 | static uint8_t rgb_last_effect = UINT8_MAX; | ||
| 132 | static effect_params_t rgb_effect_params = {0, 0xFF}; | ||
| 133 | static rgb_task_states rgb_task_state = SYNCING; | ||
| 134 | #if RGB_DISABLE_TIMEOUT > 0 | ||
| 135 | static uint32_t rgb_anykey_timer; | ||
| 136 | #endif // RGB_DISABLE_TIMEOUT > 0 | ||
| 137 | |||
| 138 | // double buffers | ||
| 139 | static uint32_t rgb_timer_buffer; | ||
| 125 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 140 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 126 | last_hit_t g_last_hit_tracker; | ||
| 127 | static last_hit_t last_hit_buffer; | 141 | static last_hit_t last_hit_buffer; |
| 128 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | 142 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
| 129 | 143 | ||
| @@ -169,21 +183,24 @@ void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { | |||
| 169 | void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(red, green, blue); } | 183 | void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(red, green, blue); } |
| 170 | 184 | ||
| 171 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { | 185 | bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) { |
| 186 | #if RGB_DISABLE_TIMEOUT > 0 | ||
| 187 | if (record->event.pressed) { | ||
| 188 | rgb_anykey_timer = 0; | ||
| 189 | } | ||
| 190 | #endif // RGB_DISABLE_TIMEOUT > 0 | ||
| 191 | |||
| 172 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 192 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 173 | uint8_t led[LED_HITS_TO_REMEMBER]; | 193 | uint8_t led[LED_HITS_TO_REMEMBER]; |
| 174 | uint8_t led_count = 0; | 194 | uint8_t led_count = 0; |
| 175 | 195 | ||
| 176 | # if defined(RGB_MATRIX_KEYRELEASES) | 196 | # if defined(RGB_MATRIX_KEYRELEASES) |
| 177 | if (!record->event.pressed) { | 197 | if (!record->event.pressed) |
| 178 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); | ||
| 179 | g_rgb_counters.any_key_hit = 0; | ||
| 180 | } | ||
| 181 | # elif defined(RGB_MATRIX_KEYPRESSES) | 198 | # elif defined(RGB_MATRIX_KEYPRESSES) |
| 182 | if (record->event.pressed) { | 199 | if (record->event.pressed) |
| 183 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); | ||
| 184 | g_rgb_counters.any_key_hit = 0; | ||
| 185 | } | ||
| 186 | # endif // defined(RGB_MATRIX_KEYRELEASES) | 200 | # endif // defined(RGB_MATRIX_KEYRELEASES) |
| 201 | { | ||
| 202 | led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led); | ||
| 203 | } | ||
| 187 | 204 | ||
| 188 | if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { | 205 | if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) { |
| 189 | memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); | 206 | memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count); |
| @@ -216,7 +233,7 @@ void rgb_matrix_test(void) { | |||
| 216 | // Mask out bits 4 and 5 | 233 | // Mask out bits 4 and 5 |
| 217 | // Increase the factor to make the test animation slower (and reduce to make it faster) | 234 | // Increase the factor to make the test animation slower (and reduce to make it faster) |
| 218 | uint8_t factor = 10; | 235 | uint8_t factor = 10; |
| 219 | switch ((g_rgb_counters.tick & (0b11 << factor)) >> factor) { | 236 | switch ((g_rgb_timer & (0b11 << factor)) >> factor) { |
| 220 | case 0: { | 237 | case 0: { |
| 221 | rgb_matrix_set_color_all(20, 0, 0); | 238 | rgb_matrix_set_color_all(20, 0, 0); |
| 222 | break; | 239 | break; |
| @@ -241,29 +258,26 @@ static bool rgb_matrix_none(effect_params_t *params) { | |||
| 241 | return false; | 258 | return false; |
| 242 | } | 259 | } |
| 243 | 260 | ||
| 244 | RGB_MATRIX_USE_LIMITS(led_min, led_max); | 261 | rgb_matrix_set_color_all(0, 0, 0); |
| 245 | for (uint8_t i = led_min; i < led_max; i++) { | 262 | return false; |
| 246 | rgb_matrix_set_color(i, 0, 0, 0); | ||
| 247 | } | ||
| 248 | return led_max < DRIVER_LED_TOTAL; | ||
| 249 | } | 263 | } |
| 250 | 264 | ||
| 251 | static uint8_t rgb_last_enable = UINT8_MAX; | ||
| 252 | static uint8_t rgb_last_effect = UINT8_MAX; | ||
| 253 | static effect_params_t rgb_effect_params = {0, 0xFF}; | ||
| 254 | static rgb_task_states rgb_task_state = SYNCING; | ||
| 255 | |||
| 256 | static void rgb_task_timers(void) { | 265 | static void rgb_task_timers(void) { |
| 266 | #if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 | ||
| 267 | uint32_t deltaTime = timer_elapsed32(rgb_timer_buffer); | ||
| 268 | #endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 | ||
| 269 | rgb_timer_buffer = timer_read32(); | ||
| 270 | |||
| 257 | // Update double buffer timers | 271 | // Update double buffer timers |
| 258 | uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer); | 272 | #if RGB_DISABLE_TIMEOUT > 0 |
| 259 | rgb_counters_buffer = timer_read32(); | 273 | if (rgb_anykey_timer < UINT32_MAX) { |
| 260 | if (g_rgb_counters.any_key_hit < UINT32_MAX) { | 274 | if (UINT32_MAX - deltaTime < rgb_anykey_timer) { |
| 261 | if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) { | 275 | rgb_anykey_timer = UINT32_MAX; |
| 262 | g_rgb_counters.any_key_hit = UINT32_MAX; | ||
| 263 | } else { | 276 | } else { |
| 264 | g_rgb_counters.any_key_hit += deltaTime; | 277 | rgb_anykey_timer += deltaTime; |
| 265 | } | 278 | } |
| 266 | } | 279 | } |
| 280 | #endif // RGB_DISABLE_TIMEOUT > 0 | ||
| 267 | 281 | ||
| 268 | // Update double buffer last hit timers | 282 | // Update double buffer last hit timers |
| 269 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 283 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| @@ -280,7 +294,7 @@ static void rgb_task_timers(void) { | |||
| 280 | 294 | ||
| 281 | static void rgb_task_sync(void) { | 295 | static void rgb_task_sync(void) { |
| 282 | // next task | 296 | // next task |
| 283 | if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; | 297 | if (timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; |
| 284 | } | 298 | } |
| 285 | 299 | ||
| 286 | static void rgb_task_start(void) { | 300 | static void rgb_task_start(void) { |
| @@ -288,7 +302,7 @@ static void rgb_task_start(void) { | |||
| 288 | rgb_effect_params.iter = 0; | 302 | rgb_effect_params.iter = 0; |
| 289 | 303 | ||
| 290 | // update double buffers | 304 | // update double buffers |
| 291 | g_rgb_counters.tick = rgb_counters_buffer; | 305 | g_rgb_timer = rgb_timer_buffer; |
| 292 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 306 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 293 | g_last_hit_tracker = last_hit_buffer; | 307 | g_last_hit_tracker = last_hit_buffer; |
| 294 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | 308 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
| @@ -370,8 +384,16 @@ void rgb_matrix_task(void) { | |||
| 370 | 384 | ||
| 371 | // Ideally we would also stop sending zeros to the LED driver PWM buffers | 385 | // Ideally we would also stop sending zeros to the LED driver PWM buffers |
| 372 | // while suspended and just do a software shutdown. This is a cheap hack for now. | 386 | // while suspended and just do a software shutdown. This is a cheap hack for now. |
| 373 | bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_rgb_counters.any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20)); | 387 | bool suspend_backlight = |
| 374 | uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; | 388 | #if RGB_DISABLE_WHEN_USB_SUSPENDED == true |
| 389 | g_suspend_state || | ||
| 390 | #endif // RGB_DISABLE_WHEN_USB_SUSPENDED == true | ||
| 391 | #if RGB_DISABLE_TIMEOUT > 0 | ||
| 392 | (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || | ||
| 393 | #endif // RGB_DISABLE_TIMEOUT > 0 | ||
| 394 | false; | ||
| 395 | |||
| 396 | uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; | ||
| 375 | 397 | ||
| 376 | switch (rgb_task_state) { | 398 | switch (rgb_task_state) { |
| 377 | case STARTING: | 399 | case STARTING: |
| @@ -405,8 +427,6 @@ __attribute__((weak)) void rgb_matrix_indicators_user(void) {} | |||
| 405 | void rgb_matrix_init(void) { | 427 | void rgb_matrix_init(void) { |
| 406 | rgb_matrix_driver.init(); | 428 | rgb_matrix_driver.init(); |
| 407 | 429 | ||
| 408 | // TODO: put the 1 second startup delay here? | ||
| 409 | |||
| 410 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | 430 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED |
| 411 | g_last_hit_tracker.count = 0; | 431 | g_last_hit_tracker.count = 0; |
| 412 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { | 432 | for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) { |
