From 7ba6456c0b2e041bb9f97dbed265c5b8b4b12192 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 31 Dec 2019 08:33:49 -0800 Subject: Use White channel on RGBW LEDs (#7678) * Use White channel on RGBW LEDs Co-authored-by: kwerdenker * Manually apply white channel to array * Move where convert_rgb_to_rgbw is called * Fix type for rgbw led struct * Add changes to Ergodox EZ can revert if deemed necessary * Revert "Add changes to Ergodox EZ" This reverts commit aa44db198d40d758ca10470eb94615513592d1dd. * Revert "Fix type for rgbw led struct" This reverts commit c5c744cba040201cc0d124400773cf13f8a2cf22. * Revert "Move where convert_rgb_to_rgbw is called" This reverts commit cd7f17caf6dd30731c54b3be54490fe4519444f9. * Revert changes and fix up functions * Enable white channel for Ergodox EZ as well * Only run conversion of rgblight is enabled Co-authored-by: kwerdenker --- keyboards/ergodox_ez/led_i2c.c | 8 +++++++- quantum/color.c | 14 ++++++++++++++ quantum/color.h | 4 +++- quantum/rgb_matrix_drivers.c | 2 +- quantum/rgblight.c | 9 ++++++++- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/keyboards/ergodox_ez/led_i2c.c b/keyboards/ergodox_ez/led_i2c.c index 3e75a8cd0..4a7a02f46 100644 --- a/keyboards/ergodox_ez/led_i2c.c +++ b/keyboards/ergodox_ez/led_i2c.c @@ -51,7 +51,13 @@ void rgblight_set(void) { #endif } } - +#ifdef RGBW + else { + for (uint8_t i = 0; i < RGBLED_NUM; i++) { + convert_rgb_to_rgbw(&led[i]); + } + } +#endif uint8_t led_num = RGBLED_NUM; i2c_init(); diff --git a/quantum/color.c b/quantum/color.c index 1f398e240..8bd52444f 100644 --- a/quantum/color.c +++ b/quantum/color.c @@ -85,3 +85,17 @@ RGB hsv_to_rgb(HSV hsv) { return rgb; } + +#ifdef RGBW +#ifndef MIN +# define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif +void convert_rgb_to_rgbw(LED_TYPE *led) { + // Determine lowest value in all three colors, put that into + // the white channel and then shift all colors by that amount + led->w = MIN(led->r, MIN(led->g, led->b)); + led->r -= led->w; + led->g -= led->w; + led->b -= led->w; +} +#endif diff --git a/quantum/color.h b/quantum/color.h index 678164662..58d4f0407 100644 --- a/quantum/color.h +++ b/quantum/color.h @@ -64,5 +64,7 @@ typedef struct PACKED { #endif RGB hsv_to_rgb(HSV hsv); - +#ifdef RGBW +void convert_rgb_to_rgbw(LED_TYPE *led); +#endif #endif // COLOR_H diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c index 9729a3064..ea41b0d39 100644 --- a/quantum/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix_drivers.c @@ -113,7 +113,7 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { led[i].g = g; led[i].b = b; # ifdef RGBW - led[i].w = 0; + convert_rgb_to_rgbw(led[i]); # endif } diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 7949bb688..141dc2e7b 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -611,6 +611,7 @@ void rgblight_set(void) { # endif } } + # ifdef RGBLIGHT_LED_MAP LED_TYPE led0[RGBLED_NUM]; for (uint8_t i = 0; i < RGBLED_NUM; i++) { @@ -620,7 +621,13 @@ void rgblight_set(void) { # else start_led = led + clipping_start_pos; # endif - ws2812_setleds(start_led, num_leds); + +#ifdef RGBW + for (uint8_t i = 0; i < num_leds; i++) { + convert_rgb_to_rgbw(&start_led[i]); + } +#endif + ws2812_setleds(start_led, num_leds); } #endif -- cgit v1.2.3-70-g09d2