diff --git a/src/blocking/delay.rs b/src/blocking/delay.rs new file mode 100644 index 0000000..1fc8957 --- /dev/null +++ b/src/blocking/delay.rs @@ -0,0 +1,26 @@ +//! Delays +//! +//! # What's the difference between these traits and the `Timer` trait? +//! +//! The `Timer` trait provides a *non-blocking* timer abstraction and it's meant to be used to build +//! higher level abstractions like I/O operations with timeouts. OTOH, these delays traits only +//! provide blocking functionality. Note that you can also use the `Timer` trait to implement +//! blocking delays. + +/// Microsecond delay +/// +/// `UXX` denotes the range type of the delay time. `UXX` can be `u8`, `u16`, etc. A single type can +/// implement this trait for different types of `UXX`. +pub trait DelayMs { + /// Pauses execution for `ms` milliseconds + fn delay_ms(&mut self, ms: UXX); +} + +/// Millisecond delay +/// +/// `UXX` denotes the range type of the delay time. `UXX` can be `u8`, `u16`, etc. A single type can +/// implement this trait for different types of `UXX`. +pub trait DelayUs { + /// Pauses execution for `us` microseconds + fn delay_us(&mut self, us: UXX); +} diff --git a/src/blocking/mod.rs b/src/blocking/mod.rs index dcbf6a0..a14f94c 100644 --- a/src/blocking/mod.rs +++ b/src/blocking/mod.rs @@ -1,4 +1,5 @@ //! Blocking API +pub mod delay; pub mod i2c; pub mod spi; diff --git a/src/prelude.rs b/src/prelude.rs index 3c353aa..d7a5e82 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -8,6 +8,8 @@ pub use ::Pwm as _embedded_hal_Pwm; pub use ::PwmPin as _embedded_hal_PwmPin; pub use ::Qei as _embedded_hal_Qei; pub use ::Timer as _embedded_hal_Timer; +pub use ::blocking::delay::DelayMs as _embedded_hal_blocking_delay_DelayMs; +pub use ::blocking::delay::DelayUs as _embedded_hal_blocking_delay_DelayUs; pub use ::digital::OutputPin as _embedded_hal_digital_OutputPin; pub use ::serial::Read as _embedded_hal_serial_Read; pub use ::serial::Write as _embedded_hal_serial_Write;