Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update embedded-hal to 1.0.0-rc.2. #133

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
42 changes: 23 additions & 19 deletions src/hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,21 +27,21 @@ impl Delay {
/// `DelayMs<u8>` trait implementation for `embedded-hal` v0.2.7.
impl embedded_hal_0::blocking::delay::DelayMs<u8> for Delay {
fn delay_ms(&mut self, ms: u8) {
DelayUs::delay_ms(self, ms as u32);
DelayNs::delay_ms(self, ms as u32);
}
}

/// `DelayMs<u16>` trait implementation for `embedded-hal` v0.2.7.
impl embedded_hal_0::blocking::delay::DelayMs<u16> for Delay {
fn delay_ms(&mut self, ms: u16) {
DelayUs::delay_ms(self, ms as u32);
DelayNs::delay_ms(self, ms as u32);
}
}

/// `DelayMs<u32>` trait implementation for `embedded-hal` v0.2.7.
impl embedded_hal_0::blocking::delay::DelayMs<u32> for Delay {
fn delay_ms(&mut self, ms: u32) {
DelayUs::delay_ms(self, ms);
DelayNs::delay_ms(self, ms);
}
}

Expand All @@ -50,54 +50,58 @@ impl embedded_hal_0::blocking::delay::DelayMs<u64> 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<u8>` trait implementation for `embedded-hal` v0.2.7.
/// `DelayNs<u8>` trait implementation for `embedded-hal` v0.2.7.
impl embedded_hal_0::blocking::delay::DelayUs<u8> for Delay {
fn delay_us(&mut self, us: u8) {
DelayUs::delay_us(self, us as u32);
DelayNs::delay_us(self, us as u32);
}
}

/// `DelayUs<u16>` trait implementation for `embedded-hal` v0.2.7.
/// `DelayNs<u16>` trait implementation for `embedded-hal` v0.2.7.
impl embedded_hal_0::blocking::delay::DelayUs<u16> 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<u32>` trait implementation for `embedded-hal` v0.2.7.
/// `DelayNs<u32>` trait implementation for `embedded-hal` v0.2.7.
impl embedded_hal_0::blocking::delay::DelayUs<u32> for Delay {
fn delay_us(&mut self, us: u32) {
DelayUs::delay_us(self, us);
DelayNs::delay_us(self, us);
}
}

/// `DelayUs<u64>` trait implementation for `embedded-hal` v0.2.7.
/// `DelayNs<u64>` trait implementation for `embedded-hal` v0.2.7.
impl embedded_hal_0::blocking::delay::DelayUs<u64> 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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/spi/hal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use embedded_hal::{
delay::DelayUs,
delay::DelayNs,
spi::{self, ErrorType, SpiBus, SpiDevice, Operation},
};
use embedded_hal_nb::spi::FullDuplex;
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<B: SpiBus<u8>> SpiDevice<u8> for SimpleHalSpiDevice<B> {
))
})?;
}
Operation::DelayUs(us) => {
Operation::DelayNs(us) => {
Delay::new().delay_us(*us);
}
}
Expand Down