diff --git a/boards/arm/stm32/common/include/stm32_ws2812.h b/boards/arm/stm32/common/include/stm32_ws2812.h new file mode 100644 index 00000000000..4a002dba8f2 --- /dev/null +++ b/boards/arm/stm32/common/include/stm32_ws2812.h @@ -0,0 +1,85 @@ +/**************************************************************************** + * boards/arm/stm32/common/include/stm32_ws2812.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __STM32_WS2812_H +#define __STM32_WS2812_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_ws2812_initialize + * + * Description: + * Initialize and register the WS2812 LED driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/leddrvN + * spino - SPI port number + * nleds - number of LEDs + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_ws2812_initialize(int devno, int spino, uint16_t nleds); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif // __STM32_WS2812_H diff --git a/boards/arm/stm32/common/src/Make.defs b/boards/arm/stm32/common/src/Make.defs index 4ff9bb9b411..531757f4908 100644 --- a/boards/arm/stm32/common/src/Make.defs +++ b/boards/arm/stm32/common/src/Make.defs @@ -26,6 +26,10 @@ ifeq ($(CONFIG_LEDS_APA102),y) CSRCS += stm32_apa102.c endif +ifeq ($(CONFIG_WS2812),y) + CSRCS += stm32_ws2812.c +endif + ifeq ($(CONFIG_SENSORS_MAX6675),y) CSRCS += stm32_max6675.c endif diff --git a/boards/arm/stm32/common/src/stm32_ws2812.c b/boards/arm/stm32/common/src/stm32_ws2812.c new file mode 100644 index 00000000000..fcd34144f77 --- /dev/null +++ b/boards/arm/stm32/common/src/stm32_ws2812.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * boards/arm/stm32/common/src/stm32_ws2812.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include "stm32.h" +#include "stm32_spi.h" + +#ifdef CONFIG_WS2812 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_ws2812_initialize + * + * Description: + * Initialize and register the WS2812 LED driver. + * + * Input Parameters: + * devno - The device number, used to build the device path as /dev/leddrvN + * spino - SPI port number + * nleds - number of LEDs + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_ws2812_initialize(int devno, int spino, uint16_t nleds) +{ + FAR struct spi_dev_s *spi; + char devpath[13]; + int ret; + + spi = stm32_spibus_initialize(spino); + if (spi == NULL) + { + return -ENODEV; + } + + /* Register the WS2812 driver at the specified location. */ + + snprintf(devpath, 13, "/dev/leddrv%d", devno); + ret = ws2812_leds_register(devpath, spi, nleds); + if (ret < 0) + { + lederr("ERROR: ws2812_leds_register(%s) failed: %d\n", + devpath, ret); + return ret; + } + + return OK; +} + +#endif diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c index 21f8a0578f7..c0b39b3478c 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c +++ b/boards/arm/stm32/stm32f103-minimum/src/stm32_bringup.c @@ -93,6 +93,10 @@ #include "stm32_apa102.h" #endif +#ifdef CONFIG_WS2812 +#include "stm32_ws2812.h" +#endif + #ifdef CONFIG_SENSORS_MAX6675 #include "stm32_max6675.h" #endif @@ -323,6 +327,16 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_WS2812 + /* Configure and initialize the WS2812 LEDs. */ + + ret = board_ws2812_initialize(0, WS2812_SPI, WS2812_NLEDS); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: board_ws2812_initialize() failed: %d\n", ret); + } +#endif + #ifdef CONFIG_LM75_I2C /* Configure and initialize the LM75 sensor */ diff --git a/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h b/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h index 171a2e077fb..9e352cfaab9 100644 --- a/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h +++ b/boards/arm/stm32/stm32f103-minimum/src/stm32f103_minimum.h @@ -197,6 +197,11 @@ #define GPIO_INT1 (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_PORTA|GPIO_PIN2) +/* WS2812 LEDs */ + +#define WS2812_NLEDS 2 +#define WS2812_SPI 1 + /**************************************************************************** * Public Function Prototypes ****************************************************************************/