Crate apa102_spi

Source
Expand description

Send data to APA102 LEDs (also known as DotStar LEDs) via SPI. This crate is also compatible with SK9822 LEDs which share the same protocol as APA102 LEDs. Both blocking and asynchronous implementations are provided, which require a HAL crate for your microcontroller with an implementation of the embedded_hal::spi::SpiBus or embedded_hal_async::spi::SpiBus trait.

There are several ways to send pixel data:

use apa102_spi::{u5, Apa102Pixel, Apa102Writer, PixelOrder, SmartLedsWrite, RGB8};

// You only need to specify MOSI and clock pins for your SPI peripheral.
// APA102 LEDs do not send data over MISO and do not have a CS pin.
let spi = get_spi_peripheral_from_your_hal;
let mut led_strip = Apa102Writer::new(spi, 1, PixelOrder::default());

// Specify pixel values as 8 bit RGB + 5 bit brightness
let led_buffer = [Apa102Pixel { red: 255, green: 0, blue: 0, brightness: u5::new(1) }];
led_strip.write(led_buffer);

// Specify pixel values with 8 bit RGB values
let led_buffer_rgb = [RGB8 { r: 255, g: 0, b: 0 }];
// Brightness is set to maximum value (31) in `impl From<RGB8> for Apa102Pixel`
led_strip.write(led_buffer_rgb);

// Convert RGB8 + 8 bit brightness into Apa102Pixels
// using FastLED's pseudo-13-bit gamma correction algorithm.
led_strip.write(led_buffer_rgb.map(
  |p| Apa102Pixel::from_rgb8_with_brightness(p, 255, None)));

§Cargo features

Structs§

Apa102Pixel
A single APA102 pixel: 8 bits each for red, green, and blue, plus 5 bits for brightness
Apa102Writer
A writer for APA102 LEDs
Apa102WriterAsync
A writer for APA102 LEDs
RGB
A Red + Green + Blue pixel.
u5
The 5-bit unsigned integer type.

Enums§

PixelOrder
What order to transmit pixel colors. The standard order is PixelOrder::BGR, however in practice, some LEDs swap the order of the colors in the protocol.

Constants§

MODE
SPI mode that is needed for this crate

Traits§

SmartLedsWrite
A trait that Smart Led Drivers implement
SmartLedsWriteAsync
An async trait that Smart Led Drivers implement

Type Aliases§

RGB8
8-bit RGB
RGB16
16-bit RGB in machine’s native endian