1
0
Fork 0

WS2812 API rework (#24364)

* Begin WS2812 API rework

* Move RGBW conversion, clean up color.h, fix RGBW for AVR bitbang

* Formatting & update PS2AVRGB I2C driver (untested)

* Tested ARM bitbang RGB+RGBW

* Tested ARM SPI RGB - RGBW not working

* Tested ARM PWM RGB+RGBW

* Tested RP2040 PIO driver RGB+RGBW

* Update RGBLight

* Formatting

* Fix BM60HSRGB rev2

* Fix oddforge/vea

* Fix 1k and XD002 RGBLite

* Fix model_m/mschwingen

* Fix handwired/promethium

* Rename `WS2812_LED_TOTAL` for BM60HSRGB

* Fix work_louder boards

* Fix dawn60

* Fix rgbkb/pan

* Fix neson_design/700e and n6

* Fix ergodox_ez/shine

* ergodox_ez/shine: invert indices for left half

* Fix matrix/abelx

* Fix matrix/m20add

* Remove custom rgblight driver for matrix/noah - should be done with lighting layers

* Fix LED indexes for RGBLight split

* Rename `convert_rgb_to_rgbw()` to `ws2812_rgb_to_rgbw()`

* Update WS2812 API docs

* `ergodox_ez/shine`: simplify LED index calculation

* LED/RGB Matrix: Add weak function for LED index resolution

* Bandaid fix for RGB Matrix splits not using WS2812

* `steelseries/prime_plus`: redo custom RGBLight driver

* Update keyboards/steelseries/prime_plus/rgblight_custom.c

Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com>

---------

Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com>
This commit is contained in:
Ryan 2024-10-06 19:01:07 +11:00 committed by GitHub
parent 43e82ed5c7
commit 208ebf54a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 649 additions and 672 deletions

View file

@ -18,9 +18,11 @@
*/
#include "quantum.h"
#include "i2c_master.h"
#include "drivers/led/issi/is31fl3731.h"
#include "ws2812.h"
#ifdef RGBLIGHT_ENABLE
# include "i2c_master.h"
# include "drivers/led/issi/is31fl3731.h"
# include "ws2812.h"
enum {
SELF_TESTING,
@ -67,7 +69,6 @@ enum {
#endif
#define ST_RIGHT_END (ST_RIGHT_BEGIN+ST_RIGHT_SIZE-1)
#ifdef RGBLIGHT_ENABLE
typedef struct {
uint8_t state;
@ -295,7 +296,6 @@ void matrix_init_kb(void)
gpio_set_pin_output(LED_CAPS_LOCK_PIN);
gpio_write_pin_low(LED_CAPS_LOCK_PIN);
is31fl3731_init_drivers();
update_ticks();
matrix_init_user();
@ -313,17 +313,10 @@ void housekeeping_task_kb(void)
} else if (rgb_state.state == CAPS_ALERT) {
if (rgb_state.alert) {
is31fl3731_set_color_all(ALERM_LED_R, ALERM_LED_G, ALERM_LED_B);
rgb_led_t leds[4];
for (int i = 0; i < 4; i++) {
leds[i].r = ALERM_LED_G;
leds[i].g = ALERM_LED_R;
leds[i].b = ALERM_LED_B;
}
ws2812_setleds(leds, 4);
ws2812_set_color_all(ALERM_LED_G, ALERM_LED_R, ALERM_LED_B);
} else {
is31fl3731_set_color_all(0, 0, 0);
rgb_led_t leds[4] = {0};
ws2812_setleds(leds, 4);
ws2812_set_color_all(0, 0, 0);
}
if (timer_elapsed(rgb_state.ticks) > ALERT_INTERVAL) {
@ -333,28 +326,40 @@ void housekeeping_task_kb(void)
}
is31fl3731_flush();
ws2812_flush();
}
void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{
void init_custom(void) {
is31fl3731_init_drivers();
ws2812_init();
}
void set_color_custom(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index < IS31FL3731_LED_COUNT) {
is31fl3731_set_color(index, red, green, blue);
} else if (index < IS31FL3731_LED_COUNT + WS2812_LED_COUNT) {
ws2812_set_color(index - IS31FL3731_LED_COUNT, green, red, blue);
}
}
void set_color_all_custom(uint8_t red, uint8_t green, uint8_t blue) {
for (int i = 0; i < RGBLIGHT_LED_COUNT; i++) {
set_color_custom(i, red, green, blue);
}
}
void flush_custom(void) {
if (rgb_state.state != NORMAL) return;
for (uint8_t i = 0; i < IS31FL3731_LED_COUNT; i++) {
is31fl3731_set_color(i, start_led[i].r, start_led[i].g, start_led[i].b);
}
rgb_led_t leds[4];
for (int i = 0; i < 4; i++) {
leds[i].r = start_led[IS31FL3731_LED_COUNT+i].g;
leds[i].g = start_led[IS31FL3731_LED_COUNT+i].r;
leds[i].b = start_led[IS31FL3731_LED_COUNT+i].b;
}
//ws2812_setleds(start_led+IS31FL3731_LED_COUNT, 4);
ws2812_setleds(leds, 4);
is31fl3731_flush();
ws2812_flush();
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
.init = init_custom,
.set_color = set_color_custom,
.set_color_all = set_color_all_custom,
.flush = flush_custom,
};
bool led_update_kb(led_t led_state)

View file

@ -21,5 +21,6 @@
#define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND
#define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_VCC
#define IS31FL3731_LED_COUNT 64
#define WS2812_LED_COUNT 4
#define USB_SUSPEND_WAKEUP_DELAY 1000

View file

@ -21,3 +21,4 @@
#define IS31FL3731_I2C_ADDRESS_1 IS31FL3731_I2C_ADDRESS_GND
#define IS31FL3731_I2C_ADDRESS_2 IS31FL3731_I2C_ADDRESS_VCC
#define IS31FL3731_LED_COUNT 64
#define WS2812_LED_COUNT 1

View file

@ -18,9 +18,11 @@
*/
#include "quantum.h"
#include "i2c_master.h"
#include "drivers/led/issi/is31fl3731.h"
#include "ws2812.h"
#ifdef RGBLIGHT_ENABLE
# include "i2c_master.h"
# include "drivers/led/issi/is31fl3731.h"
# include "ws2812.h"
enum {
SELF_TESTING,
@ -67,7 +69,6 @@ enum {
#endif
#define ST_RIGHT_END (ST_RIGHT_BEGIN+ST_RIGHT_SIZE-1)
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
typedef struct {
@ -299,8 +300,6 @@ void matrix_init_kb(void)
gpio_set_pin_output(LED_CAPS_LOCK_PIN);
gpio_write_pin_low(LED_CAPS_LOCK_PIN);
is31fl3731_init_drivers();
update_ticks();
matrix_init_user();
}
@ -310,22 +309,12 @@ void housekeeping_task_kb(void)
if (rgb_state.state == SELF_TESTING) {
self_testing();
} else if (rgb_state.state == CAPS_ALERT) {
//gold 0xFF, 0xD9, 0x00
rgb_led_t led = {
.r = 0xFF,
//.g = 0xD9,
.g = 0xA5,
.b = 0x00,
};
if (rgb_state.alert) {
is31fl3731_set_color_all(led.r, led.g, led.b);
ws2812_setleds(&led, 1);
is31fl3731_set_color_all(0xFF, 0xA5, 0x00);
ws2812_set_color_all(0xFF, 0xA5, 0x00);
} else {
led.r = 0;
led.g = 0;
led.b = 0;
is31fl3731_set_color_all(0, 0, 0);
ws2812_setleds(&led, 1);
ws2812_set_color_all(0, 0, 0);
}
if (timer_elapsed(rgb_state.ticks) > ALERT_INTERVAL) {
@ -337,19 +326,37 @@ void housekeeping_task_kb(void)
is31fl3731_flush();
}
void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{
void init_custom(void) {
is31fl3731_init_drivers();
ws2812_init();
}
void set_color_custom(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index < IS31FL3731_LED_COUNT) {
is31fl3731_set_color(index, red, green, blue);
} else if (index < IS31FL3731_LED_COUNT + WS2812_LED_COUNT) {
ws2812_set_color(index - IS31FL3731_LED_COUNT, red, green, blue);
}
}
void set_color_all_custom(uint8_t red, uint8_t green, uint8_t blue) {
for (int i = 0; i < RGBLIGHT_LED_COUNT; i++) {
set_color_custom(i, red, green, blue);
}
}
void flush_custom(void) {
if (rgb_state.state != NORMAL) return;
for (uint8_t i = 0; i < IS31FL3731_LED_COUNT; i++) {
is31fl3731_set_color(i, start_led[i].r, start_led[i].g, start_led[i].b);
}
ws2812_setleds(start_led+IS31FL3731_LED_COUNT, 1);
is31fl3731_flush();
ws2812_flush();
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
.init = init_custom,
.set_color = set_color_custom,
.set_color_all = set_color_all_custom,
.flush = flush_custom,
};
bool led_update_kb(led_t led_state)