diff options
author | Nick Brassel <[email protected]> | 2024-11-27 21:29:12 +1100 |
---|---|---|
committer | Nick Brassel <[email protected]> | 2024-11-27 21:29:12 +1100 |
commit | 9f76541b29056150cf57d69569a14a59e13995c7 (patch) | |
tree | 66c7398d873fcda88aebe3090603aefe045ff52e /platforms/avr/drivers/ws2812_bitbang.c | |
parent | 57be4871616ee9a8fe042f6186010d436ec7d4b1 (diff) | |
parent | eb04b94eecbb9b3e64ca9c74f937b5f762440b17 (diff) | |
download | qmk_firmware-9f76541b29056150cf57d69569a14a59e13995c7.tar.gz qmk_firmware-9f76541b29056150cf57d69569a14a59e13995c7.zip |
Merge branch 'develop'0.27.0
Diffstat (limited to 'platforms/avr/drivers/ws2812_bitbang.c')
-rw-r--r-- | platforms/avr/drivers/ws2812_bitbang.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/platforms/avr/drivers/ws2812_bitbang.c b/platforms/avr/drivers/ws2812_bitbang.c index be127e501c..183690c967 100644 --- a/platforms/avr/drivers/ws2812_bitbang.c +++ b/platforms/avr/drivers/ws2812_bitbang.c @@ -29,28 +29,6 @@ #define pinmask(pin) (_BV((pin)&0xF)) /* - * Forward declare internal functions - * - * The functions take a byte-array and send to the data output as WS2812 bitstream. - * The length is the number of bytes to send - three per LED. - */ - -static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t masklo, uint8_t maskhi); - -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); - - ws2812_sendarray_mask((uint8_t *)ledarray, number_of_leds * sizeof(rgb_led_t), masklo, maskhi); - - _delay_us(WS2812_TRST_US); -} - -/* This routine writes an array of bytes with RGB values to the Dataout pin using the fast 800kHz clockless WS2811/2812 protocol. */ @@ -172,3 +150,33 @@ static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t SREG = sreg_prev; } + +ws2812_led_t ws2812_leds[WS2812_LED_COUNT]; + +void ws2812_init(void) { + DDRx_ADDRESS(WS2812_DI_PIN) |= pinmask(WS2812_DI_PIN); +} + +void ws2812_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { + ws2812_leds[index].r = red; + ws2812_leds[index].g = green; + ws2812_leds[index].b = blue; +#if defined(WS2812_RGBW) + ws2812_rgb_to_rgbw(&ws2812_leds[index]); +#endif +} + +void ws2812_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { + for (int i = 0; i < WS2812_LED_COUNT; i++) { + ws2812_set_color(i, red, green, blue); + } +} + +void ws2812_flush(void) { + uint8_t masklo = ~(pinmask(WS2812_DI_PIN)) & PORTx_ADDRESS(WS2812_DI_PIN); + uint8_t maskhi = pinmask(WS2812_DI_PIN) | PORTx_ADDRESS(WS2812_DI_PIN); + + ws2812_sendarray_mask((uint8_t *)ws2812_leds, WS2812_LED_COUNT * sizeof(ws2812_led_t), masklo, maskhi); + + _delay_us(WS2812_TRST_US); +} |