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
pull/193/head
Niccolò Izzo 2023-08-11 16:21:35 +02:00 zatwierdzone przez Silvano Seva
rodzic c60f580396
commit 4df315473f
4 zmienionych plików z 187 dodań i 104 usunięć

Wyświetl plik

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

Wyświetl plik

@ -24,13 +24,14 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/drivers/led_strip.h>
#include "pmu.h"
#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 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 =
{
@ -42,6 +43,10 @@ static const hwInfo_t hwInfo =
.uhf_minFreq = 440,
};
// RGB led color data
static struct led_rgb led_color = {0};
void platform_init()
{
// Setup GPIO for PTT and rotary encoder
@ -61,6 +66,14 @@ void platform_init()
// Initialize PMU
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()
@ -116,12 +129,44 @@ bool platform_pwrButtonStatus()
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) 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)

Wyświetl plik

@ -11,26 +11,27 @@
#include <zephyr/dt-bindings/led/led.h>
/ {
model = "ttwrplus";
compatible = "espressif,esp32s3";
model = "ttwrplus";
compatible = "espressif,esp32s3";
aliases {
i2c-0 = &i2c0;
watchdog0 = &wdt0;
radio = &uart0;
aliases {
i2c-0 = &i2c0;
watchdog0 = &wdt0;
radio = &uart0;
radio-pwr = &radio_pwr;
radio-pdn = &radio_pdn;
radio-ptt = &radio_ptt;
qdec0 = &pcnt;
};
qdec0 = &pcnt;
led0 = &ws2812c;
};
chosen {
zephyr,sram = &sram0;
zephyr,console = &usb_serial;
zephyr,shell-uart = &usb_serial;
zephyr,flash = &flash0;
zephyr,display = &ssd1306;
};
chosen {
zephyr,sram = &sram0;
zephyr,console = &usb_serial;
zephyr,shell-uart = &usb_serial;
zephyr,flash = &flash0;
zephyr,display = &ssd1306;
};
leds: leds {
compatible = "gpio-leds";
@ -51,55 +52,55 @@
};
};
buttons: buttons {
compatible = "zephyr,gpio-keys";
buttons: buttons {
compatible = "gpio-keys";
button_boot: button_0 {
gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
zephyr,code = <INPUT_KEY_VOLUMEDOWN>;
label = "BOOT Button";
};
button_boot: button_0 {
gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
zephyr,code = <INPUT_KEY_VOLUMEDOWN>;
label = "BOOT Button";
};
button_user: button_1 {
gpios = <&gpio0 21 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
zephyr,code = <INPUT_BTN_START>;
label = "Encoder Button";
};
button_user: button_1 {
gpios = <&gpio0 21 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
zephyr,code = <INPUT_BTN_START>;
label = "Encoder Button";
};
button_ptt: button_2 {
gpios = <&gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
zephyr,code = <INPUT_BTN_SELECT>;
label = "PTT Button";
};
button_ptt: button_2 {
gpios = <&gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
zephyr,code = <INPUT_BTN_SELECT>;
label = "PTT Button";
};
};
};
&cpu0 {
clock-frequency = <ESP32_CLK_CPU_240M>;
clock-frequency = <ESP32_CLK_CPU_240M>;
};
&cpu1 {
clock-frequency = <ESP32_CLK_CPU_240M>;
clock-frequency = <ESP32_CLK_CPU_240M>;
};
&usb_serial {
status = "okay";
status = "okay";
};
&uart0 {
status = "okay";
current-speed = <9600>;
pinctrl-0 = <&uart0_default>;
pinctrl-names = "default";
status = "okay";
current-speed = <9600>;
pinctrl-0 = <&uart0_default>;
pinctrl-names = "default";
};
&i2c0 {
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
pinctrl-0 = <&i2c0_default>;
pinctrl-names = "default";
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;
pinctrl-0 = <&i2c0_default>;
pinctrl-names = "default";
ssd1306: ssd1306@3c {
ssd1306: ssd1306@3c {
compatible = "solomon,ssd1306fb";
reg = <0x3c>;
@ -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 {
pinctrl-0 = <&pcnt_default>;
pinctrl-names = "default";
@ -139,50 +166,56 @@
};
&timer0 {
status = "disabled";
status = "disabled";
};
&timer1 {
status = "disabled";
status = "disabled";
};
&timer2 {
status = "disabled";
status = "disabled";
};
&timer3 {
status = "disabled";
status = "disabled";
};
&wdt0 {
status = "okay";
status = "okay";
};
&trng0 {
status = "okay";
status = "okay";
};
&pinctrl {
uart0_default: uart0_default {
group1 {
pinmux = <UART0_TX_GPIO39>;
output-high;
};
group2 {
pinmux = <UART0_RX_GPIO48>;
bias-pull-up;
};
};
uart0_default: uart0_default {
group1 {
pinmux = <UART0_TX_GPIO39>;
output-high;
};
group2 {
pinmux = <UART0_RX_GPIO48>;
bias-pull-up;
};
};
i2c0_default: i2c0_default {
group1 {
pinmux = <I2C0_SDA_GPIO8>,
<I2C0_SCL_GPIO9>;
bias-pull-up;
drive-open-drain;
output-high;
};
};
i2c0_default: i2c0_default {
group1 {
pinmux = <I2C0_SDA_GPIO8>,
<I2C0_SCL_GPIO9>;
bias-pull-up;
drive-open-drain;
output-high;
};
};
spim3_default: spim3_default {
group2 {
pinmux = <SPIM3_MOSI_GPIO42>;
};
};
pcnt_default: pcnt_default {
group1 {
@ -194,40 +227,40 @@
};
&flash0 {
status = "okay";
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
status = "okay";
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
/* Reserve 64kB for the bootloader */
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 0x00010000>;
read-only;
};
/* Reserve 64kB for the bootloader */
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 0x00010000>;
read-only;
};
/* Reserve 1024kB for the application in slot 0 */
slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 0x00100000>;
};
/* Reserve 1024kB for the application in slot 0 */
slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 0x00100000>;
};
/* Reserve 1024kB for the application in slot 1 */
slot1_partition: partition@110000 {
label = "image-1";
reg = <0x00110000 0x00100000>;
};
/* Reserve 1024kB for the application in slot 1 */
slot1_partition: partition@110000 {
label = "image-1";
reg = <0x00110000 0x00100000>;
};
/* Reserve 256kB for the scratch partition */
scratch_partition: partition@210000 {
label = "image-scratch";
reg = <0x00210000 0x00040000>;
};
/* Reserve 256kB for the scratch partition */
scratch_partition: partition@210000 {
label = "image-scratch";
reg = <0x00210000 0x00040000>;
};
storage_partition: partition@250000 {
label = "storage";
reg = <0x00250000 0x00006000>;
};
};
storage_partition: partition@250000 {
label = "storage";
reg = <0x00250000 0x00006000>;
};
};
};

Wyświetl plik

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