embedded-hal icon indicating copy to clipboard operation
embedded-hal copied to clipboard

`Delay` trait using `core::time::Duration`

Open madsmtm opened this issue 2 years ago • 4 comments
trafficstars

Is there a reason that the embedded_hal::delay::DelayUs API is not defined as follows:

use core::time::Duration;

pub trait Delay {
    fn delay(&mut self, duration: Duration);

    #[inline]
    fn delay_us(&mut self, us: u32) {
        self.delay(Duration::from_micros(us))
    }

    #[inline]
    fn delay_ms(&mut self, ms: u32) {
        self.delay(Duration::from_millis(us))
    }
}

impl<T: Delay> Delay for &mut T { ... }

I haven't actually implemented this API myself, but it seems like this would be both much cleaner, and much more flexible (e.g. allowing nanosecond resolution as well)?

Is the issue that core::time::Duration is too large to pass around?

madsmtm avatar Nov 21 '23 20:11 madsmtm