fugit_timer/
lib.rs

1#![no_std]
2
3/// Reexport `fugit`
4pub use fugit::*;
5
6/// Provides non-blocking `CountDown` timing capabilities
7pub trait Timer<const TIMER_HZ: u32> {
8    /// An error that might happen during waiting
9    type Error: core::fmt::Debug;
10
11    /// Return current time `Instant`
12    fn now(&mut self) -> TimerInstantU32<TIMER_HZ>;
13
14    /// Start timer with a `duration`
15    fn start(&mut self, duration: TimerDurationU32<TIMER_HZ>) -> Result<(), Self::Error>;
16
17    /// Tries to stop this timer.
18    /// An error will be returned if the timer has already been canceled or was never started.
19    /// An error is also returned if the timer is not `Periodic` and has already expired.
20    fn cancel(&mut self) -> Result<(), Self::Error>;
21
22    /// Wait until timer `duration` has expired.
23    /// Must return `nb::Error::WouldBlock` if timer `duration` is not yet over.
24    /// Must return `OK(())` as soon as timer `duration` has expired.
25    fn wait(&mut self) -> nb::Result<(), Self::Error>;
26}
27
28/// Provides blocking `Delay`
29pub trait Delay<const TIMER_HZ: u32> {
30    /// An error that might happen during waiting
31    type Error: core::fmt::Debug;
32
33    /// Wait until timer `duration` has expired.
34    fn delay(&mut self, duration: TimerDurationU32<TIMER_HZ>) -> Result<(), Self::Error>;
35}