diff --git a/app/Kconfig b/app/Kconfig new file mode 100644 index 00000000..cc7de561 --- /dev/null +++ b/app/Kconfig @@ -0,0 +1,14 @@ +menu "Led Subsystem" + +config APP_HEARTBEAT_PERIOD_MS + int "Configure Hearteab Period (ms)" + range 500 1000 + default 500 + +endmenu + +menu "Zephyr" + +source "Kconfig.zephyr" + +endmenu \ No newline at end of file diff --git a/app/app.overlay b/app/app.overlay new file mode 100644 index 00000000..770b0aad --- /dev/null +++ b/app/app.overlay @@ -0,0 +1,39 @@ +#include +#include +#include + +/ { + + aliases { + app-led = &led_strip; + }; +}; + +&pinctrl { + spim2_ws2812: spim2_ws2812 { + group1 { + pinmux = ; + output-high; + }; + }; +}; + +&spi2 { + line-idle-low; + status = "okay"; + pinctrl-0 = <&spim2_ws2812>; + pinctrl-names = "default"; + + led_strip: ws2812@0 { + compatible = "worldsemi,ws2812-spi"; + reg = <0>; + spi-max-frequency = <6400000>; + chain-length = <1>; + color-mapping = ; + spi-one-frame = <0xf0>; + spi-zero-frame = <0xc0>; + reset-delay = <50>; + }; +}; diff --git a/app/prj.conf b/app/prj.conf index 244cc784..8612f561 100644 --- a/app/prj.conf +++ b/app/prj.conf @@ -1,2 +1,6 @@ CONFIG_GPIO=y CONFIG_LOG=y +CONFIG_APP_HEARTBEAT_PERIOD_MS=500 +CONFIG_SPI=y +CONFIG_LED_STRIP=y +CONFIG_WS2812_STRIP_SPI=y \ No newline at end of file diff --git a/app/src/main.cpp b/app/src/main.cpp index 5dfdde9c..db4e29dd 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -1,13 +1,17 @@ #include #include #include - -#define SLEEP_TIME_MS 1000 +#include +#include /* The devicetree node identifier for the "led0" alias. */ -#define LED_NODE DT_ALIAS(led0) +#define LED_NODE DT_ALIAS(app_led) + +static const struct device *strip = DEVICE_DT_GET(LED_NODE); + +struct led_rgb red[] = { {.r = 255, .g = 0, .b = 0} }; /* red */ +struct led_rgb blue[] = { {.r = 0, .g = 0, .b = 255} }; /* red */ -static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios); LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); @@ -15,16 +19,15 @@ int main(void) { bool led_state = true; - if (!gpio_is_ready_dt(&led)) return 0; - - if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) return 0; - while (1) { - if (gpio_pin_toggle_dt(&led) < 0) return 0; led_state = !led_state; + + if (led_strip_update_rgb(strip, led_state ? red : blue, ARRAY_SIZE(red)) < 0) { + return 0; + }; LOG_INF("LED state: %s", led_state ? "ON" : "OFF"); - k_msleep(SLEEP_TIME_MS); + k_msleep(CONFIG_APP_HEARTBEAT_PERIOD_MS); } return 0; } diff --git a/app/tools/build.sh b/app/tools/build.sh new file mode 100755 index 00000000..5ab7e14f --- /dev/null +++ b/app/tools/build.sh @@ -0,0 +1,6 @@ +#!/usr/bin/bash +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) + +pushd $SCRIPT_DIR/.. +west build -p always -b esp32s3_devkitc/esp32s3/procpu +popd diff --git a/west.yml b/west.yml index eb3a6de7..f69c629f 100644 --- a/west.yml +++ b/west.yml @@ -4,11 +4,9 @@ manifest: projects: - name: zephyr url: https://github.com/zephyrproject-rtos/zephyr - revision: v4.3.0 + revision: v4.4.0-rc2 import: name-allowlist: - cmsis_6 - - hal_nxp - - hal_stm32 - - hal_nordic + - hal_espressif path-prefix: deps