1
0
Fork 0

Add init function to RGBLight driver struct (#23076)

This commit is contained in:
Ryan 2024-03-18 22:03:27 +11:00 committed by GitHub
parent 23b7a02ebe
commit f7cf40fa77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 306 additions and 93 deletions

View file

@ -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);

View file

@ -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);
}

View file

@ -177,7 +177,7 @@ static void ws2812_dma_callback(void* p, uint32_t ct) {
osalSysUnlockFromISR();
}
bool ws2812_init(void) {
void ws2812_init(void) {
uint pio_idx = pio_get_index(pio);
/* Get PIOx peripheral out of reset state. */
hal_lld_peripheral_unreset(pio_idx == 0 ? RESETS_ALLREG_PIO0 : RESETS_ALLREG_PIO1);
@ -196,7 +196,7 @@ bool ws2812_init(void) {
STATE_MACHINE = pio_claim_unused_sm(pio, true);
if (STATE_MACHINE < 0) {
dprintln("ERROR: Failed to acquire state machine for WS2812 output!");
return false;
return;
}
uint offset = pio_add_program(pio, &ws2812_program);
@ -246,8 +246,6 @@ bool ws2812_init(void) {
DMA_CTRL_TRIG_TREQ_SEL(pio == pio0 ? STATE_MACHINE : STATE_MACHINE + 8) |
DMA_CTRL_TRIG_PRIORITY(RP_DMA_PRIORITY_WS2812);
// clang-format on
return true;
}
static inline void sync_ws2812_transfer(void) {
@ -269,11 +267,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();
}
sync_ws2812_transfer();
for (int i = 0; i < leds; i++) {

View file

@ -82,12 +82,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();

View file

@ -389,12 +389,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);

View file

@ -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);
}