diff --git a/.github/workflows/clippy-async.yml b/.github/workflows/clippy-async.yml new file mode 100644 index 000000000..ce6abdb9f --- /dev/null +++ b/.github/workflows/clippy-async.yml @@ -0,0 +1,19 @@ +on: + push: + branches: [ staging, trying, master ] + pull_request: + +name: Clippy check +jobs: + clippy_check-async: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: clippy + - run: cargo clippy + working-directory: embedded-hal-async diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index f23b98b1f..adc3a6ed1 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -18,5 +18,3 @@ jobs: - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - - run: cargo clippy - working-directory: embedded-hal-async diff --git a/embedded-hal-async/src/delay.rs b/embedded-hal-async/src/delay.rs new file mode 100644 index 000000000..a7b8f6313 --- /dev/null +++ b/embedded-hal-async/src/delay.rs @@ -0,0 +1,52 @@ +//! Delays + +use core::future::Future; + +/// Microsecond delay +pub trait DelayUs { + /// Enumeration of errors + type Error: core::fmt::Debug; + + /// The future returned by the `delay_us` function. + type DelayUsFuture<'a>: Future> + 'a + where + Self: 'a; + + /// 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) -> Self::DelayUsFuture<'_>; + + /// The future returned by the `delay_ms` function. + type DelayMsFuture<'a>: Future> + 'a + where + Self: 'a; + + /// 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) -> Self::DelayMsFuture<'_>; +} + +impl DelayUs for &mut T +where + T: DelayUs, +{ + type Error = T::Error; + + type DelayUsFuture<'a> + where + Self: 'a, + = T::DelayUsFuture<'a>; + + fn delay_us(&mut self, us: u32) -> Self::DelayUsFuture<'_> { + T::delay_us(self, us) + } + + type DelayMsFuture<'a> + where + Self: 'a, + = T::DelayMsFuture<'a>; + + fn delay_ms(&mut self, ms: u32) -> Self::DelayMsFuture<'_> { + T::delay_ms(self, ms) + } +} diff --git a/embedded-hal-async/src/lib.rs b/embedded-hal-async/src/lib.rs index 31cfc9070..9e29b5110 100644 --- a/embedded-hal-async/src/lib.rs +++ b/embedded-hal-async/src/lib.rs @@ -9,3 +9,6 @@ #![deny(missing_docs)] #![no_std] +#![feature(generic_associated_types)] + +pub mod delay;