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

@ -932,7 +932,7 @@ ifeq ($(strip $(WS2812_DRIVER_REQUIRED)), yes)
OPT_DEFS += -DWS2812_$(strip $(shell echo $(WS2812_DRIVER) | tr '[:lower:]' '[:upper:]'))
SRC += ws2812_$(strip $(WS2812_DRIVER)).c
SRC += ws2812.c ws2812_$(strip $(WS2812_DRIVER)).c
ifeq ($(strip $(PLATFORM)), CHIBIOS)
ifeq ($(strip $(WS2812_DRIVER)), pwm)

View File

@ -241,13 +241,44 @@ Using a complementary timer output (`TIMx_CHyN`) is possible only for advanced-c
## API {#api}
### `void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds)` {#api-ws2812-setleds}
### `void ws2812_init(void)` {#api-ws2812-init}
Send RGB data to the WS2812 LED chain.
Initialize the LED driver. This function should be called first.
#### Arguments {#api-ws2812-setleds-arguments}
---
- `rgb_led_t *ledarray`
A pointer to the LED array.
- `uint16_t number_of_leds`
The length of the LED array.
### `void ws2812_set_color(int index, uint8_t red, uint8_t green, uint8_t blue)` {#api-ws2812-set-color}
Set the color of a single LED. This function does not immediately update the LEDs; call `ws2812_flush()` after you are finished.
#### Arguments {#api-ws2812-set-color-arguments}
- `int index`
The LED index in the WS2812 chain.
- `uint8_t red`
The red value to set.
- `uint8_t green`
The green value to set.
- `uint8_t blue`
The blue value to set.
---
### `void ws812_set_color_all(uint8_t red, uint8_t green, uint8_t blue)` {#api-ws2812-set-color-all}
Set the color of all LEDs.
#### Arguments {#api-ws2812-set-color-all-arguments}
- `uint8_t red`
The red value to set.
- `uint8_t green`
The green value to set.
- `uint8_t blue`
The blue value to set.
---
### `void ws2812_flush(void)` {#api-ws2812-flush}
Flush the PWM values to the LED chain.

15
drivers/ws2812.c Normal file
View File

@ -0,0 +1,15 @@
// Copyright 2024 QMK
// SPDX-License-Identifier: GPL-2.0-or-later
#include "ws2812.h"
#if defined(WS2812_RGBW)
void ws2812_rgb_to_rgbw(ws2812_led_t *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

View File

@ -15,7 +15,7 @@
#pragma once
#include "quantum/color.h"
#include "util.h"
/*
* The WS2812 datasheets define T1H 900ns, T0H 350ns, T1L 350ns, T0L 900ns. Hence, by default, these
@ -62,17 +62,36 @@
# define WS2812_LED_COUNT RGB_MATRIX_LED_COUNT
#endif
void ws2812_init(void);
#define WS2812_BYTE_ORDER_RGB 0
#define WS2812_BYTE_ORDER_GRB 1
#define WS2812_BYTE_ORDER_BGR 2
/* User Interface
*
* Input:
* ledarray: An array of GRB data describing the LED colors
* number_of_leds: The number of LEDs to write
*
* The functions will perform the following actions:
* - Set the data-out pin as output
* - Send out the LED data
* - Wait 50us to reset the LEDs
*/
void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds);
#ifndef WS2812_BYTE_ORDER
# define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_GRB
#endif
typedef struct PACKED ws2812_led_t {
#if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB)
uint8_t g;
uint8_t r;
uint8_t b;
#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB)
uint8_t r;
uint8_t g;
uint8_t b;
#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
uint8_t b;
uint8_t g;
uint8_t r;
#endif
#ifdef WS2812_RGBW
uint8_t w;
#endif
} ws2812_led_t;
void ws2812_init(void);
void ws2812_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void ws2812_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
void ws2812_flush(void);
void ws2812_rgb_to_rgbw(ws2812_led_t *led);

View File

@ -32,3 +32,5 @@
#define USB_INTR_ENABLE_BIT PCIE
#define USB_INTR_PENDING_BIT PCIF
#define USB_INTR_VECTOR SIG_PIN_CHANGE
#define WS2812_LED_COUNT 1

