Skip to content

Commit

Permalink
delay: make infallible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Dec 20, 2022
1 parent 812471b commit 9365ca8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
13 changes: 4 additions & 9 deletions embedded-hal-async/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@

/// Microsecond delay
pub trait DelayUs {
/// Enumeration of errors
type Error: core::fmt::Debug;

/// Pauses execution for at minimum `us` microseconds. Pause can be longer
/// if the implementation requires it due to precision/timing issues.
async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error>;
async 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.
async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error>;
async fn delay_ms(&mut self, ms: u32);
}

impl<T> DelayUs for &mut T
where
T: DelayUs,
{
type Error = T::Error;

async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
async fn delay_us(&mut self, us: u32) {
T::delay_us(self, us).await
}

async fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> {
async fn delay_ms(&mut self, ms: u32) {
T::delay_ms(self, ms).await
}
}
17 changes: 5 additions & 12 deletions embedded-hal/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,28 @@
/// Microsecond delay
///
pub trait DelayUs {
/// Enumeration of `DelayUs` errors
type Error: core::fmt::Debug;

/// 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) -> Result<(), Self::Error>;
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) -> Result<(), Self::Error> {
fn delay_ms(&mut self, ms: u32) {
for _ in 0..ms {
self.delay_us(1000)?;
self.delay_us(1000);
}

Ok(())
}
}

impl<T> DelayUs for &mut T
where
T: DelayUs,
{
type Error = T::Error;

fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
fn delay_us(&mut self, us: u32) {
T::delay_us(self, us)
}

fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> {
fn delay_ms(&mut self, ms: u32) {
T::delay_ms(self, ms)
}
}

0 comments on commit 9365ca8

Please sign in to comment.