diff options
| author | Drashna Jaelre <drashna@live.com> | 2019-12-31 08:33:49 -0800 |
|---|---|---|
| committer | Joel Challis <git@zvecr.com> | 2019-12-31 16:33:49 +0000 |
| commit | 7ba6456c0b2e041bb9f97dbed265c5b8b4b12192 (patch) | |
| tree | 4e01ff717ab7d4c1d6d979f5d01ad8d4d841962e | |
| parent | a52e55ec09c587ca58a156a6c174d51e0ad228b4 (diff) | |
| download | qmk_firmware-7ba6456c0b2e041bb9f97dbed265c5b8b4b12192.tar.gz qmk_firmware-7ba6456c0b2e041bb9f97dbed265c5b8b4b12192.zip | |
Use White channel on RGBW LEDs (#7678)
* Use White channel on RGBW LEDs
Co-authored-by: kwerdenker <sebastian.spindler@gmail.com>
* 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 <sebastian.spindler@gmail.com>
| -rw-r--r-- | keyboards/ergodox_ez/led_i2c.c | 8 | ||||
| -rw-r--r-- | quantum/color.c | 14 | ||||
| -rw-r--r-- | quantum/color.h | 4 | ||||
| -rw-r--r-- | quantum/rgb_matrix_drivers.c | 2 | ||||
| -rw-r--r-- | 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) { | |||
| 51 | #endif | 51 | #endif |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | 54 | #ifdef RGBW | |
| 55 | else { | ||
| 56 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | ||
| 57 | convert_rgb_to_rgbw(&led[i]); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | #endif | ||
| 55 | 61 | ||
| 56 | uint8_t led_num = RGBLED_NUM; | 62 | uint8_t led_num = RGBLED_NUM; |
| 57 | i2c_init(); | 63 | 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) { | |||
| 85 | 85 | ||
| 86 | return rgb; | 86 | return rgb; |
| 87 | } | 87 | } |
| 88 | |||
| 89 | #ifdef RGBW | ||
| 90 | #ifndef MIN | ||
| 91 | # define MIN(a, b) ((a) < (b) ? (a) : (b)) | ||
| 92 | #endif | ||
| 93 | void convert_rgb_to_rgbw(LED_TYPE *led) { | ||
| 94 | // Determine lowest value in all three colors, put that into | ||
| 95 | // the white channel and then shift all colors by that amount | ||
| 96 | led->w = MIN(led->r, MIN(led->g, led->b)); | ||
| 97 | led->r -= led->w; | ||
| 98 | led->g -= led->w; | ||
| 99 | led->b -= led->w; | ||
| 100 | } | ||
| 101 | #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 { | |||
| 64 | #endif | 64 | #endif |
| 65 | 65 | ||
| 66 | RGB hsv_to_rgb(HSV hsv); | 66 | RGB hsv_to_rgb(HSV hsv); |
| 67 | 67 | #ifdef RGBW | |
| 68 | void convert_rgb_to_rgbw(LED_TYPE *led); | ||
| 69 | #endif | ||
| 68 | #endif // COLOR_H | 70 | #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) { | |||
| 113 | led[i].g = g; | 113 | led[i].g = g; |
| 114 | led[i].b = b; | 114 | led[i].b = b; |
| 115 | # ifdef RGBW | 115 | # ifdef RGBW |
| 116 | led[i].w = 0; | 116 | convert_rgb_to_rgbw(led[i]); |
| 117 | # endif | 117 | # endif |
| 118 | } | 118 | } |
| 119 | 119 | ||
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) { | |||
| 611 | # endif | 611 | # endif |
| 612 | } | 612 | } |
| 613 | } | 613 | } |
| 614 | |||
| 614 | # ifdef RGBLIGHT_LED_MAP | 615 | # ifdef RGBLIGHT_LED_MAP |
| 615 | LED_TYPE led0[RGBLED_NUM]; | 616 | LED_TYPE led0[RGBLED_NUM]; |
| 616 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | 617 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { |
| @@ -620,7 +621,13 @@ void rgblight_set(void) { | |||
| 620 | # else | 621 | # else |
| 621 | start_led = led + clipping_start_pos; | 622 | start_led = led + clipping_start_pos; |
| 622 | # endif | 623 | # endif |
| 623 | ws2812_setleds(start_led, num_leds); | 624 | |
| 625 | #ifdef RGBW | ||
| 626 | for (uint8_t i = 0; i < num_leds; i++) { | ||
| 627 | convert_rgb_to_rgbw(&start_led[i]); | ||
| 628 | } | ||
| 629 | #endif | ||
| 630 | ws2812_setleds(start_led, num_leds); | ||
| 624 | } | 631 | } |
| 625 | #endif | 632 | #endif |
| 626 | 633 | ||
