Skip to content

Commit dd9f5e2

Browse files
Johan Hedbergcarlescufi
authored andcommitted
samples: led_strip: Extend ws2812 sample with ws2812b_sw support
Add support for building the WS2812 LED strip driver sample against the new ws2812b_sw driver. Currently a configuration is only provided for the BBC micro:bit board. Signed-off-by: Johan Hedberg <[email protected]>
1 parent 9639c00 commit dd9f5e2

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

samples/drivers/led_ws2812/boards/96b_carbon.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
CONFIG_POLL=y
2+
CONFIG_SPI=y
3+
# CONFIG_SPI_LEGACY_API is not set
4+
5+
CONFIG_WS2812_STRIP=y
6+
CONFIG_WS2812_STRIP_SPI_DEV_NAME="ws2812_spi"
7+
18
CONFIG_SPI_STM32=y
29
CONFIG_SPI_STM32_INTERRUPT=y
310
CONFIG_SPI_2=y
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_GPIO=y
2+
CONFIG_WS2812B_SW=y

samples/drivers/led_ws2812/prj.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,5 @@
22

33
CONFIG_SYS_LOG=y
44
CONFIG_BOOT_BANNER=y
5-
CONFIG_POLL=y
6-
7-
CONFIG_SPI=y
8-
# CONFIG_SPI_LEGACY_API is not set
95

106
CONFIG_LED_STRIP=y
11-
CONFIG_WS2812_STRIP=y
12-
CONFIG_WS2812_STRIP_SPI_DEV_NAME="ws2812_spi"

samples/drivers/led_ws2812/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ sample:
44
platforms: all
55
tests:
66
test:
7-
platform_whitelist: 96b_carbon
7+
platform_whitelist: 96b_carbon bbc_microbit
88
tags: samples

samples/drivers/led_ws2812/src/main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2017 Linaro Limited
3+
* Copyright (c) 2018 Intel Corporation
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -19,10 +20,15 @@
1920
/*
2021
* Number of RGB LEDs in the LED strip, adjust as needed.
2122
*/
23+
#if defined(CONFIG_WS2812_STRIP)
2224
#define STRIP_NUM_LEDS 12
25+
#define STRIP_DEV_NAME CONFIG_WS2812_STRIP_NAME
26+
#else
27+
#define STRIP_NUM_LEDS 24
28+
#define STRIP_DEV_NAME CONFIG_WS2812B_SW_NAME
29+
#endif
2330

2431
#define SPI_DEV_NAME "ws2812_spi"
25-
#define STRIP_DEV_NAME CONFIG_WS2812_STRIP_NAME
2632
#define DELAY_TIME K_MSEC(40)
2733

2834
static const struct led_rgb colors[] = {
@@ -52,8 +58,10 @@ const struct led_rgb *color_at(size_t time, size_t i)
5258

5359
void main(void)
5460
{
55-
struct device *spi, *strip;
61+
struct device *strip;
5662
size_t i, time;
63+
#if defined(CONFIG_SPI)
64+
struct device *spi;
5765

5866
/* Double-check the configuration. */
5967
spi = device_get_binding(SPI_DEV_NAME);
@@ -65,6 +73,8 @@ void main(void)
6573
SPI_DEV_NAME);
6674
return;
6775
}
76+
#endif
77+
6878
strip = device_get_binding(STRIP_DEV_NAME);
6979
if (strip) {
7080
SYS_LOG_INF("Found LED strip device %s", STRIP_DEV_NAME);

0 commit comments

Comments
 (0)