Update dependencies

pull/10/head
Louis Dupré Bertoni 2024-07-17 13:42:33 +03:00
parent fa43172087
commit c395fa7f38
12 changed files with 46 additions and 44 deletions

View File

@ -21,12 +21,12 @@ include = [
edition = "2018" edition = "2018"
[dependencies] [dependencies]
embedded-hal = "0.2.7" embedded-hal = "1.0.0"
rtcc = "0.3" rtcc = "0.3"
[dev-dependencies] [dev-dependencies]
embedded-hal-mock = "0.9.0" embedded-hal-mock = { version = "0.11.0", features = ["eh1"] }
linux-embedded-hal = "0.3.2" linux-embedded-hal = "0.4.0"
[profile.release] [profile.release]
lto = true lto = true

View File

@ -2,11 +2,11 @@
use crate::{ic, interface::I2cInterface, BitFlags, Ds323x, CONTROL_POR_VALUE}; use crate::{ic, interface::I2cInterface, BitFlags, Ds323x, CONTROL_POR_VALUE};
use core::marker::PhantomData; use core::marker::PhantomData;
use embedded_hal::blocking::i2c; use embedded_hal::i2c;
impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3231> impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3231>
where where
I2C: i2c::Write<Error = E> + i2c::WriteRead<Error = E>, I2C: i2c::I2c<Error = E>,
{ {
/// Create a new instance of the DS3231 device. /// Create a new instance of the DS3231 device.
pub fn new_ds3231(i2c: I2C) -> Self { pub fn new_ds3231(i2c: I2C) -> Self {

View File

@ -4,11 +4,11 @@ use crate::{
ic, interface::I2cInterface, BitFlags, Ds323x, Error, TempConvRate, CONTROL_POR_VALUE, ic, interface::I2cInterface, BitFlags, Ds323x, Error, TempConvRate, CONTROL_POR_VALUE,
}; };
use core::marker::PhantomData; use core::marker::PhantomData;
use embedded_hal::blocking::i2c; use embedded_hal::i2c;
impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3232> impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3232>
where where
I2C: i2c::Write<Error = E> + i2c::WriteRead<Error = E>, I2C: i2c::I2c<Error = E>,
{ {
/// Create a new instance of the DS3232 device. /// Create a new instance of the DS3232 device.
pub fn new_ds3232(i2c: I2C) -> Self { pub fn new_ds3232(i2c: I2C) -> Self {

View File

@ -2,11 +2,11 @@
use crate::interface::{SpiInterface, WriteData}; use crate::interface::{SpiInterface, WriteData};
use crate::{ic, BitFlags, Ds323x, Error, Register, TempConvRate, CONTROL_POR_VALUE}; use crate::{ic, BitFlags, Ds323x, Error, Register, TempConvRate, CONTROL_POR_VALUE};
use core::marker::PhantomData; use core::marker::PhantomData;
use embedded_hal::{blocking::spi, digital::v2::OutputPin}; use embedded_hal::{spi, digital::OutputPin};
impl<SPI, CS, CommE, PinE> Ds323x<SpiInterface<SPI, CS>, ic::DS3234> impl<SPI, CS, CommE, PinE> Ds323x<SpiInterface<SPI, CS>, ic::DS3234>
where where
SPI: spi::Transfer<u8, Error = CommE> + spi::Write<u8, Error = CommE>, SPI: spi::SpiDevice<u8, Error = CommE>,
CS: OutputPin<Error = PinE>, CS: OutputPin<Error = PinE>,
{ {
/// Create a new instance. /// Create a new instance.

View File

@ -2,8 +2,8 @@
use crate::{private, Error, DEVICE_ADDRESS}; use crate::{private, Error, DEVICE_ADDRESS};
use embedded_hal::{ use embedded_hal::{
blocking::{i2c, spi}, i2c, spi,
digital::v2::OutputPin, digital::OutputPin,
}; };
/// I2C interface /// I2C interface
@ -31,7 +31,7 @@ pub trait WriteData: private::Sealed {
impl<I2C, E> WriteData for I2cInterface<I2C> impl<I2C, E> WriteData for I2cInterface<I2C>
where where
I2C: i2c::Write<Error = E>, I2C: i2c::I2c<Error = E>,
{ {
type Error = Error<E, ()>; type Error = Error<E, ()>;
fn write_register(&mut self, register: u8, data: u8) -> Result<(), Self::Error> { fn write_register(&mut self, register: u8, data: u8) -> Result<(), Self::Error> {
@ -48,7 +48,7 @@ where
impl<SPI, CS, CommE, PinE> WriteData for SpiInterface<SPI, CS> impl<SPI, CS, CommE, PinE> WriteData for SpiInterface<SPI, CS>
where where
SPI: spi::Write<u8, Error = CommE>, SPI: spi::SpiDevice<u8, Error = CommE>,
CS: OutputPin<Error = PinE>, CS: OutputPin<Error = PinE>,
{ {
type Error = Error<CommE, PinE>; type Error = Error<CommE, PinE>;
@ -84,7 +84,7 @@ pub trait ReadData: private::Sealed {
impl<I2C, E> ReadData for I2cInterface<I2C> impl<I2C, E> ReadData for I2cInterface<I2C>
where where
I2C: i2c::WriteRead<Error = E>, I2C: i2c::I2c<Error = E>,
{ {
type Error = Error<E, ()>; type Error = Error<E, ()>;
fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> { fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> {
@ -105,23 +105,22 @@ where
impl<SPI, CS, CommE, PinE> ReadData for SpiInterface<SPI, CS> impl<SPI, CS, CommE, PinE> ReadData for SpiInterface<SPI, CS>
where where
SPI: spi::Transfer<u8, Error = CommE>, SPI: spi::SpiDevice<u8, Error = CommE>,
CS: OutputPin<Error = PinE>, CS: OutputPin<Error = PinE>,
{ {
type Error = Error<CommE, PinE>; type Error = Error<CommE, PinE>;
fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> { fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> {
self.cs.set_low().map_err(Error::Pin)?; self.cs.set_low().map_err(Error::Pin)?;
let mut data = [register, 0]; 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)?; 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> { fn read_data(&mut self, payload: &mut [u8]) -> Result<(), Self::Error> {
self.cs.set_low().map_err(Error::Pin)?; 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)?; self.cs.set_high().map_err(Error::Pin)?;
result?; result
Ok(())
} }
} }

View File

@ -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; mod common;
use self::common::{ use self::common::{
destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234, 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 ),+) => { ($name:ident, $method:ident, $register:ident, [ $( $registers:expr ),+ ], $( $value:expr ),+) => {
set_values_test!($name, $method, set_values_test!($name, $method,
[ I2cTrans::write(DEV_ADDR, vec![Register::$register, $( $registers ),*]) ], [ I2cTrans::write(DEV_ADDR, vec![Register::$register, $( $registers ),*]) ],
[ SpiTrans::write(vec![Register::$register + 0x80, $( $registers ),*]) ], [ SpiTrans::write_vec(vec![Register::$register + 0x80, $( $registers ),*]) ],
$($value),* $($value),*
); );
}; };

View File

@ -1,5 +1,5 @@
use ds323x::{ic, interface, Ds323x}; use ds323x::{ic, interface, Ds323x};
use embedded_hal_mock::{ use embedded_hal_mock::eh1::{
i2c::{Mock as I2cMock, Transaction as I2cTrans}, i2c::{Mock as I2cMock, Transaction as I2cTrans},
spi::{Mock as SpiMock, Transaction as SpiTrans}, spi::{Mock as SpiMock, Transaction as SpiTrans},
}; };
@ -59,8 +59,7 @@ impl BitFlags {
pub struct DummyOutputPin; pub struct DummyOutputPin;
impl embedded_hal::digital::v2::OutputPin for DummyOutputPin { impl embedded_hal::digital::OutputPin for DummyOutputPin {
type Error = ();
fn set_low(&mut self) -> Result<(), Self::Error> { fn set_low(&mut self) -> Result<(), Self::Error> {
Ok(()) 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( pub fn new_ds3231(
transactions: &[I2cTrans], transactions: &[I2cTrans],
) -> Ds323x<interface::I2cInterface<I2cMock>, ic::DS3231> { ) -> Ds323x<interface::I2cInterface<I2cMock>, ic::DS3231> {
@ -82,8 +85,8 @@ pub fn new_ds3232(
} }
pub fn new_ds3234( pub fn new_ds3234(
transactions: &[SpiTrans], transactions: &[SpiTrans<u8>],
) -> Ds323x<interface::SpiInterface<SpiMock, DummyOutputPin>, ic::DS3234> { ) -> Ds323x<interface::SpiInterface<SpiMock<u8>, DummyOutputPin>, ic::DS3234> {
Ds323x::new_ds3234(SpiMock::new(transactions), DummyOutputPin) Ds323x::new_ds3234(SpiMock::new(transactions), DummyOutputPin)
} }
@ -95,7 +98,7 @@ pub fn destroy_ds3232(dev: Ds323x<interface::I2cInterface<I2cMock>, ic::DS3232>)
dev.destroy_ds3232().done(); dev.destroy_ds3232().done();
} }
pub fn destroy_ds3234(dev: Ds323x<interface::SpiInterface<SpiMock, DummyOutputPin>, ic::DS3234>) { pub fn destroy_ds3234(dev: Ds323x<interface::SpiInterface<SpiMock<u8>, DummyOutputPin>, ic::DS3234>) {
dev.destroy_ds3234().0.done(); dev.destroy_ds3234().0.done();
} }
@ -280,7 +283,7 @@ macro_rules! set_param_test {
DEV_ADDR, DEV_ADDR,
vec![Register::$register, $binary_value] vec![Register::$register, $binary_value]
)], )],
[SpiTrans::write(vec![ [SpiTrans::write_vec(vec![
Register::$register + 0x80, Register::$register + 0x80,
$binary_value $binary_value
])] ])]

View File

@ -1,5 +1,5 @@
use ds323x::SqWFreq; 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; mod common;
use self::common::{ use self::common::{
@ -46,7 +46,7 @@ macro_rules! call_method_test {
DEV_ADDR, DEV_ADDR,
vec![Register::$register, $value_enabled] vec![Register::$register, $value_enabled]
)], )],
[SpiTrans::write(vec![ [SpiTrans::write_vec(vec![
Register::$register + 0x80, Register::$register + 0x80,
$value_enabled $value_enabled
])] ])]
@ -83,7 +83,7 @@ macro_rules! call_method_status_test {
$method, $method,
new_ds3234, new_ds3234,
destroy_ds3234, destroy_ds3234,
[SpiTrans::write(vec![ [SpiTrans::write_vec(vec![
Register::STATUS + 0x80, Register::STATUS + 0x80,
$value_ds323x $value_ds323x
])] ])]
@ -126,7 +126,7 @@ macro_rules! change_if_necessary_test {
vec![Register::$register, 0], vec![Register::$register, 0],
vec![Register::$register, $value_disabled] vec![Register::$register, $value_disabled]
), ),
SpiTrans::write(vec![Register::$register + 0x80, $value_enabled]) SpiTrans::write_vec(vec![Register::$register + 0x80, $value_enabled])
] ]
); );
} }

View File

@ -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; use rtcc::NaiveDateTime;
mod common; mod common;
use self::common::{ use self::common::{
@ -39,7 +39,7 @@ macro_rules! read_set_param_write_two_test {
vec![Register::$register, 0], vec![Register::$register, 0],
vec![Register::$register, $binary_value1_read] 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, 0],
vec![Register::$register, $binary_value_read] 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 { macro_rules! transactions_spi_write {
($register:ident, [ $( $exp_bin:expr ),+ ]) => { ($register:ident, [ $( $exp_bin:expr ),+ ]) => {
[ SpiTrans::write(vec![Register::$register + 0x80, $( $exp_bin ),*]) ] [ SpiTrans::write_vec(vec![Register::$register + 0x80, $( $exp_bin ),*]) ]
}; };
} }

View File

@ -1,5 +1,5 @@
use ds323x::TempConvRate; 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)] #[allow(unused)]
mod common; mod common;
@ -24,7 +24,7 @@ macro_rules! call_method_status_test {
$method, $method,
new_ds3234, new_ds3234,
destroy_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, DEV_ADDR,
vec![Register::$register, $binary_value] vec![Register::$register, $binary_value]
)], )],
[SpiTrans::write(vec![ [SpiTrans::write_vec(vec![
Register::$register + 0x80, Register::$register + 0x80,
$binary_value $binary_value
])] ])]

View File

@ -1,4 +1,4 @@
use embedded_hal_mock::spi::Transaction as SpiTrans; use embedded_hal_mock::eh1::spi::Transaction as SpiTrans;
#[allow(unused)] #[allow(unused)]
mod common; mod common;
@ -9,7 +9,7 @@ call_test!(
enable_temperature_conversions_on_battery, enable_temperature_conversions_on_battery,
new_ds3234, new_ds3234,
destroy_ds3234, destroy_ds3234,
[SpiTrans::write(vec![Register::TEMP_CONV + 0x80, 0])] [SpiTrans::write_vec(vec![Register::TEMP_CONV + 0x80, 0])]
); );
call_test!( call_test!(
@ -17,7 +17,7 @@ call_test!(
disable_temperature_conversions_on_battery, disable_temperature_conversions_on_battery,
new_ds3234, new_ds3234,
destroy_ds3234, destroy_ds3234,
[SpiTrans::write(vec![ [SpiTrans::write_vec(vec![
Register::TEMP_CONV + 0x80, Register::TEMP_CONV + 0x80,
BitFlags::TEMP_CONV_BAT BitFlags::TEMP_CONV_BAT
])] ])]

View File

@ -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; mod common;
use self::common::{ use self::common::{
destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234, destroy_ds3231, destroy_ds3232, destroy_ds3234, new_ds3231, new_ds3232, new_ds3234,