Skip to content

Commit

Permalink
unify DelayUs and DelayMs to DelayUs for v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
almindor committed Sep 22, 2021
1 parent bd7f607 commit 3f3f3e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Removed
- Removed `DelayMs` in favor of `DelayUs` with `u32` as type for clarity.

## [v1.0.0-alpha.5] - 2021-09-11

Expand Down
29 changes: 12 additions & 17 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,22 @@
/// Blocking delay traits
pub mod blocking {
/// 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 DelayMs<UXX> {
/// Enumeration of `DelayMs` errors
type Error: core::fmt::Debug;

/// Pauses execution for `ms` milliseconds
fn delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error>;
}

/// 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 DelayUs<UXX> {
/// Enumeration of `DelayMs` errors
pub trait DelayUs {
/// Enumeration of `DelayUs` errors
type Error: core::fmt::Debug;

/// Pauses execution for `us` microseconds
fn delay_us(&mut self, us: UXX) -> Result<(), Self::Error>;
fn delay_us(&mut self, us: u32) -> Result<(), Self::Error>;

/// Pauses execution for `ms` milliseconds
fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> {
for _ in 0..ms {
self.delay_us(1000)?;
}

Ok(())
}
}
}

0 comments on commit 3f3f3e8

Please sign in to comment.