1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Delays

/// Microsecond delay
///
pub trait DelayUs {
    /// 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);

    /// 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) {
        for _ in 0..ms {
            self.delay_us(1000);
        }
    }
}

impl<T> DelayUs for &mut T
where
    T: DelayUs + ?Sized,
{
    fn delay_us(&mut self, us: u32) {
        T::delay_us(self, us)
    }

    fn delay_ms(&mut self, ms: u32) {
        T::delay_ms(self, ms)
    }
}