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`.
|
- 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`.
|
- Enable and disable the square-wave generation. See `enable_square_wave`.
|
||||||
- Select the square-wave frequency. See `set_square_wave_frequency`.
|
- 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`.
|
- 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
|
## The devices
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
extern crate embedded_hal as hal;
|
extern crate embedded_hal as hal;
|
||||||
use hal::blocking;
|
use hal::blocking;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use super::{ Ds323x, TempConvRate, BitFlags, Error, ic, CONTROL_POR_VALUE };
|
use super::{ Ds323x, TempConvRate, Register, BitFlags, Error, ic, CONTROL_POR_VALUE };
|
||||||
use interface::SpiInterface;
|
use interface::{ SpiInterface, WriteData };
|
||||||
|
|
||||||
impl<SPI, CS, E> Ds323x<SpiInterface<SPI, CS>, ic::DS3234>
|
impl<SPI, CS, E> Ds323x<SpiInterface<SPI, CS>, ic::DS3234>
|
||||||
where
|
where
|
||||||
|
@ -69,4 +69,18 @@ where
|
||||||
}
|
}
|
||||||
self.write_status_without_clearing_alarm(status)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
//! - Select the square-wave frequency. See [`set_square_wave_frequency`].
|
//! - 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`].
|
//! - 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_datetime`]: struct.Ds323x.html#method.get_datetime
|
||||||
//! [`get_year`]: struct.Ds323x.html#method.get_year
|
//! [`get_year`]: struct.Ds323x.html#method.get_year
|
||||||
|
@ -35,6 +36,7 @@
|
||||||
//! [`set_square_wave_frequency`]: Struct.Ds323x.html#method.set_square_wave_frequency
|
//! [`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
|
//! [`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
|
//! [`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
|
//! ## The devices
|
||||||
//!
|
//!
|
||||||
|
@ -438,6 +440,7 @@ impl Register {
|
||||||
const STATUS : u8 = 0x0F;
|
const STATUS : u8 = 0x0F;
|
||||||
const AGING_OFFSET : u8 = 0x10;
|
const AGING_OFFSET : u8 = 0x10;
|
||||||
const TEMP_MSB : u8 = 0x11;
|
const TEMP_MSB : u8 = 0x11;
|
||||||
|
const TEMP_CONV : u8 = 0x13;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BitFlags;
|
struct BitFlags;
|
||||||
|
@ -460,6 +463,7 @@ impl BitFlags {
|
||||||
const BUSY : u8 = 0b0000_0100;
|
const BUSY : u8 = 0b0000_0100;
|
||||||
const ALARM2F : u8 = 0b0000_0010;
|
const ALARM2F : u8 = 0b0000_0010;
|
||||||
const ALARM1F : u8 = 0b0000_0001;
|
const ALARM1F : u8 = 0b0000_0001;
|
||||||
|
const TEMP_CONV_BAT : u8 = 0b0000_0001;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEVICE_ADDRESS : u8 = 0b110_1000;
|
const DEVICE_ADDRESS : u8 = 0b110_1000;
|
||||||
|
|
|
@ -26,6 +26,7 @@ impl Register {
|
||||||
pub const STATUS : u8 = 0x0F;
|
pub const STATUS : u8 = 0x0F;
|
||||||
pub const AGING_OFFSET : u8 = 0x10;
|
pub const AGING_OFFSET : u8 = 0x10;
|
||||||
pub const TEMP_MSB : u8 = 0x11;
|
pub const TEMP_MSB : u8 = 0x11;
|
||||||
|
pub const TEMP_CONV : u8 = 0x13;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BitFlags;
|
pub struct BitFlags;
|
||||||
|
@ -46,6 +47,7 @@ impl BitFlags {
|
||||||
pub const BUSY : u8 = 0b0000_0100;
|
pub const BUSY : u8 = 0b0000_0100;
|
||||||
pub const ALARM2F : u8 = 0b0000_0010;
|
pub const ALARM2F : u8 = 0b0000_0010;
|
||||||
pub const ALARM1F : u8 = 0b0000_0001;
|
pub const ALARM1F : u8 = 0b0000_0001;
|
||||||
|
pub const TEMP_CONV_BAT : u8 = 0b0000_0001;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DummyOutputPin;
|
pub struct DummyOutputPin;
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
#[deny(warnings)]
|
#[deny(warnings)]
|
||||||
|
|
||||||
extern crate embedded_hal_mock as hal;
|
extern crate embedded_hal_mock as hal;
|
||||||
|
use hal::spi::Transaction as SpiTrans;
|
||||||
extern crate ds323x;
|
extern crate ds323x;
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
mod common;
|
mod common;
|
||||||
use common::{ new_ds3234, destroy_ds3234 };
|
use common::{ new_ds3234, destroy_ds3234, Register, BitFlags };
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_create_and_destroy_ds3234() {
|
fn can_create_and_destroy_ds3234() {
|
||||||
let dev = new_ds3234(&[]);
|
let dev = new_ds3234(&[]);
|
||||||
destroy_ds3234(dev);
|
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