From 41c271d03274d7ed6267008ae474d8af3e33e3f6 Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Mon, 18 Sep 2017 16:55:12 -0600 Subject: [PATCH] configs/stm32f103-minimum: Add board support for APA102 driver --- configs/stm32f103-minimum/src/Makefile | 4 + configs/stm32f103-minimum/src/stm32_apa102.c | 103 ++++++++++++++++++ configs/stm32f103-minimum/src/stm32_bringup.c | 10 ++ .../stm32f103-minimum/src/stm32f103_minimum.h | 12 ++ 4 files changed, 129 insertions(+) create mode 100644 configs/stm32f103-minimum/src/stm32_apa102.c diff --git a/configs/stm32f103-minimum/src/Makefile b/configs/stm32f103-minimum/src/Makefile index 58acfc880f..e23d943f87 100644 --- a/configs/stm32f103-minimum/src/Makefile +++ b/configs/stm32f103-minimum/src/Makefile @@ -61,6 +61,10 @@ ifeq ($(CONFIG_PWM),y) CSRCS += stm32_pwm.c endif +ifeq ($(CONFIG_LEDS_APA102),y) + CSRCS += stm32_apa102.c +endif + ifeq ($(CONFIG_RGBLED),y) CSRCS += stm32_rgbled.c endif diff --git a/configs/stm32f103-minimum/src/stm32_apa102.c b/configs/stm32f103-minimum/src/stm32_apa102.c new file mode 100644 index 0000000000..32717b212b --- /dev/null +++ b/configs/stm32f103-minimum/src/stm32_apa102.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * configs/stm32f103-minium/src/stm32_apa102.c + * + * Copyright (C) 2017 Alan Carvalho de Assis. All rights reserved. + * Author: Alan Carvalho de Assis + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +#include "stm32.h" +#include "stm32_spi.h" +#include "stm32f103_minimum.h" + +#if defined(CONFIG_SPI) && defined(CONFIG_STM32_SPI1) && \ + defined(CONFIG_LEDS_APA102) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define APA102_SPI_PORTNO 1 /* On SPI1 */ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: stm32_apa102init + * + * Description: + * Initialize and register the APA102 LED Strip driver. + * + * Input parameters: + * devpath - The full path to the driver to register. E.g., "/dev/leddrv0" + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ************************************************************************************/ + +int stm32_apa102init(FAR const char *devpath) +{ + FAR struct spi_dev_s *spi; + int ret; + + spi = stm32_spibus_initialize(APA102_SPI_PORTNO); + if (spi == NULL) + { + return -ENODEV; + } + + /* Register the APA102 Driver at the specified location. */ + + ret = apa102_register(devpath, spi); + if (ret < 0) + { + lederr("ERROR: apa102_register(%s) failed: %d\n", + devpath, ret); + return ret; + } + + return OK; +} + +#endif /* CONFIG_SPI && CONFIG_CAN_APA102 */ diff --git a/configs/stm32f103-minimum/src/stm32_bringup.c b/configs/stm32f103-minimum/src/stm32_bringup.c index bd5515cb81..293c55e482 100644 --- a/configs/stm32f103-minimum/src/stm32_bringup.c +++ b/configs/stm32f103-minimum/src/stm32_bringup.c @@ -194,6 +194,16 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_LEDS_APA102 + /* Configure and initialize the APA102 LED Strip. */ + + ret = stm32_apa102init("/dev/leddrv0"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_apa102init() failed: %d\n", ret); + } +#endif + #ifdef CONFIG_RGBLED /* Configure and initialize the RGB LED. */ diff --git a/configs/stm32f103-minimum/src/stm32f103_minimum.h b/configs/stm32f103-minimum/src/stm32f103_minimum.h index f346b87c53..88a212972b 100644 --- a/configs/stm32f103-minimum/src/stm32f103_minimum.h +++ b/configs/stm32f103-minimum/src/stm32f103_minimum.h @@ -249,6 +249,18 @@ int stm32_qencoder_initialize(FAR const char *devpath, int timer); int stm32_rgbled_setup(void); #endif +/************************************************************************************ + * Name: stm32_apa102init + * + * Description: + * Initialize and register the APA102 LED Strip driver + * + ************************************************************************************/ + +#ifdef CONFIG_LEDS_APA102 +int stm32_apa102init(FAR const char *devpath); +#endif + /************************************************************************************ * Name: stm32_mcp2515initialize *