diff options
-rw-r--r-- | src/devices/features/tier2.rs | 11 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | tests/common/mod.rs | 2 | ||||
-rw-r--r-- | tests/tier2_i2c.rs | 8 |
4 files changed, 25 insertions, 0 deletions
diff --git a/src/devices/features/tier2.rs b/src/devices/features/tier2.rs index 5d7ec92..17502e6 100644 --- a/src/devices/features/tier2.rs +++ b/src/devices/features/tier2.rs @@ -58,4 +58,15 @@ where self.config = config; Ok(()) } + /// Disable comparator (default) + /// + /// This will set the ALERT/RDY pin to high-impedance. + /// The comparator can be enabled by setting the comparator queue. + /// See [`set_comparator_queue()`](struct.Ads1x1x.html#method.set_comparator_queue) + pub fn disable_comparator(&mut self) -> Result<(), Error<E>> { + let config = self.config.with_high(BitFlags::COMP_QUE1).with_high(BitFlags::COMP_QUE0); + self.iface.write_register(Register::CONFIG, config.bits)?; + self.config = config; + Ok(()) + } } @@ -12,6 +12,7 @@ //! - Set the comparator mode. See: [`set_comparator_mode()`]. //! - Set the comparator polarity. See: [`set_comparator_polarity()`]. //! - Set the comparator latching. See: [`set_comparator_latching()`]. +//! - Disable the comparator. See: [`disable_comparator()`]. //! //! [`into_continuous()`]: struct.Ads1x1x.html#method.into_continuous //! [`read()`]: struct.Ads1x1x.html#method.read @@ -20,6 +21,7 @@ //! [`set_comparator_mode()`]: struct.Ads1x1x.html#method.set_comparator_mode //! [`set_comparator_polarity()`]: struct.Ads1x1x.html#method.set_comparator_polarity //! [`set_comparator_latching()`]: struct.Ads1x1x.html#method.set_comparator_latching +//! [`disable_comparator()`]: struct.Ads1x1x.html#method.disable_comparator //! //! ## The devices //! @@ -267,6 +269,8 @@ impl BitFlags { const COMP_MODE : u16 = 0b0000_0000_0001_0000; const COMP_POL : u16 = 0b0000_0000_0000_1000; const COMP_LAT : u16 = 0b0000_0000_0000_0100; + const COMP_QUE1 : u16 = 0b0000_0000_0000_0010; + const COMP_QUE0 : u16 = 0b0000_0000_0000_0001; } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 140941e..dc66431 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -27,6 +27,8 @@ impl BitFlags { pub const COMP_MODE : u16 = 0b0000_0000_0001_0000; pub const COMP_POL : u16 = 0b0000_0000_0000_1000; pub const COMP_LAT : u16 = 0b0000_0000_0000_0100; + pub const COMP_QUE1 : u16 = 0b0000_0000_0000_0010; + pub const COMP_QUE0 : u16 = 0b0000_0000_0000_0001; } pub struct Config { diff --git a/tests/tier2_i2c.rs b/tests/tier2_i2c.rs index 956aeb2..75c4b5f 100644 --- a/tests/tier2_i2c.rs +++ b/tests/tier2_i2c.rs @@ -50,3 +50,11 @@ mod can_set_comparator_latching { config_test!(lat, set_comparator_latching, ComparatorLatching::Latching, Config::default().with_high(BitFlags::COMP_LAT)); } +#[test] +fn can_disable_comparator() { + let config = Config::default().with_high(BitFlags::COMP_QUE1).with_high(BitFlags::COMP_QUE0); + let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]) ]; + let mut dev = new_ads1014(&transactions); + dev.disable_comparator().unwrap(); + destroy_ads1014(dev); +} |