2018-10-28 19:17:36 +00:00
|
|
|
#[deny(warnings)]
|
|
|
|
|
|
|
|
extern crate embedded_hal_mock as hal;
|
|
|
|
use hal::i2c::Transaction as I2cTrans;
|
|
|
|
use hal::spi::Transaction as SpiTrans;
|
|
|
|
mod common;
|
2018-10-29 17:09:02 +00:00
|
|
|
use common::{ DEVICE_ADDRESS as DEV_ADDR, Register, new_ds3231,
|
|
|
|
new_ds3232, new_ds3234, destroy_ds3231, destroy_ds3232,
|
|
|
|
destroy_ds3234, BitFlags as BF };
|
2018-10-28 19:17:36 +00:00
|
|
|
|
|
|
|
macro_rules! call_method_test {
|
2018-10-29 17:09:02 +00:00
|
|
|
($name:ident, $method:ident, $i2c_transactions:expr, $spi_transactions:expr) => {
|
|
|
|
mod $name {
|
|
|
|
use super::*;
|
|
|
|
call_test!(can_call_ds3231, $method, new_ds3231, destroy_ds3231, $i2c_transactions);
|
|
|
|
call_test!(can_call_ds3232, $method, new_ds3232, destroy_ds3232, $i2c_transactions);
|
|
|
|
call_test!(can_call_ds3234, $method, new_ds3234, destroy_ds3234, $spi_transactions);
|
|
|
|
}
|
2018-10-28 19:17:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-29 17:09:02 +00:00
|
|
|
macro_rules! change_if_necessary_test {
|
|
|
|
($name:ident, $method:ident, $register:ident, $value_enabled:expr, $value_disabled:expr) => {
|
|
|
|
mod $name {
|
|
|
|
use super::*;
|
|
|
|
call_method_test!(do_nothing_if_not_necessary, $method,
|
|
|
|
[ I2cTrans::write_read(DEV_ADDR, vec![Register::$register], vec![$value_enabled]) ],
|
|
|
|
[ SpiTrans::transfer(vec![Register::$register, 0], vec![Register::$register, $value_enabled]) ]);
|
|
|
|
|
|
|
|
call_method_test!(change, $method,
|
|
|
|
[ I2cTrans::write_read(DEV_ADDR, vec![Register::$register], vec![$value_disabled]),
|
|
|
|
I2cTrans::write(DEV_ADDR, vec![Register::$register, $value_enabled]) ],
|
|
|
|
|
|
|
|
[ SpiTrans::transfer(vec![Register::$register, 0], vec![Register::$register, $value_disabled]),
|
|
|
|
SpiTrans::write(vec![Register::$register + 0x80, $value_enabled]) ]);
|
|
|
|
}
|
|
|
|
};
|
2018-10-28 19:17:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 17:09:02 +00:00
|
|
|
change_if_necessary_test!(enable, enable, CONTROL, 0xFF & !BF::EOSC, 0xFF);
|
|
|
|
change_if_necessary_test!(disable, disable, CONTROL, 0xFF, 0xFF & !BF::EOSC);
|
2018-10-29 17:22:44 +00:00
|
|
|
change_if_necessary_test!(clr_stop, clear_has_been_stopped_flag, STATUS, 0xFF & !BF::OSC_STOP, 0xFF);
|
2018-10-28 19:17:36 +00:00
|
|
|
|