Skip to content

Commit f32df6f

Browse files
committed
update esp-hal-smartled for esp-hal 1.0.0-rc.1
This replaces esp-hal-embassy with esp-rtos and updates deps. It makes backwards-incompatible changes for updates to the esp-hal rmt api: - https://docs.rs/esp-hal/1.0.0-rc.0/esp_hal/rmt/index.html - https://docs.rs/esp-hal/1.0.0-rc.1/esp_hal/rmt/index.html
1 parent 11f8fbd commit f32df6f

File tree

5 files changed

+75
-84
lines changed

5 files changed

+75
-84
lines changed

esp-hal-smartled/Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,37 @@ targets = ["riscv32imac-unknown-none-elf"]
1414
[dependencies]
1515
defmt = { version = "1.0.1", optional = true }
1616
document-features = "0.2.10"
17-
esp-hal = { version = "1.0.0-rc.0", features = ["requires-unstable"] }
17+
esp-hal = { version = "1.0.0-rc.1", features = ["unstable"] }
1818
rgb = "0.8.52"
1919
smart-leds-trait = "0.3.1"
2020

2121
[dev-dependencies]
2222
cfg-if = "1.0.0"
23-
esp-backtrace = { version = "0.17.0", features = [
24-
"exception-handler",
23+
esp-backtrace = { version = "0.18.0", features = [
2524
"panic-handler",
2625
"println",
2726
] }
28-
esp-hal-embassy = "0.9.0"
29-
esp-bootloader-esp-idf = "0.2"
30-
embassy-executor = "0.7"
31-
embassy-time = "0.5"
32-
esp-println = "0.15.0"
27+
# Use esp-rtos for embassy support instead of esp-hal-embassy
28+
esp-rtos = { version = "0.1.1", features = ["embassy"] }
29+
esp-bootloader-esp-idf = "0.3.0"
30+
embassy-executor = { version = "0.9.0" }
31+
embassy-time = { version = "0.5.0" }
32+
esp-println = "0.16.0"
3333
smart-leds = "0.4.0"
3434

3535
[features]
3636
## Implement `defmt::Format` on certain types.
3737
defmt = ["dep:defmt", "esp-hal/defmt"]
3838
#! ### Chip Support Feature Flags
3939
## Target the ESP32.
40-
esp32 = ["esp-backtrace/esp32", "esp-hal/esp32", "esp-println/esp32", "esp-hal-embassy/esp32", "esp-bootloader-esp-idf/esp32"]
40+
esp32 = ["esp-backtrace/esp32", "esp-hal/esp32", "esp-println/esp32", "esp-bootloader-esp-idf/esp32", "esp-rtos/esp32"]
4141
## Target the ESP32-C3.
42-
esp32c3 = ["esp-backtrace/esp32c3", "esp-hal/esp32c3", "esp-println/esp32c3", "esp-hal-embassy/esp32c3", "esp-bootloader-esp-idf/esp32c3"]
42+
esp32c3 = ["esp-backtrace/esp32c3", "esp-hal/esp32c3", "esp-println/esp32c3", "esp-bootloader-esp-idf/esp32c3", "esp-rtos/esp32c3"]
4343
## Target the ESP32-C6.
44-
esp32c6 = ["esp-backtrace/esp32c6", "esp-hal/esp32c6", "esp-println/esp32c6", "esp-hal-embassy/esp32c6", "esp-bootloader-esp-idf/esp32c6"]
44+
esp32c6 = ["esp-backtrace/esp32c6", "esp-hal/esp32c6", "esp-println/esp32c6", "esp-bootloader-esp-idf/esp32c6", "esp-rtos/esp32c6"]
4545
## Target the ESP32-H2.
46-
esp32h2 = ["esp-backtrace/esp32h2", "esp-hal/esp32h2", "esp-println/esp32h2", "esp-hal-embassy/esp32h2", "esp-bootloader-esp-idf/esp32h2"]
46+
esp32h2 = ["esp-backtrace/esp32h2", "esp-hal/esp32h2", "esp-println/esp32h2", "esp-bootloader-esp-idf/esp32h2", "esp-rtos/esp32h2"]
4747
## Target the ESP32-S2.
48-
esp32s2 = ["esp-backtrace/esp32s2", "esp-hal/esp32s2", "esp-println/esp32s2", "esp-hal-embassy/esp32s2", "esp-bootloader-esp-idf/esp32s2"]
48+
esp32s2 = ["esp-backtrace/esp32s2", "esp-hal/esp32s2", "esp-println/esp32s2", "esp-bootloader-esp-idf/esp32s2", "esp-rtos/esp32s2"]
4949
## Target the ESP32-S3.
50-
esp32s3 = ["esp-backtrace/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-hal-embassy/esp32s3", "esp-bootloader-esp-idf/esp32s3"]
50+
esp32s3 = ["esp-backtrace/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3", "esp-bootloader-esp-idf/esp32s3", "esp-rtos/esp32s3"]

esp-hal-smartled/examples/hello_rgb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn main() -> ! {
6565

6666
// Each devkit uses a unique GPIO for the RGB LED, so in order to support
6767
// all chips we must unfortunately use `#[cfg]`s:
68-
let mut led: SmartLedsAdapter<_, 25> = {
68+
let mut led = {
6969
cfg_if::cfg_if! {
7070
if #[cfg(feature = "esp32")] {
7171
SmartLedsAdapter::new(rmt_channel, p.GPIO33, rmt_buffer)

esp-hal-smartled/examples/hello_rgb_async.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,22 @@ use smart_leds::{
3434

3535
esp_bootloader_esp_idf::esp_app_desc!();
3636

37-
#[esp_hal_embassy::main]
37+
#[esp_rtos::main]
3838
async fn main(_spawner: Spawner) -> ! {
3939
// Initialize the HAL Peripherals
4040
let p = esp_hal::init(Config::default());
41-
let timg0 = TimerGroup::new(p.TIMG0);
42-
esp_hal_embassy::init(timg0.timer0);
41+
#[cfg(target_arch = "riscv32")]
42+
{
43+
let timg0 = TimerGroup::new(p.TIMG0);
44+
let sw_interrupt =
45+
esp_hal::interrupt::software::SoftwareInterruptControl::new(p.SW_INTERRUPT);
46+
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
47+
}
48+
#[cfg(target_arch = "xtensa")]
49+
{
50+
let timg0 = TimerGroup::new(p.TIMG0);
51+
esp_rtos::start(timg0.timer0);
52+
}
4353

4454
// Configure RMT (Remote Control Transceiver) peripheral globally
4555
// <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/rmt.html>
@@ -61,11 +71,11 @@ async fn main(_spawner: Spawner) -> ! {
6171
// We use one of the RMT channels to instantiate a `SmartLedsAdapterAsync` which can
6272
// be used directly with all `smart_led` implementations
6373
let rmt_channel = rmt.channel0;
64-
let rmt_buffer = [0_u32; buffer_size_async(1)];
74+
let rmt_buffer = [esp_hal::rmt::PulseCode::default(); buffer_size_async(1)];
6575

6676
// Each devkit uses a unique GPIO for the RGB LED, so in order to support
6777
// all chips we must unfortunately use `#[cfg]`s:
68-
let mut led: SmartLedsAdapterAsync<_, 25> = {
78+
let mut led = {
6979
cfg_if::cfg_if! {
7080
if #[cfg(feature = "esp32")] {
7181
SmartLedsAdapterAsync::new(rmt_channel, p.GPIO33, rmt_buffer)

esp-hal-smartled/examples/hello_rgbw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn main() -> ! {
6363

6464
// Each devkit uses a unique GPIO for the RGB LED, so in order to support
6565
// all chips we must unfortunately use `#[cfg]`s:
66-
let mut led: SmartLedsAdapter<_, 33, rgb::Rgba<u8>> = {
66+
let mut led: SmartLedsAdapter<'_, { esp_hal_smartled::buffer_size_rgbw(1) }, rgb::Rgba<u8>> = {
6767
cfg_if::cfg_if! {
6868
if #[cfg(feature = "esp32")] {
6969
SmartLedsAdapter::new_with_color(rmt_channel, p.GPIO33, rmt_buffer)

esp-hal-smartled/src/lib.rs

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ use esp_hal::{
4545
Async, Blocking,
4646
clock::Clocks,
4747
gpio::{Level, interconnect::PeripheralOutput},
48-
rmt::{
49-
Channel, Error as RmtError, PulseCode, RawChannelAccess, TxChannel, TxChannelAsync,
50-
TxChannelConfig, TxChannelCreator, TxChannelInternal,
51-
},
48+
rmt::{Channel, Error as RmtError, PulseCode, Tx, TxChannelConfig, TxChannelCreator},
5249
};
5350
use rgb::Grb;
5451
use smart_leds_trait::{SmartLedsWrite, SmartLedsWriteAsync};
@@ -81,7 +78,7 @@ impl From<RmtError> for LedAdapterError {
8178
}
8279
}
8380

84-
fn led_pulses_for_clock(src_clock: u32) -> (u32, u32) {
81+
fn led_pulses_for_clock(src_clock: u32) -> (PulseCode, PulseCode) {
8582
(
8683
PulseCode::new(
8784
Level::High,
@@ -108,8 +105,8 @@ fn led_config() -> TxChannelConfig {
108105

109106
fn convert_to_pulses(
110107
value: &[u8],
111-
mut_iter: &mut IterMut<u32>,
112-
pulses: (u32, u32),
108+
mut_iter: &mut IterMut<PulseCode>,
109+
pulses: (PulseCode, PulseCode),
113110
) -> Result<(), LedAdapterError> {
114111
for v in value {
115112
convert_rgb_channel_to_pulses(*v, mut_iter, pulses)?;
@@ -119,8 +116,8 @@ fn convert_to_pulses(
119116

120117
fn convert_rgb_channel_to_pulses(
121118
channel_value: u8,
122-
mut_iter: &mut IterMut<u32>,
123-
pulses: (u32, u32),
119+
mut_iter: &mut IterMut<PulseCode>,
120+
pulses: (PulseCode, PulseCode),
124121
) -> Result<(), LedAdapterError> {
125122
for position in [128, 64, 32, 16, 8, 4, 2, 1] {
126123
*mut_iter.next().ok_or(LedAdapterError::BufferSizeExceeded)? =
@@ -148,7 +145,7 @@ pub const fn buffer_size(num_leds: usize) -> usize {
148145
/// Function to calculate the required RMT buffer size for a given number of RGBW LEDs when using
149146
/// the blocking API.
150147
///
151-
/// For RGB leds use [buffer_size_rgb].
148+
/// For RGB leds use [buffer_size].
152149
///
153150
/// This buffer size is calculated for the synchronous API provided by the [SmartLedsAdapter].
154151
/// [buffer_size_async] should be used for the asynchronous API.
@@ -167,10 +164,10 @@ pub const fn buffer_size_rgbw(num_leds: usize) -> usize {
167164
#[macro_export]
168165
macro_rules! smart_led_buffer {
169166
( $num_leds: expr ) => {
170-
[0u32; $crate::buffer_size($num_leds)]
167+
[::esp_hal::rmt::PulseCode::default(); $crate::buffer_size($num_leds)]
171168
};
172169
( $num_leds: expr; RGBW ) => {
173-
[0u32; $crate::buffer_size_rgbw($num_leds)]
170+
[::esp_hal::rmt::PulseCode::default(); $crate::buffer_size_rgbw($num_leds)]
174171
};
175172
}
176173

@@ -185,44 +182,37 @@ macro_rules! smartLedBuffer {
185182

186183
/// Adapter taking an RMT channel and a specific pin and providing RGB LED
187184
/// interaction functionality using the `smart-leds` crate
188-
pub struct SmartLedsAdapter<TX, const BUFFER_SIZE: usize, Color = Grb<u8>>
189-
where
190-
TX: RawChannelAccess + TxChannelInternal + 'static,
191-
{
192-
channel: Option<Channel<Blocking, TX>>,
193-
rmt_buffer: [u32; BUFFER_SIZE],
194-
pulses: (u32, u32),
185+
pub struct SmartLedsAdapter<'ch, const BUFFER_SIZE: usize, Color = Grb<u8>> {
186+
channel: Option<Channel<'ch, Blocking, Tx>>,
187+
rmt_buffer: [PulseCode; BUFFER_SIZE],
188+
pulses: (PulseCode, PulseCode),
195189
color: PhantomData<Color>,
196190
}
197191

198-
impl<'d, TX, const BUFFER_SIZE: usize> SmartLedsAdapter<TX, BUFFER_SIZE, Grb<u8>>
199-
where
200-
TX: RawChannelAccess + TxChannelInternal + 'static,
201-
{
192+
impl<'ch, const BUFFER_SIZE: usize> SmartLedsAdapter<'ch, BUFFER_SIZE, Grb<u8>> {
202193
/// Create a new adapter object that drives the pin using the RMT channel.
203-
pub fn new<C, O>(channel: C, pin: O, rmt_buffer: [u32; BUFFER_SIZE]) -> Self
194+
pub fn new<C, O>(channel: C, pin: O, rmt_buffer: [PulseCode; BUFFER_SIZE]) -> Self
204195
where
205-
O: PeripheralOutput<'d>,
206-
C: TxChannelCreator<'d, Blocking, Raw = TX>,
196+
O: PeripheralOutput<'ch>,
197+
C: TxChannelCreator<'ch, Blocking>,
207198
{
208199
Self::new_with_color(channel, pin, rmt_buffer)
209200
}
210201
}
211202

212-
impl<'d, TX, const BUFFER_SIZE: usize, Color> SmartLedsAdapter<TX, BUFFER_SIZE, Color>
203+
impl<'ch, const BUFFER_SIZE: usize, Color> SmartLedsAdapter<'ch, BUFFER_SIZE, Color>
213204
where
214-
TX: RawChannelAccess + TxChannelInternal + 'static,
215205
Color: rgb::ComponentSlice<u8>,
216206
{
217207
/// Create a new adapter object that drives the pin using the RMT channel.
218208
pub fn new_with_color<C, O>(
219209
channel: C,
220210
pin: O,
221-
rmt_buffer: [u32; BUFFER_SIZE],
222-
) -> SmartLedsAdapter<TX, BUFFER_SIZE, Color>
211+
rmt_buffer: [PulseCode; BUFFER_SIZE],
212+
) -> SmartLedsAdapter<'ch, BUFFER_SIZE, Color>
223213
where
224-
O: PeripheralOutput<'d>,
225-
C: TxChannelCreator<'d, Blocking, Raw = TX>,
214+
O: PeripheralOutput<'ch>,
215+
C: TxChannelCreator<'ch, Blocking>,
226216
{
227217
let channel = channel.configure_tx(pin, led_config()).unwrap();
228218

@@ -238,10 +228,9 @@ where
238228
}
239229
}
240230

241-
impl<TX, const BUFFER_SIZE: usize, Color> SmartLedsWrite
242-
for SmartLedsAdapter<TX, BUFFER_SIZE, Color>
231+
impl<'ch, const BUFFER_SIZE: usize, Color> SmartLedsWrite
232+
for SmartLedsAdapter<'ch, BUFFER_SIZE, Color>
243233
where
244-
TX: RawChannelAccess + TxChannelInternal + 'static,
245234
Color: rgb::ComponentSlice<u8>,
246235
{
247236
type Error = LedAdapterError;
@@ -266,9 +255,9 @@ where
266255
}
267256

268257
// Finally, add an end element.
269-
*seq_iter.next().ok_or(LedAdapterError::BufferSizeExceeded)? = 0;
258+
*seq_iter.next().ok_or(LedAdapterError::BufferSizeExceeded)? = PulseCode::end_marker();
270259

271-
// Perform the actual RMT operation. We use the u32 values here right away.
260+
// Perform the actual RMT operation.
272261
let channel = self.channel.take().unwrap();
273262
match channel.transmit(&self.rmt_buffer)?.wait() {
274263
Ok(chan) => {
@@ -311,44 +300,37 @@ pub const fn buffer_size_async_rgbw(num_leds: usize) -> usize {
311300

312301
/// Adapter taking an RMT channel and a specific pin and providing RGB LED
313302
/// interaction functionality.
314-
pub struct SmartLedsAdapterAsync<Tx, const BUFFER_SIZE: usize, Color = Grb<u8>>
315-
where
316-
Tx: RawChannelAccess + TxChannelInternal + 'static,
317-
{
318-
channel: Channel<Async, Tx>,
319-
rmt_buffer: [u32; BUFFER_SIZE],
320-
pulses: (u32, u32),
303+
pub struct SmartLedsAdapterAsync<'ch, const BUFFER_SIZE: usize, Color = Grb<u8>> {
304+
channel: Channel<'ch, Async, Tx>,
305+
rmt_buffer: [PulseCode; BUFFER_SIZE],
306+
pulses: (PulseCode, PulseCode),
321307
color: PhantomData<Color>,
322308
}
323309

324-
impl<'d, Tx, const BUFFER_SIZE: usize> SmartLedsAdapterAsync<Tx, BUFFER_SIZE, Grb<u8>>
325-
where
326-
Tx: RawChannelAccess + TxChannelInternal + 'static,
327-
{
310+
impl<'ch, const BUFFER_SIZE: usize> SmartLedsAdapterAsync<'ch, BUFFER_SIZE, Grb<u8>> {
328311
/// Create a new adapter object that drives the pin using the RMT channel.
329-
pub fn new<C, O>(channel: C, pin: O, rmt_buffer: [u32; BUFFER_SIZE]) -> Self
312+
pub fn new<C, O>(channel: C, pin: O, rmt_buffer: [PulseCode; BUFFER_SIZE]) -> Self
330313
where
331-
O: PeripheralOutput<'d>,
332-
C: TxChannelCreator<'d, Async, Raw = Tx>,
314+
O: PeripheralOutput<'ch>,
315+
C: TxChannelCreator<'ch, Async>,
333316
{
334317
Self::new_with_color(channel, pin, rmt_buffer)
335318
}
336319
}
337320

338-
impl<'d, Tx, const BUFFER_SIZE: usize, Color> SmartLedsAdapterAsync<Tx, BUFFER_SIZE, Color>
321+
impl<'ch, const BUFFER_SIZE: usize, Color> SmartLedsAdapterAsync<'ch, BUFFER_SIZE, Color>
339322
where
340-
Tx: RawChannelAccess + TxChannelInternal + 'static,
341323
Color: rgb::ComponentSlice<u8>,
342324
{
343325
/// Create a new adapter object that drives the pin using the RMT channel.
344326
pub fn new_with_color<C, O>(
345327
channel: C,
346328
pin: O,
347-
rmt_buffer: [u32; BUFFER_SIZE],
348-
) -> SmartLedsAdapterAsync<Tx, BUFFER_SIZE, Color>
329+
rmt_buffer: [PulseCode; BUFFER_SIZE],
330+
) -> SmartLedsAdapterAsync<'ch, BUFFER_SIZE, Color>
349331
where
350-
O: PeripheralOutput<'d>,
351-
C: TxChannelCreator<'d, Async, Raw = Tx>,
332+
O: PeripheralOutput<'ch>,
333+
C: TxChannelCreator<'ch, Async>,
352334
{
353335
let channel = channel.configure_tx(pin, led_config()).unwrap();
354336

@@ -382,21 +364,20 @@ where
382364
/// Async sends one pixel at a time so needs a delimiter after each pixel
383365
fn convert_to_pulses(
384366
value: &[u8],
385-
mut_iter: &mut IterMut<u32>,
386-
pulses: (u32, u32),
367+
mut_iter: &mut IterMut<PulseCode>,
368+
pulses: (PulseCode, PulseCode),
387369
) -> Result<(), LedAdapterError> {
388370
for v in value {
389371
convert_rgb_channel_to_pulses(*v, mut_iter, pulses)?;
390372
}
391-
*mut_iter.next().ok_or(LedAdapterError::BufferSizeExceeded)? = 0;
373+
*mut_iter.next().ok_or(LedAdapterError::BufferSizeExceeded)? = PulseCode::end_marker();
392374
Ok(())
393375
}
394376
}
395377

396-
impl<Tx, const BUFFER_SIZE: usize, Color> SmartLedsWriteAsync
397-
for SmartLedsAdapterAsync<Tx, BUFFER_SIZE, Color>
378+
impl<'ch, const BUFFER_SIZE: usize, Color> SmartLedsWriteAsync
379+
for SmartLedsAdapterAsync<'ch, BUFFER_SIZE, Color>
398380
where
399-
Tx: RawChannelAccess + TxChannelInternal + 'static,
400381
Color: rgb::ComponentSlice<u8>,
401382
{
402383
type Error = LedAdapterError;

0 commit comments

Comments
 (0)