Skip to content

Commit fc8e4f5

Browse files
drashnanoroadsleft
authored andcommitted
Add advanced/efficient RGB Matrix Indicators (qmk#8564)
* Add Advanced RGB Matrix effects Add a new option, so that we can better handle custom indicators * Switch to led min/max instead of params Because params has already been incremented and is wrong now * Add indicator color function for use with advanced indicator functions * Add docs and helper macros * Add comment for explanations * Fix macro variables * Fix typo * Run clang-format on rgb_matrix.h
1 parent c876f15 commit fc8e4f5

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

docs/feature_rgb_matrix.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,14 @@ void rgb_matrix_indicators_kb(void) {
482482
}
483483
```
484484

485+
In addition, there are the advanced indicator functions. These are aimed at those with heavily customized displays, where rendering every LED per cycle is expensive. Such as some of the "drashna" layouts. This includes a special macro to help make this easier to use: `RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b)`.
486+
487+
```c
488+
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
489+
RGB_MATRIX_INDICATOR_SET_COLOR(index, red, green, blue);
490+
}
491+
```
492+
485493
### Suspended state :id=suspended-state
486494
To use the suspend feature, make sure that `#define RGB_DISABLE_WHEN_USB_SUSPENDED true` is added to the `config.h` file.
487495

quantum/rgb_matrix.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ void rgb_matrix_task(void) {
401401
break;
402402
case RENDERING:
403403
rgb_task_render(effect);
404+
if (!suspend_backlight) {
405+
rgb_matrix_indicators();
406+
rgb_matrix_indicators_advanced(&rgb_effect_params);
407+
}
404408
break;
405409
case FLUSHING:
406410
rgb_task_flush(effect);
@@ -409,10 +413,6 @@ void rgb_matrix_task(void) {
409413
rgb_task_sync();
410414
break;
411415
}
412-
413-
if (!suspend_backlight) {
414-
rgb_matrix_indicators();
415-
}
416416
}
417417

418418
void rgb_matrix_indicators(void) {
@@ -424,6 +424,28 @@ __attribute__((weak)) void rgb_matrix_indicators_kb(void) {}
424424

425425
__attribute__((weak)) void rgb_matrix_indicators_user(void) {}
426426

427+
void rgb_matrix_indicators_advanced(effect_params_t *params) {
428+
/* special handling is needed for "params->iter", since it's already been incremented.
429+
* Could move the invocations to rgb_task_render, but then it's missing a few checks
430+
* and not sure which would be better. Otherwise, this should be called from
431+
* rgb_task_render, right before the iter++ line.
432+
*/
433+
#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
434+
uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1);
435+
uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT;
436+
if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
437+
#else
438+
uint8_t min = 0;
439+
uint8_t max = DRIVER_LED_TOTAL;
440+
#endif
441+
rgb_matrix_indicators_advanced_kb(min, max);
442+
rgb_matrix_indicators_advanced_user(min, max);
443+
}
444+
445+
__attribute__((weak)) void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {}
446+
447+
__attribute__((weak)) void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {}
448+
427449
void rgb_matrix_init(void) {
428450
rgb_matrix_driver.init();
429451

quantum/rgb_matrix.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
uint8_t max = DRIVER_LED_TOTAL;
5858
#endif
5959

60+
#define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \
61+
if (i >= led_min && i <= led_max) { \
62+
rgb_matrix_set_color(i, r, g, b); \
63+
}
64+
6065
#define RGB_MATRIX_TEST_LED_FLAGS() \
6166
if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
6267

@@ -103,6 +108,10 @@ void rgb_matrix_indicators(void);
103108
void rgb_matrix_indicators_kb(void);
104109
void rgb_matrix_indicators_user(void);
105110

111+
void rgb_matrix_indicators_advanced(effect_params_t *params);
112+
void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
113+
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
114+
106115
void rgb_matrix_init(void);
107116

108117
void rgb_matrix_set_suspend_state(bool state);

0 commit comments

Comments
 (0)