mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 12:12:50 +01:00
Update embedded-hal-async
This commit is contained in:
parent
688ba1cf5b
commit
9eae3ed4be
5 changed files with 33 additions and 49 deletions
|
@ -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"
|
||||
|
|
|
@ -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<F: Future>(
|
||||
|
@ -160,28 +165,18 @@ macro_rules! make_rtc {
|
|||
pub async fn delay_until(instant: <Self as Monotonic>::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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<F: Future>(
|
||||
|
@ -196,28 +201,18 @@ macro_rules! make_timer {
|
|||
pub async fn delay_until(instant: <Self as Monotonic>::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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ impl Systick {
|
|||
}
|
||||
|
||||
/// Delay to some specific time instant.
|
||||
#[inline]
|
||||
pub async fn delay_until(instant: <Self as Monotonic>::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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue