Skip to content

Commit 7ba6456

Browse files
drashnakwerdenker
authored andcommitted
Use White channel on RGBW LEDs (qmk#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 aa44db1. * Revert "Fix type for rgbw led struct" This reverts commit c5c744c. * Revert "Move where convert_rgb_to_rgbw is called" This reverts commit cd7f17c. * 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>
1 parent a52e55e commit 7ba6456

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

keyboards/ergodox_ez/led_i2c.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ void rgblight_set(void) {
5151
#endif
5252
}
5353
}
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
5561

5662
uint8_t led_num = RGBLED_NUM;
5763
i2c_init();

quantum/color.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,17 @@ RGB hsv_to_rgb(HSV hsv) {
8585

8686
return rgb;
8787
}
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

quantum/color.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,7 @@ typedef struct PACKED {
6464
#endif
6565

6666
RGB hsv_to_rgb(HSV hsv);
67-
67+
#ifdef RGBW
68+
void convert_rgb_to_rgbw(LED_TYPE *led);
69+
#endif
6870
#endif // COLOR_H

quantum/rgb_matrix_drivers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
113113
led[i].g = g;
114114
led[i].b = b;
115115
# ifdef RGBW
116-
led[i].w = 0;
116+
convert_rgb_to_rgbw(led[i]);
117117
# endif
118118
}
119119

quantum/rgblight.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ void rgblight_set(void) {
611611
# endif
612612
}
613613
}
614+
614615
# ifdef RGBLIGHT_LED_MAP
615616
LED_TYPE led0[RGBLED_NUM];
616617
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
@@ -620,7 +621,13 @@ void rgblight_set(void) {
620621
# else
621622
start_led = led + clipping_start_pos;
622623
# 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);
624631
}
625632
#endif
626633

0 commit comments

Comments
 (0)