diff --git a/CHANGELOG.md b/CHANGELOG.md index e18f2d84..cce64e7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 0.16.0 (TBD) +* (Breaking change) Update `embedded-hal` to v1.0.0-rc.2 (contributed by @reitermarkus). * (Breaking change) Update `embedded-hal` to v1.0.0-rc.1 (contributed by @mbuesch). * (Breaking change) Change Minimum Supported Rust Version (MSRV) to v1.60.0. diff --git a/Cargo.toml b/Cargo.toml index a3989278..18b5af07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,8 +17,8 @@ keywords = ["raspberry", "pi", "embedded-hal", "embedded-hal-impl", "hal"] libc = "0.2" nb = { version = "0.1.1", optional = true } embedded-hal-0 = { version = "0.2.7", optional = true, package = "embedded-hal" } -embedded-hal = { version = "=1.0.0-rc.1", optional = true } -embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true } +embedded-hal = { version = "=1.0.0-rc.2", optional = true } +embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true } void = { version = "1.0.2", optional = true } spin_sleep = { version = "1.0.0", optional = true } diff --git a/src/hal.rs b/src/hal.rs index de74e967..ba33fab7 100644 --- a/src/hal.rs +++ b/src/hal.rs @@ -8,11 +8,11 @@ use std::time::{Duration, Instant}; -use embedded_hal::delay::DelayUs; +use embedded_hal::delay::DelayNs; use spin_sleep::sleep; use void::Void; -/// Implements the `embedded-hal` `DelayMs` and `DelayUs` traits. +/// Implements the `embedded-hal` `DelayMs` and `DelayNs` traits. #[derive(Debug, Default)] pub struct Delay; @@ -27,21 +27,21 @@ impl Delay { /// `DelayMs` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u8) { - DelayUs::delay_ms(self, ms as u32); + DelayNs::delay_ms(self, ms as u32); } } /// `DelayMs` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u16) { - DelayUs::delay_ms(self, ms as u32); + DelayNs::delay_ms(self, ms as u32); } } /// `DelayMs` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u32) { - DelayUs::delay_ms(self, ms); + DelayNs::delay_ms(self, ms); } } @@ -50,54 +50,58 @@ impl embedded_hal_0::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, mut ms: u64) { while ms > (u32::MAX as u64) { ms -= u32::MAX as u64; - DelayUs::delay_ms(self, u32::MAX); + DelayNs::delay_ms(self, u32::MAX); } - DelayUs::delay_ms(self, ms as u32); + DelayNs::delay_ms(self, ms as u32); } } -/// `DelayUs` trait implementation for `embedded-hal` v0.2.7. +/// `DelayNs` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u8) { - DelayUs::delay_us(self, us as u32); + DelayNs::delay_us(self, us as u32); } } -/// `DelayUs` trait implementation for `embedded-hal` v0.2.7. +/// `DelayNs` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u16) { - DelayUs::delay_us(self, us as u32); + DelayNs::delay_us(self, us as u32); } } -/// `DelayUs` trait implementation for `embedded-hal` v1.0.0. -impl DelayUs for Delay { +/// `DelayNs` trait implementation for `embedded-hal` v1.0.0. +impl DelayNs for Delay { + fn delay_ns(&mut self, ns: u32) { + sleep(Duration::from_nanos(ns.into())); + } + fn delay_us(&mut self, us: u32) { sleep(Duration::from_micros(us.into())); } fn delay_ms(&mut self, ms: u32) { - sleep(Duration::from_millis(u64::from(ms))); + sleep(Duration::from_millis(ms.into())); } } -/// `DelayUs` trait implementation for `embedded-hal` v0.2.7. +/// `DelayNs` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u32) { - DelayUs::delay_us(self, us); + DelayNs::delay_us(self, us); } } -/// `DelayUs` trait implementation for `embedded-hal` v0.2.7. +/// `DelayNs` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, mut us: u64) { while us > (u32::MAX as u64) { us -= u32::MAX as u64; - DelayUs::delay_us(self, u32::MAX); + DelayNs::delay_us(self, u32::MAX); } - DelayUs::delay_us(self, us as u32); + DelayNs::delay_us(self, us as u32); } } diff --git a/src/spi/hal.rs b/src/spi/hal.rs index a0052247..88293bae 100644 --- a/src/spi/hal.rs +++ b/src/spi/hal.rs @@ -1,5 +1,5 @@ use embedded_hal::{ - delay::DelayUs, + delay::DelayNs, spi::{self, ErrorType, SpiBus, SpiDevice, Operation}, }; use embedded_hal_nb::spi::FullDuplex; @@ -153,7 +153,7 @@ impl> SpiDevice for SimpleHalSpiDevice { )) })?; } - Operation::DelayUs(us) => { + Operation::DelayNs(us) => { Delay::new().delay_us(*us); } }