diff --git a/rtic-monotonics/Cargo.toml b/rtic-monotonics/Cargo.toml index 3c294ea728..764abbaa14 100644 --- a/rtic-monotonics/Cargo.toml +++ b/rtic-monotonics/Cargo.toml @@ -20,7 +20,7 @@ rustdoc-flags = ["--cfg", "docsrs"] [dependencies] rtic-time = { version = "1.0.0-alpha.1", path = "../rtic-time" } -embedded-hal-async = { version = "0.2.0-alpha.0", optional = true } +embedded-hal-async = { version = "0.2.0-alpha.1", optional = true } fugit = { version = "0.3.6" } atomic-polyfill = "1" cfg-if = "1.0.0" diff --git a/rtic-monotonics/src/nrf/rtc.rs b/rtic-monotonics/src/nrf/rtc.rs index 50087ab644..c74c9861c9 100644 --- a/rtic-monotonics/src/nrf/rtc.rs +++ b/rtic-monotonics/src/nrf/rtc.rs @@ -40,8 +40,7 @@ use nrf5340_net_pac::{self as pac, Interrupt, RTC0_NS as RTC0, RTC1_NS as RTC1}; #[cfg(feature = "nrf9160")] use nrf9160_pac::{self as pac, Interrupt, RTC0_NS as RTC0, RTC1_NS as RTC1}; -use super::super::Monotonic; -pub use super::super::{TimeoutError, TimerQueue}; +use crate::{Monotonic, TimeoutError, TimerQueue}; use atomic_polyfill::{AtomicU32, Ordering}; use core::future::Future; pub use fugit::{self, ExtU64}; @@ -131,6 +130,12 @@ macro_rules! make_rtc { &$tq } + #[inline(always)] + fn is_overflow() -> bool { + let rtc = unsafe { &*$rtc::PTR }; + rtc.events_ovrflw.read().bits() == 1 + } + /// Timeout at a specific time. #[inline] pub async fn timeout_at( @@ -160,28 +165,18 @@ macro_rules! make_rtc { pub async fn delay_until(instant: ::Instant) { $tq.delay_until(instant).await; } - - #[inline(always)] - fn is_overflow() -> bool { - let rtc = unsafe { &*$rtc::PTR }; - rtc.events_ovrflw.read().bits() == 1 - } } #[cfg(feature = "embedded-hal-async")] impl embedded_hal_async::delay::DelayUs for $mono_name { - type Error = core::convert::Infallible; - #[inline] - async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { - $tq.delay((us as u64).micros()).await; - Ok(()) + async fn delay_us(&mut self, us: u32) { + Self::delay((us as u64).micros()).await; } #[inline] - async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { - $tq.delay((ms as u64).millis()).await; - Ok(()) + async fn delay_ms(&mut self, ms: u32) { + Self::delay((ms as u64).millis()).await; } } diff --git a/rtic-monotonics/src/nrf/timer.rs b/rtic-monotonics/src/nrf/timer.rs index 6b7ade6a0c..1b90f16fcb 100644 --- a/rtic-monotonics/src/nrf/timer.rs +++ b/rtic-monotonics/src/nrf/timer.rs @@ -26,8 +26,7 @@ //! } //! ``` -use super::super::Monotonic; -pub use super::super::{TimeoutError, TimerQueue}; +use crate::{Monotonic, TimeoutError, TimerQueue}; use atomic_polyfill::{AtomicU32, Ordering}; use core::future::Future; pub use fugit::{self, ExtU64}; @@ -167,6 +166,12 @@ macro_rules! make_timer { &$tq } + #[inline(always)] + fn is_overflow() -> bool { + let timer = unsafe { &*$timer::PTR }; + timer.events_compare[1].read().bits() & 1 != 0 + } + /// Timeout at a specific time. #[inline] pub async fn timeout_at( @@ -196,28 +201,18 @@ macro_rules! make_timer { pub async fn delay_until(instant: ::Instant) { $tq.delay_until(instant).await; } - - #[inline(always)] - fn is_overflow() -> bool { - let timer = unsafe { &*$timer::PTR }; - timer.events_compare[1].read().bits() & 1 != 0 - } } #[cfg(feature = "embedded-hal-async")] impl embedded_hal_async::delay::DelayUs for $mono_name { - type Error = core::convert::Infallible; - #[inline] - async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { - $tq.delay((us as u64).micros()).await; - Ok(()) + async fn delay_us(&mut self, us: u32) { + Self::delay((us as u64).micros()).await; } #[inline] - async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { - $tq.delay((ms as u64).millis()).await; - Ok(()) + async fn delay_ms(&mut self, ms: u32) { + Self::delay((ms as u64).millis()).await; } } diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs index ac1fc1a7a5..a9fd3f3f4b 100644 --- a/rtic-monotonics/src/rp2040.rs +++ b/rtic-monotonics/src/rp2040.rs @@ -25,6 +25,7 @@ //! ``` use super::Monotonic; + pub use super::{TimeoutError, TimerQueue}; use core::future::Future; pub use fugit::{self, ExtU64}; @@ -152,16 +153,12 @@ impl Monotonic for Timer { #[cfg(feature = "embedded-hal-async")] impl embedded_hal_async::delay::DelayUs for Timer { - type Error = core::convert::Infallible; - - async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { - TIMER_QUEUE.delay((us as u64).micros()).await; - Ok(()) + async fn delay_us(&mut self, us: u32) { + Self::delay((us as u64).micros()).await; } - async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { - TIMER_QUEUE.delay((ms as u64).millis()).await; - Ok(()) + async fn delay_ms(&mut self, ms: u32) { + Self::delay((ms as u64).millis()).await; } } diff --git a/rtic-monotonics/src/systick.rs b/rtic-monotonics/src/systick.rs index 0f215a7c3c..fe66a20aed 100644 --- a/rtic-monotonics/src/systick.rs +++ b/rtic-monotonics/src/systick.rs @@ -129,6 +129,7 @@ impl Systick { } /// Delay to some specific time instant. + #[inline] pub async fn delay_until(instant: ::Instant) { SYSTICK_TIMER_QUEUE.delay_until(instant).await; } @@ -173,16 +174,12 @@ impl Monotonic for Systick { #[cfg(feature = "embedded-hal-async")] impl embedded_hal_async::delay::DelayUs for Systick { - type Error = core::convert::Infallible; - - async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { - SYSTICK_TIMER_QUEUE.delay(us.micros()).await; - Ok(()) + async fn delay_us(&mut self, us: u32) { + Self::delay(us.micros()).await; } - async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { - SYSTICK_TIMER_QUEUE.delay(ms.millis()).await; - Ok(()) + async fn delay_ms(&mut self, ms: u32) { + Self::delay(ms.millis()).await; } }