Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for updated embedded hal #847

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rtic-monotonics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ rustdoc-flags = ["--cfg", "docsrs"]

[dependencies]
rtic-time = { version = "1.0.0", path = "../rtic-time" }
embedded-hal = { version = "1.0.0-rc.1" }
embedded-hal-async = { version = "1.0.0-rc.1", optional = true }
embedded-hal = { version = "1.0.0-rc.2" }
embedded-hal-async = { version = "1.0.0-rc.2", optional = true }
fugit = { version = "0.3.6" }
atomic-polyfill = "1"
cfg-if = "1.0.0"
Expand Down
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
6 changes: 3 additions & 3 deletions rtic-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ heapless = "0.7"
critical-section = "1"
rtic-common = { version = "1.0.0", path = "../rtic-common" }
portable-atomic = { version = "1", default-features = false }
embedded-hal = { version = "1.0.0-rc.1", optional = true }
embedded-hal-async = { version = "1.0.0-rc.1", optional = true }
embedded-hal-bus = { version = "0.1.0-rc.1", optional = true, features = ["async"] }
embedded-hal = { version = "1.0.0-rc.2", optional = true }
embedded-hal-async = { version = "1.0.0-rc.2", optional = true }
embedded-hal-bus = { version = "0.1.0-rc.2", optional = true, features = ["async"] }

[dev-dependencies]
tokio = { version = "1", features = ["rt", "macros", "time"] }
Expand Down
8 changes: 4 additions & 4 deletions rtic-sync/src/arbiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub mod spi {
use super::Arbiter;
use embedded_hal::digital::OutputPin;
use embedded_hal_async::{
delay::DelayUs,
delay::DelayNs,
spi::{ErrorType, Operation, SpiBus, SpiDevice},
};
use embedded_hal_bus::spi::DeviceError;
Expand Down Expand Up @@ -229,7 +229,7 @@ pub mod spi {
Word: Copy + 'static,
BUS: SpiBus<Word>,
CS: OutputPin,
D: DelayUs,
D: DelayNs,
{
async fn transaction(
&mut self,
Expand All @@ -246,10 +246,10 @@ pub mod spi {
Operation::Write(buf) => bus.write(buf).await,
Operation::Transfer(read, write) => bus.transfer(read, write).await,
Operation::TransferInPlace(buf) => bus.transfer_in_place(buf).await,
Operation::DelayUs(us) => match bus.flush().await {
Operation::DelayNs(ns) => match bus.flush().await {
Err(e) => Err(e),
Ok(()) => {
self.delay.delay_us(*us).await;
self.delay.delay_ns(*ns).await;
Ok(())
}
},
Expand Down