Skip to content

Commit 6b3cfe8

Browse files
committed
cortex-m: add support for embedded-hal 1.0 delays
1 parent ff2bb75 commit 6b3cfe8

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

cortex-m/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2222
- Add `std` and `serde` crate features for improved host-side ITM decode functionality when working with the downstream `itm`, `cargo-rtic-scope` crates (#363, #366).
2323
- Added the ability to name the statics generated by `singleton!()` for better debuggability (#364, #380).
2424
- Added `critical-section-single-core` feature which provides an implementation for the `critical_section` crate for single-core systems, based on disabling all interrupts. (#447)
25+
- Added support for `embedded-hal` version 1 delay traits.
2526

2627
### Fixed
2728
- Fixed `singleton!()` statics sometimes ending up in `.data` instead of `.bss` (#364, #380).

cortex-m/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ links = "cortex-m" # prevent multiple versions of this crate to be linked toget
2020
critical-section = "1.0.0"
2121
volatile-register = "0.2.2"
2222
bitfield = "0.13.2"
23-
embedded-hal = "0.2.4"
23+
embedded-hal-0 = { package = "embedded-hal", version = "0.2.4" }
24+
embedded-hal-1 = { package = "embedded-hal", version = "1.0.0" }
2425

2526
[dependencies.serde]
2627
version = "1"

cortex-m/src/delay.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! A delay driver based on SysTick.
22
33
use crate::peripheral::{syst::SystClkSource, SYST};
4-
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
4+
use embedded_hal_0::blocking::delay::{DelayMs, DelayUs};
5+
use embedded_hal_1::delay::DelayNs;
56

67
/// System timer (SysTick) as a delay provider.
78
pub struct Delay {
@@ -134,3 +135,20 @@ impl DelayUs<u8> for Delay {
134135
Delay::delay_us(self, u32::from(us))
135136
}
136137
}
138+
139+
impl DelayNs for Delay {
140+
#[inline]
141+
fn delay_ns(&mut self, ns: u32) {
142+
Delay::delay_us(self, ns.saturating_add(999) / 1000)
143+
}
144+
145+
#[inline]
146+
fn delay_us(&mut self, us: u32) {
147+
Delay::delay_us(self, us)
148+
}
149+
150+
#[inline]
151+
fn delay_ms(&mut self, ms: u32) {
152+
Delay::delay_ms(self, ms)
153+
}
154+
}

0 commit comments

Comments
 (0)