diff --git a/CHANGELOG.md b/CHANGELOG.md index 495576757..f5ed43e2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Removed +- Removed `DelayMs` in favor of `DelayUs` with `u32` as type for clarity. ## [v1.0.0-alpha.5] - 2021-09-11 diff --git a/src/delay.rs b/src/delay.rs index 18b6d2f49..fcb5f302d 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -9,42 +9,34 @@ /// Blocking delay traits pub mod blocking { - /// Millisecond delay + /// Microsecond delay /// - /// `UXX` denotes the range type of the delay time. `UXX` can be `u8`, `u16`, etc. A single type can - /// implement this trait for different types of `UXX`. - pub trait DelayMs { - /// Enumeration of `DelayMs` errors + pub trait DelayUs { + /// Enumeration of `DelayUs` errors type Error: core::fmt::Debug; - /// Pauses execution for `ms` milliseconds - fn delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error>; - } + /// Pauses execution for at minimum `us` microseconds. Pause can be longer + /// if the implementation requires it due to precision/timing issues. + fn delay_us(&mut self, us: u32) -> Result<(), Self::Error>; - impl> DelayMs for &mut T { - type Error = T::Error; + /// Pauses execution for at minimum `ms` milliseconds. Pause can be longer + /// if the implementation requires it due to precision/timing issues. + fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { + for _ in 0..ms { + self.delay_us(1000)?; + } - fn delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error> { - T::delay_ms(self, ms) + Ok(()) } } - /// Microsecond delay - /// - /// `UXX` denotes the range type of the delay time. `UXX` can be `u8`, `u16`, etc. A single type can - /// implement this trait for different types of `UXX`. - pub trait DelayUs { - /// Enumeration of `DelayMs` errors - type Error: core::fmt::Debug; - - /// Pauses execution for `us` microseconds - fn delay_us(&mut self, us: UXX) -> Result<(), Self::Error>; - } - - impl> DelayUs for &mut T { + impl DelayUs for &mut T + where + T: DelayUs, + { type Error = T::Error; - fn delay_us(&mut self, us: UXX) -> Result<(), Self::Error> { + fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { T::delay_us(self, us) } }