summaryrefslogtreecommitdiffstats
path: root/src/devices
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-08 19:08:57 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-08 19:08:57 +0100
commitdf30ade977dceef79b69fa8d7fe193bcc23d35c3 (patch)
tree98ceee01369a5a2ebd9f1e80f8b09bc271c3f01f /src/devices
parente316baaf8ca226caa2447041e1d895fb72ed4f19 (diff)
downloadads1x1x-async-df30ade977dceef79b69fa8d7fe193bcc23d35c3.tar.gz
ads1x1x-async-df30ade977dceef79b69fa8d7fe193bcc23d35c3.tar.xz
ads1x1x-async-df30ade977dceef79b69fa8d7fe193bcc23d35c3.zip
Add support for setting the comparator mode
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/ads1x1x/features/mod.rs2
-rw-r--r--src/devices/ads1x1x/features/tier2.rs23
2 files changed, 24 insertions, 1 deletions
diff --git a/src/devices/ads1x1x/features/mod.rs b/src/devices/ads1x1x/features/mod.rs
index ad26258..c24b7b4 100644
--- a/src/devices/ads1x1x/features/mod.rs
+++ b/src/devices/ads1x1x/features/mod.rs
@@ -2,4 +2,4 @@
//! support.
mod tier1;
-
+mod tier2;
diff --git a/src/devices/ads1x1x/features/tier2.rs b/src/devices/ads1x1x/features/tier2.rs
new file mode 100644
index 0000000..d238691
--- /dev/null
+++ b/src/devices/ads1x1x/features/tier2.rs
@@ -0,0 +1,23 @@
+//! Tier 2 features.
+//!
+//! These are the features included only in ADS1x14, ADS1x15
+
+use { Ads1x1x, Error, interface, ic, ComparatorMode, Register, BitFlags };
+
+impl<DI, IC, MODE, E> Ads1x1x<DI, IC, MODE>
+where
+ DI: interface::WriteData<Error = E>,
+ IC: ic::Resolution + ic::Tier2Features
+{
+ /// Set comparator mode
+ pub fn set_comparator_mode(&mut self, mode: ComparatorMode) -> Result<(), Error<E>> {
+ let config;
+ match mode {
+ ComparatorMode::Traditional => config = self.config.with_low(BitFlags::COMP_MODE),
+ ComparatorMode::Window => config = self.config.with_high(BitFlags::COMP_MODE)
+ }
+ self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.config = config;
+ Ok(())
+ }
+}