summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/devices/ads1x1x/features/tier2.rs15
-rw-r--r--src/lib.rs10
2 files changed, 24 insertions, 1 deletions
diff --git a/src/devices/ads1x1x/features/tier2.rs b/src/devices/ads1x1x/features/tier2.rs
index d238691..7d22796 100644
--- a/src/devices/ads1x1x/features/tier2.rs
+++ b/src/devices/ads1x1x/features/tier2.rs
@@ -2,7 +2,8 @@
//!
//! These are the features included only in ADS1x14, ADS1x15
-use { Ads1x1x, Error, interface, ic, ComparatorMode, Register, BitFlags };
+use { Ads1x1x, Error, interface, ic, ComparatorMode, ComparatorPolarity,
+ Register, BitFlags };
impl<DI, IC, MODE, E> Ads1x1x<DI, IC, MODE>
where
@@ -20,4 +21,16 @@ where
self.config = config;
Ok(())
}
+
+ /// Set comparator polarity
+ pub fn set_comparator_polarity(&mut self, polarity: ComparatorPolarity) -> Result<(), Error<E>> {
+ let config;
+ match polarity {
+ ComparatorPolarity::ActiveLow => config = self.config.with_low( BitFlags::COMP_POL),
+ ComparatorPolarity::ActiveHigh => config = self.config.with_high(BitFlags::COMP_POL)
+ }
+ self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.config = config;
+ Ok(())
+ }
}
diff --git a/src/lib.rs b/src/lib.rs
index 21b63c5..7dc1388 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -124,6 +124,15 @@ pub enum ComparatorMode {
Window
}
+/// Comparator polarity (only for ADS1x14, ADS1x15)
+#[derive(Debug, Clone)]
+pub enum ComparatorPolarity {
+ /// Active low (default)
+ ActiveLow,
+ /// Active high
+ ActiveHigh
+}
+
/// Possible slave addresses
#[derive(Debug, Clone)]
pub enum SlaveAddr {
@@ -168,6 +177,7 @@ impl BitFlags {
const DR1 : u16 = 0b0000_0000_0100_0000;
const DR0 : u16 = 0b0000_0000_0010_0000;
const COMP_MODE : u16 = 0b0000_0000_0001_0000;
+ const COMP_POL : u16 = 0b0000_0000_0000_1000;
}