View File

@ -11,8 +11,8 @@ static inline void rgblite_init(void) {
}
static inline void rgblite_setrgb(RGB rgb) {
rgb_led_t leds[RGBLIGHT_LED_COUNT] = {{.r = rgb.r, .g = rgb.g, .b = rgb.b}};
ws2812_setleds(leds, RGBLIGHT_LED_COUNT);
ws2812_set_color_all(rgb.r, rgb.g, rgb.b);
ws2812_flush();
}
static void rgblite_increase_hue(void) {

View File

@ -33,8 +33,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef ERGODOX_LED_30
// If using 30 LEDs, then define that many
# define WS2812_LED_COUNT 30
# define RGBLIGHT_LED_COUNT 30 // Number of LEDs
#else
// If not, then only define 15
# define WS2812_LED_COUNT 15
# define RGBLIGHT_LED_COUNT 15 // Number of LEDs
#endif

View File

@ -21,47 +21,55 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ergodox_ez.h"
#include "ws2812.h"
void setleds_custom(rgb_led_t *led, uint16_t led_num) {
uint16_t length = 0;
int i = 0;
int j = 0;
# ifdef WS2812_RGBW
int bytes_per_led = 4;
# else
int bytes_per_led = 3;
# endif
# if defined(ERGODOX_LED_30)
// prevent right-half code from trying to bitbang all 30
// so with 30 LEDs, we count from 29 to 15 here, and the
// other half does 0 to 14.
uint8_t half_led_num = RGBLIGHT_LED_COUNT / 2;
length = half_led_num * bytes_per_led;
uint8_t data[length];
for (i = half_led_num + half_led_num - 1; i >= half_led_num; --i)
# elif defined(ERGODOX_LED_15_MIRROR)
length = led_num * bytes_per_led;
uint8_t data[length];
for (i = 0; i < led_num; ++i)
# else // ERGDOX_LED_15 non-mirrored
length = led_num * bytes_per_led;
uint8_t data[length];
for (i = led_num - 1; i >= 0; --i)
# endif
{
uint8_t *data_byte = (uint8_t *)(led + i);
data[j++] = data_byte[0];
data[j++] = data_byte[1];
data[j++] = data_byte[2];
#ifdef WS2812_RGBW
data[j++] = data_byte[3];
#endif
}
i2c_transmit(0x84, data, sizeof(data), ERGODOX_EZ_I2C_TIMEOUT);
#define WS2812_I2C_ADDRESS_LEFT 0x84
ws2812_setleds(led, led_num);
#if defined(ERGODOX_LED_30)
# define WS2812_LED_COUNT_LEFT (RGBLIGHT_LED_COUNT / 2)
ws2812_led_t ws2812_leds_left[WS2812_LED_COUNT_LEFT];
#else
# define WS2812_LED_COUNT_LEFT RGBLIGHT_LED_COUNT
ws2812_led_t ws2812_leds_left[WS2812_LED_COUNT_LEFT];
#endif
void set_color_left(int index, uint8_t red, uint8_t green, uint8_t blue) {
ws2812_leds_left[index].r = red;
ws2812_leds_left[index].g = green;
ws2812_leds_left[index].b = blue;
#if defined(WS2812_RGBW)
ws2812_rgb_to_rgbw(&ws2812_leds_left[index]);
#endif
}
void set_color_custom(int index, uint8_t red, uint8_t green, uint8_t blue) {
#if defined(ERGODOX_LED_30)
if (index < WS2812_LED_COUNT_LEFT) {
ws2812_set_color(index, red, green, blue);
} else {
set_color_left(RGBLIGHT_LED_COUNT - index - 1, red, green, blue);
}
#elif defined(ERGODOX_LED_15_MIRROR)
ws2812_set_color(index, red, green, blue);
set_color_left(index, red, green, blue);
#else
ws2812_set_color(index, red, green, blue);
set_color_left(WS2812_LED_COUNT_LEFT - index - 1, red, green, blue);
#endif
}
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) {
i2c_transmit(WS2812_I2C_ADDRESS_LEFT, (uint8_t *)ws2812_leds_left, sizeof(ws2812_leds_left), ERGODOX_EZ_I2C_TIMEOUT);
ws2812_flush();
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
.init = ws2812_init,
.set_color = set_color_custom,
.set_color_all = set_color_all_custom,
.flush = flush_custom,
};

View File

@ -155,6 +155,7 @@ enum led_sequence {
};
# define RGBSPS_NUM LED_TOTAL
# define WS2812_LED_COUNT RGBSPS_NUM
#endif
/* PS/2 mouse */

View File

@ -2,8 +2,6 @@
#include "ws2812.h"
#include "rgbsps.h"
rgb_led_t led[RGBSPS_NUM];
void keyboard_pre_init_kb(void) {
ws2812_init();
@ -11,9 +9,7 @@ void keyboard_pre_init_kb(void) {
}
void rgbsps_set(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
led[index].r = r;
led[index].g = g;
led[index].b = b;
ws2812_set_color(index, r, g, b);
}
void rgbsps_setall(uint8_t r, uint8_t g, uint8_t b) {
@ -27,7 +23,7 @@ void rgbsps_turnoff(void) {
}
void rgbsps_send(void) {
ws2812_setleds(led, RGBSPS_NUM);
ws2812_flush();
}
void rgbsps_sethsv(uint8_t index, uint16_t hue, uint8_t sat, uint8_t val) {

View File

@ -65,6 +65,7 @@
# define MODELM_LED_SCROLLOCK MODELM_LED3
# define MODELM_LED_NUMLOCK MODELM_LED1
#elif defined(KEYBOARD_ibm_model_m_mschwingen_led_ws2812)
# define WS2812_LED_COUNT 3
#else
# error one of MODELM_LEDS_FFC, MODELM_LEDS_WIRED or MODELM_LEDS_WS2812 must be set!
#endif

View File

@ -39,27 +39,10 @@ static uint8_t isRecording = 0;
# if RGBLIGHT_LED_COUNT < 3
# error we need at least 3 RGB LEDs!
# endif
static rgb_led_t led[RGBLIGHT_LED_COUNT] = {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}};
# define BRIGHT 32
# define DIM 6
static const rgb_led_t black = {.r = 0, .g = 0, .b = 0};
static const __attribute__((unused)) rgb_led_t green = {.r = 0, .g = BRIGHT, .b = 0};
static const __attribute__((unused)) rgb_led_t lgreen = {.r = 0, .g = DIM, .b = 0};
static const __attribute__((unused)) rgb_led_t red = {.r = BRIGHT, .g = 0, .b = 0};
static const __attribute__((unused)) rgb_led_t lred = {.r = DIM, .g = 0, .b = 0};
static const __attribute__((unused)) rgb_led_t blue = {.r = 0, .g = 0, .b = BRIGHT};
static const __attribute__((unused)) rgb_led_t lblue = {.r = 0, .g = 0, .b = DIM};
static const __attribute__((unused)) rgb_led_t turq = {.r = 0, .g = BRIGHT, .b = BRIGHT};
static const __attribute__((unused)) rgb_led_t lturq = {.r = 0, .g = DIM, .b = DIM};
static const __attribute__((unused)) rgb_led_t white = {.r = BRIGHT, .g = BRIGHT, .b = BRIGHT};
static led_t led_state;
static uint8_t layer;
static uint8_t default_layer;
@ -81,17 +64,15 @@ void sleep_led_enable(void) {
suspend_active = true;
gpio_write_pin_low(MODELM_STATUS_LED);
#ifdef KEYBOARD_ibm_model_m_mschwingen_led_ws2812
led[0] = black;
led[1] = black;
led[2] = black;
ws2812_setleds(led, RGBLIGHT_LED_COUNT);
ws2812_set_color_all(0, 0, 0);
ws2812_flush();
#endif
}
void keyboard_pre_init_kb(void) {
#ifdef KEYBOARD_ibm_model_m_mschwingen_led_ws2812
ws2812_init();
ws2812_setleds(led, RGBLIGHT_LED_COUNT);
ws2812_flush();
#else
/* Set status LEDs pins to output and Low (on) */
gpio_set_pin_output(MODELM_LED_CAPSLOCK);
@ -121,35 +102,59 @@ void keyboard_pre_init_kb(void) {
#ifdef KEYBOARD_ibm_model_m_mschwingen_led_ws2812
static void led_update_rgb(void) {
if (isRecording && blink_state) {
led[0] = white;
ws2812_set_color(0, BRIGHT, BRIGHT, BRIGHT);
} else {
switch (default_layer) {
case 0:
led[0] = led_state.num_lock ? blue : lblue;
if (led_state.num_lock) {
ws2812_set_color(0, 0, 0, BRIGHT);
} else {
ws2812_set_color(0, 0, 0, DIM);
}
break;
case 1:
led[0] = led_state.num_lock ? green : black;
if (led_state.num_lock) {
ws2812_set_color(0, 0, BRIGHT, 0);
} else {
ws2812_set_color(0, 0, 0, 0);
}
break;
}
}
led[1] = led_state.caps_lock ? green : black;
if (led_state.caps_lock) {
ws2812_set_color(1, 0, BRIGHT, 0);
} else {
ws2812_set_color(1, 0, 0, 0);
}
switch (layer) {
case 0:
case 1:
default:
led[2] = led_state.scroll_lock ? green : black;
if (led_state.scroll_lock) {
ws2812_set_color(2, 0, BRIGHT, 0);
} else {
ws2812_set_color(2, 0, 0, 0);
}
break;
case 2:
led[2] = led_state.scroll_lock ? red : lred;
if (led_state.scroll_lock) {
ws2812_set_color(2, BRIGHT, 0, 0);
} else {
ws2812_set_color(2, DIM, 0, 0);
}
break;
case 3:
led[2] = led_state.scroll_lock ? turq : lturq;
if (led_state.scroll_lock) {
ws2812_set_color(2, 0, BRIGHT, BRIGHT);
} else {
ws2812_set_color(2, 0, DIM, DIM);
}
break;
}
if (!suspend_active) {
ws2812_setleds(led, RGBLIGHT_LED_COUNT);
ws2812_flush();
}
}

View File

@ -209,6 +209,10 @@ const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
// 71 70 69
{ 0, C3_7 }, { 0, C2_7 }, { 0, C1_7 },
};
int led_matrix_led_index(int index) {
return index;
}
#endif
#ifdef ST7565_ENABLE

View File

@ -125,4 +125,8 @@ const snled27351_led_t PROGMEM g_snled27351_leds[SNLED27351_LED_COUNT] = {
{0, CB7_CA1, CB9_CA1, CB8_CA1}, // Down
{0, CB7_CA7, CB9_CA7, CB8_CA7}, // Right
};
int rgb_matrix_led_index(int index) {
return index;
}
#endif

View File

@ -126,4 +126,8 @@ const snled27351_led_t PROGMEM g_snled27351_leds[SNLED27351_LED_COUNT] = {
{0, CB7_CA1, CB9_CA1, CB8_CA1}, // Down
{0, CB7_CA7, CB9_CA7, CB8_CA7}, // Right
};
int rgb_matrix_led_index(int index) {
return index;
}
#endif

View File

@ -25,9 +25,9 @@
// Underglow LEDs are WS2812, but someone might want to use RGBLIGHT for them;
// don't use those LEDs in RGB Matrix in that case.
#ifdef RGBLIGHT_ENABLE
# define WS2812_LED_TOTAL 0
# define WS2812_LED_COUNT 0
#else
# define WS2812_LED_TOTAL 6
# define WS2812_LED_COUNT 6
#endif
#define RGB_MATRIX_LED_COUNT (IS31FL3733_LED_COUNT + WS2812_LED_TOTAL)
#define RGB_MATRIX_LED_COUNT (IS31FL3733_LED_COUNT + WS2812_LED_COUNT)

View File

@ -110,7 +110,7 @@ led_config_t g_led_config = {
{ 18, 48 }, { 30, 48 }, { 45, 48 }, { 60, 48 }, { 75, 48 }, { 90, 48 }, { 105, 48 }, { 120, 48 }, { 135, 48 }, { 150, 48 }, { 165, 48 }, { 191, 48 }, { 210, 48 },
// Ctrl, GUI, Alt, Space, RAlt, FN, Left, Down, Right
{ 3, 64 }, { 22, 64 }, { 33, 64 }, { 101, 64 }, { 135, 64 }, { 153, 64 }, { 195, 64 }, { 210, 64 }, { 225, 64 }
# if WS2812_LED_TOTAL > 0
# if WS2812_LED_COUNT > 0
,{ 28, 40}, { 62, 40}, { 96, 40}, {130, 40}, {164, 40}, {198, 40}
# endif
}, {
@ -124,7 +124,7 @@ led_config_t g_led_config = {
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4,
// Ctrl, GUI, Alt, Space, RAlt, FN, Left, Down, Right
1, 1, 1, 4, 1, 1, 1, 1, 1
# if WS2812_LED_TOTAL > 0
# if WS2812_LED_COUNT > 0
,2, 2, 2, 2, 2, 2
# endif
}
@ -147,10 +147,6 @@ bool rgb_matrix_indicators_kb(void) {
// Custom RGB Matrix driver that combines IS31FL3733 and WS2812
// ==========================================================================
# if WS2812_LED_TOTAL > 0
rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
# endif
static void rgb_matrix_driver_init(void) {
i2c_init();
is31fl3733_init(0);
@ -164,31 +160,25 @@ static void rgb_matrix_driver_init(void) {
static void rgb_matrix_driver_flush(void) {
is31fl3733_update_pwm_buffers(0);
# if WS2812_LED_TOTAL > 0
ws2812_setleds(rgb_matrix_ws2812_array, WS2812_LED_TOTAL);
# if WS2812_LED_COUNT > 0
ws2812_flush();
# endif
}
static void rgb_matrix_driver_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index < IS31FL3733_LED_COUNT) {
is31fl3733_set_color(index, red, green, blue);
# if WS2812_LED_COUNT > 0
} else {
# if WS2812_LED_TOTAL > 0
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].r = red;
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].g = green;
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].b = blue;
ws2812_set_color(index - IS31FL3733_LED_COUNT, red, green, blue);
# endif
}
}
static void rgb_matrix_driver_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
is31fl3733_set_color_all(red, green, blue);
# if WS2812_LED_TOTAL > 0
for (uint8_t i = 0; i < WS2812_LED_TOTAL; i++) {
rgb_matrix_ws2812_array[i].r = red;
rgb_matrix_ws2812_array[i].g = green;
rgb_matrix_ws2812_array[i].b = blue;
}
# if WS2812_LED_COUNT > 0
ws2812_set_color_all(red, green, blue);
# endif
}

View File

@ -23,9 +23,9 @@
// Underglow LEDs are WS2812, but someone might want to use RGBLIGHT for them;
// don't use those LEDs in RGB Matrix in that case.
#ifdef RGBLIGHT_ENABLE
# define WS2812_LED_TOTAL 0
# define WS2812_LED_COUNT 0
#else
# define WS2812_LED_TOTAL 6
# define WS2812_LED_COUNT 6
#endif
#define RGB_MATRIX_LED_COUNT (IS31FL3733_LED_COUNT + WS2812_LED_TOTAL)
#define RGB_MATRIX_LED_COUNT (IS31FL3733_LED_COUNT + WS2812_LED_COUNT)

View File

@ -112,7 +112,7 @@ led_config_t g_led_config = { {
{ 3, 48 }, { 22, 48 }, { 33, 48 }, { 48, 48 }, { 63, 48 }, { 78, 48 }, { 93, 48 }, { 108, 48 }, { 123, 48 }, { 138, 48 }, { 153, 48 }, { 168, 48 }, { 194, 48 }, { 213, 48 },
// Ctrl, GUI, Alt, Space, RAlt, FN, Left, Down, Right
{ 3, 64 }, { 22, 64 }, { 33, 64 }, { 101, 64 }, { 135, 64 }, { 153, 64 }, { 195, 64 }, { 210, 64 }, { 225, 64 }
# if WS2812_LED_TOTAL > 0
# if WS2812_LED_COUNT > 0
,{ 28, 40}, { 62, 40}, { 96, 40}, {130, 40}, {164, 40}, {198, 40}
# endif
}, {
@ -126,7 +126,7 @@ led_config_t g_led_config = { {
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 4,
// Ctrl, GUI, Alt, Space, RAlt, FN, Left, Down, Right
1, 1, 1, 4, 1, 1, 1, 1, 1
# if WS2812_LED_TOTAL > 0
# if WS2812_LED_COUNT > 0
,2, 2, 2, 2, 2, 2
# endif
} };
@ -147,10 +147,6 @@ bool rgb_matrix_indicators_kb(void) {
// Custom RGB Matrix driver that combines IS31FL3733 and WS2812
// ==========================================================================
# if WS2812_LED_TOTAL > 0
rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
# endif
static void rgb_matrix_driver_init(void) {
i2c_init();
is31fl3733_init(0);
@ -164,31 +160,25 @@ static void rgb_matrix_driver_init(void) {
static void rgb_matrix_driver_flush(void) {
is31fl3733_update_pwm_buffers(0);
# if WS2812_LED_TOTAL > 0
ws2812_setleds(rgb_matrix_ws2812_array, WS2812_LED_TOTAL);
# if WS2812_LED_COUNT > 0
ws2812_flush();
# endif
}
static void rgb_matrix_driver_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index < IS31FL3733_LED_COUNT) {
is31fl3733_set_color(index, red, green, blue);
# if WS2812_LED_COUNT > 0
} else {
# if WS2812_LED_TOTAL > 0
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].r = red;
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].g = green;
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].b = blue;
ws2812_set_color(index - IS31FL3733_LED_COUNT, red, green, blue);
# endif
}
}
static void rgb_matrix_driver_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
is31fl3733_set_color_all(red, green, blue);
# if WS2812_LED_TOTAL > 0
for (uint8_t i = 0; i < WS2812_LED_TOTAL; i++) {
rgb_matrix_ws2812_array[i].r = red;
rgb_matrix_ws2812_array[i].g = green;
rgb_matrix_ws2812_array[i].b = blue;
}
# if WS2812_LED_COUNT > 0
ws2812_set_color_all(red, green, blue);
# endif
}

View File

@ -21,9 +21,9 @@
// Underglow LEDs are WS2812, but someone might want to use RGBLIGHT for them;
// don't use those LEDs in RGB Matrix in that case.
#ifdef RGBLIGHT_ENABLE
# define WS2812_LED_TOTAL 0
# define WS2812_LED_COUNT 0
#else
# define WS2812_LED_TOTAL 6
# define WS2812_LED_COUNT 6
#endif
#define RGB_MATRIX_LED_COUNT (IS31FL3733_LED_COUNT + WS2812_LED_TOTAL)
#define RGB_MATRIX_LED_COUNT (IS31FL3733_LED_COUNT + WS2812_LED_COUNT)

View File

@ -107,7 +107,7 @@ led_config_t g_led_config = {
{ 18, 48 }, { 30, 48 }, { 45, 48 }, { 60, 48 }, { 75, 48 }, { 90, 48 }, { 105, 48 }, { 120, 48 }, { 135, 48 }, { 150, 48 }, { 165, 48 }, { 191, 48 },
// Ctrl, GUI, Alt, Space, RAlt, FN, Left, Down, Right
{ 3, 64 }, { 22, 64 }, { 33, 64 }, { 101, 64 }, { 135, 64 }, { 153, 64 }, { 210, 64 }, { 225, 64 }
# if WS2812_LED_TOTAL > 0
# if WS2812_LED_COUNT > 0
,{ 28, 40}, { 62, 40}, { 96, 40}, {130, 40}, {164, 40}, {198, 40}
# endif
}, {
@ -121,7 +121,7 @@ led_config_t g_led_config = {
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
// Ctrl, GUI, Alt, Space, RAlt, FN, Left, Down, Right
1, 1, 1, 4, 1, 1, 1, 1
# if WS2812_LED_TOTAL > 0
# if WS2812_LED_COUNT > 0
,2, 2, 2, 2, 2, 2
# endif
}
@ -143,10 +143,6 @@ bool rgb_matrix_indicators_kb(void) {
// Custom RGB Matrix driver that combines IS31FL3733 and WS2812
// ==========================================================================
# if WS2812_LED_TOTAL > 0
rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
# endif
static void rgb_matrix_driver_init(void) {
i2c_init();
is31fl3733_init(0);
@ -160,31 +156,25 @@ static void rgb_matrix_driver_init(void) {
static void rgb_matrix_driver_flush(void) {
is31fl3733_update_pwm_buffers(0);
# if WS2812_LED_TOTAL > 0
ws2812_setleds(rgb_matrix_ws2812_array, WS2812_LED_TOTAL);
# if WS2812_LED_COUNT > 0
ws2812_flush();
# endif
}
static void rgb_matrix_driver_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index < IS31FL3733_LED_COUNT) {
is31fl3733_set_color(index, red, green, blue);
# if WS2812_LED_COUNT > 0
} else {
# if WS2812_LED_TOTAL > 0
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].r = red;
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].g = green;
rgb_matrix_ws2812_array[index - IS31FL3733_LED_COUNT].b = blue;
ws2812_set_color(index - IS31FL3733_LED_COUNT, red, green, blue);
# endif
}
}
static void rgb_matrix_driver_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
is31fl3733_set_color_all(red, green, blue);
# if WS2812_LED_TOTAL > 0
for (uint8_t i = 0; i < WS2812_LED_TOTAL; i++) {
rgb_matrix_ws2812_array[i].r = red;
rgb_matrix_ws2812_array[i].g = green;
rgb_matrix_ws2812_array[i].b = blue;
}
# if WS2812_LED_COUNT > 0
ws2812_set_color_all(red, green, blue);
# endif
}

