summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/color.c14
-rw-r--r--quantum/color.h4
-rw-r--r--quantum/rgb_matrix_drivers.c2
-rw-r--r--quantum/rgblight.c9
4 files changed, 26 insertions, 3 deletions
diff --git a/quantum/color.c b/quantum/color.c
index 1f398e2403..8bd52444fa 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 6781646628..58d4f0407f 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 9729a3064e..ea41b0d396 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 7949bb688e..141dc2e7bc 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