mirror of
https://github.com/apache/nuttx.git
synced 2026-09-26 18:16:27 +08:00
Add driver for APA102 LED controller. These LEDs are used on LED Strips and are controlled over SPI.
This commit is contained in:
committed by
Gregory Nutt
parent
780435d9f1
commit
dca62a68a8
@@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/leds/apa102.h
|
||||
*
|
||||
* Copyright (C) 2017 Alan Carvalho de Assis.
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_LEDS_APA102_H
|
||||
#define __INCLUDE_NUTTX_LEDS_APA102_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/* Configuration
|
||||
* CONFIG_SPI - Enables support for SPI drivers
|
||||
* CONFIG_LEDS_APA102 - Enables support for the APA102 driver
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_SPI) && defined(CONFIG_LEDS_APA102)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* SPI definitions */
|
||||
|
||||
#define APA102_SPI_MAXFREQUENCY (100000) /* Default 4MHz */
|
||||
|
||||
/* APA102 register addresses */
|
||||
|
||||
#define APA102_START_FRAME 0x00000000
|
||||
#define APA102_HEADER_FRAME 0xe1
|
||||
#define APA102_END_FRAME 0x00
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct apa102_ledstrip_s
|
||||
{
|
||||
uint8_t bright;
|
||||
uint8_t blue;
|
||||
uint8_t green;
|
||||
uint8_t red;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: apa102_register
|
||||
*
|
||||
* Description:
|
||||
* Register the APA102 device as 'devpath'
|
||||
*
|
||||
* Input Parameters:
|
||||
* devpath - The full path to the driver to register. E.g., "/dev/leddrv0".
|
||||
* spi - An instance of the SPI interface to use to communicate
|
||||
* with the APA102.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int apa102_register(FAR const char *devpath, FAR struct spi_dev_s *spi);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SPI && CONFIG_LEDS_APA102 */
|
||||
#endif /* __INCLUDE_NUTTX_LEDS_APA102_H */
|
||||
Reference in New Issue
Block a user