mirror of https://github.com/eldruin/ds323x-rs
Add support for reading busy status
parent
75c2988fa4
commit
0ad4a4e585
|
@ -1,3 +1,4 @@
|
||||||
mod configuration;
|
mod configuration;
|
||||||
|
mod status;
|
||||||
mod datetime;
|
mod datetime;
|
||||||
pub use self::datetime::{ Hours, DateTime };
|
pub use self::datetime::{ Hours, DateTime };
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
//! Device configuration
|
||||||
|
|
||||||
|
extern crate embedded_hal as hal;
|
||||||
|
use super::super::{ Ds323x, Register, BitFlags, Error };
|
||||||
|
use interface::{ ReadData, WriteData };
|
||||||
|
|
||||||
|
impl<DI, IC, E> Ds323x<DI, IC>
|
||||||
|
where
|
||||||
|
DI: ReadData<Error = E> + WriteData<Error = E>
|
||||||
|
{
|
||||||
|
/// Read busy status.
|
||||||
|
pub fn is_busy(&mut self) -> Result<bool, Error<E>> {
|
||||||
|
let status = self.iface.read_register(Register::STATUS)?;
|
||||||
|
Ok((status & BitFlags::BUSY) != 0)
|
||||||
|
}
|
||||||
|
}
|
|
@ -285,6 +285,7 @@ impl Register {
|
||||||
const MONTH : u8 = 0x05;
|
const MONTH : u8 = 0x05;
|
||||||
const YEAR : u8 = 0x06;
|
const YEAR : u8 = 0x06;
|
||||||
const CONTROL : u8 = 0x0E;
|
const CONTROL : u8 = 0x0E;
|
||||||
|
const STATUS : u8 = 0x0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BitFlags;
|
struct BitFlags;
|
||||||
|
@ -294,6 +295,7 @@ impl BitFlags {
|
||||||
const AM_PM : u8 = 0b0010_0000;
|
const AM_PM : u8 = 0b0010_0000;
|
||||||
const CENTURY : u8 = 0b1000_0000;
|
const CENTURY : u8 = 0b1000_0000;
|
||||||
const EOSC : u8 = 0b1000_0000;
|
const EOSC : u8 = 0b1000_0000;
|
||||||
|
const BUSY : u8 = 0b0000_0100;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEVICE_ADDRESS: u8 = 0b110_1000;
|
const DEVICE_ADDRESS: u8 = 0b110_1000;
|
||||||
|
|
|
@ -17,6 +17,7 @@ impl Register {
|
||||||
pub const DOM : u8 = 0x04;
|
pub const DOM : u8 = 0x04;
|
||||||
pub const MONTH : u8 = 0x05;
|
pub const MONTH : u8 = 0x05;
|
||||||
pub const CONTROL : u8 = 0x0E;
|
pub const CONTROL : u8 = 0x0E;
|
||||||
|
pub const STATUS : u8 = 0x0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BitFlags;
|
pub struct BitFlags;
|
||||||
|
@ -24,6 +25,7 @@ pub struct BitFlags;
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
impl BitFlags {
|
impl BitFlags {
|
||||||
pub const EOSC : u8 = 0b1000_0000;
|
pub const EOSC : u8 = 0b1000_0000;
|
||||||
|
pub const BUSY : u8 = 0b0000_0100;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DummyOutputPin;
|
pub struct DummyOutputPin;
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#[deny(warnings)]
|
||||||
|
|
||||||
|
extern crate embedded_hal_mock as hal;
|
||||||
|
use hal::i2c::Transaction as I2cTrans;
|
||||||
|
use hal::spi::Transaction as SpiTrans;
|
||||||
|
mod common;
|
||||||
|
use common::{ DEVICE_ADDRESS as DEV_ADDR, Register, new_ds3231,
|
||||||
|
new_ds3232, new_ds3234, destroy_ds3231, destroy_ds3232,
|
||||||
|
destroy_ds3234, BitFlags as BF };
|
||||||
|
|
||||||
|
get_param_test!(is_busy, is_busy, STATUS, true, 0xFF);
|
||||||
|
get_param_test!(is_not_busy, is_busy, STATUS, false, 0xFF & !BF::BUSY);
|
Loading…
Reference in New Issue