View File

@ -41,20 +41,6 @@ uint8_t read_pin(uint16_t pin)
return (data & (1<<GET_PIN(pin))) ? 1 : 0;
}
void matrix_init_kb(void) {
#ifdef RGBLIGHT_ENABLE
aw9523b_init(AW9523B_ADDR);
#endif
matrix_init_user();
}
void housekeeping_task_kb(void) {
#ifdef RGBLIGHT_ENABLE
aw9523b_update_pwm_buffers(AW9523B_ADDR);
#endif
}
#ifdef RGBLIGHT_ENABLE
#include "rgblight.h"
#include "ws2812.h"
@ -67,20 +53,35 @@ const aw9523b_led g_aw9523b_leds[AW9523B_RGB_NUM] = {
{AW9523B_P07_PWM, AW9523B_P06_PWM, AW9523B_P05_PWM},
};
void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{
uint8_t num = num_leds < AW9523B_RGB_NUM ? num_leds : AW9523B_RGB_NUM;
void init_custom(void) {
aw9523b_init(AW9523B_ADDR);
ws2812_init();
}
ws2812_setleds(start_led, num);
for (int i = 0; i < num; i++) {
aw9523b_set_color(i, start_led[i].r, start_led[i].g, start_led[i].b);
void set_color_custom(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index < AW9523B_RGB_NUM) {
aw9523b_set_color(index, red, green, blue);
} else {
ws2812_set_color(index - AW9523B_RGB_NUM, 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) {
aw9523b_update_pwm_buffers(AW9523B_ADDR);
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,
};
#endif

View File

@ -89,5 +89,6 @@
#define I2C1_DUTY_CYCLE FAST_DUTY_CYCLE_2
#define AW9523B_RGB_NUM 4
#define WS2812_LED_COUNT 5
#define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE

View File

@ -27,13 +27,6 @@ uint8_t read_pin(uint16_t pin)
return (data & (1<<GET_PIN(pin))) ? 1 : 0;
}
void matrix_init_kb(void) {
#ifdef RGBLIGHT_ENABLE
rgb_ring_init();
#endif
matrix_init_user();
}
void housekeeping_task_kb(void) {
#ifdef RGBLIGHT_ENABLE
rgb_ring_task();

View File

@ -361,27 +361,22 @@ static void custom_effects(void)
effect_funcs[rgb_ring.effect]();
}
void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{
void flush_custom(void) {
if (rgb_ring.state != RING_STATE_QMK) {
return;
}
for (uint8_t i = 0; i < num_leds; i++) {
is31fl3731_set_color(i, start_led[i].r, start_led[i].g, start_led[i].b);
}
is31fl3731_flush();
}
const rgblight_driver_t rgblight_driver = {
.setleds = setleds_custom,
.init = is31fl3731_init_drivers,
.set_color = is31fl3731_set_color,
.set_color_all = is31fl3731_set_color_all,
.flush = flush_custom,
};
void rgb_ring_init(void)
{
is31fl3731_init_drivers();
}
void rgb_ring_task(void)
{
switch (rgb_ring.state) {
@ -397,8 +392,6 @@ void rgb_ring_task(void)
default:
break;
};
is31fl3731_flush();
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record)

View File

@ -19,5 +19,4 @@
#pragma once
void rgb_ring_init(void);
void rgb_ring_task(void);

View File

@ -10,7 +10,7 @@
"no_startup_check": true
},
"rgblight": {
"driver": "custom",
"driver": "ws2812",
"led_count": 7,
"animations": {
"breathing": true,

View File

@ -9,57 +9,6 @@ void bootloader_jump(void) {
NVIC_SystemReset();
}
#ifdef RGBLIGHT_ENABLE
#include <string.h>
#include "rgblight.h"
#include "ws2812.h"
extern rgblight_config_t rgblight_config;
// led 0 for caps lock, led 1 for scroll lock, led 3 for num lock
// led 4 for layer 1, led 5 for layer 2, led 6 for layer 3, led 7 for layer 4
#if RGBLIGHT_LED_COUNT < 7
#error "MUST set the RGBLIGHT_LED_COUNT bigger than 7"
#endif
rgb_led_t noah_leds[RGBLIGHT_LED_COUNT];
static bool noah_led_mode = false;
void setleds_custom(rgb_led_t *ledarray, uint16_t num_leds) {
memset(&noah_leds[0], 0, sizeof(noah_leds));
if (!rgblight_config.enable) {
for (uint8_t i = 0; i < RGBLIGHT_LED_COUNT; i++) {
ledarray[i].r = 0;
ledarray[i].g = 0;
ledarray[i].b = 0;
}
}
if (noah_led_mode) {
led_t led_state = host_keyboard_led_state();
if (led_state.caps_lock) {
noah_leds[0] = ledarray[0];
}
if (led_state.scroll_lock) {
noah_leds[1] = ledarray[1];
}
if (led_state.num_lock) {
noah_leds[2] = ledarray[2];
}
for (int32_t i = 0; i < 4; i++) {
if(layer_state_is(i+1)) {
noah_leds[i + 3] = ledarray[i + 3];
}
}
} else {
memcpy(&noah_leds[0], &ledarray[0], sizeof(noah_leds));
}
ws2812_setleds(noah_leds, RGBLIGHT_LED_COUNT);
}
const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = setleds_custom,
};
#endif
#ifdef RGB_MATRIX_ENABLE
const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
/* Refer to IS31 manual for these locations
@ -150,11 +99,6 @@ const is31fl3731_led_t PROGMEM g_is31fl3731_leds[IS31FL3731_LED_COUNT] = {
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch(keycode) {
#ifdef RGBLIGHT_ENABLE
case KC_F24: // switch the led mode on or off
noah_led_mode = !noah_led_mode;
return false;
#ifdef RGB_MATRIX_ENABLE
case KC_F13: // toggle rgb matrix
rgb_matrix_toggle();
@ -162,7 +106,6 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
case KC_F14:
rgb_matrix_step();
return false;
#endif
#endif
default:
break;

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

Some files were not shown because too many files have changed in this diff Show More