From c395fa7f38c6717e27bcd53d1b09a2ede1a8fc46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20Dupr=C3=A9=20Bertoni?= Date: Wed, 17 Jul 2024 13:42:33 +0300 Subject: [PATCH] Update dependencies --- Cargo.toml | 6 +++--- src/ds3231.rs | 4 ++-- src/ds3232.rs | 4 ++-- src/ds3234.rs | 4 ++-- src/interface.rs | 21 ++++++++++----------- tests/alarms.rs | 4 ++-- tests/common/mod.rs | 17 ++++++++++------- tests/configuration.rs | 8 ++++---- tests/datetime.rs | 8 ++++---- tests/ds3232_4.rs | 6 +++--- tests/ds3234.rs | 6 +++--- tests/status.rs | 2 +- 12 files changed, 46 insertions(+), 44 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab3f766..e25f8a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,12 +21,12 @@ include = [ edition = "2018" [dependencies] -embedded-hal = "0.2.7" +embedded-hal = "1.0.0" rtcc = "0.3" [dev-dependencies] -embedded-hal-mock = "0.9.0" -linux-embedded-hal = "0.3.2" +embedded-hal-mock = { version = "0.11.0", features = ["eh1"] } +linux-embedded-hal = "0.4.0" [profile.release] lto = true diff --git a/src/ds3231.rs b/src/ds3231.rs index 21fb176..944515a 100644 --- a/src/ds3231.rs +++ b/src/ds3231.rs @@ -2,11 +2,11 @@ use crate::{ic, interface::I2cInterface, BitFlags, Ds323x, CONTROL_POR_VALUE}; use core::marker::PhantomData; -use embedded_hal::blocking::i2c; +use embedded_hal::i2c; impl Ds323x, ic::DS3231> where - I2C: i2c::Write + i2c::WriteRead, + I2C: i2c::I2c, { /// Create a new instance of the DS3231 device. pub fn new_ds3231(i2c: I2C) -> Self { diff --git a/src/ds3232.rs b/src/ds3232.rs index 1d24669..7be45f9 100644 --- a/src/ds3232.rs +++ b/src/ds3232.rs @@ -4,11 +4,11 @@ use crate::{ ic, interface::I2cInterface, BitFlags, Ds323x, Error, TempConvRate, CONTROL_POR_VALUE, }; use core::marker::PhantomData; -use embedded_hal::blocking::i2c; +use embedded_hal::i2c; impl Ds323x, ic::DS3232> where - I2C: i2c::Write + i2c::WriteRead, + I2C: i2c::I2c, { /// Create a new instance of the DS3232 device. pub fn new_ds3232(i2c: I2C) -> Self { diff --git a/src/ds3234.rs b/src/ds3234.rs index c5f0dfd..3147dec 100644 --- a/src/ds3234.rs +++ b/src/ds3234.rs @@ -2,11 +2,11 @@ use crate::interface::{SpiInterface, WriteData}; use crate::{ic, BitFlags, Ds323x, Error, Register, TempConvRate, CONTROL_POR_VALUE}; use core::marker::PhantomData; -use embedded_hal::{blocking::spi, digital::v2::OutputPin}; +use embedded_hal::{spi, digital::OutputPin}; impl Ds323x, ic::DS3234> where - SPI: spi::Transfer + spi::Write, + SPI: spi::SpiDevice, CS: OutputPin, { /// Create a new instance. diff --git a/src/interface.rs b/src/interface.rs index dc588e8..f097b92 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -2,8 +2,8 @@ use crate::{private, Error, DEVICE_ADDRESS}; use embedded_hal::{ - blocking::{i2c, spi}, - digital::v2::OutputPin, + i2c, spi, + digital::OutputPin, }; /// I2C interface @@ -31,7 +31,7 @@ pub trait WriteData: private::Sealed { impl WriteData for I2cInterface where - I2C: i2c::Write, + I2C: i2c::I2c, { type Error = Error; fn write_register(&mut self, register: u8, data: u8) -> Result<(), Self::Error> { @@ -48,7 +48,7 @@ where impl WriteData for SpiInterface where - SPI: spi::Write, + SPI: spi::SpiDevice, CS: OutputPin, { type Error = Error; @@ -84,7 +84,7 @@ pub trait ReadData: private::Sealed { impl ReadData for I2cInterface where - I2C: i2c::WriteRead, + I2C: i2c::I2c, { type Error = Error; fn read_register(&mut self, register: u8) -> Result { @@ -105,23 +105,22 @@ where impl ReadData for SpiInterface where - SPI: spi::Transfer, + SPI: spi::SpiDevice, CS: OutputPin, { type Error = Error; fn read_register(&mut self, register: u8) -> Result { self.cs.set_low().map_err(Error::Pin)?; let mut data = [register, 0]; - let result = self.spi.transfer(&mut data).map_err(Error::Comm); + let result = self.spi.transfer_in_place(&mut data).map_err(Error::Comm); self.cs.set_high().map_err(Error::Pin)?; - Ok(result?[1]) + result.and(Ok(data[1])) } fn read_data(&mut self, payload: &mut [u8]) -> Result<(), Self::Error> { self.cs.set_low().map_err(Error::Pin)?; - let result = self.spi.transfer(payload).map_err(Error::Comm); + let result = self.spi.transfer(payload, &[]).map_err(Error::Comm); self.cs.set_high().map_err(Error::Pin)?; - result?; - Ok(()) + result } } diff --git a/tests/alarms.rs b/tests/alarms.rs index 73224fe..11106f6 100644 --- a/tests/alarms.rs +++ b/tests/alarms.rs @@ -1,4 +1,4 @@ -use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; +use embedded_hal_mock::eh1::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; mod common; use self::common::{ destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234, @@ -583,7 +583,7 @@ macro_rules! set_alarm_test { ($name:ident, $method:ident, $register:ident, [ $( $registers:expr ),+ ], $( $value:expr ),+) => { set_values_test!($name, $method, [ I2cTrans::write(DEV_ADDR, vec![Register::$register, $( $registers ),*]) ], - [ SpiTrans::write(vec![Register::$register + 0x80, $( $registers ),*]) ], + [ SpiTrans::write_vec(vec![Register::$register + 0x80, $( $registers ),*]) ], $($value),* ); }; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 5a4f31a..7e9476c 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,5 +1,5 @@ use ds323x::{ic, interface, Ds323x}; -use embedded_hal_mock::{ +use embedded_hal_mock::eh1::{ i2c::{Mock as I2cMock, Transaction as I2cTrans}, spi::{Mock as SpiMock, Transaction as SpiTrans}, }; @@ -59,8 +59,7 @@ impl BitFlags { pub struct DummyOutputPin; -impl embedded_hal::digital::v2::OutputPin for DummyOutputPin { - type Error = (); +impl embedded_hal::digital::OutputPin for DummyOutputPin { fn set_low(&mut self) -> Result<(), Self::Error> { Ok(()) } @@ -69,6 +68,10 @@ impl embedded_hal::digital::v2::OutputPin for DummyOutputPin { } } +impl embedded_hal::digital::ErrorType for DummyOutputPin { + type Error = embedded_hal::digital::ErrorKind; +} + pub fn new_ds3231( transactions: &[I2cTrans], ) -> Ds323x, ic::DS3231> { @@ -82,8 +85,8 @@ pub fn new_ds3232( } pub fn new_ds3234( - transactions: &[SpiTrans], -) -> Ds323x, ic::DS3234> { + transactions: &[SpiTrans], +) -> Ds323x, DummyOutputPin>, ic::DS3234> { Ds323x::new_ds3234(SpiMock::new(transactions), DummyOutputPin) } @@ -95,7 +98,7 @@ pub fn destroy_ds3232(dev: Ds323x, ic::DS3232>) dev.destroy_ds3232().done(); } -pub fn destroy_ds3234(dev: Ds323x, ic::DS3234>) { +pub fn destroy_ds3234(dev: Ds323x, DummyOutputPin>, ic::DS3234>) { dev.destroy_ds3234().0.done(); } @@ -280,7 +283,7 @@ macro_rules! set_param_test { DEV_ADDR, vec![Register::$register, $binary_value] )], - [SpiTrans::write(vec![ + [SpiTrans::write_vec(vec![ Register::$register + 0x80, $binary_value ])] diff --git a/tests/configuration.rs b/tests/configuration.rs index 59ed9cd..e8762d2 100644 --- a/tests/configuration.rs +++ b/tests/configuration.rs @@ -1,5 +1,5 @@ use ds323x::SqWFreq; -use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; +use embedded_hal_mock::eh1::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; mod common; use self::common::{ @@ -46,7 +46,7 @@ macro_rules! call_method_test { DEV_ADDR, vec![Register::$register, $value_enabled] )], - [SpiTrans::write(vec![ + [SpiTrans::write_vec(vec![ Register::$register + 0x80, $value_enabled ])] @@ -83,7 +83,7 @@ macro_rules! call_method_status_test { $method, new_ds3234, destroy_ds3234, - [SpiTrans::write(vec![ + [SpiTrans::write_vec(vec![ Register::STATUS + 0x80, $value_ds323x ])] @@ -126,7 +126,7 @@ macro_rules! change_if_necessary_test { vec![Register::$register, 0], vec![Register::$register, $value_disabled] ), - SpiTrans::write(vec![Register::$register + 0x80, $value_enabled]) + SpiTrans::write_vec(vec![Register::$register + 0x80, $value_enabled]) ] ); } diff --git a/tests/datetime.rs b/tests/datetime.rs index 7012575..744d8b8 100644 --- a/tests/datetime.rs +++ b/tests/datetime.rs @@ -1,4 +1,4 @@ -use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; +use embedded_hal_mock::eh1::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; use rtcc::NaiveDateTime; mod common; use self::common::{ @@ -39,7 +39,7 @@ macro_rules! read_set_param_write_two_test { vec![Register::$register, 0], vec![Register::$register, $binary_value1_read] ), - SpiTrans::write(vec![Register::$register + 0x80, $bin1, $bin2]) + SpiTrans::write_vec(vec![Register::$register + 0x80, $bin1, $bin2]) ] ); }; @@ -64,7 +64,7 @@ macro_rules! read_set_param_test { vec![Register::$register, 0], vec![Register::$register, $binary_value_read] ), - SpiTrans::write(vec![Register::$register + 0x80, $binary_value_write]) + SpiTrans::write_vec(vec![Register::$register + 0x80, $binary_value_write]) ] ); }; @@ -256,7 +256,7 @@ macro_rules! transactions_i2c_write { macro_rules! transactions_spi_write { ($register:ident, [ $( $exp_bin:expr ),+ ]) => { - [ SpiTrans::write(vec![Register::$register + 0x80, $( $exp_bin ),*]) ] + [ SpiTrans::write_vec(vec![Register::$register + 0x80, $( $exp_bin ),*]) ] }; } diff --git a/tests/ds3232_4.rs b/tests/ds3232_4.rs index e368a8d..d6f564e 100644 --- a/tests/ds3232_4.rs +++ b/tests/ds3232_4.rs @@ -1,5 +1,5 @@ use ds323x::TempConvRate; -use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; +use embedded_hal_mock::eh1::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; #[allow(unused)] mod common; @@ -24,7 +24,7 @@ macro_rules! call_method_status_test { $method, new_ds3234, destroy_ds3234, - [SpiTrans::write(vec![Register::STATUS + 0x80, $value])] + [SpiTrans::write_vec(vec![Register::STATUS + 0x80, $value])] ); } }; @@ -66,7 +66,7 @@ macro_rules! set_param_test_2_4 { DEV_ADDR, vec![Register::$register, $binary_value] )], - [SpiTrans::write(vec![ + [SpiTrans::write_vec(vec![ Register::$register + 0x80, $binary_value ])] diff --git a/tests/ds3234.rs b/tests/ds3234.rs index e937caf..3c3801d 100644 --- a/tests/ds3234.rs +++ b/tests/ds3234.rs @@ -1,4 +1,4 @@ -use embedded_hal_mock::spi::Transaction as SpiTrans; +use embedded_hal_mock::eh1::spi::Transaction as SpiTrans; #[allow(unused)] mod common; @@ -9,7 +9,7 @@ call_test!( enable_temperature_conversions_on_battery, new_ds3234, destroy_ds3234, - [SpiTrans::write(vec![Register::TEMP_CONV + 0x80, 0])] + [SpiTrans::write_vec(vec![Register::TEMP_CONV + 0x80, 0])] ); call_test!( @@ -17,7 +17,7 @@ call_test!( disable_temperature_conversions_on_battery, new_ds3234, destroy_ds3234, - [SpiTrans::write(vec![ + [SpiTrans::write_vec(vec![ Register::TEMP_CONV + 0x80, BitFlags::TEMP_CONV_BAT ])] diff --git a/tests/status.rs b/tests/status.rs index b8e5b67..8b05c30 100644 --- a/tests/status.rs +++ b/tests/status.rs @@ -1,4 +1,4 @@ -use embedded_hal_mock::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; +use embedded_hal_mock::eh1::{i2c::Transaction as I2cTrans, spi::Transaction as SpiTrans}; mod common; use self::common::{ destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234,