From 5e8eced16e5175ab5638991833de9ca8cc73c48e Mon Sep 17 00:00:00 2001 From: Michael Daffin Date: Sat, 4 Jan 2025 14:21:40 +0000 Subject: [PATCH] Upgrade to embedded-hal 1.0.0 There was one breaking change that will propergate to a breaking change for end users. CountDown is no longer a trait in embedded_hal 1 and there is no replacment. There are two main paths we could take here: using the CountDown timer from rp2040-hal crate or convert to DelayNs which is what embedded_hal suggested since we only actually use it for a 60micro second delay. This does mean that you need to pass in the Timer instance rather than a CountDown instead but overall keeps the code a bit more generic and requires fewer trait bounds. It would be nice to rename the generics from C to T as they really now represent the Timer rather than CountDown but T is already used by some iterators later on and renaming those to I conflicts with other generics - so i opted to avoid the renaming bikeshedding in this completely. --- Cargo.toml | 2 +- src/lib.rs | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6e8abe5..19a9a25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ documentation = "https://docs.rs/ws2812-pio" repository = "https://github.com/rp-rs/ws2812-pio-rs/" [dependencies] -embedded-hal = "0.2.5" +embedded-hal = "1.0.0" fugit = "0.3.5" rp2040-hal = "0.11" pio = "0.2.0" diff --git a/src/lib.rs b/src/lib.rs index 75ad292..fe73481 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,8 @@ //! Bear in mind that you will have to take care of timing requirements //! yourself then. -use embedded_hal::timer::CountDown; -use fugit::{ExtU32, HertzU32, MicrosDurationU32}; +use embedded_hal::delay::DelayNs; +use fugit::HertzU32; use rp2040_hal::{ gpio::AnyPin, pio::{PIOExt, StateMachineIndex, Tx, UninitStateMachine, PIO}, @@ -239,18 +239,18 @@ where ///``` pub struct Ws2812 where - C: CountDown, + C: DelayNs, I: AnyPin, P: PIOExt, SM: StateMachineIndex, { driver: Ws2812Direct, - cd: C, + timer: C, } impl Ws2812 where - C: CountDown, + C: DelayNs, I: AnyPin, P: PIOExt, SM: StateMachineIndex, @@ -261,18 +261,17 @@ where pio: &mut PIO

, sm: UninitStateMachine<(P, SM)>, clock_freq: fugit::HertzU32, - cd: C, + timer: C, ) -> Ws2812 { let driver = Ws2812Direct::new(pin, pio, sm, clock_freq); - Self { driver, cd } + Self { driver, timer } } } impl SmartLedsWrite for Ws2812 where - C: CountDown, - C::Time: From, + C: DelayNs, I: AnyPin, P: PIOExt, SM: StateMachineIndex, @@ -287,17 +286,14 @@ where self.driver.tx.clear_stalled_flag(); while !self.driver.tx.is_empty() && !self.driver.tx.has_stalled() {} - self.cd.start(60u32.micros()); - let _ = nb::block!(self.cd.wait()); - + self.timer.delay_us(60); SmartLedsWrite::write(&mut self.driver, iterator) } } impl SmartLedsWrite02 for Ws2812 where - C: CountDown, - C::Time: From, + C: DelayNs, I: AnyPin, P: PIOExt, SM: StateMachineIndex,