commit 1f1b153d6f5a25c6929af1562cb9d67b9843007e
parent ff97177aa004c6e564b253aae6aec3aa07cec24c
Author: Louis Burda <quent.burda@gmail.com>
Date: Wed, 1 Feb 2023 13:10:46 +0100
Move rgb convert into ws2814.c
Diffstat:
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/led.c b/src/led.c
@@ -36,7 +36,7 @@ led_task(void)
break;
case LED_ON:
if (led_reset)
- ws2812_put(&onboard_led, WS2812_U32RGB(led_rgb));
+ ws2812_put(&onboard_led, led_rgb);
break;
case LED_BLINK:
if (led_reset)
@@ -47,7 +47,7 @@ led_task(void)
start_ms += led_blink_ms;
state = !state;
- ws2812_put(&onboard_led, state ? WS2812_U32RGB(led_rgb) : 0);
+ ws2812_put(&onboard_led, state ? led_rgb : 0);
break;
}
@@ -59,7 +59,7 @@ led_blip(uint32_t rgb)
{
uint32_t start;
- ws2812_put(&onboard_led, WS2812_U32RGB(rgb));
+ ws2812_put(&onboard_led, rgb);
start = board_millis();
while (board_millis() < start + BLINK_DELAY)
tud_task();
diff --git a/src/ws2812.c b/src/ws2812.c
@@ -39,5 +39,7 @@ ws2812_init(struct ws2812 *pix, PIO pio, uint pin)
void
ws2812_put(struct ws2812 *pix, uint32_t rgb) {
+ rgb = ((rgb & 0xFF0000) >> 16) | ((rgb & 0x00FF00) << 8)
+ | ((rgb & 0x0000FF) << 8);
pio_sm_put_blocking(pix->pio, pix->sm, rgb << 8u);
}
diff --git a/src/ws2812.h b/src/ws2812.h
@@ -5,10 +5,6 @@
#include <stdbool.h>
-#define _WS2812_U8(v, si, so) ((((uint32_t) (v) >> si) & 0xFF) << so)
-#define WS2812_U32RGB(rgb) (_WS2812_U8(rgb, 16, 0) \
- | _WS2812_U8(rgb, 0, 8) | _WS2812_U8(rgb, 8, 16))
-
struct ws2812 {
PIO pio;
uint sm;