8 releases (4 breaking)
new 0.5.0 | Apr 10, 2025 |
---|---|
0.4.0 | Jan 14, 2024 |
0.3.2 | Nov 20, 2019 |
0.3.1 | Sep 20, 2019 |
0.1.0 | Mar 5, 2019 |
#678 in Embedded development
1,577 downloads per month
Used in 4 crates
(3 directly)
34KB
638 lines
APA102 driver for embedded-hal spi traits
For usage with the smart-leds crate.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Todo
- Implement a
WriteIter
based version
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
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:
- Handle all details of the protocol yourself with the [Apa102Pixel] struct, 8 bit RGB + 5 bits brightness
- Simply provide [RGB8] values, hardcoding maximum brightness. This may be uncomfortably bright.
- Use FastLED's pseudo-13-bit gamma correction algorithm to convert [RGB8] + 8 bit brightness to 8 bit RGB + 5 bit brightness.
#
#
#
#
#
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
defmt
: impl defmt::Format for [Apa102Pixel] (off by default)
Dependencies
~335–490KB