Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions esp-hal-smartled/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 0.17.0

### Changed

- `esp-hal` version update: `v1.0.0-rc.0` -> `v1.0.0-rc.1`, see [migration guide](https://github.com/esp-rs/esp-hal/blob/main/esp-hal/MIGRATING-1.0.0-rc.0.md) for details.
- Replaced `esp-hal-embassy` with `esp-rtos`.
- Update `SmartLedsAdapter` and `SmartLedsAdapterAsync` generics according to the `esp-hal` version bump.

## 0.16.0

## 0.15.0

### Added
Expand Down
21 changes: 10 additions & 11 deletions esp-hal-smartled/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "esp-hal-smartled"
version = "0.16.0"
version = "0.17.0"
edition = "2024"
rust-version = "1.88"
description = "RMT peripheral adapter for smart LEDs"
Expand All @@ -14,20 +14,19 @@ targets = ["riscv32imac-unknown-none-elf"]
[dependencies]
defmt = { version = "1.0.1", optional = true }
document-features = "0.2.10"
esp-hal = { version = "1.0.0-rc.0", features = ["requires-unstable"] }
esp-hal = { version = "=1.0.0-rc.1", features = ["unstable"] }
esp-rtos = { version = "0.1.1", features = ["embassy"] }
rgb = "0.8.52"
smart-leds-trait = "0.3.1"

[dev-dependencies]
cfg-if = "1.0.0"
esp-backtrace = { version = "0.17.0", features = [
"exception-handler",
"panic-handler",
"println",
] }
esp-hal-embassy = "0.9.0"
esp-bootloader-esp-idf = "0.2"
embassy-executor = "0.7"
embassy-executor = "0.9"
embassy-time = "0.5"
esp-println = "0.15.0"
smart-leds = "0.4.0"
Expand All @@ -37,14 +36,14 @@ smart-leds = "0.4.0"
defmt = ["dep:defmt", "esp-hal/defmt"]
#! ### Chip Support Feature Flags
## Target the ESP32.
esp32 = ["esp-backtrace/esp32", "esp-hal/esp32", "esp-println/esp32", "esp-hal-embassy/esp32", "esp-bootloader-esp-idf/esp32"]
esp32 = ["esp-backtrace/esp32", "esp-hal/esp32", "esp-println/esp32", "esp-rtos/esp32", "esp-bootloader-esp-idf/esp32"]
## Target the ESP32-C3.
esp32c3 = ["esp-backtrace/esp32c3", "esp-hal/esp32c3", "esp-println/esp32c3", "esp-hal-embassy/esp32c3", "esp-bootloader-esp-idf/esp32c3"]
esp32c3 = ["esp-backtrace/esp32c3", "esp-hal/esp32c3", "esp-println/esp32c3", "esp-rtos/esp32c3", "esp-bootloader-esp-idf/esp32c3"]
## Target the ESP32-C6.
esp32c6 = ["esp-backtrace/esp32c6", "esp-hal/esp32c6", "esp-println/esp32c6", "esp-hal-embassy/esp32c6", "esp-bootloader-esp-idf/esp32c6"]
esp32c6 = ["esp-backtrace/esp32c6", "esp-hal/esp32c6", "esp-println/esp32c6", "esp-rtos/esp32c6", "esp-bootloader-esp-idf/esp32c6"]
## Target the ESP32-H2.
esp32h2 = ["esp-backtrace/esp32h2", "esp-hal/esp32h2", "esp-println/esp32h2", "esp-hal-embassy/esp32h2", "esp-bootloader-esp-idf/esp32h2"]
esp32h2 = ["esp-backtrace/esp32h2", "esp-hal/esp32h2", "esp-println/esp32h2", "esp-rtos/esp32h2", "esp-bootloader-esp-idf/esp32h2"]
## Target the ESP32-S2.
esp32s2 = ["esp-backtrace/esp32s2", "esp-hal/esp32s2", "esp-println/esp32s2", "esp-hal-embassy/esp32s2", "esp-bootloader-esp-idf/esp32s2"]
esp32s2 = ["esp-backtrace/esp32s2", "esp-hal/esp32s2", "esp-println/esp32s2", "esp-rtos/esp32s2", "esp-bootloader-esp-idf/esp32s2"]
## Target the ESP32-S3.
esp32s3 = ["esp-backtrace/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-hal-embassy/esp32s3", "esp-bootloader-esp-idf/esp32s3"]
esp32s3 = ["esp-backtrace/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-rtos/esp32s3", "esp-bootloader-esp-idf/esp32s3"]
2 changes: 1 addition & 1 deletion esp-hal-smartled/examples/hello_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn main() -> ! {

// Each devkit uses a unique GPIO for the RGB LED, so in order to support
// all chips we must unfortunately use `#[cfg]`s:
let mut led: SmartLedsAdapter<_, 25> = {
let mut led: SmartLedsAdapter<'_, 25> = {
cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
SmartLedsAdapter::new(rmt_channel, p.GPIO33, rmt_buffer)
Expand Down
14 changes: 10 additions & 4 deletions esp-hal-smartled/examples/hello_rgb_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ use smart_leds::{

esp_bootloader_esp_idf::esp_app_desc!();

#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) -> ! {
#[esp_rtos::main]
async fn main(_spawner: Spawner) {
// Initialize the HAL Peripherals
let p = esp_hal::init(Config::default());
let timg0 = TimerGroup::new(p.TIMG0);
esp_hal_embassy::init(timg0.timer0);

esp_rtos::start(
timg0.timer0,
#[cfg(target_arch = "riscv32")]
esp_hal::interrupt::software::SoftwareInterruptControl::new(p.SW_INTERRUPT)
.software_interrupt0,
);

// Configure RMT (Remote Control Transceiver) peripheral globally
// <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/rmt.html>
Expand All @@ -65,7 +71,7 @@ async fn main(_spawner: Spawner) -> ! {

// Each devkit uses a unique GPIO for the RGB LED, so in order to support
// all chips we must unfortunately use `#[cfg]`s:
let mut led: SmartLedsAdapterAsync<_, 25> = {
let mut led: SmartLedsAdapterAsync<'_, 25> = {
cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
SmartLedsAdapterAsync::new(rmt_channel, p.GPIO33, rmt_buffer)
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-smartled/examples/hello_rgbw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn main() -> ! {

// Each devkit uses a unique GPIO for the RGB LED, so in order to support
// all chips we must unfortunately use `#[cfg]`s:
let mut led: SmartLedsAdapter<_, 33, rgb::Rgba<u8>> = {
let mut led: SmartLedsAdapter<'_, 33, rgb::Rgba<u8>> = {
cfg_if::cfg_if! {
if #[cfg(feature = "esp32")] {
SmartLedsAdapter::new_with_color(rmt_channel, p.GPIO33, rmt_buffer)
Expand Down
72 changes: 24 additions & 48 deletions esp-hal-smartled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ use esp_hal::{
Async, Blocking,
clock::Clocks,
gpio::{Level, interconnect::PeripheralOutput},
rmt::{
Channel, Error as RmtError, PulseCode, RawChannelAccess, TxChannel, TxChannelAsync,
TxChannelConfig, TxChannelCreator, TxChannelInternal,
},
rmt::{Channel, Error as RmtError, PulseCode, Tx, TxChannelConfig, TxChannelCreator},
};
use rgb::Grb;
use smart_leds_trait::{SmartLedsWrite, SmartLedsWriteAsync};
Expand Down Expand Up @@ -81,20 +78,23 @@ impl From<RmtError> for LedAdapterError {
}
}

// todo Should probably cascade the use of the new `PulseCode` type.
fn led_pulses_for_clock(src_clock: u32) -> (u32, u32) {
(
PulseCode::new(
Level::High,
((SK68XX_T0H_NS * src_clock) / 1000) as u16,
Level::Low,
((SK68XX_T0L_NS * src_clock) / 1000) as u16,
),
)
.into(),
PulseCode::new(
Level::High,
((SK68XX_T1H_NS * src_clock) / 1000) as u16,
Level::Low,
((SK68XX_T1L_NS * src_clock) / 1000) as u16,
),
)
.into(),
)
}

Expand Down Expand Up @@ -185,44 +185,33 @@ macro_rules! smartLedBuffer {

/// Adapter taking an RMT channel and a specific pin and providing RGB LED
/// interaction functionality using the `smart-leds` crate
pub struct SmartLedsAdapter<TX, const BUFFER_SIZE: usize, Color = Grb<u8>>
where
TX: RawChannelAccess + TxChannelInternal + 'static,
{
channel: Option<Channel<Blocking, TX>>,
pub struct SmartLedsAdapter<'d, const BUFFER_SIZE: usize, Color = Grb<u8>> {
channel: Option<Channel<'d, Blocking, Tx>>,
rmt_buffer: [u32; BUFFER_SIZE],
pulses: (u32, u32),
color: PhantomData<Color>,
}

impl<'d, TX, const BUFFER_SIZE: usize> SmartLedsAdapter<TX, BUFFER_SIZE, Grb<u8>>
where
TX: RawChannelAccess + TxChannelInternal + 'static,
{
impl<'d, const BUFFER_SIZE: usize> SmartLedsAdapter<'d, BUFFER_SIZE, Grb<u8>> {
/// Create a new adapter object that drives the pin using the RMT channel.
pub fn new<C, O>(channel: C, pin: O, rmt_buffer: [u32; BUFFER_SIZE]) -> Self
where
O: PeripheralOutput<'d>,
C: TxChannelCreator<'d, Blocking, Raw = TX>,
C: TxChannelCreator<'d, Blocking>,
{
Self::new_with_color(channel, pin, rmt_buffer)
}
}

impl<'d, TX, const BUFFER_SIZE: usize, Color> SmartLedsAdapter<TX, BUFFER_SIZE, Color>
impl<'d, const BUFFER_SIZE: usize, Color> SmartLedsAdapter<'d, BUFFER_SIZE, Color>
where
TX: RawChannelAccess + TxChannelInternal + 'static,
Color: rgb::ComponentSlice<u8>,
{
/// Create a new adapter object that drives the pin using the RMT channel.
pub fn new_with_color<C, O>(
channel: C,
pin: O,
rmt_buffer: [u32; BUFFER_SIZE],
) -> SmartLedsAdapter<TX, BUFFER_SIZE, Color>
pub fn new_with_color<C, O>(channel: C, pin: O, rmt_buffer: [u32; BUFFER_SIZE]) -> Self
where
O: PeripheralOutput<'d>,
C: TxChannelCreator<'d, Blocking, Raw = TX>,
C: TxChannelCreator<'d, Blocking>,
{
let channel = channel.configure_tx(pin, led_config()).unwrap();

Expand All @@ -238,10 +227,9 @@ where
}
}

impl<TX, const BUFFER_SIZE: usize, Color> SmartLedsWrite
for SmartLedsAdapter<TX, BUFFER_SIZE, Color>
impl<'d, const BUFFER_SIZE: usize, Color> SmartLedsWrite
for SmartLedsAdapter<'d, BUFFER_SIZE, Color>
where
TX: RawChannelAccess + TxChannelInternal + 'static,
Color: rgb::ComponentSlice<u8>,
{
type Error = LedAdapterError;
Expand Down Expand Up @@ -311,44 +299,33 @@ pub const fn buffer_size_async_rgbw(num_leds: usize) -> usize {

/// Adapter taking an RMT channel and a specific pin and providing RGB LED
/// interaction functionality.
pub struct SmartLedsAdapterAsync<Tx, const BUFFER_SIZE: usize, Color = Grb<u8>>
where
Tx: RawChannelAccess + TxChannelInternal + 'static,
{
channel: Channel<Async, Tx>,
pub struct SmartLedsAdapterAsync<'d, const BUFFER_SIZE: usize, Color = Grb<u8>> {
channel: Channel<'d, Async, Tx>,
rmt_buffer: [u32; BUFFER_SIZE],
pulses: (u32, u32),
color: PhantomData<Color>,
}

impl<'d, Tx, const BUFFER_SIZE: usize> SmartLedsAdapterAsync<Tx, BUFFER_SIZE, Grb<u8>>
where
Tx: RawChannelAccess + TxChannelInternal + 'static,
{
impl<'d, const BUFFER_SIZE: usize> SmartLedsAdapterAsync<'d, BUFFER_SIZE, Grb<u8>> {
/// Create a new adapter object that drives the pin using the RMT channel.
pub fn new<C, O>(channel: C, pin: O, rmt_buffer: [u32; BUFFER_SIZE]) -> Self
where
O: PeripheralOutput<'d>,
C: TxChannelCreator<'d, Async, Raw = Tx>,
C: TxChannelCreator<'d, Async>,
{
Self::new_with_color(channel, pin, rmt_buffer)
}
}

impl<'d, Tx, const BUFFER_SIZE: usize, Color> SmartLedsAdapterAsync<Tx, BUFFER_SIZE, Color>
impl<'d, const BUFFER_SIZE: usize, Color> SmartLedsAdapterAsync<'d, BUFFER_SIZE, Color>
where
Tx: RawChannelAccess + TxChannelInternal + 'static,
Color: rgb::ComponentSlice<u8>,
{
/// Create a new adapter object that drives the pin using the RMT channel.
pub fn new_with_color<C, O>(
channel: C,
pin: O,
rmt_buffer: [u32; BUFFER_SIZE],
) -> SmartLedsAdapterAsync<Tx, BUFFER_SIZE, Color>
pub fn new_with_color<C, O>(channel: C, pin: O, rmt_buffer: [u32; BUFFER_SIZE]) -> Self
where
O: PeripheralOutput<'d>,
C: TxChannelCreator<'d, Async, Raw = Tx>,
C: TxChannelCreator<'d, Async>,
{
let channel = channel.configure_tx(pin, led_config()).unwrap();

Expand Down Expand Up @@ -393,10 +370,9 @@ where
}
}

impl<Tx, const BUFFER_SIZE: usize, Color> SmartLedsWriteAsync
for SmartLedsAdapterAsync<Tx, BUFFER_SIZE, Color>
impl<'d, const BUFFER_SIZE: usize, Color> SmartLedsWriteAsync
for SmartLedsAdapterAsync<'d, BUFFER_SIZE, Color>
where
Tx: RawChannelAccess + TxChannelInternal + 'static,
Color: rgb::ComponentSlice<u8>,
{
type Error = LedAdapterError;
Expand Down
Loading