apa102 1.0
apa102 driver library
Loading...
Searching...
No Matches
apa102

Version: 1.0 Release Build License GPLv3

APA102 RGB LED Driver

Ask DeepWiki

This hardware abstracted driver can be used to interact with an APA102 or any compatible type over TWI/I2C. The hardware layer is fully abstract an can be switched between different plattforms. The SPI library has to impelement the spi.h-header used in this repository.

File Structure

File Structure

drivers/
└── led/
└── apa102/
├── apa102.c
└── apa102.h
hal/
├── common/
| ├── enums/
| | └── SPI_enums.h
| └── macros/
| └── PORT_macros.h
└── avr0/
└── spi/
├── spi.c
└── spi.h
core_types/
└── gfx/
└── color.h
utils/
└──macros/
└── stringify.h

The plattform avr0 can completely be exchanged with any other hardware abstraction library.

Downloads

The library can be downloaded (zip or tar), cloned or used as submodule in a project.

Type File Description
Library zip / tar APA102 RGB LED library including all required libraries (including hal-avr0-spi).

Using with git clone

mkdir -p ./core_types/
git clone https://github.com/0x007E/core_types-gfx.git ./core_types
mv ./core_types/core_types-gfx ./core_types/gfx
mkdir -p ./drivers/led/
git clone https://github.com/0x007E/drivers-led-apa102.git ./drivers/led
mv ./drivers/led/drivers-led-apa102 ./drivers/led/apa102
mkdir -p ./hal/
git clone https://github.com/0x007E/hal-common.git ./hal
mv ./hal/hal-common ./hal/common
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Hardware abstraction layer of SPI (Must fit the used plattform)
mkdir -p ./hal/avr0/
git clone https://github.com/0x007E/hal-avr0-spi.git ./hal/avr0
mv ./hal/avr0/hal-avr0-spi ./hal/avr0/spi
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
mkdir -p ./utils/
git clone https://github.com/0x007E/utils-macros.git ./utils
mv ./utils/utils-macros ./utils/macros

Using as git submodule

git submodule add https://github.com/0x007E/core_types-gfx.git core_types/gfx
git submodule add https://github.com/0x007E/drivers-led-apa102.git drivers/led/apa102
git submodule add https://github.com/0x007E/hal-common.git hal/common
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Hardware abstraction layer of SPI (Must fit the used plattform)
git submodule add https://github.com/0x007E/hal-avr0-spi.git hal/avr0/spi
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
git submodule add https://github.com/0x007E/utils-macros.git utils/macros

Programming

int main(void)
{
GFX_RGBA_Color color = {
0x0F,
0xF0,
0xFF,
}
// To change the color independently on every led
for (unsigned char i=0; i < APA102_NUMBER_OF_LEDS; i++)
{
apa102_led(&color);
color.red++;
color.blue--;
}
// Set the same color on all leds
apa102_leds(&color);
// Disable every second led
for (unsigned char i=0; i < APA102_NUMBER_OF_LEDS; i++)
{
if(!((i + 1)%2))
{
apa102_led(&color);
continue;
}
}
// Disable all leds
}
@ SPI_Rising
Definition SPI_enums.h:54
@ SPI_MSB
Definition SPI_enums.h:33
void apa102_leds_off(void)
Disable all LEDs by sending sleep commands (if supported) and turning off the SPI peripheral.
Definition apa102.c:154
void apa102_init(void)
Initialize the LED control interface and hardware.
Definition apa102.c:42
void apa102_led_off(void)
Send an LED data frame to a single LED to turn it off.
Definition apa102.c:135
void apa102_leds(const GFX_RGBA_Color *color)
Send an LED data frame to all LEDs with specified color and intensity.
Definition apa102.c:108
void apa102_led(const GFX_RGBA_Color *color)
Send an LED data frame with specified color and intensity.
Definition apa102.c:87
APA102 control interface for AVR microcontrollers using SPI.
#define APA102_SOF()
Sends the Start-of-Frame (SOF) signal to the LED strip.
Definition apa102.h:183
#define APA102_MAX_INTENSITY
The maximum intensity value for LED brightness.
Definition apa102.h:113
#define APA102_EOF()
Sends the End-of-Frame (EOF) signal to the LED strip.
Definition apa102.h:192
#define APA102_NUMBER_OF_LEDS
Defines the total number of LEDs controlled by the driver.
Definition apa102.h:45
struct GFX_RGBA_Color_t GFX_RGBA_Color
Definition color.h:59
SPI_Status spi_init(SPI_Direction direction, SPI_Polarity setup, SPI_Phase sample)
Initialize the SPI hardware interface in master mode with specified configuration.
Definition spi.c:48
Header file with declarations and macros for hardware SPI.
unsigned char red
Definition color.h:50
unsigned char blue
Definition color.h:52

Additional Information

Type Link Description
APA102 pdf RGB Full Color LED
T3A33BRG pdf Harvatek Surface Mount PLCC IC+RGB LEDs Data Sheet

R. GAECHTER