Update embedded-hal-async

This commit is contained in:
datdenkikniet 2023-04-23 16:34:18 +02:00
parent 688ba1cf5b
commit 9eae3ed4be
5 changed files with 33 additions and 49 deletions

View file

@ -20,7 +20,7 @@ rustdoc-flags = ["--cfg", "docsrs"]
[dependencies] [dependencies]
rtic-time = { version = "1.0.0-alpha.1", path = "../rtic-time" } 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" } fugit = { version = "0.3.6" }
atomic-polyfill = "1" atomic-polyfill = "1"
cfg-if = "1.0.0" cfg-if = "1.0.0"

View file

@ -40,8 +40,7 @@ use nrf5340_net_pac::{self as pac, Interrupt, RTC0_NS as RTC0, RTC1_NS as RTC1};
#[cfg(feature = "nrf9160")] #[cfg(feature = "nrf9160")]
use nrf9160_pac::{self as pac, Interrupt, RTC0_NS as RTC0, RTC1_NS as RTC1}; use nrf9160_pac::{self as pac, Interrupt, RTC0_NS as RTC0, RTC1_NS as RTC1};
use super::super::Monotonic; use crate::{Monotonic, TimeoutError, TimerQueue};
pub use super::super::{TimeoutError, TimerQueue};
use atomic_polyfill::{AtomicU32, Ordering}; use atomic_polyfill::{AtomicU32, Ordering};
use core::future::Future; use core::future::Future;
pub use fugit::{self, ExtU64}; pub use fugit::{self, ExtU64};
@ -131,6 +130,12 @@ macro_rules! make_rtc {
&$tq &$tq
} }
#[inline(always)]
fn is_overflow() -> bool {
let rtc = unsafe { &*$rtc::PTR };
rtc.events_ovrflw.read().bits() == 1
}
/// Timeout at a specific time. /// Timeout at a specific time.
#[inline] #[inline]
pub async fn timeout_at<F: Future>( pub async fn timeout_at<F: Future>(
@ -160,28 +165,18 @@ macro_rules! make_rtc {
pub async fn delay_until(instant: <Self as Monotonic>::Instant) { pub async fn delay_until(instant: <Self as Monotonic>::Instant) {
$tq.delay_until(instant).await; $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")] #[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for $mono_name { impl embedded_hal_async::delay::DelayUs for $mono_name {
type Error = core::convert::Infallible;
#[inline] #[inline]
async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { async fn delay_us(&mut self, us: u32) {
$tq.delay((us as u64).micros()).await; Self::delay((us as u64).micros()).await;
Ok(())
} }
#[inline] #[inline]
async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { async fn delay_ms(&mut self, ms: u32) {
$tq.delay((ms as u64).millis()).await; Self::delay((ms as u64).millis()).await;
Ok(())
} }
} }

View file

@ -26,8 +26,7 @@
//! } //! }
//! ``` //! ```
use super::super::Monotonic; use crate::{Monotonic, TimeoutError, TimerQueue};
pub use super::super::{TimeoutError, TimerQueue};
use atomic_polyfill::{AtomicU32, Ordering}; use atomic_polyfill::{AtomicU32, Ordering};
use core::future::Future; use core::future::Future;
pub use fugit::{self, ExtU64}; pub use fugit::{self, ExtU64};
@ -167,6 +166,12 @@ macro_rules! make_timer {
&$tq &$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. /// Timeout at a specific time.
#[inline] #[inline]
pub async fn timeout_at<F: Future>( pub async fn timeout_at<F: Future>(
@ -196,28 +201,18 @@ macro_rules! make_timer {
pub async fn delay_until(instant: <Self as Monotonic>::Instant) { pub async fn delay_until(instant: <Self as Monotonic>::Instant) {
$tq.delay_until(instant).await; $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")] #[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for $mono_name { impl embedded_hal_async::delay::DelayUs for $mono_name {
type Error = core::convert::Infallible;
#[inline] #[inline]
async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { async fn delay_us(&mut self, us: u32) {
$tq.delay((us as u64).micros()).await; Self::delay((us as u64).micros()).await;
Ok(())
} }
#[inline] #[inline]
async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { async fn delay_ms(&mut self, ms: u32) {
$tq.delay((ms as u64).millis()).await; Self::delay((ms as u64).millis()).await;
Ok(())
} }
} }

View file

@ -25,6 +25,7 @@
//! ``` //! ```
use super::Monotonic; use super::Monotonic;
pub use super::{TimeoutError, TimerQueue}; pub use super::{TimeoutError, TimerQueue};
use core::future::Future; use core::future::Future;
pub use fugit::{self, ExtU64}; pub use fugit::{self, ExtU64};
@ -152,16 +153,12 @@ impl Monotonic for Timer {
#[cfg(feature = "embedded-hal-async")] #[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for Timer { impl embedded_hal_async::delay::DelayUs for Timer {
type Error = core::convert::Infallible; async fn delay_us(&mut self, us: u32) {
Self::delay((us as u64).micros()).await;
async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
TIMER_QUEUE.delay((us as u64).micros()).await;
Ok(())
} }
async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { async fn delay_ms(&mut self, ms: u32) {
TIMER_QUEUE.delay((ms as u64).millis()).await; Self::delay((ms as u64).millis()).await;
Ok(())
} }
} }

View file

@ -129,6 +129,7 @@ impl Systick {
} }
/// Delay to some specific time instant. /// Delay to some specific time instant.
#[inline]
pub async fn delay_until(instant: <Self as Monotonic>::Instant) { pub async fn delay_until(instant: <Self as Monotonic>::Instant) {
SYSTICK_TIMER_QUEUE.delay_until(instant).await; SYSTICK_TIMER_QUEUE.delay_until(instant).await;
} }
@ -173,16 +174,12 @@ impl Monotonic for Systick {
#[cfg(feature = "embedded-hal-async")] #[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for Systick { impl embedded_hal_async::delay::DelayUs for Systick {
type Error = core::convert::Infallible; async fn delay_us(&mut self, us: u32) {
Self::delay(us.micros()).await;
async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
SYSTICK_TIMER_QUEUE.delay(us.micros()).await;
Ok(())
} }
async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { async fn delay_ms(&mut self, ms: u32) {
SYSTICK_TIMER_QUEUE.delay(ms.millis()).await; Self::delay(ms.millis()).await;
Ok(())
} }
} }