ttwrplus: add RGB LED support

Implemented WS2812C support with Zephyr driver.
Hooked up the RGB control to the existing RED and GREEN LED support.

TG-553
This commit is contained in:
Niccolò Izzo 2023-08-11 16:21:35 +02:00 committed by Silvano Seva
parent c60f580396
commit 4df315473f
4 changed files with 187 additions and 104 deletions

View File

@ -55,7 +55,7 @@ static void gpio_keys_cb_handler(struct input_event *evt)
keys &= ~keyCode; keys &= ~keyCode;
} }
INPUT_LISTENER_CB_DEFINE(buttons_dev, gpio_keys_cb_handler); INPUT_CALLBACK_DEFINE(buttons_dev, gpio_keys_cb_handler);
void kbd_init() void kbd_init()

View File

@ -24,13 +24,14 @@
#include <zephyr/drivers/gpio.h> #include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/sensor.h> #include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/uart.h> #include <zephyr/drivers/uart.h>
#include <zephyr/drivers/led_strip.h>
#include "pmu.h" #include "pmu.h"
#define BUTTON_PTT_NODE DT_NODELABEL(button_ptt) #define BUTTON_PTT_NODE DT_NODELABEL(button_ptt)
static const struct gpio_dt_spec button_ptt = GPIO_DT_SPEC_GET_OR(BUTTON_PTT_NODE, gpios, {0}); static const struct gpio_dt_spec button_ptt = GPIO_DT_SPEC_GET_OR(BUTTON_PTT_NODE, gpios, {0});
static const struct device *const qdec_dev = DEVICE_DT_GET(DT_ALIAS(qdec0)); static const struct device *const qdec_dev = DEVICE_DT_GET(DT_ALIAS(qdec0));
static const struct device *const led_dev = DEVICE_DT_GET(DT_ALIAS(led0));
static const hwInfo_t hwInfo = static const hwInfo_t hwInfo =
{ {
@ -42,6 +43,10 @@ static const hwInfo_t hwInfo =
.uhf_minFreq = 440, .uhf_minFreq = 440,
}; };
// RGB led color data
static struct led_rgb led_color = {0};
void platform_init() void platform_init()
{ {
// Setup GPIO for PTT and rotary encoder // Setup GPIO for PTT and rotary encoder
@ -61,6 +66,14 @@ void platform_init()
// Initialize PMU // Initialize PMU
pmu_init(); pmu_init();
// Initialize LED
if (device_is_ready(led_dev) == false)
printk("LED device %s is not ready", led_dev->name);
ret = led_strip_update_rgb(led_dev, &led_color, 1);
if (ret)
printk("couldn't update strip: %d", ret);
} }
void platform_terminate() void platform_terminate()
@ -116,12 +129,44 @@ bool platform_pwrButtonStatus()
void platform_ledOn(led_t led) void platform_ledOn(led_t led)
{ {
(void) led; int ret = 0;
switch(led)
{
case GREEN:
led_color.g = 0xff;
break;
case RED:
led_color.r = 0xff;
break;
default:
break;
}
ret = led_strip_update_rgb(led_dev, &led_color, 1);
if (ret)
printk("couldn't update strip: %d", ret);
} }
void platform_ledOff(led_t led) void platform_ledOff(led_t led)
{ {
(void) led; int ret = 0;
switch(led)
{
case GREEN:
led_color.g = 0x00;
break;
case RED:
led_color.r = 0x00;
break;
default:
break;
}
ret = led_strip_update_rgb(led_dev, &led_color, 1);
if (ret)
printk("couldn't update strip: %d", ret);
} }
void platform_beepStart(uint16_t freq) void platform_beepStart(uint16_t freq)

View File

@ -22,6 +22,7 @@
radio-pdn = &radio_pdn; radio-pdn = &radio_pdn;
radio-ptt = &radio_ptt; radio-ptt = &radio_ptt;
qdec0 = &pcnt; qdec0 = &pcnt;
led0 = &ws2812c;
}; };
chosen { chosen {
@ -52,7 +53,7 @@
}; };
buttons: buttons { buttons: buttons {
compatible = "zephyr,gpio-keys"; compatible = "gpio-keys";
button_boot: button_0 { button_boot: button_0 {
gpios = <&gpio0 0 GPIO_ACTIVE_LOW>; gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
@ -117,6 +118,32 @@
}; };
}; };
&spi3 {
#address-cells = <1>;
#size-cells = <0>;
line-idle-low; /* Workaround to have low signal for latching */
status = "okay";
pinctrl-0 = <&spim3_default>;
pinctrl-names = "default";
ws2812c: ws2812@0 {
compatible = "worldsemi,ws2812-spi";
/* SPI */
reg = <0x0>; /* ignored, but necessary for SPI bindings */
spi-max-frequency = <6400000>;
/* WS2812C */
chain-length = <1>; /* arbitrary; change at will */
spi-cpha;
spi-one-frame = <0xf0>; /* 11110000: 625 ns high and 625 ns low */
spi-zero-frame = <0xc0>; /* 11000000: 312.5 ns high and 937.5 ns low */
color-mapping = <LED_COLOR_ID_GREEN
LED_COLOR_ID_RED
LED_COLOR_ID_BLUE>;
reset-delay = <280>; /* > 280us by WS2812C datasheet */
};
};
&pcnt { &pcnt {
pinctrl-0 = <&pcnt_default>; pinctrl-0 = <&pcnt_default>;
pinctrl-names = "default"; pinctrl-names = "default";
@ -184,6 +211,12 @@
}; };
}; };
spim3_default: spim3_default {
group2 {
pinmux = <SPIM3_MOSI_GPIO42>;
};
};
pcnt_default: pcnt_default { pcnt_default: pcnt_default {
group1 { group1 {
pinmux = <PCNT0_CH0SIG_GPIO46>, pinmux = <PCNT0_CH0SIG_GPIO46>,

View File

@ -12,7 +12,12 @@ CONFIG_COMMON_LIBC_MALLOC=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072 CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072
CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE=0 CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE=0
CONFIG_INPUT=y CONFIG_INPUT=y
CONFIG_INPUT_GPIO_KEYS=y
CONFIG_SENSOR=y CONFIG_SENSOR=y
CONFIG_SERIAL=y CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_ASSERT=y CONFIG_ASSERT=y
CONFIG_SPI=y
CONFIG_LED_STRIP=y
CONFIG_WS2812_STRIP=y
CONFIG_WS2812_STRIP_SPI=y