Add functions to enable/disable the 32kHz output when battery-powered
parent
8bea870813
commit
4361e87645
@ -0,0 +1,33 @@
|
||||
//! Functions exclusive of DS3232
|
||||
|
||||
extern crate embedded_hal as hal;
|
||||
use hal::blocking;
|
||||
use super::{ Ds323x, BitFlags, Error, ic };
|
||||
use interface::I2cInterface;
|
||||
|
||||
impl<I2C, E> Ds323x<I2cInterface<I2C>, ic::DS3232>
|
||||
where
|
||||
I2C: blocking::i2c::Write<Error = E> + blocking::i2c::WriteRead<Error = E>
|
||||
{
|
||||
/// Enable the 32kHz output when battery-powered.
|
||||
///
|
||||
/// Additionally, the 32kHz output needs to be enabled. See
|
||||
/// [`enable_32khz_output`](#method.enable_32khz_output).
|
||||
///
|
||||
/// Note: This is only available for DS3232 and DS3234 devices.
|
||||
pub fn enable_32khz_output_on_battery(&mut self) -> Result<(), Error<E>> {
|
||||
let status = self.status | BitFlags::BB32KHZ;
|
||||
self.write_status_without_clearing_alarm(status)
|
||||
}
|
||||
|
||||
/// Disable the 32kHz output when battery-powered.
|
||||
///
|
||||
/// The 32kHz output will still generate a wave when not battery-powered if
|
||||
/// it enabled. See [`enable_32khz_output`](#method.enable_32khz_output).
|
||||
///
|
||||
/// Note: This is only available for DS3232 and DS3234 devices.
|
||||
pub fn disable_32khz_output_on_battery(&mut self) -> Result<(), Error<E>> {
|
||||
let status = self.status & !BitFlags::BB32KHZ;
|
||||
self.write_status_without_clearing_alarm(status)
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
//! Functions exclusive of DS3234
|
||||
|
||||
extern crate embedded_hal as hal;
|
||||
use hal::blocking;
|
||||
use super::{ Ds323x, BitFlags, Error, ic };
|
||||
use interface::SpiInterface;
|
||||
|
||||
impl<SPI, CS, E> Ds323x<SpiInterface<SPI, CS>, ic::DS3234>
|
||||
where
|
||||
SPI: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>,
|
||||
CS: hal::digital::OutputPin
|
||||
{
|
||||
/// Enable the 32kHz output when battery-powered.
|
||||
///
|
||||
/// Additionally, the 32kHz output needs to be enabled. See
|
||||
/// [`enable_32khz_output`](#method.enable_32khz_output).
|
||||
///
|
||||
/// Note: This is only available for DS3232 and DS3234 devices.
|
||||
pub fn enable_32khz_output_on_battery(&mut self) -> Result<(), Error<E>> {
|
||||
let status = self.status | BitFlags::BB32KHZ;
|
||||
self.write_status_without_clearing_alarm(status)
|
||||
}
|
||||
|
||||
/// Disable the 32kHz output when battery-powered.
|
||||
///
|
||||
/// The 32kHz output will still generate a wave when not battery-powered if
|
||||
/// it enabled. See [`enable_32khz_output`](#method.enable_32khz_output).
|
||||
///
|
||||
/// Note: This is only available for DS3232 and DS3234 devices.
|
||||
pub fn disable_32khz_output_on_battery(&mut self) -> Result<(), Error<E>> {
|
||||
let status = self.status & !BitFlags::BB32KHZ;
|
||||
self.write_status_without_clearing_alarm(status)
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#[deny(warnings)]
|
||||
|
||||
extern crate embedded_hal_mock as hal;
|
||||
extern crate ds323x;
|
||||
use ds323x::Ds323x;
|
||||
|
||||
#[test]
|
||||
fn can_create_and_destroy() {
|
||||
let dev = Ds323x::new_ds3232(hal::i2c::Mock::new(&[]));
|
||||
let mut i2c = dev.destroy_ds3232();
|
||||
i2c.done();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
#[deny(warnings)]
|
||||
|
||||
extern crate embedded_hal_mock as hal;
|
||||
use hal::i2c::Transaction as I2cTrans;
|
||||
use hal::spi::Transaction as SpiTrans;
|
||||
|
||||
#[allow(unused)]
|
||||
mod common;
|
||||
use common::{ DEVICE_ADDRESS as DEV_ADDR, Register,
|
||||
new_ds3232, new_ds3234, destroy_ds3232,
|
||||
destroy_ds3234, BitFlags as BF, DS323X_POR_STATUS };
|
||||
|
||||
macro_rules! call_method_status_test {
|
||||
($name:ident, $method:ident, $value:expr) => {
|
||||
mod $name {
|
||||
use super::*;
|
||||
call_test!(can_call_ds3232, $method, new_ds3232, destroy_ds3232,
|
||||
[ I2cTrans::write(DEV_ADDR, vec![Register::STATUS, $value]) ]);
|
||||
call_test!(can_call_ds3234, $method, new_ds3234, destroy_ds3234,
|
||||
[ SpiTrans::write(vec![Register::STATUS + 0x80, $value]) ]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_create_and_destroy_ds3232() {
|
||||
let dev = new_ds3232(&[]);
|
||||
destroy_ds3232(dev);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_create_and_destroy_ds3234() {
|
||||
let dev = new_ds3234(&[]);
|
||||
destroy_ds3234(dev);
|
||||
}
|
||||
|
||||
call_method_status_test!(can_en_32khz_bat, enable_32khz_output_on_battery,
|
||||
DS323X_POR_STATUS | BF::BB32KHZ | BF::ALARM2F | BF::ALARM1F );
|
||||
|
||||
call_method_status_test!(can_dis_32khz_bat, disable_32khz_output_on_battery,
|
||||
DS323X_POR_STATUS & !BF::BB32KHZ | BF::ALARM2F | BF::ALARM1F );
|
||||
|
@ -1,15 +0,0 @@
|
||||
#[deny(warnings)]
|
||||
|
||||
extern crate embedded_hal_mock as hal;
|
||||
extern crate ds323x;
|
||||
use ds323x::Ds323x;
|
||||
#[allow(dead_code)]
|
||||
mod common;
|
||||
use common::DummyOutputPin;
|
||||
|
||||
#[test]
|
||||
fn can_create_and_destroy() {
|
||||
let dev = Ds323x::new_ds3234(hal::spi::Mock::new(&[]), DummyOutputPin);
|
||||
let (mut spi, _cs) = dev.destroy_ds3234();
|
||||
spi.done();
|
||||
}
|
Loading…
Reference in New Issue