mirror of https://github.com/eldruin/ds323x-rs
Update dependencies
parent
fa43172087
commit
c395fa7f38
|
@ -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
|
||||
|
|
|
@ -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<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3231>
|
||||
where
|
||||
I2C: i2c::Write<Error = E> + i2c::WriteRead<Error = E>,
|
||||
I2C: i2c::I2c<Error = E>,
|
||||
{
|
||||
/// Create a new instance of the DS3231 device.
|
||||
pub fn new_ds3231(i2c: I2C) -> Self {
|
||||
|
|
|
@ -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<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3232>
|
||||
where
|
||||
I2C: i2c::Write<Error = E> + i2c::WriteRead<Error = E>,
|
||||
I2C: i2c::I2c<Error = E>,
|
||||
{
|
||||
/// Create a new instance of the DS3232 device.
|
||||
pub fn new_ds3232(i2c: I2C) -> Self {
|
||||
|
|
|
@ -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<SPI, CS, CommE, PinE> Ds323x<SpiInterface<SPI, CS>, ic::DS3234>
|
||||
where
|
||||
SPI: spi::Transfer<u8, Error = CommE> + spi::Write<u8, Error = CommE>,
|
||||
SPI: spi::SpiDevice<u8, Error = CommE>,
|
||||
CS: OutputPin<Error = PinE>,
|
||||
{
|
||||
/// Create a new instance.
|
||||
|
|
|
@ -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<I2C, E> WriteData for I2cInterface<I2C>
|
||||
where
|
||||
I2C: i2c::Write<Error = E>,
|
||||
I2C: i2c::I2c<Error = E>,
|
||||
{
|
||||
type Error = Error<E, ()>;
|
||||
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>
|
||||
where
|
||||
SPI: spi::Write<u8, Error = CommE>,
|
||||
SPI: spi::SpiDevice<u8, Error = CommE>,
|
||||
CS: OutputPin<Error = PinE>,
|
||||
{
|
||||
type Error = Error<CommE, PinE>;
|
||||
|
@ -84,7 +84,7 @@ pub trait ReadData: private::Sealed {
|
|||
|
||||
impl<I2C, E> ReadData for I2cInterface<I2C>
|
||||
where
|
||||
I2C: i2c::WriteRead<Error = E>,
|
||||
I2C: i2c::I2c<Error = E>,
|
||||
{
|
||||
type Error = Error<E, ()>;
|
||||
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>
|
||||
where
|
||||
SPI: spi::Transfer<u8, Error = CommE>,
|
||||
SPI: spi::SpiDevice<u8, Error = CommE>,
|
||||
CS: OutputPin<Error = PinE>,
|
||||
{
|
||||
type Error = Error<CommE, PinE>;
|
||||
fn read_register(&mut self, register: u8) -> Result<u8, Self::Error> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),*
|
||||
);
|
||||
};
|
||||
|
|
|
@ -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<interface::I2cInterface<I2cMock>, ic::DS3231> {
|
||||
|
@ -82,8 +85,8 @@ pub fn new_ds3232(
|
|||
}
|
||||
|
||||
pub fn new_ds3234(
|
||||
transactions: &[SpiTrans],
|
||||
) -> Ds323x<interface::SpiInterface<SpiMock, DummyOutputPin>, ic::DS3234> {
|
||||
transactions: &[SpiTrans<u8>],
|
||||
) -> Ds323x<interface::SpiInterface<SpiMock<u8>, DummyOutputPin>, ic::DS3234> {
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
])]
|
||||
|
|
|
@ -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])
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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 ),*]) ]
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
])]
|
||||
|
|
|
@ -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
|
||||
])]
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue