rtic-monotonics: Implement blocking DelayUs from embedded-hal 1

This commit is contained in:
Nils Fitinghoff 2023-09-14 16:47:52 +02:00 committed by Emil Fresk
parent 54aec9b398
commit a2ec8f983c
7 changed files with 39 additions and 0 deletions

View file

@ -10,6 +10,7 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
### Added ### Added
- STM32 support. - STM32 support.
- `embedded-hal` 1.0.0-rc.1 `DelayUs` support
## v1.1.0 - 2023-08-29 ## v1.1.0 - 2023-08-29

View file

@ -21,6 +21,7 @@ rustdoc-flags = ["--cfg", "docsrs"]
[dependencies] [dependencies]
rtic-time = { version = "1.0.0", path = "../rtic-time" } 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-async = { version = "1.0.0-rc.1", optional = true }
fugit = { version = "0.3.6" } fugit = { version = "0.3.6" }
atomic-polyfill = "1" atomic-polyfill = "1"

View file

@ -180,6 +180,13 @@ macro_rules! make_rtc {
} }
} }
impl embedded_hal::delay::DelayUs for $mono_name {
fn delay_us(&mut self, us: u32) {
let done = Self::now() + u64::from(us).micros();
while Self::now() < done {}
}
}
impl Monotonic for $mono_name { impl Monotonic for $mono_name {
const ZERO: Self::Instant = Self::Instant::from_ticks(0); const ZERO: Self::Instant = Self::Instant::from_ticks(0);

View file

@ -216,6 +216,13 @@ macro_rules! make_timer {
} }
} }
impl embedded_hal::delay::DelayUs for $mono_name {
fn delay_us(&mut self, us: u32) {
let done = Self::now() + (us as u64).micros();
while Self::now() < done {}
}
}
impl Monotonic for $mono_name { impl Monotonic for $mono_name {
const ZERO: Self::Instant = Self::Instant::from_ticks(0); const ZERO: Self::Instant = Self::Instant::from_ticks(0);

View file

@ -162,6 +162,13 @@ impl embedded_hal_async::delay::DelayUs for Timer {
} }
} }
impl embedded_hal::delay::DelayUs for Timer {
fn delay_us(&mut self, us: u32) {
let done = Self::now() + u64::from(us).micros();
while Self::now() < done {}
}
}
/// Register the Timer interrupt for the monotonic. /// Register the Timer interrupt for the monotonic.
#[macro_export] #[macro_export]
macro_rules! create_rp2040_monotonic_token { macro_rules! create_rp2040_monotonic_token {

View file

@ -230,6 +230,13 @@ macro_rules! make_timer {
} }
} }
impl embedded_hal::delay::DelayUs for $mono_name {
fn delay_us(&mut self, us: u32) {
let done = Self::now() + (us as u64).micros();
while Self::now() < done {}
}
}
impl Monotonic for $mono_name { impl Monotonic for $mono_name {
type Instant = fugit::TimerInstantU64<TIMER_HZ>; type Instant = fugit::TimerInstantU64<TIMER_HZ>;
type Duration = fugit::TimerDurationU64<TIMER_HZ>; type Duration = fugit::TimerDurationU64<TIMER_HZ>;

View file

@ -203,6 +203,15 @@ impl embedded_hal_async::delay::DelayUs for Systick {
} }
} }
impl embedded_hal::delay::DelayUs for Systick {
fn delay_us(&mut self, us: u32) {
#[cfg(feature = "systick-64bit")]
let us = u64::from(us);
let done = Self::now() + us.micros();
while Self::now() < done {}
}
}
/// Register the Systick interrupt for the monotonic. /// Register the Systick interrupt for the monotonic.
#[macro_export] #[macro_export]
macro_rules! create_systick_token { macro_rules! create_systick_token {