diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 293120799..0a8b2fc38 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -18,8 +18,8 @@ targets = ["thumbv6m-none-eabi"] [dependencies] cortex-m = "0.7.2" embedded-hal = { version = "0.2.5", features = ["unproven"] } -eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true } -eh_nb_1_0_alpha = { package = "embedded-hal-nb", version = "=1.0.0-rc.1", optional = true } +eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-rc.3", optional = true } +eh_nb_1_0_alpha = { package = "embedded-hal-nb", version = "=1.0.0-rc.3", optional = true } embedded-dma = "0.2.0" fugit = "0.3.6" itertools = { version = "0.10.1", default-features = false } diff --git a/rp2040-hal/src/gpio/mod.rs b/rp2040-hal/src/gpio/mod.rs index 00923ad12..b54f71f67 100644 --- a/rp2040-hal/src/gpio/mod.rs +++ b/rp2040-hal/src/gpio/mod.rs @@ -1434,11 +1434,11 @@ mod eh1 { I: PinId, P: PullType, { - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Ok(self._is_set_high()) } - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Ok(self._is_set_low()) } } @@ -1459,11 +1459,11 @@ mod eh1 { I: PinId, P: PullType, { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self._is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self._is_low()) } } @@ -1480,11 +1480,11 @@ mod eh1 { impl<'a, I: PinId, F: super::func::Function, P: PullType> InputPin for super::AsInputPin<'a, I, F, P> { - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result { Ok(self.0._is_high()) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result { Ok(self.0._is_low()) } } diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index ca6832a3c..4b897c6c9 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -167,10 +167,26 @@ macro_rules! impl_delay_traits { impl_delay_traits!(u8, u16, u32, i32); #[cfg(feature = "eh1_0_alpha")] -impl eh1_0_alpha::delay::DelayUs for Timer { +impl eh1_0_alpha::delay::DelayNs for Timer { + fn delay_ns(&mut self, ns: u32) { + // For now, just use microsecond delay, internally. Of course, this + // might cause a much longer delay than necessary. So a more advanced + // implementation would be desirable for sub-microsecond delays. + let us = ns / 1000 + if ns % 1000 == 0 { 0 } else { 1 }; + // With rustc 1.73, this can be replaced by: + // let us = ns.div_ceil(1000); + self.delay_us_internal(us) + } + fn delay_us(&mut self, us: u32) { self.delay_us_internal(us) } + + fn delay_ms(&mut self, ms: u32) { + for _ in 0..ms { + self.delay_us_internal(1000); + } + } } /// Implementation of the embedded_hal::Timer traits using rp2040_hal::timer counter