Skip to content

Commit

Permalink
Fixes for updated embedded hal
Browse files Browse the repository at this point in the history
  • Loading branch information
korken89 committed Nov 29, 2023
1 parent a13cb30 commit d6bf28e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 12 deletions.
14 changes: 12 additions & 2 deletions rtic-monotonics/src/imxrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ macro_rules! make_timer {
}

#[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for $mono_name {
impl embedded_hal_async::delay::DelayNs for $mono_name {
#[inline]
async fn delay_ns(&mut self, ns: u32) {
Self::delay((ns as u64).nanos()).await;
}

#[inline]
async fn delay_us(&mut self, us: u32) {
Self::delay((us as u64).micros()).await;
Expand All @@ -229,7 +234,12 @@ macro_rules! make_timer {
}
}

impl embedded_hal::delay::DelayUs for $mono_name {
impl embedded_hal::delay::DelayNs for $mono_name {
fn delay_ns(&mut self, ns: u32) {
let done = Self::now() + u64::from(ns).nanos();
while Self::now() < done {}
}

fn delay_us(&mut self, us: u32) {
let done = Self::now() + (us as u64).micros();
while Self::now() < done {}
Expand Down
14 changes: 12 additions & 2 deletions rtic-monotonics/src/nrf/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ macro_rules! make_rtc {
}

#[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for $mono_name {
impl embedded_hal_async::delay::DelayNs for $mono_name {
#[inline]
async fn delay_ns(&mut self, ns: u32) {
Self::delay((ns as u64).nanos()).await;
}

#[inline]
async fn delay_us(&mut self, us: u32) {
Self::delay((us as u64).micros()).await;
Expand All @@ -180,7 +185,12 @@ macro_rules! make_rtc {
}
}

impl embedded_hal::delay::DelayUs for $mono_name {
impl embedded_hal::delay::DelayNs for $mono_name {
fn delay_ns(&mut self, ns: u32) {
let done = Self::now() + u64::from(ns).nanos();
while Self::now() < done {}
}

fn delay_us(&mut self, us: u32) {
let done = Self::now() + u64::from(us).micros();
while Self::now() < done {}
Expand Down
14 changes: 12 additions & 2 deletions rtic-monotonics/src/nrf/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ macro_rules! make_timer {
}

#[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for $mono_name {
impl embedded_hal_async::delay::DelayNs for $mono_name {
#[inline]
async fn delay_ns(&mut self, ns: u32) {
Self::delay((ns as u64).nanos()).await;
}

#[inline]
async fn delay_us(&mut self, us: u32) {
Self::delay((us as u64).micros()).await;
Expand All @@ -216,7 +221,12 @@ macro_rules! make_timer {
}
}

impl embedded_hal::delay::DelayUs for $mono_name {
impl embedded_hal::delay::DelayNs for $mono_name {
fn delay_ns(&mut self, ns: u32) {
let done = Self::now() + u64::from(ns).nanos();
while Self::now() < done {}
}

fn delay_us(&mut self, us: u32) {
let done = Self::now() + (us as u64).micros();
while Self::now() < done {}
Expand Down
13 changes: 11 additions & 2 deletions rtic-monotonics/src/rp2040.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ impl Monotonic for Timer {
}

#[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for Timer {
impl embedded_hal_async::delay::DelayNs for Timer {
async fn delay_ns(&mut self, ns: u32) {
Self::delay((ns as u64).nanos()).await;
}

async fn delay_us(&mut self, us: u32) {
Self::delay((us as u64).micros()).await;
}
Expand All @@ -162,7 +166,12 @@ impl embedded_hal_async::delay::DelayUs for Timer {
}
}

impl embedded_hal::delay::DelayUs for Timer {
impl embedded_hal::delay::DelayNs for Timer {
fn delay_ns(&mut self, ns: u32) {
let done = Self::now() + u64::from(ns).nanos();
while Self::now() < done {}
}

fn delay_us(&mut self, us: u32) {
let done = Self::now() + u64::from(us).micros();
while Self::now() < done {}
Expand Down
14 changes: 12 additions & 2 deletions rtic-monotonics/src/stm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ macro_rules! make_timer {
}

#[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for $mono_name {
impl embedded_hal_async::delay::DelayNs for $mono_name {
#[inline]
async fn delay_ns(&mut self, ns: u32) {
Self::delay((ns as u64).nanos()).await;
}

#[inline]
async fn delay_us(&mut self, us: u32) {
Self::delay((us as u64).micros()).await;
Expand All @@ -231,7 +236,12 @@ macro_rules! make_timer {
}
}

impl embedded_hal::delay::DelayUs for $mono_name {
impl embedded_hal::delay::DelayNs for $mono_name {
fn delay_ns(&mut self, ns: u32) {
let done = Self::now() + u64::from(ns).nanos();
while Self::now() < done {}
}

fn delay_us(&mut self, us: u32) {
let done = Self::now() + (us as u64).micros();
while Self::now() < done {}
Expand Down
17 changes: 15 additions & 2 deletions rtic-monotonics/src/systick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ impl Monotonic for Systick {
}

#[cfg(feature = "embedded-hal-async")]
impl embedded_hal_async::delay::DelayUs for Systick {
impl embedded_hal_async::delay::DelayNs for Systick {
async fn delay_ns(&mut self, ns: u32) {
#[cfg(feature = "systick-64bit")]
let ns = u64::from(ns);
Self::delay(ns.nanos()).await;
}

async fn delay_us(&mut self, us: u32) {
#[cfg(feature = "systick-64bit")]
let us = u64::from(us);
Expand All @@ -203,7 +209,14 @@ impl embedded_hal_async::delay::DelayUs for Systick {
}
}

impl embedded_hal::delay::DelayUs for Systick {
impl embedded_hal::delay::DelayNs for Systick {
fn delay_ns(&mut self, ns: u32) {
#[cfg(feature = "systick-64bit")]
let ns = u64::from(ns);
let done = Self::now() + ns.nanos();
while Self::now() < done {}
}

fn delay_us(&mut self, us: u32) {
#[cfg(feature = "systick-64bit")]
let us = u64::from(us);
Expand Down

0 comments on commit d6bf28e

Please sign in to comment.