configs/stm32f103-minimum: Add board support for APA102 driver

This commit is contained in:
Alan Carvalho de Assis 2017-09-18 16:55:12 -06:00 committed by Gregory Nutt
parent dca62a68a8
commit 41c271d032
4 changed files with 129 additions and 0 deletions

View file

@ -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

View file

@ -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 <acassis@gmail.com>
*
* 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 <nuttx/config.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/spi/spi.h>
#include <nuttx/leds/apa102.h>
#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 */

View file

@ -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. */

View file

@ -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
*