feat: LED-Treiber, Licht-Task und UART-Testkonsole

This commit is contained in:
Michael Sauer
2026-09-11 13:51:31 +02:00
parent 1074a8f034
commit 757620f222
11 changed files with 530 additions and 10 deletions
+87
View File
@@ -0,0 +1,87 @@
#include <string.h>
#include "wm_include.h"
#include "drivers/nl_led.h"
#define SM_ADDR_CURRENT 0xC0u
#define SM_ADDR_WY 0xC5u
#define SM_CHANNEL_WY 0x80u /* channel select bit 7: 0 = RGB, 1 = WY */
extern void delay_us(unsigned int us); /* provided by libwlan.a */
static uint8_t s_clk, s_dat, s_current;
static uint8_t s_last[NL_CH_COUNT];
static bool s_have_last;
static void pin(uint8_t p, int v)
{
tls_gpio_write((enum tls_io_name)p, (u8)v);
}
static void bus_start(void)
{
pin(s_clk, 1); pin(s_dat, 1); delay_us(1);
pin(s_dat, 0); delay_us(1);
pin(s_clk, 0); delay_us(1);
}
static void bus_stop(void)
{
pin(s_clk, 0); pin(s_dat, 0); delay_us(1);
pin(s_clk, 1); delay_us(1);
pin(s_dat, 1); delay_us(1);
}
static void write_byte(uint8_t b)
{
for (uint8_t m = 0x80; m; m >>= 1) {
pin(s_dat, (b & m) ? 1 : 0); delay_us(1);
pin(s_clk, 1); delay_us(1);
pin(s_clk, 0); delay_us(1);
}
/* ack clock; the SM2135EH does not drive an ack */
pin(s_dat, 0); delay_us(1);
pin(s_clk, 1); delay_us(1);
pin(s_clk, 0); pin(s_dat, 0);
}
static void sm_send(const uint8_t *d, int n)
{
bus_start();
for (int i = 0; i < n; i++)
write_byte(d[i]);
bus_stop();
}
void nl_sm2135eh_init(const nl_board_t *board)
{
uint8_t off[NL_CH_COUNT] = {0};
s_clk = board->sm_clk_pin;
s_dat = board->sm_dat_pin;
s_current = board->sm_current;
s_have_last = false;
tls_gpio_cfg((enum tls_io_name)s_clk, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
tls_gpio_cfg((enum tls_io_name)s_dat, WM_GPIO_DIR_OUTPUT, WM_GPIO_ATTR_PULLHIGH);
nl_sm2135eh_set(off);
}
void nl_sm2135eh_set(const uint8_t ch[NL_CH_COUNT])
{
bool white = ch[NL_CH_CW] || ch[NL_CH_WW];
if (s_have_last && memcmp(ch, s_last, NL_CH_COUNT) == 0)
return;
memcpy(s_last, ch, NL_CH_COUNT);
s_have_last = true;
if (!white) {
uint8_t d[6] = {SM_ADDR_CURRENT, s_current, 0x00, ch[NL_CH_B], ch[NL_CH_G], ch[NL_CH_R]};
sm_send(d, 6);
} else {
uint8_t h[3] = {SM_ADDR_CURRENT, s_current, SM_CHANNEL_WY};
uint8_t d[3] = {SM_ADDR_WY, ch[NL_CH_WW], ch[NL_CH_CW]};
sm_send(h, 3);
sm_send(d, 3);
}
}