Rework RGBLight driver system

This commit is contained in:
fauxpark 2023-11-22 12:06:39 +11:00
parent 7ae826476e
commit 2b5befcf8c
29 changed files with 89 additions and 29 deletions

View File

@ -313,6 +313,7 @@ ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
OPT_DEFS += -DRGBLIGHT_$(strip $(shell echo $(RGBLIGHT_DRIVER) | tr '[:lower:]' '[:upper:]')) OPT_DEFS += -DRGBLIGHT_$(strip $(shell echo $(RGBLIGHT_DRIVER) | tr '[:lower:]' '[:upper:]'))
SRC += $(QUANTUM_DIR)/color.c SRC += $(QUANTUM_DIR)/color.c
SRC += $(QUANTUM_DIR)/rgblight/rgblight.c SRC += $(QUANTUM_DIR)/rgblight/rgblight.c
SRC += $(QUANTUM_DIR)/rgblight/rgblight_drivers.c
CIE1931_CURVE := yes CIE1931_CURVE := yes
RGB_KEYCODES_ENABLE := yes RGB_KEYCODES_ENABLE := yes
endif endif

View File

@ -71,11 +71,6 @@ void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) {
apa102_end_frame(num_leds); apa102_end_frame(num_leds);
} }
// Overwrite the default rgblight_call_driver to use apa102 driver
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) {
apa102_setleds(start_led, num_leds);
}
void static apa102_init(void) { void static apa102_init(void) {
setPinOutput(APA102_DI_PIN); setPinOutput(APA102_DI_PIN);
setPinOutput(APA102_CI_PIN); setPinOutput(APA102_CI_PIN);

View File

@ -14,10 +14,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dp60.h" #include QMK_KEYBOARD_H
#include "ws2812.h"
#include "rgblight.h"
// caps led // caps led
const rgblight_segment_t PROGMEM dp60_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS( const rgblight_segment_t PROGMEM dp60_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
@ -72,13 +70,17 @@ extern rgblight_config_t rgblight_config;
extern void rgblight_layers_write(void); extern void rgblight_layers_write(void);
extern void indicator_write(rgb_led_t *start_led, uint8_t num_leds); extern void indicator_write(rgb_led_t *start_led, uint8_t num_leds);
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{ {
ws2812_setleds(start_led, RGBLED_NUM-RGB_INDICATOR_NUM); ws2812_setleds(start_led, RGBLED_NUM-RGB_INDICATOR_NUM);
indicator_write(start_led + (RGBLED_NUM - RGB_INDICATOR_NUM), RGB_INDICATOR_NUM); indicator_write(start_led + (RGBLED_NUM - RGB_INDICATOR_NUM), RGB_INDICATOR_NUM);
} }
const rgblight_driver_t rgblight_driver = {
.setleds = setleds_custom,
};
void led_update_ports(led_t led_state) { void led_update_ports(led_t led_state) {
rgblight_set_layer_state(0, led_state.caps_lock); rgblight_set_layer_state(0, led_state.caps_lock);
rgblight_set_layer_state(1, led_state.scroll_lock); rgblight_set_layer_state(1, led_state.scroll_lock);

View File

@ -1,4 +1,6 @@
RGBLIGHT_ENABLE = yes # Use RGB underglow light RGBLIGHT_ENABLE = yes # Use RGB underglow light
RGBLIGHT_DRIVER = custom
WS2812_DRIVER_REQUIRED = yes
SRC += indicator.c led_driver.c SRC += indicator.c led_driver.c

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "ergodox_ez.h" # include "ergodox_ez.h"
void rgblight_call_driver(rgb_led_t *led, uint8_t led_num) { void setleds_custom(rgb_led_t *led, uint16_t led_num) {
i2c_init(); i2c_init();
i2c_start(0x84, ERGODOX_EZ_I2C_TIMEOUT); i2c_start(0x84, ERGODOX_EZ_I2C_TIMEOUT);
int i = 0; int i = 0;
@ -51,5 +51,8 @@ void rgblight_call_driver(rgb_led_t *led, uint8_t led_num) {
ws2812_setleds(led, led_num); ws2812_setleds(led, led_num);
} }
const rgblight_driver_t rgblight_driver = {
.setleds = setleds_custom,
};
#endif // RGBLIGHT_ENABLE #endif // RGBLIGHT_ENABLE

View File

@ -57,6 +57,7 @@ void housekeeping_task_kb(void) {
#ifdef RGBLIGHT_ENABLE #ifdef RGBLIGHT_ENABLE
#include "rgblight.h" #include "rgblight.h"
#include "ws2812.h"
#include "i2c_master.h" #include "i2c_master.h"
const aw9523b_led g_aw9523b_leds[AW9523B_RGB_NUM] = { const aw9523b_led g_aw9523b_leds[AW9523B_RGB_NUM] = {
@ -66,7 +67,7 @@ const aw9523b_led g_aw9523b_leds[AW9523B_RGB_NUM] = {
{AW9523B_P07_PWM, AW9523B_P06_PWM, AW9523B_P05_PWM}, {AW9523B_P07_PWM, AW9523B_P06_PWM, AW9523B_P05_PWM},
}; };
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) 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; uint8_t num = num_leds < AW9523B_RGB_NUM ? num_leds : AW9523B_RGB_NUM;
@ -77,6 +78,10 @@ void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds)
} }
} }
const rgblight_driver_t rgblight_driver = {
.setleds = setleds_custom,
};
#endif #endif
static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3); static uint16_t caps_lock_pin = DEF_PIN(TCA6424_PORT2, 3);

View File

@ -10,6 +10,7 @@
}, },
"rgblight": { "rgblight": {
"led_count": 9, "led_count": 9,
"driver": "custom",
"animations": { "animations": {
"breathing": true, "breathing": true,
"rainbow_mood": true, "rainbow_mood": true,

View File

@ -46,3 +46,4 @@ CUSTOM_MATRIX = lite
# project specific files # project specific files
SRC += matrix.c tca6424.c aw9523b.c SRC += matrix.c tca6424.c aw9523b.c
I2C_DRIVER_REQUIRED = yes I2C_DRIVER_REQUIRED = yes
WS2812_DRIVER_REQUIRED = yes

View File

@ -10,6 +10,7 @@
}, },
"rgblight": { "rgblight": {
"led_count": 20, "led_count": 20,
"driver": "custom",
"animations": { "animations": {
"breathing": true, "breathing": true,
"rainbow_mood": true, "rainbow_mood": true,

View File

@ -357,7 +357,7 @@ static void custom_effects(void)
effect_funcs[rgb_ring.effect](); effect_funcs[rgb_ring.effect]();
} }
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{ {
if (rgb_ring.state != RING_STATE_QMK) { if (rgb_ring.state != RING_STATE_QMK) {
return; return;
@ -368,6 +368,10 @@ void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds)
} }
} }
const rgblight_driver_t rgblight_driver = {
.setleds = setleds_custom,
};
void rgb_ring_init(void) void rgb_ring_init(void)
{ {

View File

@ -20,6 +20,7 @@
#include "quantum.h" #include "quantum.h"
#include "i2c_master.h" #include "i2c_master.h"
#include "drivers/led/issi/is31fl3731.h" #include "drivers/led/issi/is31fl3731.h"
#include "ws2812.h"
enum { enum {
SELF_TESTING, SELF_TESTING,
@ -336,7 +337,7 @@ void housekeeping_task_kb(void)
housekeeping_task_user(); housekeeping_task_user();
} }
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{ {
if (rgb_state.state != NORMAL) return; if (rgb_state.state != NORMAL) return;
@ -353,6 +354,10 @@ void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds)
ws2812_setleds(leds, 4); ws2812_setleds(leds, 4);
} }
const rgblight_driver_t rgblight_driver = {
.setleds = setleds_custom,
};
bool led_update_kb(led_t led_state) bool led_update_kb(led_t led_state)
{ {
bool res = led_update_user(led_state); bool res = led_update_user(led_state);

View File

@ -20,6 +20,7 @@
"saturation_steps": 8, "saturation_steps": 8,
"brightness_steps": 8, "brightness_steps": 8,
"led_count": 68, "led_count": 68,
"driver": "custom",
"animations": { "animations": {
"breathing": true, "breathing": true,
"rainbow_mood": true, "rainbow_mood": true,

View File

@ -12,4 +12,5 @@ RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
NO_USB_STARTUP_CHECK = yes NO_USB_STARTUP_CHECK = yes
QUANTUM_LIB_SRC += drivers/led/issi/is31fl3731.c QUANTUM_LIB_SRC += drivers/led/issi/is31fl3731.c
WS2812_DRIVER_REQUIRED = yes
I2C_DRIVER_REQUIRED = yes I2C_DRIVER_REQUIRED = yes

View File

@ -23,6 +23,7 @@
"saturation_steps": 8, "saturation_steps": 8,
"brightness_steps": 8, "brightness_steps": 8,
"led_count": 65, "led_count": 65,
"driver": "custom",
"max_brightness": 192, "max_brightness": 192,
"animations": { "animations": {
"breathing": true, "breathing": true,

View File

@ -20,6 +20,7 @@
#include "quantum.h" #include "quantum.h"
#include "i2c_master.h" #include "i2c_master.h"
#include "drivers/led/issi/is31fl3731.h" #include "drivers/led/issi/is31fl3731.h"
#include "ws2812.h"
enum { enum {
SELF_TESTING, SELF_TESTING,
@ -338,7 +339,7 @@ void housekeeping_task_kb(void)
housekeeping_task_user(); housekeeping_task_user();
} }
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{ {
if (rgb_state.state != NORMAL) return; if (rgb_state.state != NORMAL) return;
@ -348,6 +349,10 @@ void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds)
ws2812_setleds(start_led+IS31FL3731_LED_COUNT, 1); ws2812_setleds(start_led+IS31FL3731_LED_COUNT, 1);
} }
const rgblight_driver_t rgblight_driver = {
.setleds = setleds_custom,
};
bool led_update_kb(led_t led_state) bool led_update_kb(led_t led_state)
{ {
bool res = led_update_user(led_state); bool res = led_update_user(led_state);

View File

@ -11,4 +11,5 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
QUANTUM_LIB_SRC += drivers/led/issi/is31fl3731.c QUANTUM_LIB_SRC += drivers/led/issi/is31fl3731.c
WS2812_DRIVER_REQUIRED = yes
I2C_DRIVER_REQUIRED = yes I2C_DRIVER_REQUIRED = yes

View File

@ -25,7 +25,8 @@
"pin": "B0" "pin": "B0"
}, },
"rgblight": { "rgblight": {
"led_count": 5 "led_count": 5,
"driver": "custom"
}, },
"url": "", "url": "",
"usb": { "usb": {

View File

@ -18,6 +18,7 @@
*/ */
#include "quantum.h" #include "quantum.h"
#include "ws2812.h"
#ifdef RGBLIGHT_ENABLE #ifdef RGBLIGHT_ENABLE
static bool alert = false; static bool alert = false;
@ -66,7 +67,7 @@ void housekeeping_task_kb(void)
housekeeping_task_user(); housekeeping_task_user();
} }
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
{ {
start_led[2].r = start_led[0].r; start_led[2].r = start_led[0].r;
start_led[2].g = start_led[0].g; start_led[2].g = start_led[0].g;
@ -82,4 +83,7 @@ void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds)
ws2812_setleds(start_led, RGBLED_NUM); ws2812_setleds(start_led, RGBLED_NUM);
} }
const rgblight_driver_t rgblight_driver = {
.setleds = setleds_custom,
};
#endif #endif

View File

@ -1 +1 @@
# This file intentionally left blank WS2812_DRIVER_REQUIRED = yes

View File

@ -30,6 +30,7 @@
"pin": "F1" "pin": "F1"
}, },
"rgblight": { "rgblight": {
"driver": "custom",
"max_brightness": 120, "max_brightness": 120,
"sleep": true, "sleep": true,
"animations": { "animations": {

View File

@ -21,6 +21,7 @@
}, },
"processor": "atmega32u4", "processor": "atmega32u4",
"rgblight": { "rgblight": {
"driver": "custom",
"animations": { "animations": {
"alternating": false, "alternating": false,
"breathing": true, "breathing": true,

View File

@ -27,6 +27,7 @@
}, },
"rgblight": { "rgblight": {
"led_count": 6, "led_count": 6,
"driver": "custom",
"max_brightness": 120, "max_brightness": 120,
"sleep": true, "sleep": true,
"animations": { "animations": {

View File

@ -50,6 +50,7 @@
] ]
}, },
"rgblight": { "rgblight": {
"driver": "custom",
"animations": { "animations": {
"breathing": true, "breathing": true,
"knight": true, "knight": true,

View File

@ -24,9 +24,9 @@
#include "ws2812_bitbang.c" #include "ws2812_bitbang.c"
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) { const rgblight_driver_t rgblight_driver = {
ws2812_setleds(start_led, num_leds); .setleds = ws2812_setleds,
} };
#endif #endif
#ifdef RGB_MATRIX_ENABLE #ifdef RGB_MATRIX_ENABLE

View File

@ -25,6 +25,7 @@
"pin": "D1" "pin": "D1"
}, },
"rgblight": { "rgblight": {
"driver": "custom",
"max_brightness": 120, "max_brightness": 120,
"sleep": true, "sleep": true,
"animations": { "animations": {

View File

@ -900,12 +900,6 @@ void rgblight_wakeup(void) {
#endif #endif
__attribute__((weak)) void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) {
ws2812_setleds(start_led, num_leds);
}
#ifndef RGBLIGHT_CUSTOM
void rgblight_set(void) { void rgblight_set(void) {
rgb_led_t *start_led; rgb_led_t *start_led;
uint8_t num_leds = rgblight_ranges.clipping_num_leds; uint8_t num_leds = rgblight_ranges.clipping_num_leds;
@ -948,9 +942,8 @@ void rgblight_set(void) {
convert_rgb_to_rgbw(&start_led[i]); convert_rgb_to_rgbw(&start_led[i]);
} }
# endif # endif
rgblight_call_driver(start_led, num_leds); rgblight_driver.setleds(start_led, num_leds);
} }
#endif
#ifdef RGBLIGHT_SPLIT #ifdef RGBLIGHT_SPLIT
/* for split keyboard master side */ /* for split keyboard master side */

View File

@ -160,6 +160,7 @@ enum RGBLIGHT_EFFECT_MODE {
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "rgblight_drivers.h"
#include "progmem.h" #include "progmem.h"
#include "eeconfig.h" #include "eeconfig.h"
#include "ws2812.h" #include "ws2812.h"

View File

@ -0,0 +1,17 @@
#include "rgblight_drivers.h"
#if defined(RGBLIGHT_WS2812)
# include "ws2812.h"
const rgblight_driver_t rgblight_driver = {
.setleds = ws2812_setleds,
};
#elif defined(RGBLIGHT_APA102)
# include "apa102.h"
const rgblight_driver_t rgblight_driver = {
.setleds = apa102_setleds,
};
#endif

View File

@ -0,0 +1,10 @@
#pragma once
#include <stdint.h>
#include "color.h"
typedef struct {
void (*setleds)(rgb_led_t *ledarray, uint16_t number_of_leds);
} rgblight_driver_t;
extern const rgblight_driver_t rgblight_driver;