|
9 | 9 |
|
10 | 10 | /// Blocking delay traits
|
11 | 11 | pub mod blocking {
|
12 |
| - /// Millisecond delay |
| 12 | + /// Microsecond delay |
13 | 13 | ///
|
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 |
18 | 16 | type Error: core::fmt::Debug;
|
19 | 17 |
|
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>; |
23 | 21 |
|
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 | + } |
26 | 28 |
|
27 |
| - fn delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error> { |
28 |
| - T::delay_ms(self, ms) |
| 29 | + Ok(()) |
29 | 30 | }
|
30 | 31 | }
|
31 | 32 |
|
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 | + { |
45 | 37 | type Error = T::Error;
|
46 | 38 |
|
47 |
| - fn delay_us(&mut self, us: UXX) -> Result<(), Self::Error> { |
| 39 | + fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { |
48 | 40 | T::delay_us(self, us)
|
49 | 41 | }
|
50 | 42 | }
|
|
0 commit comments