Skip to content

Commit

Permalink
Rename RGBW define to WS2812_RGBW (#23585)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark committed Apr 27, 2024
1 parent 8f8fffc commit 0ff53b2
Show file tree
Hide file tree
Showing 24 changed files with 68 additions and 44 deletions.
3 changes: 2 additions & 1 deletion data/mappings/info_config.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@
"RGBLIGHT_DEFAULT_SAT": {"info_key": "rgblight.default.sat", "value_type": "int"},
"RGBLIGHT_DEFAULT_VAL": {"info_key": "rgblight.default.val", "value_type": "int"},
"RGBLIGHT_DEFAULT_SPD": {"info_key": "rgblight.default.speed", "value_type": "int"},
"RGBW": {"info_key": "rgblight.rgbw", "value_type": "flag"},

// Secure
"SECURE_IDLE_TIMEOUT": {"info_key": "secure.idle_timeout", "value_type": "int"},
Expand Down Expand Up @@ -215,6 +214,7 @@
"WS2812_DI_PIN": {"info_key": "ws2812.pin"},
"WS2812_I2C_ADDRESS": {"info_key": "ws2812.i2c_address", "value_type": "hex"},
"WS2812_I2C_TIMEOUT": {"info_key": "ws2812.i2c_timeout", "value_type": "int"},
"WS2812_RGBW": {"info_key": "ws2812.rgbw", "value_type": "flag"},

"LAYOUTS": {"info_key": "layout_aliases", "value_type": "mapping"},

Expand All @@ -229,6 +229,7 @@
"PREVENT_STUCK_MODIFIERS": {"info_key": "_invalid.prevent_stuck_mods", "invalid": true},
"QMK_KEYS_PER_SCAN": {"info_key": "qmk.keys_per_scan", "value_type": "int", "deprecated": true},
"RGB_DI_PIN": {"info_key": "rgblight.pin", "invalid": true, "replace_with": "WS2812_DI_PIN or APA102_DI_PIN"},
"RGBW": {"info_key": "rgblight.rgbw", "invalid": true, "replace_with": "WS2812_RGBW"},
"RGB_DISABLE_WHEN_USB_SUSPENDED": {"info_key": "_invalid.rgb_matrix_sleep", "invalid": true, "replace_with": "RGB_MATRIX_SLEEP"},
"RGBLIGHT_ANIMATIONS": {"info_key": "_invalid.rgblight.animations.all", "value_type": "flag", "invalid": true},
"TAPPING_FORCE_HOLD": {"info_key": "tapping.force_hold", "value_type": "flag", "deprecated": true},
Expand Down
6 changes: 5 additions & 1 deletion data/schemas/keyboard.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,10 @@
"$ref": "qmk.definitions.v1#/mcu_pin",
"$comment": "Deprecated: use ws2812.pin instead"
},
"rgbw": {"type": "boolean"},
"rgbw": {
"type": "boolean",
"$comment": "Deprecated: use ws2812.rgbw instead"
},
"saturation_steps": {"$ref": "qmk.definitions.v1#/unsigned_int"},
"sleep": {"type": "boolean"},
"split": {"type": "boolean"},
Expand Down Expand Up @@ -937,6 +940,7 @@
"enum": ["bitbang", "custom", "i2c", "pwm", "spi", "vendor"]
},
"pin": {"$ref": "qmk.definitions.v1#/mcu_pin"},
"rgbw": {"type": "boolean"},
"i2c_address": {"$ref": "qmk.definitions.v1#/hex_number_2d"},
"i2c_timeout": {"$ref": "qmk.definitions.v1#/unsigned_int"}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/config_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ If you define these options you will enable the associated feature, which may in
* units to step when in/decreasing saturation
* `#define RGBLIGHT_VAL_STEP 12`
* units to step when in/decreasing value (brightness)
* `#define RGBW`
* `#define WS2812_RGBW`
* Enables RGBW LED support

