summaryrefslogtreecommitdiffstats
path: root/src/devices/features/tier2.rs
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-17 07:43:01 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-17 07:43:01 +0100
commit311103b79eb800a756c7ae5b771921322ff92459 (patch)
treea3c235c745c16b72ae4460ccab0540504bdb6ad8 /src/devices/features/tier2.rs
parent254a0dce912e252e78a42eead98429dc0b27f1ba (diff)
downloadads1x1x-async-311103b79eb800a756c7ae5b771921322ff92459.tar.gz
ads1x1x-async-311103b79eb800a756c7ae5b771921322ff92459.tar.xz
ads1x1x-async-311103b79eb800a756c7ae5b771921322ff92459.zip
Add support for setting the comparator queue
Diffstat (limited to 'src/devices/features/tier2.rs')
-rw-r--r--src/devices/features/tier2.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/devices/features/tier2.rs b/src/devices/features/tier2.rs
index 17502e6..25b618a 100644
--- a/src/devices/features/tier2.rs
+++ b/src/devices/features/tier2.rs
@@ -3,7 +3,7 @@
//! These are the features included only in ADS1x14, ADS1x15
use { Ads1x1x, Error, interface, ic, ComparatorMode, ComparatorPolarity,
- ComparatorLatching, Register, BitFlags, conversion };
+ ComparatorLatching, ComparatorQueue, Register, BitFlags, conversion };
impl<DI, IC, CONV, MODE, E> Ads1x1x<DI, IC, CONV, MODE>
where
@@ -58,6 +58,22 @@ where
self.config = config;
Ok(())
}
+
+ /// Activate comparator and set the alert queue
+ ///
+ /// The comparator can be disabled with [`disable_comparator()`](struct.Ads1x1x.html#method.disable_comparator)
+ pub fn set_comparator_queue(&mut self, queue: ComparatorQueue) -> Result<(), Error<E>> {
+ let config;
+ match queue {
+ ComparatorQueue::One => config = self.config.with_low( BitFlags::COMP_QUE1).with_low( BitFlags::COMP_QUE0),
+ ComparatorQueue::Two => config = self.config.with_low( BitFlags::COMP_QUE1).with_high(BitFlags::COMP_QUE0),
+ ComparatorQueue::Four => config = self.config.with_high(BitFlags::COMP_QUE1).with_low( BitFlags::COMP_QUE0)
+ }
+ self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.config = config;
+ Ok(())
+ }
+
/// Disable comparator (default)
///
/// This will set the ALERT/RDY pin to high-impedance.