diff --git a/boards/feather-nrf52840-sense/Makefile.dep b/boards/feather-nrf52840-sense/Makefile.dep index d7a80382127a..c52f9ec66bc7 100644 --- a/boards/feather-nrf52840-sense/Makefile.dep +++ b/boards/feather-nrf52840-sense/Makefile.dep @@ -5,6 +5,7 @@ ifneq (,$(filter saul_default,$(USEMODULE))) USEMODULE += lsm6dsxx USEMODULE += saul_gpio USEMODULE += sht3x + USEMODULE += ws281x endif # include common nrf52 dependencies diff --git a/boards/feather-nrf52840-sense/include/board.h b/boards/feather-nrf52840-sense/include/board.h index 27de7b841465..fbdfc325da1f 100644 --- a/boards/feather-nrf52840-sense/include/board.h +++ b/boards/feather-nrf52840-sense/include/board.h @@ -97,6 +97,9 @@ extern "C" { #ifndef WS281X_PARAM_PIN #define WS281X_PARAM_PIN GPIO_PIN(0, 16) /**< GPIO pin connected to the data pin of the first LED */ #endif +#ifndef WS281X_PARAM_NUMOF +#define WS281X_PARAM_NUMOF (1U) /**< Number of LEDs chained */ +#endif /** @} */ #ifdef __cplusplus diff --git a/drivers/saul/init_devs/auto_init_ws281x.c b/drivers/saul/init_devs/auto_init_ws281x.c new file mode 100644 index 000000000000..d54d71d5c767 --- /dev/null +++ b/drivers/saul/init_devs/auto_init_ws281x.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2024 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + * + */ + +/** + * @ingroup sys_auto_init_saul + * @{ + * + * @file + * @brief Auto initialization of ws281x RGB LED devices + * + * @author Kevin Weiss + * + * @} + */ + +#include "assert.h" +#include "log.h" +#include "saul_reg.h" + +#include "ws281x.h" +#include "ws281x_params.h" + +/** + * @brief Define the number of configured sensors + */ +#define WS281X_NUM ARRAY_SIZE(ws281x_params) + +/** + * @brief Allocate memory for the device descriptors + */ +static ws281x_t ws281x_devs[WS281X_NUM]; + +/** + * @brief Memory for the SAUL registry entries + */ +static saul_reg_t saul_entries[WS281X_NUM]; + +/** + * @brief Define the number of saul info + */ +#define WS281X_INFO_NUM ARRAY_SIZE(ws281x_saul_info) + +/** + * @brief Reference the driver struct + */ +extern const saul_driver_t ws281x_saul_driver; + +void auto_init_ws281x(void) +{ + assert(WS281X_NUM == WS281X_INFO_NUM); + + for (unsigned i = 0; i < WS281X_NUM; i++) { + LOG_DEBUG("[auto_init_saul] initializing WS281x #%u: ", i); + + if (ws281x_init(&ws281x_devs[i], &ws281x_params[i]) != 0) { + LOG_ERROR("ERROR\n"); + continue; + } + LOG_DEBUG("SUCCESS\n"); + saul_entries[i].dev = &(ws281x_devs[i]); + saul_entries[i].name = ws281x_saul_info[i].name; + saul_entries[i].driver = &ws281x_saul_driver; + saul_reg_add(&(saul_entries[i])); + } +} diff --git a/drivers/saul/init_devs/init.c b/drivers/saul/init_devs/init.c index ad4d4704447e..1e9146fce520 100644 --- a/drivers/saul/init_devs/init.c +++ b/drivers/saul/init_devs/init.c @@ -343,4 +343,8 @@ void saul_init_devs(void) extern void auto_init_servo(void); auto_init_servo(); } + if (IS_USED(MODULE_WS281X)) { + extern void auto_init_ws281x(void); + auto_init_ws281x(); + } } diff --git a/drivers/ws281x/Makefile b/drivers/ws281x/Makefile index de0e17ec3b8e..35d1f8508ba2 100644 --- a/drivers/ws281x/Makefile +++ b/drivers/ws281x/Makefile @@ -1,3 +1,14 @@ SRC := ws281x.c # All other sources files provide ws281x_write as submodule SUBMODULES := 1 + +# Since we have submodules we need to manually handle saul instead of +# including driver_with_saul.mk +MODULE ?= $(shell basename $(CURDIR)) +SAUL_INTERFACE ?= $(MODULE)_saul.c + +# only include _saul.c if saul module is used +ifneq (,$(filter saul,$(USEMODULE))) + SRC += $(SAUL_INTERFACE) +endif + include $(RIOTBASE)/Makefile.base diff --git a/drivers/ws281x/Makefile.dep b/drivers/ws281x/Makefile.dep index f539c4de83d7..31f00f6c33f0 100644 --- a/drivers/ws281x/Makefile.dep +++ b/drivers/ws281x/Makefile.dep @@ -37,3 +37,6 @@ endif ifneq (,$(filter ws281x_timer_gpio_ll,$(USEMODULE))) FEATURES_REQUIRED += periph_gpio_ll periph_timer periph_timer_poll endif + +# It would seem xtimer is always required as it is used in the header... +USEMODULE += xtimer diff --git a/drivers/ws281x/include/ws281x_params.h b/drivers/ws281x/include/ws281x_params.h index e68b8f91839b..1f7d0262155d 100644 --- a/drivers/ws281x/include/ws281x_params.h +++ b/drivers/ws281x/include/ws281x_params.h @@ -20,6 +20,8 @@ #define WS281X_PARAMS_H #include "board.h" +#include "saul_reg.h" + #include "ws281x.h" #ifdef __cplusplus @@ -105,6 +107,21 @@ static const ws281x_params_t ws281x_params[] = #define WS281X_TIMER_FREQ 16000000 #endif +/** + * @brief SAUL info + */ +#ifndef WS281X_SAUL_INFO +#define WS281X_SAUL_INFO { .name = "WS281X RGB LED" } +#endif + +/** + * @brief Additional meta information to keep in the SAUL registry + */ +static const saul_reg_info_t ws281x_saul_info[] = +{ + WS281X_SAUL_INFO +}; + #ifdef __cplusplus } #endif diff --git a/drivers/ws281x/ws281x_saul.c b/drivers/ws281x/ws281x_saul.c new file mode 100644 index 000000000000..88edc0dd0f1a --- /dev/null +++ b/drivers/ws281x/ws281x_saul.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2024 HAW Hamburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup drivers_ws281x + * @{ + * + * @file + * @brief NEOPixel/ws281x adaption to SAUL + * + * @author Kevin Weiss + * + * @} + */ + +#include +#include + +#include "saul.h" +#include "ws281x.h" + +static int set_rgb_led(const void *dev, const phydat_t *res) +{ + ws281x_t *ws281x = (ws281x_t *)dev; + color_rgb_t color = { + .r = res->val[0], + .g = res->val[1], + .b = res->val[2] + }; + for (unsigned idx = 0; idx < ws281x->params.numof; idx++) { + puts("Setting LED"); + ws281x_set(ws281x, idx, color); + } + ws281x_write(ws281x); + return 1; +} + +const saul_driver_t ws281x_saul_driver = { + .read = saul_read_notsup, + .write = set_rgb_led, + .type = SAUL_ACT_LED_RGB, +}; diff --git a/examples/rust-gcoap/Cargo.lock b/examples/rust-gcoap/Cargo.lock index 1143bb3b7aad..06855c8813cf 100644 --- a/examples/rust-gcoap/Cargo.lock +++ b/examples/rust-gcoap/Cargo.lock @@ -785,7 +785,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.8.3" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#de348dce223543babe4763dda39196bd5f881c8d" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#ea8d7fad95c8cb256ba9bc178f7779d266cc0def" dependencies = [ "bare-metal", "coap-handler 0.1.6", diff --git a/examples/rust-hello-world/Cargo.lock b/examples/rust-hello-world/Cargo.lock index 2da593648a0b..0af45438d926 100644 --- a/examples/rust-hello-world/Cargo.lock +++ b/examples/rust-hello-world/Cargo.lock @@ -574,7 +574,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.8.3" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#de348dce223543babe4763dda39196bd5f881c8d" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#ea8d7fad95c8cb256ba9bc178f7779d266cc0def" dependencies = [ "bare-metal", "coap-handler 0.1.6", diff --git a/sys/rust_riotmodules_standalone/Cargo.lock b/sys/rust_riotmodules_standalone/Cargo.lock index f6992acaaabe..95b0899c05b1 100644 --- a/sys/rust_riotmodules_standalone/Cargo.lock +++ b/sys/rust_riotmodules_standalone/Cargo.lock @@ -600,7 +600,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.8.3" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#de348dce223543babe4763dda39196bd5f881c8d" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#ea8d7fad95c8cb256ba9bc178f7779d266cc0def" dependencies = [ "bare-metal", "coap-handler 0.1.6", diff --git a/tests/rust_minimal/Cargo.lock b/tests/rust_minimal/Cargo.lock index 00c034dae2ff..19c3997743cf 100644 --- a/tests/rust_minimal/Cargo.lock +++ b/tests/rust_minimal/Cargo.lock @@ -574,7 +574,7 @@ dependencies = [ [[package]] name = "riot-wrappers" version = "0.8.3" -source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#de348dce223543babe4763dda39196bd5f881c8d" +source = "git+https://github.com/RIOT-OS/rust-riot-wrappers#ea8d7fad95c8cb256ba9bc178f7779d266cc0def" dependencies = [ "bare-metal", "coap-handler 0.1.6",