Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add init function to RGBLight driver struct #23076

Merged
merged 8 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions drivers/led/apa102.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ static void apa102_send_byte(uint8_t byte) {
}

static void apa102_start_frame(void) {
apa102_init();
writePinLow(APA102_DI_PIN);
writePinLow(APA102_CI_PIN);

for (uint16_t i = 0; i < 4; i++) {
apa102_send_byte(0);
}
Expand Down Expand Up @@ -103,7 +105,8 @@ static void apa102_end_frame(uint16_t num_leds) {
apa102_send_byte(0);
}

apa102_init();
writePinLow(APA102_DI_PIN);
writePinLow(APA102_CI_PIN);
}

static void apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness) {
Expand All @@ -116,9 +119,6 @@ static void apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t
void apa102_init(void) {
setPinOutput(APA102_DI_PIN);
setPinOutput(APA102_CI_PIN);

writePinLow(APA102_DI_PIN);
writePinLow(APA102_CI_PIN);
}

void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) {
Expand Down
2 changes: 2 additions & 0 deletions drivers/ws2812.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
# define WS2812_LED_COUNT RGB_MATRIX_LED_COUNT
#endif

void ws2812_init(void);

/* User Interface
*
* Input:
Expand Down
6 changes: 0 additions & 6 deletions keyboards/oddforge/vea/ws2812_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ void ws2812_init(void) {

// Setleds for standard RGB
void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}

i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(rgb_led_t) * (leds >> 1), WS2812_I2C_TIMEOUT);
i2c_transmit(WS2812_I2C_ADDRESS_RIGHT, (uint8_t *)ledarray+(sizeof(rgb_led_t) * (leds >> 1)), sizeof(rgb_led_t) * (leds - (leds >> 1)), WS2812_I2C_TIMEOUT);
}
4 changes: 3 additions & 1 deletion platforms/avr/drivers/ws2812_bitbang.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@

static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi);

void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds) {
void ws2812_init(void) {
DDRx_ADDRESS(WS2812_DI_PIN) |= pinmask(WS2812_DI_PIN);
}

void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds) {
uint8_t masklo = ~(pinmask(WS2812_DI_PIN)) & PORTx_ADDRESS(WS2812_DI_PIN);
uint8_t maskhi = pinmask(WS2812_DI_PIN) | PORTx_ADDRESS(WS2812_DI_PIN);

Expand Down
6 changes: 0 additions & 6 deletions platforms/avr/drivers/ws2812_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,5 @@ void ws2812_init(void) {

// Setleds for standard RGB
void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}

i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(rgb_led_t) * leds, WS2812_I2C_TIMEOUT);
}
5 changes: 0 additions & 5 deletions platforms/chibios/drivers/vendor/RP/RP2040/ws2812_vendor.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,6 @@ static inline void sync_ws2812_transfer(void) {
}

void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
static bool is_initialized = false;
if (unlikely(!is_initialized)) {
is_initialized = ws2812_init();
fauxpark marked this conversation as resolved.
Show resolved Hide resolved
}

sync_ws2812_transfer();

for (int i = 0; i < leds; i++) {
Expand Down
6 changes: 0 additions & 6 deletions platforms/chibios/drivers/ws2812_bitbang.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ void ws2812_init(void) {

// Setleds for standard RGB
void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}

// this code is very time dependent, so we need to disable interrupts
chSysLock();

Expand Down
6 changes: 0 additions & 6 deletions platforms/chibios/drivers/ws2812_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,6 @@ 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) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}

for (uint16_t i = 0; i < leds; i++) {
#ifdef RGBW
ws2812_write_led_rgbw(i, ledarray[i].r, ledarray[i].g, ledarray[i].b, ledarray[i].w);
Expand Down
6 changes: 0 additions & 6 deletions platforms/chibios/drivers/ws2812_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ void ws2812_init(void) {
}

void ws2812_setleds(rgb_led_t* ledarray, uint16_t leds) {
static bool s_init = false;
if (!s_init) {
ws2812_init();
s_init = true;
}

for (uint8_t i = 0; i < leds; i++) {
set_led_color_rgb(ledarray[i], i);
}
Expand Down
1 change: 1 addition & 0 deletions quantum/rgb_matrix/rgb_matrix_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_COUNT];
bool ws2812_dirty = false;

static void init(void) {
ws2812_init();
ws2812_dirty = false;
}

Expand Down
2 changes: 2 additions & 0 deletions quantum/rgblight/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ void rgblight_init(void) {
rgblight_mode_noeeprom(rgblight_config.mode);
}

rgblight_driver.init();

is_rgblight_initialized = true;
}

Expand Down
2 changes: 2 additions & 0 deletions quantum/rgblight/rgblight_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
# include "ws2812.h"

const rgblight_driver_t rgblight_driver = {
.init = ws2812_init,
.setleds = ws2812_setleds,
};

#elif defined(RGBLIGHT_APA102)
# include "apa102.h"

const rgblight_driver_t rgblight_driver = {
.init = apa102_init,
.setleds = apa102_setleds,
};

Expand Down
1 change: 1 addition & 0 deletions quantum/rgblight/rgblight_drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "color.h"

typedef struct {
void (*init)(void);
void (*setleds)(rgb_led_t *ledarray, uint16_t number_of_leds);
} rgblight_driver_t;

Expand Down
Loading