Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (c) 2019 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

menuconfig APP_LED_SUBSYSTEM
bool "LED Subsystem"
default y

if APP_LED_SUBSYSTEM
rsource "deps/Kconfig.deps"
endif


menu "Board Configuration"
menu "LED WS2812"

config SAMPLE_LED_UPDATE_DELAY
int "Delay between LED updates in ms"
default 50
range 10 1000
help
Delay between LED updates in ms.

config SAMPLE_LED_BRIGHTNESS
int "LED brightness"
default 16
range 1 255
help
Brightness level of each LED. Defaults to a low value to make
it easier to distinguish colors.
endmenu




menu "Options"
choice
prompt "LED Subsystem"
default BLINK_PERIOD_1000MS
optional

config BLINK_PERIOD_1000MS
bool "1000 period"
config BLINK_PERIOD_500MS
bool "500MS period"
endchoice

config PERIOD_BLINKING
bool
default 1000 if BLINK_PERIOD_1000MS
default 500 if BLINK_PERIOD_500MS
default 100
help
Enable blinking pattern. If disabled, the LEDs will be updated
with a static pattern.
endmenu

endmenu




menu "zephyr"
source "Kconfig.zephyr"
endmenu
41 changes: 41 additions & 0 deletions app/esp32s3_devkitc_procpu.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2024-2025 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/dt-bindings/led/led.h>

/ {
aliases {
led-strip = &led_strip;
};
};

&i2s0_default {
group1 {
pinmux = <I2S0_O_SD_GPIO48>;
};
};

i2s_led: &i2s0 {
status = "okay";

dmas = <&dma 3>;
dma-names = "tx";

led_strip: ws2812@0 {
compatible = "worldsemi,ws2812-i2s";

reg = <0>;
chain-length = <1>;
color-mapping = <LED_COLOR_ID_GREEN
LED_COLOR_ID_RED
LED_COLOR_ID_BLUE>;
reset-delay = <500>;
};
};

&dma {
status = "okay";
};
10 changes: 9 additions & 1 deletion app/prj.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
CONFIG_GPIO=y
CONFIG_LOG=y
CONFIG_LED_STRIP=y
CONFIG_LED_STRIP_LOG_LEVEL_DBG=y

CONFIG_I2S=y
CONFIG_WS2812_STRIP_I2S=y
CONFIG_DMA=y

CONFIG_APP_LED_INT_SAMPLE_BRIGHTNESS=75
CONFIG_APP_LED_ENABLE_CUSTOM_BLINK_PATTERN=y
78 changes: 61 additions & 17 deletions app/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,74 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
/*
* Copyright (c) 2017 Linaro Limited
* Copyright (c) 2018 Intel Corporation
* Copyright (c) 2024 TOKITA Hiroshi
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <errno.h>
#include <string.h>

#define LOG_LEVEL 4
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);

#include <zephyr/kernel.h>
#include <zephyr/drivers/led_strip.h>
#include <zephyr/device.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/sys/util.h>

#define SLEEP_TIME_MS 1000
#define STRIP_NODE DT_ALIAS(led_strip)

/* The devicetree node identifier for the "led0" alias. */
#define LED_NODE DT_ALIAS(led0)
#if DT_NODE_HAS_PROP(DT_ALIAS(led_strip), chain_length)
#define STRIP_NUM_PIXELS DT_PROP(DT_ALIAS(led_strip), chain_length)
#else
#error Unable to determine length of LED strip
#endif

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios);
#define DELAY_TIME K_MSEC(CONFIG_SAMPLE_LED_UPDATE_DELAY)

LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
#define RGB(_r, _g, _b) { .r = (_r), .g = (_g), .b = (_b) }

static const struct led_rgb colors[] = {
RGB(CONFIG_SAMPLE_LED_BRIGHTNESS, 0x00, 0x00), /* red */
RGB(0x00, CONFIG_SAMPLE_LED_BRIGHTNESS, 0x00), /* green */
RGB(0x00, 0x00, CONFIG_SAMPLE_LED_BRIGHTNESS), /* blue */
};

static struct led_rgb pixels[STRIP_NUM_PIXELS];

static const struct device *const strip = DEVICE_DT_GET(STRIP_NODE);

int main(void)
{
bool led_state = true;
size_t color = 0;
int rc;

if (device_is_ready(strip)) {
LOG_INF("Found LED strip device %s", strip->name);
} else {
LOG_ERR("LED strip device %s is not ready", strip->name);
return 0;
}

LOG_INF("Displaying pattern on strip");
while (1) {
for (size_t cursor = 0; cursor < ARRAY_SIZE(pixels); cursor++) {
memset(&pixels, 0x00, sizeof(pixels));
memcpy(&pixels[cursor], &colors[color], sizeof(struct led_rgb));

if (!gpio_is_ready_dt(&led)) return 0;
rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);
if (rc) {
LOG_ERR("couldn't update strip: %d", rc);
}

if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) return 0;
k_sleep(DELAY_TIME);
}

while (1) {
if (gpio_pin_toggle_dt(&led) < 0) return 0;
color = (color + 1) % ARRAY_SIZE(colors);
}

led_state = !led_state;
LOG_INF("LED state: %s", led_state ? "ON" : "OFF");
k_msleep(SLEEP_TIME_MS);
}
return 0;
return 0;
}
4 changes: 1 addition & 3 deletions west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ manifest:
import:
name-allowlist:
- cmsis_6
- hal_nxp
- hal_stm32
- hal_nordic
- hal_espressif
path-prefix: deps