mirror of https://github.com/eldruin/ds323x-rs
DS3234: Add function to enable/disable temperature conversions on battery
parent
46aff07f81
commit
10ac7e4b7c
|
@ -19,8 +19,9 @@ This driver allows you to:
|
|||
- Select the function of the INT/SQW output pin. See `use_int_sqw_output_as_interrupt`.
|
||||
- Enable and disable the square-wave generation. See `enable_square_wave`.
|
||||
- Select the square-wave frequency. See `set_square_wave_frequency`.
|
||||
- Enable and disable the 32kHz output when battery powered. See `enable_32khz_output_on_battery`.
|
||||
- Enable and disable the 32kHz output when battery-powered. See `enable_32khz_output_on_battery`.
|
||||
- Set the temperature conversion rate. See `set_temperature_conversion_rate`.
|
||||
- Enable and disable the temperature conversions when battery-powered. See `enable_temperature_conversions_on_battery`.
|
||||
|
||||
## The devices
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
extern crate embedded_hal as hal;
|
||||
use hal::blocking;
|
||||
use core::marker::PhantomData;
|
||||
use super::{ Ds323x, TempConvRate, BitFlags, Error, ic, CONTROL_POR_VALUE };
|
||||
use interface::SpiInterface;
|
||||
use super::{ Ds323x, TempConvRate, Register, BitFlags, Error, ic, CONTROL_POR_VALUE };
|
||||
use interface::{ SpiInterface, WriteData };
|
||||
|
||||
impl<SPI, CS, E> Ds323x<SpiInterface<SPI, CS>, ic::DS3234>
|
||||
where
|
||||
|
@ -69,4 +69,18 @@ where
|
|||
}
|
||||
self.write_status_without_clearing_alarm(status)
|
||||
}
|
||||
|
||||
/// Enable the temperature conversions when battery-powered. (enabled per default)
|
||||
///
|
||||
/// Note: This is only available for DS3234 devices.
|
||||
pub fn enable_temperature_conversions_on_battery(&mut self) -> Result<(), Error<E>> {
|
||||
self.iface.write_register(Register::TEMP_CONV, 0)
|
||||
}
|
||||
|
||||
/// Disable the temperature conversions when battery-powered.
|
||||
///
|
||||
/// Note: This is only available for DS3234 devices.
|
||||
pub fn disable_temperature_conversions_on_battery(&mut self) -> Result<(), Error<E>> {
|
||||
self.iface.write_register(Register::TEMP_CONV, BitFlags::TEMP_CONV_BAT)
|
||||
}
|
||||
}
|
||||
|
|
38
src/lib.rs
38
src/lib.rs
|
@ -19,6 +19,7 @@
|
|||
//! - Select the square-wave frequency. See [`set_square_wave_frequency`].
|
||||
//! - Enable and disable the 32kHz output when battery powered. See [`enable_32khz_output_on_battery`].
|
||||
//! - Set the temperature conversion rate. See [`set_temperature_conversion_rate`].
|
||||
//! - Enable and disable the temperature conversions when battery-powered. See [`enable_temperature_conversions_on_battery`].
|
||||
//!
|
||||
//! [`get_datetime`]: struct.Ds323x.html#method.get_datetime
|
||||
//! [`get_year`]: struct.Ds323x.html#method.get_year
|
||||
|
@ -35,6 +36,7 @@
|
|||
//! [`set_square_wave_frequency`]: Struct.Ds323x.html#method.set_square_wave_frequency
|
||||
//! [`enable_32khz_output_on_battery`]: Struct.Ds323x.html#method.enable_32khz_output_on_battery
|
||||
//! [`set_temperature_conversion_rate`]: Struct.Ds323x.html#method.set_temperature_conversion_rate
|
||||
//! [`enable_temperature_conversions_on_battery`]: Struct.Ds323x.html#method.enable_temperature_conversions_on_battery
|
||||
//!
|
||||
//! ## The devices
|
||||
//!
|
||||
|
@ -438,28 +440,30 @@ impl Register {
|
|||
const STATUS : u8 = 0x0F;
|
||||
const AGING_OFFSET : u8 = 0x10;
|
||||
const TEMP_MSB : u8 = 0x11;
|
||||
const TEMP_CONV : u8 = 0x13;
|
||||
}
|
||||
|
||||
struct BitFlags;
|
||||
|
||||
impl BitFlags {
|
||||
const H24_H12 : u8 = 0b0100_0000;
|
||||
const AM_PM : u8 = 0b0010_0000;
|
||||
const CENTURY : u8 = 0b1000_0000;
|
||||
const EOSC : u8 = 0b1000_0000;
|
||||
const BBSQW : u8 = 0b0100_0000;
|
||||
const TEMP_CONV : u8 = 0b0010_0000;
|
||||
const RS2 : u8 = 0b0001_0000;
|
||||
const RS1 : u8 = 0b0000_1000;
|
||||
const INTCN : u8 = 0b0000_0100;
|
||||
const OSC_STOP : u8 = 0b1000_0000;
|
||||
const BB32KHZ : u8 = 0b0100_0000;
|
||||
const CRATE1 : u8 = 0b0010_0000;
|
||||
const CRATE0 : u8 = 0b0001_0000;
|
||||
const EN32KHZ : u8 = 0b0000_1000;
|
||||
const BUSY : u8 = 0b0000_0100;
|
||||
const ALARM2F : u8 = 0b0000_0010;
|
||||
const ALARM1F : u8 = 0b0000_0001;
|
||||
const H24_H12 : u8 = 0b0100_0000;
|
||||
const AM_PM : u8 = 0b0010_0000;
|
||||
const CENTURY : u8 = 0b1000_0000;
|
||||
const EOSC : u8 = 0b1000_0000;
|
||||
const BBSQW : u8 = 0b0100_0000;
|
||||
const TEMP_CONV : u8 = 0b0010_0000;
|
||||
const RS2 : u8 = 0b0001_0000;
|
||||
const RS1 : u8 = 0b0000_1000;
|
||||
const INTCN : u8 = 0b0000_0100;
|
||||
const OSC_STOP : u8 = 0b1000_0000;
|
||||
const BB32KHZ : u8 = 0b0100_0000;
|
||||
const CRATE1 : u8 = 0b0010_0000;
|
||||
const CRATE0 : u8 = 0b0001_0000;
|
||||
const EN32KHZ : u8 = 0b0000_1000;
|
||||
const BUSY : u8 = 0b0000_0100;
|
||||
const ALARM2F : u8 = 0b0000_0010;
|
||||
const ALARM1F : u8 = 0b0000_0001;
|
||||
const TEMP_CONV_BAT : u8 = 0b0000_0001;
|
||||
}
|
||||
|
||||
const DEVICE_ADDRESS : u8 = 0b110_1000;
|
||||
|
|
|
@ -26,26 +26,28 @@ impl Register {
|
|||
pub const STATUS : u8 = 0x0F;
|
||||
pub const AGING_OFFSET : u8 = 0x10;
|
||||
pub const TEMP_MSB : u8 = 0x11;
|
||||
pub const TEMP_CONV : u8 = 0x13;
|
||||
}
|
||||
|
||||
pub struct BitFlags;
|
||||
|
||||
#[allow(unused)]
|
||||
impl BitFlags {
|
||||
pub const EOSC : u8 = 0b1000_0000;
|
||||
pub const BBSQW : u8 = 0b0100_0000;
|
||||
pub const TEMP_CONV : u8 = 0b0010_0000;
|
||||
pub const RS2 : u8 = 0b0001_0000;
|
||||
pub const RS1 : u8 = 0b0000_1000;
|
||||
pub const INTCN : u8 = 0b0000_0100;
|
||||
pub const OSC_STOP : u8 = 0b1000_0000;
|
||||
pub const BB32KHZ : u8 = 0b0100_0000;
|
||||
pub const CRATE1 : u8 = 0b0010_0000;
|
||||
pub const CRATE0 : u8 = 0b0001_0000;
|
||||
pub const EN32KHZ : u8 = 0b0000_1000;
|
||||
pub const BUSY : u8 = 0b0000_0100;
|
||||
pub const ALARM2F : u8 = 0b0000_0010;
|
||||
pub const ALARM1F : u8 = 0b0000_0001;
|
||||
pub const EOSC : u8 = 0b1000_0000;
|
||||
pub const BBSQW : u8 = 0b0100_0000;
|
||||
pub const TEMP_CONV : u8 = 0b0010_0000;
|
||||
pub const RS2 : u8 = 0b0001_0000;
|
||||
pub const RS1 : u8 = 0b0000_1000;
|
||||
pub const INTCN : u8 = 0b0000_0100;
|
||||
pub const OSC_STOP : u8 = 0b1000_0000;
|
||||
pub const BB32KHZ : u8 = 0b0100_0000;
|
||||
pub const CRATE1 : u8 = 0b0010_0000;
|
||||
pub const CRATE0 : u8 = 0b0001_0000;
|
||||
pub const EN32KHZ : u8 = 0b0000_1000;
|
||||
pub const BUSY : u8 = 0b0000_0100;
|
||||
pub const ALARM2F : u8 = 0b0000_0010;
|
||||
pub const ALARM1F : u8 = 0b0000_0001;
|
||||
pub const TEMP_CONV_BAT : u8 = 0b0000_0001;
|
||||
}
|
||||
|
||||
pub struct DummyOutputPin;
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
#[deny(warnings)]
|
||||
|
||||
extern crate embedded_hal_mock as hal;
|
||||
use hal::spi::Transaction as SpiTrans;
|
||||
extern crate ds323x;
|
||||
|
||||
#[allow(unused)]
|
||||
mod common;
|
||||
use common::{ new_ds3234, destroy_ds3234 };
|
||||
use common::{ new_ds3234, destroy_ds3234, Register, BitFlags };
|
||||
|
||||
#[test]
|
||||
fn can_create_and_destroy_ds3234() {
|
||||
let dev = new_ds3234(&[]);
|
||||
destroy_ds3234(dev);
|
||||
}
|
||||
|
||||
call_test!(can_en_temp_conv_bat, enable_temperature_conversions_on_battery, new_ds3234, destroy_ds3234,
|
||||
[ SpiTrans::write(vec![Register::TEMP_CONV + 0x80, 0]) ]);
|
||||
|
||||
call_test!(can_dis_temp_conv_bat, disable_temperature_conversions_on_battery, new_ds3234, destroy_ds3234,
|
||||
[ SpiTrans::write(vec![Register::TEMP_CONV + 0x80, BitFlags::TEMP_CONV_BAT]) ]);
|
Loading…
Reference in New Issue