diff options
author | Joel Challis <git@zvecr.com> | 2019-10-29 01:00:03 +0000 |
---|---|---|
committer | Florian Didron <fdidron@users.noreply.github.com> | 2019-11-04 17:24:31 +0900 |
commit | 66d4c71b03d25b9d889f20bfa471de5fe037a428 (patch) | |
tree | b7e8d351db8b6cc24e78c5392bd8e12d06e86916 /quantum | |
parent | 0a3343aca90ea49e286d469c7c61ef4230f03552 (diff) |
Reduce duplication for ARM/AVR ws2812 RGB Matrix driver (#7180)
* Reduce duplication for ARM/AVR ws2812 rgb_matrix driver
* Reduce duplication for ARM/AVR ws2812 rgb_matrix driver - Fix setled_all use of r,g,b
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/rgb_matrix_drivers.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c index 5b54bd5956..503f97014f 100644 --- a/quantum/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix_drivers.c @@ -97,19 +97,33 @@ const rgb_matrix_driver_t rgb_matrix_driver = { #elif defined(WS2812) -extern LED_TYPE led[DRIVER_LED_TOTAL]; +// LED color buffer +LED_TYPE led[DRIVER_LED_TOTAL]; + +static void init(void) {} static void flush(void) { // Assumes use of RGB_DI_PIN ws2812_setleds(led, DRIVER_LED_TOTAL); } -static void init(void) {} +// Set an led in the buffer to a color +static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { + led[i].r = r; + led[i].g = g; + led[i].b = b; +} + +static void setled_all(uint8_t r, uint8_t g, uint8_t b) { + for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) { + setled(i, r, g, b); + } +} const rgb_matrix_driver_t rgb_matrix_driver = { .init = init, .flush = flush, - .set_color = ws2812_setled, - .set_color_all = ws2812_setled_all, + .set_color = setled, + .set_color_all = setled_all, }; #endif |