Skip to content

Commit

Permalink
Use White channel on RGBW LEDs (qmk#7678)
Browse files Browse the repository at this point in the history
* Use White channel on RGBW LEDs

Co-authored-by: kwerdenker <[email protected]>

* 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 <[email protected]>
  • Loading branch information
2 people authored and zvecr committed Dec 31, 2019
1 parent a52e55e commit 7ba6456
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
8 changes: 7 additions & 1 deletion keyboards/ergodox_ez/led_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions quantum/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion quantum/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion quantum/rgb_matrix_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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

Expand Down

0 comments on commit 7ba6456

Please sign in to comment.