Skip to content

Commit

Permalink
Add advanced/efficient RGB Matrix Indicators (#8564)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
drashna authored Oct 4, 2020
1 parent 633fe33 commit 1d40f26
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
8 changes: 8 additions & 0 deletions docs/feature_rgb_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ void rgb_matrix_indicators_kb(void) {
}
```

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)`.

```c
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
RGB_MATRIX_INDICATOR_SET_COLOR(index, red, green, blue);
}
```
### Suspended state :id=suspended-state
To use the suspend feature, make sure that `#define RGB_DISABLE_WHEN_USB_SUSPENDED true` is added to the `config.h` file.
Expand Down
30 changes: 26 additions & 4 deletions quantum/rgb_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ void rgb_matrix_task(void) {
break;
case RENDERING:
rgb_task_render(effect);
if (!suspend_backlight) {
rgb_matrix_indicators();
rgb_matrix_indicators_advanced(&rgb_effect_params);
}
break;
case FLUSHING:
rgb_task_flush(effect);
Expand All @@ -409,10 +413,6 @@ void rgb_matrix_task(void) {
rgb_task_sync();
break;
}

if (!suspend_backlight) {
rgb_matrix_indicators();
}
}

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

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

void rgb_matrix_indicators_advanced(effect_params_t *params) {
/* special handling is needed for "params->iter", since it's already been incremented.
* Could move the invocations to rgb_task_render, but then it's missing a few checks
* and not sure which would be better. Otherwise, this should be called from
* rgb_task_render, right before the iter++ line.
*/
#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1);
uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT;
if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
#else
uint8_t min = 0;
uint8_t max = DRIVER_LED_TOTAL;
#endif
rgb_matrix_indicators_advanced_kb(min, max);
rgb_matrix_indicators_advanced_user(min, max);
}

__attribute__((weak)) void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {}

__attribute__((weak)) void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {}

void rgb_matrix_init(void) {
rgb_matrix_driver.init();

Expand Down
9 changes: 9 additions & 0 deletions quantum/rgb_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
uint8_t max = DRIVER_LED_TOTAL;
#endif

#define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \
if (i >= led_min && i <= led_max) { \
rgb_matrix_set_color(i, r, g, b); \
}

#define RGB_MATRIX_TEST_LED_FLAGS() \
if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue

Expand Down Expand Up @@ -103,6 +108,10 @@ void rgb_matrix_indicators(void);
void rgb_matrix_indicators_kb(void);
void rgb_matrix_indicators_user(void);

void rgb_matrix_indicators_advanced(effect_params_t *params);
void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);

void rgb_matrix_init(void);

void rgb_matrix_set_suspend_state(bool state);
Expand Down

0 comments on commit 1d40f26

Please sign in to comment.