Crate esp_hal_smartled

Source
Expand description

This adapter allows for the use of an RMT output channel to easily interact with RGB LEDs and use the convenience functions of the smart-leds crate.

This is a simple implementation where every LED is adressed in an individual RMT operation. This is working perfectly fine in blocking mode, but in case this is used in combination with interrupts that might disturb the sequential sending, an alternative implementation (addressing the LEDs in a sequence in a single RMT send operation) might be required!

§Example

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{rmt::Rmt, time::Rate, Config};
use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter};
use smart_leds::{brightness, colors::RED, SmartLedsWrite as _};

#[esp_hal::main]
fn main() -> ! {
    let p = esp_hal::init(Config::default());
    let mut led = {
        let frequency = Rate::from_mhz(80);
        let rmt = Rmt::new(p.RMT, frequency).expect("Failed to initialize RMT0");
        SmartLedsAdapter::new(rmt.channel0, p.GPIO2, smartLedBuffer!(1))
    };
    let level = 10;
    led.write(brightness([RED].into_iter(), level)).unwrap();
    loop {} // loop forever
}

§Feature Flags

  • defmt — Implement defmt::Format on certain types.

§Chip Support Feature Flags

  • esp32 — Target the ESP32.
  • esp32c3 — Target the ESP32-C3.
  • esp32c6 — Target the ESP32-C6.
  • esp32h2 — Target the ESP32-H2.
  • esp32s2 — Target the ESP32-S2.
  • esp32s3 — Target the ESP32-S3.

Macros§

smartLedBufferDeprecated
Deprecated alias for smart_led_buffer macro.
smart_led_buffer
Macro to allocate a buffer sized for a specific number of LEDs to be addressed.

Structs§

SmartLedsAdapter
Adapter taking an RMT channel and a specific pin and providing RGB LED interaction functionality using the smart-leds crate
SmartLedsAdapterAsync
Adapter taking an RMT channel and a specific pin and providing RGB LED interaction functionality.

Enums§

LedAdapterError
All types of errors that can happen during the conversion and transmission of LED commands

Functions§

buffer_size
Function to calculate the required RMT buffer size for a given number of LEDs when using the blocking API.
buffer_size_async
Support for asynchronous and non-blocking use of the RMT peripheral to drive smart LEDs.