## Mouse Key Options
Expand Down
2 changes: 1 addition & 1 deletion docs/feature_rgblight.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ QMK has the ability to control RGB LEDs attached to your keyboard. This is commo

Some keyboards come with RGB LEDs preinstalled. Others must have them installed after the fact. See the [Hardware Modification](#hardware-modification) section for information on adding RGB lighting to your keyboard.

Currently QMK supports the following addressable LEDs (however, the white LED in RGBW variants is not supported):
Currently QMK supports the following addressable LEDs:

* WS2811, WS2812, WS2812B, WS2812C, etc.
* SK6812, SK6812MINI, SK6805
Expand Down
6 changes: 3 additions & 3 deletions docs/reference_info_json.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,6 @@ Configures the [RGB Lighting](feature_rgblight.md) feature.
* `max_brightness`
* The maximum value which the HSV "V" component is scaled to, from 0 to 255.
* Default: `255`
* `rgbw`
* Enable RGBW LEDs.
* Default: `false`
* `saturation_steps`
* The number of saturation adjustment steps.
* Default: `17`
Expand Down Expand Up @@ -855,3 +852,6 @@ Configures the [WS2812](ws2812_driver.md) driver.
* `i2c_timeout`
* The I²C timeout in milliseconds (`i2c` driver only).
* Default: `100` (100 ms)
* `rgbw`
* Enable RGBW LEDs.
* Default: `false`
22 changes: 22 additions & 0 deletions docs/ws2812_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Add the following to your `config.h`:
|`WS2812_T0H` |`350` |The length of a "0" bit's high phase in nanoseconds |
|`WS2812_TRST_US` |`280` |The length of the reset phase in microseconds |
|`WS2812_BYTE_ORDER`|`WS2812_BYTE_ORDER_GRB`|The byte order of the RGB data |
|`WS2812_RGBW` |*Not defined* |Enables RGBW support (except `i2c` driver) |

### Timing Adjustment :id=timing-adjustment

Expand All @@ -58,6 +59,27 @@ Where the byte order may be one of:
|`RGB` |WS2812B-2020 |
|`BGR` |TM1812 |
### RGBW Support :id=rgbw-support
Rendering the color white with RGB LEDs is typically inconsistent due to inherent variations between each individual LED die. However, some WS2812 variants (such as SK6812RGBW) also possess a white LED along with the red, green, and blue channels, which allows for a more accurate white to be displayed.
QMK can automatically convert the RGB data to be sent to the LEDs to mix in the white channel:
```
w = min(r, g, b)
r -= w
g -= w
b -= w
```

Thus, an RGB triplet of `255,255,255` will simply turn on the white LED fully (`0,0,0,255`).

To enable RGBW conversion, add the following to your `config.h`:

```c
#define WS2812_RGBW
```

## Driver Configuration :id=driver-configuration

Driver selection can be configured in `rules.mk` as `WS2812_DRIVER`, or in `info.json` as `ws2812.driver`. Valid values are `bitbang` (default), `i2c`, `spi`, `pwm`, `vendor`, or `custom`. See below for information on individual drivers.
Expand Down
2 changes: 0 additions & 2 deletions keyboards/ergodox_ez/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.
/* fix space cadet rollover issue */
#define DISABLE_SPACE_CADET_ROLLOVER

#define RGBW

/*
* The debounce filtering reports a key/switch change directly,
* without any extra delay. After that the debounce logic will filter
Expand Down
3 changes: 2 additions & 1 deletion keyboards/ergodox_ez/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"debounce_type": "sym_eager_pr"
},
"ws2812": {
"pin": "D7"
"pin": "D7",
"rgbw": true
},
"rgb_matrix": {
"animations": {
Expand Down
4 changes: 2 additions & 2 deletions keyboards/ergodox_ez/shine/rgblight_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void setleds_custom(rgb_led_t *led, uint16_t led_num) {
uint16_t length = 0;
int i = 0;
int j = 0;
# ifdef RGBW
# ifdef WS2812_RGBW
int bytes_per_led = 4;
# else
int bytes_per_led = 3;
Expand All @@ -52,7 +52,7 @@ void setleds_custom(rgb_led_t *led, uint16_t led_num) {
data[j++] = data_byte[0];
data[j++] = data_byte[1];
data[j++] = data_byte[2];
#ifdef RGBW
#ifdef WS2812_RGBW
data[j++] = data_byte[3];
#endif
}
Expand Down
2 changes: 0 additions & 2 deletions keyboards/handwired/tennie/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.

#pragma once

#define RGBW

/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
Expand Down
3 changes: 2 additions & 1 deletion keyboards/handwired/tennie/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
}
},
"ws2812": {
"pin": "D1"
"pin": "D1",
"rgbw": true
},
"features": {
"bootmagic": true,
Expand Down
2 changes: 1 addition & 1 deletion keyboards/oddforge/vea/ws2812_custom.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ws2812.h"
#include "i2c_master.h"

#ifdef RGBW
#ifdef WS2812_RGBW
# error "RGBW not supported"
#endif

Expand Down
2 changes: 1 addition & 1 deletion keyboards/rgbkb/pan/pan.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
rgb_matrix_ws2812_array[i].g = g;
rgb_matrix_ws2812_array[i].b = b;
}
# ifdef RGBW
# ifdef WS2812_RGBW
convert_rgb_to_rgbw(&rgb_matrix_ws2812_array[i]);
# endif
}
Expand Down
2 changes: 0 additions & 2 deletions keyboards/westfoxtrot/aanzee/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ along with this program. If not, see <http:https://www.gnu.org/licenses/>.

#pragma once

#define RGBW

/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
Expand Down
3 changes: 2 additions & 1 deletion keyboards/westfoxtrot/aanzee/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
}
},
"ws2812": {
"pin": "E6"
"pin": "E6",
"rgbw": true
},
"processor": "atmega32u4",
"bootloader": "atmel-dfu",
Expand Down
2 changes: 1 addition & 1 deletion platforms/avr/drivers/ws2812_i2c.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ws2812.h"
#include "i2c_master.h"

#ifdef RGBW
#ifdef WS2812_RGBW
# error "RGBW not supported"
#endif

Expand Down
6 changes: 3 additions & 3 deletions platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static void ws2812_dma_callback(void* p, uint32_t ct) {
// FIFO is already empty.
rtcnt_t time_to_completion = (pio_sm_get_tx_fifo_level(pio, STATE_MACHINE) + 1) * MAX(WS2812_T1H + WS2812_T1L, WS2812_T0H + WS2812_T0L);

#if defined(RGBW)
#if defined(WS2812_RGBW)
time_to_completion *= 32;
#else
time_to_completion *= 24;
Expand Down Expand Up @@ -222,7 +222,7 @@ void ws2812_init(void) {
sm_config_set_sideset(&config, 1, false, false);
#endif

#if defined(RGBW)
#if defined(WS2812_RGBW)
sm_config_set_out_shift(&config, false, true, 32);
#else
sm_config_set_out_shift(&config, false, true, 24);
Expand Down Expand Up @@ -270,7 +270,7 @@ void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
sync_ws2812_transfer();

for (int i = 0; i < leds; i++) {
#if defined(RGBW)
#if defined(WS2812_RGBW)
WS2812_BUFFER[i] = rgbw8888_to_u32(ledarray[i].r, ledarray[i].g, ledarray[i].b, ledarray[i].w);
#else
WS2812_BUFFER[i] = rgbw8888_to_u32(ledarray[i].r, ledarray[i].g, ledarray[i].b, 0);
Expand Down
2 changes: 1 addition & 1 deletion platforms/chibios/drivers/ws2812_bitbang.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
sendByte(ledarray[i].r);
#endif

#ifdef RGBW
#ifdef WS2812_RGBW
sendByte(ledarray[i].w);
#endif
}
Expand Down
8 changes: 4 additions & 4 deletions platforms/chibios/drivers/ws2812_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/* Adapted from https://github.com/joewa/WS2812-LED-Driver_ChibiOS/ */

#ifdef RGBW
#ifdef WS2812_RGBW
# define WS2812_CHANNELS 4
#else
# define WS2812_CHANNELS 3
Expand Down Expand Up @@ -262,7 +262,7 @@
# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 0, (bit))
#endif

#ifdef RGBW
#ifdef WS2812_RGBW
/**
* @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given white bit
*
Expand Down Expand Up @@ -381,7 +381,7 @@ void ws2812_write_led_rgbw(uint16_t led_number, uint8_t r, uint8_t g, uint8_t b,
ws2812_frame_buffer[WS2812_RED_BIT(led_number, bit)] = ((r >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
ws2812_frame_buffer[WS2812_GREEN_BIT(led_number, bit)] = ((g >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
ws2812_frame_buffer[WS2812_BLUE_BIT(led_number, bit)] = ((b >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
#ifdef RGBW
#ifdef WS2812_RGBW
ws2812_frame_buffer[WS2812_WHITE_BIT(led_number, bit)] = ((w >> bit) & 0x01) ? WS2812_DUTYCYCLE_1 : WS2812_DUTYCYCLE_0;
#endif
}
Expand All @@ -390,7 +390,7 @@ void ws2812_write_led_rgbw(uint16_t led_number, uint8_t r, uint8_t g, uint8_t b,
// Setleds for standard RGB
void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
for (uint16_t i = 0; i < leds; i++) {
#ifdef RGBW
#ifdef WS2812_RGBW
ws2812_write_led_rgbw(i, ledarray[i].r, ledarray[i].g, ledarray[i].b, ledarray[i].w);
#else
ws2812_write_led(i, ledarray[i].r, ledarray[i].g, ledarray[i].b);
Expand Down
4 changes: 2 additions & 2 deletions platforms/chibios/drivers/ws2812_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#endif

#define BYTES_FOR_LED_BYTE 4
#ifdef RGBW
#ifdef WS2812_RGBW
# define WS2812_CHANNELS 4
#else
# define WS2812_CHANNELS 3
Expand Down Expand Up @@ -131,7 +131,7 @@ static void set_led_color_rgb(rgb_led_t color, int pos) {
for (int j = 0; j < 4; j++)
tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.r, j);
#endif
#ifdef RGBW
#ifdef WS2812_RGBW
for (int j = 0; j < 4; j++)
tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 4 + j] = get_protocol_eq(color.w, j);
#endif
Expand Down
2 changes: 1 addition & 1 deletion quantum/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ RGB hsv_to_rgb_nocie(HSV hsv) {
return hsv_to_rgb_impl(hsv, false);
}

#ifdef RGBW
#ifdef WS2812_RGBW
void convert_rgb_to_rgbw(rgb_led_t *led) {
// Determine lowest value in all three colors, put that into
// the white channel and then shift all colors by that amount
Expand Down
4 changes: 2 additions & 2 deletions quantum/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ typedef struct PACKED rgb_led_t {
uint8_t g;
uint8_t r;
#endif
#ifdef RGBW
#ifdef WS2812_RGBW
uint8_t w;
#endif
} rgb_led_t;
Expand All @@ -111,6 +111,6 @@ typedef struct PACKED HSV {

RGB hsv_to_rgb(HSV hsv);
RGB hsv_to_rgb_nocie(HSV hsv);
#ifdef RGBW
#ifdef WS2812_RGBW
void convert_rgb_to_rgbw(rgb_led_t *led);
#endif
2 changes: 1 addition & 1 deletion quantum/rgb_matrix/rgb_matrix_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
rgb_matrix_ws2812_array[i].r = r;
rgb_matrix_ws2812_array[i].g = g;
rgb_matrix_ws2812_array[i].b = b;
# ifdef RGBW
# ifdef WS2812_RGBW
convert_rgb_to_rgbw(&rgb_matrix_ws2812_array[i]);
# endif
}
Expand Down
Loading

0 comments on commit 0ff53b2

Please sign in to comment.