diff options
| author | Nils Fitinghoff <nils.fitinghoff@mobilaris.se> | 2023-09-14 16:47:52 +0200 |
|---|---|---|
| committer | Emil Fresk <emil.fresk@gmail.com> | 2023-09-19 13:31:09 +0000 |
| commit | a2ec8f983c799dea0a6f57ba97431ded54fc6197 (patch) | |
| tree | 6e7f5397f2065d7751f13ff6ad9e825e16fc51d2 /rtic-monotonics/src | |
| parent | 54aec9b3989162a60534620b80cde78d2d5cc1ba (diff) | |
rtic-monotonics: Implement blocking DelayUs from embedded-hal 1
Diffstat (limited to 'rtic-monotonics/src')
| -rw-r--r-- | rtic-monotonics/src/nrf/rtc.rs | 7 | ||||
| -rw-r--r-- | rtic-monotonics/src/nrf/timer.rs | 7 | ||||
| -rw-r--r-- | rtic-monotonics/src/rp2040.rs | 7 | ||||
| -rw-r--r-- | rtic-monotonics/src/stm32.rs | 7 | ||||
| -rw-r--r-- | rtic-monotonics/src/systick.rs | 9 |
5 files changed, 37 insertions, 0 deletions
diff --git a/rtic-monotonics/src/nrf/rtc.rs b/rtic-monotonics/src/nrf/rtc.rs index c74c986..9491307 100644 --- a/rtic-monotonics/src/nrf/rtc.rs +++ b/rtic-monotonics/src/nrf/rtc.rs @@ -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 { const ZERO: Self::Instant = Self::Instant::from_ticks(0); diff --git a/rtic-monotonics/src/nrf/timer.rs b/rtic-monotonics/src/nrf/timer.rs index 1b90f16..bd544d0 100644 --- a/rtic-monotonics/src/nrf/timer.rs +++ b/rtic-monotonics/src/nrf/timer.rs @@ -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 { const ZERO: Self::Instant = Self::Instant::from_ticks(0); diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs index 61bd1ff..43e6770 100644 --- a/rtic-monotonics/src/rp2040.rs +++ b/rtic-monotonics/src/rp2040.rs @@ -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. #[macro_export] macro_rules! create_rp2040_monotonic_token { diff --git a/rtic-monotonics/src/stm32.rs b/rtic-monotonics/src/stm32.rs index 3232f4a..77d36e4 100644 --- a/rtic-monotonics/src/stm32.rs +++ b/rtic-monotonics/src/stm32.rs @@ -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 { type Instant = fugit::TimerInstantU64<TIMER_HZ>; type Duration = fugit::TimerDurationU64<TIMER_HZ>; diff --git a/rtic-monotonics/src/systick.rs b/rtic-monotonics/src/systick.rs index 9b8fca8..fb4f883 100644 --- a/rtic-monotonics/src/systick.rs +++ b/rtic-monotonics/src/systick.rs @@ -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. #[macro_export] macro_rules! create_systick_token { |
