Skip to content

Commit

Permalink
cortex-m: add support for embedded-hal 1.0 delays
Browse files Browse the repository at this point in the history
  • Loading branch information
newAM committed Jan 11, 2024
1 parent ff2bb75 commit 6b3cfe8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions cortex-m/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- 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).
- Added the ability to name the statics generated by `singleton!()` for better debuggability (#364, #380).
- 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)
- Added support for `embedded-hal` version 1 delay traits.

### Fixed
- Fixed `singleton!()` statics sometimes ending up in `.data` instead of `.bss` (#364, #380).
Expand Down
3 changes: 2 additions & 1 deletion cortex-m/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ links = "cortex-m" # prevent multiple versions of this crate to be linked toget
critical-section = "1.0.0"
volatile-register = "0.2.2"
bitfield = "0.13.2"
embedded-hal = "0.2.4"
embedded-hal-0 = { package = "embedded-hal", version = "0.2.4" }
embedded-hal-1 = { package = "embedded-hal", version = "1.0.0" }

[dependencies.serde]
version = "1"
Expand Down
20 changes: 19 additions & 1 deletion cortex-m/src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! A delay driver based on SysTick.

use crate::peripheral::{syst::SystClkSource, SYST};
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
use embedded_hal_0::blocking::delay::{DelayMs, DelayUs};
use embedded_hal_1::delay::DelayNs;

/// System timer (SysTick) as a delay provider.
pub struct Delay {
Expand Down Expand Up @@ -134,3 +135,20 @@ impl DelayUs<u8> for Delay {
Delay::delay_us(self, u32::from(us))
}
}

impl DelayNs for Delay {
#[inline]
fn delay_ns(&mut self, ns: u32) {
Delay::delay_us(self, ns.saturating_add(999) / 1000)
}

#[inline]
fn delay_us(&mut self, us: u32) {
Delay::delay_us(self, us)
}

#[inline]
fn delay_ms(&mut self, ms: u32) {
Delay::delay_ms(self, ms)
}
}

0 comments on commit 6b3cfe8

Please sign in to comment.