FluenTech / embedded-time

Time(ing) library (Instant/Duration/Clock/Timer/Period/Frequency) for bare-metal embedded systems
Apache License 2.0
87 stars 17 forks source link

Add implementation for embedded_hal::blocking::delay::Delay trait #86

Open Piroro-hs opened 3 years ago

Piroro-hs commented 3 years ago

How about adding Clock::delay(&self) -> impl Delay function (maybe behind feature gate)? It could be useful as currently many hal crates only provides SysTick based delay.

I will make a PR if you like.

PTaylor-us commented 3 years ago

I'm not seeing a Delay trait in embedded-hal. It does have DelayUs and DelayMs. These could possibly be implemented, but I think the proper implementation would be for Timer. I'm thinking something like this:

impl<'a, Clock: crate::Clock, Dur: Duration> embedded_hal::blocking::delay::DelayMs<Clock::T>
    for Timer<'a, OneShot, Armed, Clock, Dur>
{
    fn delay_ms(&mut self, ms: <Clock as crate::Clock>::T) {
        unimplemented!()
    }
}

It's been a while since I've worked on this code, but I think we could wrap a timer in the Clock trait.

Piroro-hs commented 3 years ago

Yes, DelayMs and DelayUs.

I thought that Timer is for constant duration...