summaryrefslogtreecommitdiffstats
path: root/src/devices
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-10 09:34:00 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-10 09:34:00 +0100
commitbad297c7e4c1f39842aa55ac44506e22d154bce0 (patch)
treed4b48ab8b25cecad2e77c034dda1716c34c93da9 /src/devices
parentdf8e200554dadee3f4addc887f775be03b7467cf (diff)
downloadads1x1x-async-bad297c7e4c1f39842aa55ac44506e22d154bce0.tar.gz
ads1x1x-async-bad297c7e4c1f39842aa55ac44506e22d154bce0.tar.xz
ads1x1x-async-bad297c7e4c1f39842aa55ac44506e22d154bce0.zip
Add support for setting the comparator polarity
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/ads1x1x/features/tier2.rs15
1 files changed, 14 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(())
+ }
}