From 756a6818c774b58b9c96b8a5d2f2f74affac130c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 11 Jan 2024 02:32:50 +0100 Subject: [PATCH] Update to `embedded-hal` 1.0. --- Cargo.toml | 4 +-- src/gpio/hal.rs | 67 +++++++++++++++++----------------------- src/gpio/hal_unproven.rs | 33 +++++++++----------- src/hal.rs | 4 +-- src/i2c/hal.rs | 2 +- src/spi/hal.rs | 4 +-- src/uart/hal.rs | 4 +-- 7 files changed, 51 insertions(+), 67 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 129419b1..d29b3b89 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.2", optional = true } -embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true } +embedded-hal = { version = "1", optional = true } +embedded-hal-nb = { version = "1", optional = true } void = { version = "1.0.2", optional = true } spin_sleep = { version = "1.0.0", optional = true } diff --git a/src/gpio/hal.rs b/src/gpio/hal.rs index 63aebb87..d4dfdce3 100644 --- a/src/gpio/hal.rs +++ b/src/gpio/hal.rs @@ -1,19 +1,14 @@ use core::convert::Infallible; -use embedded_hal::digital::{ - ErrorType, InputPin as InputPinHal, OutputPin as OutputPinHal, - StatefulOutputPin as StatefulOutputPinHal, ToggleableOutputPin as ToggleableOutputPinHal, -}; - use super::{InputPin, IoPin, Level, OutputPin, Pin}; -/// `ErrorType` trait implementation for `embedded-hal` v1.0.0. -impl ErrorType for Pin { +/// `ErrorType` trait implementation for `embedded-hal`. +impl embedded_hal::digital::ErrorType for Pin { type Error = Infallible; } -/// `InputPin` trait implementation for `embedded-hal` v1.0.0. -impl InputPinHal for Pin { +/// `InputPin` trait implementation for `embedded-hal`. +impl embedded_hal::digital::InputPin for Pin { fn is_high(&self) -> Result { Ok(Self::read(self) == Level::High) } @@ -23,13 +18,13 @@ impl InputPinHal for Pin { } } -/// `ErrorType` trait implementation for `embedded-hal` v1.0.0. -impl ErrorType for InputPin { +/// `ErrorType` trait implementation for `embedded-hal`. +impl embedded_hal::digital::ErrorType for InputPin { type Error = Infallible; } -/// `InputPin` trait implementation for `embedded-hal` v1.0.0. -impl InputPinHal for InputPin { +/// `InputPin` trait implementation for `embedded-hal`. +impl embedded_hal::digital::InputPin for InputPin { fn is_high(&self) -> Result { Ok(Self::is_high(self)) } @@ -39,13 +34,13 @@ impl InputPinHal for InputPin { } } -/// `ErrorType` trait implementation for `embedded-hal` v1.0.0. -impl ErrorType for IoPin { +/// `ErrorType` trait implementation for `embedded-hal`. +impl embedded_hal::digital::ErrorType for IoPin { type Error = Infallible; } -/// `InputPin` trait implementation for `embedded-hal` v1.0.0. -impl InputPinHal for IoPin { +/// `InputPin` trait implementation for `embedded-hal`. +impl embedded_hal::digital::InputPin for IoPin { fn is_high(&self) -> Result { Ok(Self::is_high(self)) } @@ -55,13 +50,13 @@ impl InputPinHal for IoPin { } } -/// `ErrorType` trait implementation for `embedded-hal` v1.0.0. -impl ErrorType for OutputPin { +/// `ErrorType` trait implementation for `embedded-hal`. +impl embedded_hal::digital::ErrorType for OutputPin { type Error = Infallible; } -/// `InputPin` trait implementation for `embedded-hal` v1.0.0. -impl InputPinHal for OutputPin { +/// `InputPin` trait implementation for `embedded-hal`. +impl embedded_hal::digital::InputPin for OutputPin { fn is_high(&self) -> Result { Ok(Self::is_set_high(self)) } @@ -71,8 +66,8 @@ impl InputPinHal for OutputPin { } } -/// `OutputPin` trait implementation for `embedded-hal` v1.0.0. -impl OutputPinHal for OutputPin { +/// `OutputPin` trait implementation for `embedded-hal`. +impl embedded_hal::digital::OutputPin for OutputPin { fn set_low(&mut self) -> Result<(), Self::Error> { OutputPin::set_low(self); @@ -91,16 +86,16 @@ impl embedded_hal_0::digital::v2::OutputPin for OutputPin { type Error = Infallible; fn set_low(&mut self) -> Result<(), Self::Error> { - OutputPinHal::set_low(self) + OutputPin::set_low(self) } fn set_high(&mut self) -> Result<(), Self::Error> { - OutputPinHal::set_high(self) + OutputPin::set_high(self) } } -/// `StatefulOutputPin` trait implementation for `embedded-hal` v1.0.0. -impl StatefulOutputPinHal for OutputPin { +/// `StatefulOutputPin` trait implementation for `embedded-hal`. +impl embedded_hal::digital::StatefulOutputPin for OutputPin { fn is_set_high(&self) -> Result { Ok(OutputPin::is_set_high(self)) } @@ -108,10 +103,7 @@ impl StatefulOutputPinHal for OutputPin { fn is_set_low(&self) -> Result { Ok(OutputPin::is_set_low(self)) } -} -/// `ToggleableOutputPin` trait implementation for `embedded-hal` v1.0.0. -impl ToggleableOutputPinHal for OutputPin { fn toggle(&mut self) -> Result<(), Self::Error> { OutputPin::toggle(self); @@ -119,8 +111,8 @@ impl ToggleableOutputPinHal for OutputPin { } } -/// `OutputPin` trait implementation for `embedded-hal` v1.0.0. -impl OutputPinHal for IoPin { +/// `OutputPin` trait implementation for `embedded-hal`. +impl embedded_hal::digital::OutputPin for IoPin { fn set_low(&mut self) -> Result<(), Self::Error> { IoPin::set_low(self); @@ -139,16 +131,16 @@ impl embedded_hal_0::digital::v2::OutputPin for IoPin { type Error = Infallible; fn set_low(&mut self) -> Result<(), Self::Error> { - OutputPinHal::set_low(self) + OutputPin::set_low(self) } fn set_high(&mut self) -> Result<(), Self::Error> { - OutputPinHal::set_high(self) + OutputPin::set_high(self) } } -/// `StatefulOutputPin` trait implementation for `embedded-hal` v1.0.0. -impl StatefulOutputPinHal for IoPin { +/// `StatefulOutputPin` trait implementation for `embedded-hal`. +impl embedded_hal::digital::StatefulOutputPin for IoPin { fn is_set_high(&self) -> Result { Ok(IoPin::is_high(self)) } @@ -156,10 +148,7 @@ impl StatefulOutputPinHal for IoPin { fn is_set_low(&self) -> Result { Ok(IoPin::is_low(self)) } -} -/// `ToggleableOutputPin` trait implementation for `embedded-hal` v1.0.0. -impl ToggleableOutputPinHal for IoPin { fn toggle(&mut self) -> Result<(), Self::Error> { IoPin::toggle(self); diff --git a/src/gpio/hal_unproven.rs b/src/gpio/hal_unproven.rs index a026f2f8..a46fcdce 100644 --- a/src/gpio/hal_unproven.rs +++ b/src/gpio/hal_unproven.rs @@ -1,11 +1,6 @@ use core::convert::Infallible; use std::time::Duration; -use embedded_hal::digital::{ - InputPin as InputPinHal, StatefulOutputPin as StatefulOutputPinHal, - ToggleableOutputPin as ToggleableOutputPinHal, -}; - use super::{InputPin, IoPin, OutputPin, Pin}; use crate::gpio::Mode; @@ -16,11 +11,11 @@ impl embedded_hal_0::digital::v2::InputPin for Pin { type Error = Infallible; fn is_high(&self) -> Result { - InputPinHal::is_high(self) + embedded_hal::digital::InputPin::is_high(self) } fn is_low(&self) -> Result { - InputPinHal::is_low(self) + embedded_hal::digital::InputPin::is_low(self) } } @@ -29,11 +24,11 @@ impl embedded_hal_0::digital::v2::InputPin for InputPin { type Error = Infallible; fn is_high(&self) -> Result { - InputPinHal::is_high(self) + embedded_hal::digital::InputPin::is_high(self) } fn is_low(&self) -> Result { - InputPinHal::is_low(self) + embedded_hal::digital::InputPin::is_low(self) } } @@ -42,11 +37,11 @@ impl embedded_hal_0::digital::v2::InputPin for IoPin { type Error = Infallible; fn is_high(&self) -> Result { - InputPinHal::is_high(self) + embedded_hal::digital::InputPin::is_high(self) } fn is_low(&self) -> Result { - InputPinHal::is_low(self) + embedded_hal::digital::InputPin::is_low(self) } } @@ -55,33 +50,33 @@ impl embedded_hal_0::digital::v2::InputPin for OutputPin { type Error = Infallible; fn is_high(&self) -> Result { - InputPinHal::is_high(self) + embedded_hal::digital::InputPin::is_high(self) } fn is_low(&self) -> Result { - InputPinHal::is_low(self) + embedded_hal::digital::InputPin::is_low(self) } } /// Unproven `StatefulOutputPin` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::digital::v2::StatefulOutputPin for IoPin { fn is_set_high(&self) -> Result { - StatefulOutputPinHal::is_set_high(self) + StatefulOutputPin::is_set_high(self) } fn is_set_low(&self) -> Result { - StatefulOutputPinHal::is_set_low(self) + StatefulOutputPin::is_set_low(self) } } /// Unproven `StatefulOutputPin` trait implementation for `embedded-hal` v0.2.7. impl embedded_hal_0::digital::v2::StatefulOutputPin for OutputPin { fn is_set_high(&self) -> Result { - StatefulOutputPinHal::is_set_high(self) + embedded_hal::digital::StatefulOutputPin::is_set_high(self) } fn is_set_low(&self) -> Result { - StatefulOutputPinHal::is_set_low(self) + embedded_hal::digital::StatefulOutputPin::is_set_low(self) } } @@ -90,7 +85,7 @@ impl embedded_hal_0::digital::v2::ToggleableOutputPin for IoPin { type Error = Infallible; fn toggle(&mut self) -> Result<(), Self::Error> { - ToggleableOutputPinHal::toggle(self) + embedded_hal::digital::StatefulOutputPin::toggle(self) } } @@ -99,7 +94,7 @@ impl embedded_hal_0::digital::v2::ToggleableOutputPin for OutputPin { type Error = Infallible; fn toggle(&mut self) -> Result<(), Self::Error> { - ToggleableOutputPinHal::toggle(self) + embedded_hal::digital::StatefulOutputPin::toggle(self) } } diff --git a/src/hal.rs b/src/hal.rs index ba33fab7..46c9863d 100644 --- a/src/hal.rs +++ b/src/hal.rs @@ -16,7 +16,7 @@ use void::Void; #[derive(Debug, Default)] pub struct Delay; -/// `Delay` trait implementation for `embedded-hal` v1.0.0. +/// `Delay` trait implementation for `embedded-hal`. impl Delay { /// Constructs a new `Delay`. pub fn new() -> Delay { @@ -71,7 +71,7 @@ impl embedded_hal_0::blocking::delay::DelayUs for Delay { } } -/// `DelayNs` trait implementation for `embedded-hal` v1.0.0. +/// `DelayNs` trait implementation for `embedded-hal`. impl DelayNs for Delay { fn delay_ns(&mut self, ns: u32) { sleep(Duration::from_nanos(ns.into())); diff --git a/src/i2c/hal.rs b/src/i2c/hal.rs index 6a6dfe22..4f23e74b 100644 --- a/src/i2c/hal.rs +++ b/src/i2c/hal.rs @@ -54,7 +54,7 @@ impl i2c::Error for Error { } } -/// `I2c` trait implementation for `embedded-hal` v1.0.0. +/// `I2c` trait implementation for `embedded-hal`. impl I2cHal for I2c { fn transaction( &mut self, diff --git a/src/spi/hal.rs b/src/spi/hal.rs index c28bba8b..70b9eac8 100644 --- a/src/spi/hal.rs +++ b/src/spi/hal.rs @@ -17,7 +17,7 @@ impl spi::Error for Error { } } -/// `SpiBus` trait implementation for `embedded-hal` v1.0.0. +/// `SpiBus` trait implementation for `embedded-hal`. impl SpiBus for Spi { fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> { Spi::read(self, words)?; @@ -64,7 +64,7 @@ impl embedded_hal_0::blocking::spi::Write for Spi { } } -/// `FullDuplex` trait implementation for `embedded-hal` v1.0.0 +/// `FullDuplex` trait implementation for `embedded-hal` impl FullDuplex for Spi { fn read(&mut self) -> nb::Result { if let Some(last_read) = self.last_read.take() { diff --git a/src/uart/hal.rs b/src/uart/hal.rs index f5be015d..040cb833 100644 --- a/src/uart/hal.rs +++ b/src/uart/hal.rs @@ -12,7 +12,7 @@ impl serial::Error for Error { } } -/// `Read` trait implementation for `embedded-hal` v1.0.0. +/// `Read` trait implementation for `embedded-hal`. impl Read for Uart { fn read(&mut self) -> nb::Result { let mut buffer = [0u8; 1]; @@ -33,7 +33,7 @@ impl embedded_hal_0::serial::Read for Uart { } } -/// `Write` trait implementation for `embedded-hal` v1.0.0. +/// `Write` trait implementation for `embedded-hal`. impl Write for Uart { fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> { if Uart::write(self, &[word])? == 0 {