diff --git a/Cargo.toml b/Cargo.toml index d0e8250..6ae96e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,8 @@ version = "0.4.1" edition = "2021" [dependencies] -embedded-hal = { version = "0.2.4", features = ["unproven"] } +embedded-hal = { version = "1.0.0" } shared-bus = "0.3.0" [dev-dependencies] -embedded-hal-mock = "0.9.0" +embedded-hal-mock = "0.10.0" diff --git a/src/bus.rs b/src/bus.rs index d7ffc5d..7254c9c 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -1,15 +1,13 @@ -use embedded_hal::blocking::i2c as hal_i2c; +use embedded_hal::i2c as hal_i2c; -/// Blanket trait for types implementing `i2c::WriteRead + i2c::Write + i2c::Read` -pub trait I2cBus: hal_i2c::WriteRead + hal_i2c::Write + hal_i2c::Read { - type BusError: From<::Error> - + From<::Error> - + From<::Error>; +/// Blanket trait for types implementing `i2c::I2c +pub trait I2cBus: hal_i2c::I2c { + type BusError: From<::Error>; } impl I2cBus for T where - T: hal_i2c::WriteRead + hal_i2c::Write + hal_i2c::Read, + T: hal_i2c::I2c, { type BusError = E; } diff --git a/src/dev/max7321.rs b/src/dev/max7321.rs index 4967f1b..f760f61 100644 --- a/src/dev/max7321.rs +++ b/src/dev/max7321.rs @@ -22,7 +22,7 @@ where ))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { p0: crate::Pin::new(0, &self.0), p1: crate::Pin::new(1, &self.0), @@ -92,7 +92,7 @@ impl crate::PortDriver for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn max7321() { diff --git a/src/dev/pca9536.rs b/src/dev/pca9536.rs index 7a3e8c8..888fd80 100644 --- a/src/dev/pca9536.rs +++ b/src/dev/pca9536.rs @@ -22,7 +22,7 @@ where Self(shared_bus::BusMutex::create(Driver::new(i2c))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { io0: crate::Pin::new(0, &self.0), io1: crate::Pin::new(1, &self.0), @@ -136,7 +136,7 @@ impl crate::PortDriverPolarity for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn pca9536() { diff --git a/src/dev/pca9538.rs b/src/dev/pca9538.rs index 46bf7f3..a56cab9 100644 --- a/src/dev/pca9538.rs +++ b/src/dev/pca9538.rs @@ -22,7 +22,7 @@ where Self(shared_bus::BusMutex::create(Driver::new(i2c, a0, a1))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { io0: crate::Pin::new(0, &self.0), io1: crate::Pin::new(1, &self.0), @@ -148,7 +148,7 @@ impl crate::PortDriverPolarity for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn pca9538() { diff --git a/src/dev/pca9555.rs b/src/dev/pca9555.rs index 97d9f33..4425cb6 100644 --- a/src/dev/pca9555.rs +++ b/src/dev/pca9555.rs @@ -22,7 +22,7 @@ where Self(shared_bus::BusMutex::create(Driver::new(i2c, a0, a1, a2))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { io0_0: crate::Pin::new(0, &self.0), io0_1: crate::Pin::new(1, &self.0), @@ -210,7 +210,7 @@ impl crate::PortDriverPolarity for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn pca9555() { diff --git a/src/dev/pcal6408a.rs b/src/dev/pcal6408a.rs index 4d630aa..6fe978a 100644 --- a/src/dev/pcal6408a.rs +++ b/src/dev/pcal6408a.rs @@ -22,7 +22,7 @@ where Self(shared_bus::BusMutex::create(Driver::new(i2c, addr))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { io0: crate::Pin::new(0, &self.0), io1: crate::Pin::new(1, &self.0), @@ -115,8 +115,7 @@ impl crate::PortDriver for Driver { out &= !mask_low as u8; self.out = Some(out); if (mask_high | mask_low) & 0x00FF != 0 { - self.i2c - .write_reg(self.addr, Regs::OutputPort, (out & 0xFF) as u8)?; + self.i2c.write_reg(self.addr, Regs::OutputPort, out)?; } Ok(()) } @@ -185,7 +184,7 @@ impl crate::PortDriverPolarity for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn pca6408a() { diff --git a/src/dev/pcal6416a.rs b/src/dev/pcal6416a.rs index f31554c..d0be881 100644 --- a/src/dev/pcal6416a.rs +++ b/src/dev/pcal6416a.rs @@ -22,7 +22,7 @@ where Self(shared_bus::BusMutex::create(Driver::new(i2c, addr))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { io0_0: crate::Pin::new(0, &self.0), io0_1: crate::Pin::new(1, &self.0), @@ -245,7 +245,7 @@ impl crate::PortDriverPolarity for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn pca6416a() { diff --git a/src/dev/pcf8574.rs b/src/dev/pcf8574.rs index 0635b43..f277611 100644 --- a/src/dev/pcf8574.rs +++ b/src/dev/pcf8574.rs @@ -34,7 +34,7 @@ where ))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { p0: crate::Pin::new(0, &self.0), p1: crate::Pin::new(1, &self.0), @@ -59,7 +59,7 @@ where ))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { p0: crate::Pin::new(0, &self.0), p1: crate::Pin::new(1, &self.0), @@ -133,7 +133,7 @@ impl crate::PortDriver for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn pcf8574() { diff --git a/src/dev/pcf8575.rs b/src/dev/pcf8575.rs index c5127bf..1e6d801 100644 --- a/src/dev/pcf8575.rs +++ b/src/dev/pcf8575.rs @@ -21,7 +21,7 @@ where Self(shared_bus::BusMutex::create(Driver::new(i2c, a0, a1, a2))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { p00: crate::Pin::new(0, &self.0), p01: crate::Pin::new(1, &self.0), @@ -113,7 +113,7 @@ impl crate::PortDriver for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn pcf8575() { diff --git a/src/dev/tca6408a.rs b/src/dev/tca6408a.rs index 3e0e09e..64f2ac9 100644 --- a/src/dev/tca6408a.rs +++ b/src/dev/tca6408a.rs @@ -22,7 +22,7 @@ where Self(shared_bus::BusMutex::create(Driver::new(i2c, a0))) } - pub fn split<'a>(&'a mut self) -> Parts<'a, I2C, M> { + pub fn split(&mut self) -> Parts<'_, I2C, M> { Parts { io0: crate::Pin::new(0, &self.0), io1: crate::Pin::new(1, &self.0), @@ -148,7 +148,7 @@ impl crate::PortDriverPolarity for Driver { #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn tca6408a() { diff --git a/src/lib.rs b/src/lib.rs index 9d14d6b..e232e67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ //! ```no_run //! // Initialize I2C peripheral from HAL //! let i2c = todo!(); -//! # let i2c = embedded_hal_mock::i2c::Mock::new(&[]); +//! # let i2c = embedded_hal_mock::eh1::i2c::Mock::new(&[]); //! //! // A0: HIGH, A1: LOW, A2: LOW //! let mut pca9555 = port_expander::Pca9555::new(i2c, true, false, false); diff --git a/src/multi.rs b/src/multi.rs index 6ca496c..67262c1 100644 --- a/src/multi.rs +++ b/src/multi.rs @@ -3,7 +3,7 @@ /// The usual method of setting multiple pins /// /// ```no_run -/// # let i2c = embedded_hal_mock::i2c::Mock::new(&[]); +/// # let i2c = embedded_hal_mock::eh1::i2c::Mock::new(&[]); /// # let mut pcf = port_expander::Pcf8574::new(i2c, false, false, false); /// # let p = pcf.split(); /// # let mut io0 = p.p0; @@ -18,7 +18,7 @@ /// /// ## Example /// ```no_run -/// # let i2c = embedded_hal_mock::i2c::Mock::new(&[]); +/// # let i2c = embedded_hal_mock::eh1::i2c::Mock::new(&[]); /// # let mut pcf = port_expander::Pcf8574::new(i2c, false, false, false); /// # let p = pcf.split(); /// # let mut io0 = p.p0; @@ -62,7 +62,7 @@ where /// inputs at once. The naive approach of checking the pins in order /// /// ```no_run -/// # let i2c = embedded_hal_mock::i2c::Mock::new(&[]); +/// # let i2c = embedded_hal_mock::eh1::i2c::Mock::new(&[]); /// # let mut pcf = port_expander::Pcf8574::new(i2c, false, false, false); /// # let p = pcf.split(); /// # let io0 = p.p0; @@ -81,7 +81,7 @@ where /// /// ## Example /// ```no_run -/// # let i2c = embedded_hal_mock::i2c::Mock::new(&[]); +/// # let i2c = embedded_hal_mock::eh1::i2c::Mock::new(&[]); /// # let mut pcf = port_expander::Pcf8574::new(i2c, false, false, false); /// # let p = pcf.split(); /// # let io0 = p.p0; @@ -115,7 +115,7 @@ where #[cfg(test)] mod tests { - use embedded_hal_mock::i2c as mock_i2c; + use embedded_hal_mock::eh1::i2c as mock_i2c; #[test] fn pcf8574_write_multiple() { diff --git a/src/pin.rs b/src/pin.rs index 2eba4d2..9561e55 100644 --- a/src/pin.rs +++ b/src/pin.rs @@ -1,5 +1,5 @@ use core::marker::PhantomData; -use embedded_hal::digital::v2 as hal_digital; +use embedded_hal::digital::{self as hal_digital, ErrorType}; /// Representation of a port-expander pin. /// @@ -29,11 +29,18 @@ where self.pin_mask } - pub(crate) fn port_driver<'b>(&'b self) -> &'b MUTEX { - &self.port_driver + pub(crate) fn port_driver(&self) -> &MUTEX { + self.port_driver } } - +impl<'a, MODE, MUTEX, PD> ErrorType for Pin<'a, MODE, MUTEX> +where + PD: crate::PortDriver + crate::PortDriverTotemPole, + PD::Error: embedded_hal::digital::Error, + MUTEX: shared_bus::BusMutex, +{ + type Error = PD::Error; +} impl<'a, MODE, MUTEX, PD> Pin<'a, MODE, MUTEX> where PD: crate::PortDriver + crate::PortDriverTotemPole, @@ -121,16 +128,15 @@ where impl<'a, MODE: crate::mode::HasInput, MUTEX, PD> hal_digital::InputPin for Pin<'a, MODE, MUTEX> where - PD: crate::PortDriver, + PD: crate::PortDriver + crate::PortDriverTotemPole, + ::Error: embedded_hal::digital::Error, MUTEX: shared_bus::BusMutex, { - type Error = PD::Error; - - fn is_high(&self) -> Result { + fn is_high(&mut self) -> Result::Error> { Pin::is_high(self) } - fn is_low(&self) -> Result { + fn is_low(&mut self) -> Result::Error> { Pin::is_low(self) } } @@ -178,11 +184,10 @@ where impl<'a, MODE: crate::mode::HasOutput, MUTEX, PD> hal_digital::OutputPin for Pin<'a, MODE, MUTEX> where - PD: crate::PortDriver, + PD: crate::PortDriver + crate::PortDriverTotemPole, + ::Error: embedded_hal::digital::Error, MUTEX: shared_bus::BusMutex, { - type Error = PD::Error; - fn set_low(&mut self) -> Result<(), Self::Error> { Pin::set_low(self) } @@ -195,25 +200,17 @@ where impl<'a, MODE: crate::mode::HasOutput, MUTEX, PD> hal_digital::StatefulOutputPin for Pin<'a, MODE, MUTEX> where - PD: crate::PortDriver, + PD: crate::PortDriver + crate::PortDriverTotemPole, + ::Error: embedded_hal::digital::Error, MUTEX: shared_bus::BusMutex, { - fn is_set_high(&self) -> Result { + fn is_set_high(&mut self) -> Result { Pin::is_set_high(self) } - fn is_set_low(&self) -> Result { + fn is_set_low(&mut self) -> Result { Pin::is_set_low(self) } -} - -impl<'a, MODE: crate::mode::HasOutput, MUTEX, PD> hal_digital::ToggleableOutputPin - for Pin<'a, MODE, MUTEX> -where - PD: crate::PortDriver, - MUTEX: shared_bus::BusMutex, -{ - type Error = PD::Error; fn toggle(&mut self) -> Result<(), Self::Error> { Pin::toggle(self)