-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
14 changed files
with
421 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//! Implementation of [`embedded-hal`] delay traits | ||
//! | ||
//! [`embedded-hal`]: https://docs.rs/embedded-hal | ||
use cast::{u32, u64}; | ||
use core::convert::Infallible; | ||
use embedded_hal::delay::blocking::{DelayMs, DelayUs}; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
/// Empty struct that provides delay functionality on top of `thread::sleep` | ||
pub struct Delay; | ||
|
||
impl DelayUs<u8> for Delay { | ||
type Error = Infallible; | ||
|
||
fn delay_us(&mut self, n: u8) -> Result<(), Self::Error> { | ||
thread::sleep(Duration::new(0, u32(n) * 1000)); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl DelayUs<u16> for Delay { | ||
type Error = Infallible; | ||
|
||
fn delay_us(&mut self, n: u16) -> Result<(), Self::Error> { | ||
thread::sleep(Duration::new(0, u32(n) * 1000)); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl DelayUs<u32> for Delay { | ||
type Error = Infallible; | ||
|
||
fn delay_us(&mut self, n: u32) -> Result<(), Self::Error> { | ||
let secs = n / 1_000_000; | ||
let nsecs = (n % 1_000_000) * 1_000; | ||
|
||
thread::sleep(Duration::new(u64(secs), nsecs)); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl DelayUs<u64> for Delay { | ||
type Error = Infallible; | ||
|
||
fn delay_us(&mut self, n: u64) -> Result<(), Self::Error> { | ||
let secs = n / 1_000_000; | ||
let nsecs = ((n % 1_000_000) * 1_000) as u32; | ||
|
||
thread::sleep(Duration::new(secs, nsecs)); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl DelayMs<u8> for Delay { | ||
type Error = Infallible; | ||
|
||
fn delay_ms(&mut self, n: u8) -> Result<(), Self::Error> { | ||
thread::sleep(Duration::from_millis(u64(n))); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl DelayMs<u16> for Delay { | ||
type Error = Infallible; | ||
|
||
fn delay_ms(&mut self, n: u16) -> Result<(), Self::Error> { | ||
thread::sleep(Duration::from_millis(u64(n))); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl DelayMs<u32> for Delay { | ||
type Error = Infallible; | ||
|
||
fn delay_ms(&mut self, n: u32) -> Result<(), Self::Error> { | ||
thread::sleep(Duration::from_millis(u64(n))); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl DelayMs<u64> for Delay { | ||
type Error = Infallible; | ||
|
||
fn delay_ms(&mut self, n: u64) -> Result<(), Self::Error> { | ||
thread::sleep(Duration::from_millis(n)); | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.