Skip to content

Commit d6b1c65

Browse files
bors[bot]almindor
andauthored
Merge #312
312: unify DelayUs and DelayMs to DelayUs for v1.0 r=therealprof a=almindor Implements a unified `DelayUs` using `u32` only for v1.0 of embedded-hal to prevent confusion. Keeps `Delay` open for future, better abstractions. Co-authored-by: Ales Katona <[email protected]>
2 parents 1d4e00f + 6d91a71 commit d6b1c65

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Removed
11+
- Removed `DelayMs` in favor of `DelayUs` with `u32` as type for clarity.
1012

1113
## [v1.0.0-alpha.5] - 2021-09-11
1214

src/delay.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,34 @@
99
1010
/// Blocking delay traits
1111
pub mod blocking {
12-
/// Millisecond delay
12+
/// Microsecond delay
1313
///
14-
/// `UXX` denotes the range type of the delay time. `UXX` can be `u8`, `u16`, etc. A single type can
15-
/// implement this trait for different types of `UXX`.
16-
pub trait DelayMs<UXX> {
17-
/// Enumeration of `DelayMs` errors
14+
pub trait DelayUs {
15+
/// Enumeration of `DelayUs` errors
1816
type Error: core::fmt::Debug;
1917

20-
/// Pauses execution for `ms` milliseconds
21-
fn delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error>;
22-
}
18+
/// Pauses execution for at minimum `us` microseconds. Pause can be longer
19+
/// if the implementation requires it due to precision/timing issues.
20+
fn delay_us(&mut self, us: u32) -> Result<(), Self::Error>;
2321

24-
impl<UXX, T: DelayMs<UXX>> DelayMs<UXX> for &mut T {
25-
type Error = T::Error;
22+
/// Pauses execution for at minimum `ms` milliseconds. Pause can be longer
23+
/// if the implementation requires it due to precision/timing issues.
24+
fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> {
25+
for _ in 0..ms {
26+
self.delay_us(1000)?;
27+
}
2628

27-
fn delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error> {
28-
T::delay_ms(self, ms)
29+
Ok(())
2930
}
3031
}
3132

32-
/// Microsecond delay
33-
///
34-
/// `UXX` denotes the range type of the delay time. `UXX` can be `u8`, `u16`, etc. A single type can
35-
/// implement this trait for different types of `UXX`.
36-
pub trait DelayUs<UXX> {
37-
/// Enumeration of `DelayMs` errors
38-
type Error: core::fmt::Debug;
39-
40-
/// Pauses execution for `us` microseconds
41-
fn delay_us(&mut self, us: UXX) -> Result<(), Self::Error>;
42-
}
43-
44-
impl<UXX, T: DelayUs<UXX>> DelayUs<UXX> for &mut T {
33+
impl<T> DelayUs for &mut T
34+
where
35+
T: DelayUs,
36+
{
4537
type Error = T::Error;
4638

47-
fn delay_us(&mut self, us: UXX) -> Result<(), Self::Error> {
39+
fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
4840
T::delay_us(self, us)
4941
}
5042
}

0 commit comments

Comments
 (0)