From 3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Sun, 11 Nov 2018 08:04:42 +0100 Subject: Reorganize modules --- src/devices/features/tier2.rs | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/devices/features/tier2.rs (limited to 'src/devices/features/tier2.rs') diff --git a/src/devices/features/tier2.rs b/src/devices/features/tier2.rs new file mode 100644 index 0000000..43dce5c --- /dev/null +++ b/src/devices/features/tier2.rs @@ -0,0 +1,48 @@ +//! Tier 2 features. +//! +//! These are the features included only in ADS1x14, ADS1x15 + +use { Ads1x1x, Error, interface, ic, ComparatorMode, ComparatorPolarity, + ComparatorLatching, Register, BitFlags }; + +impl Ads1x1x +where + DI: interface::WriteData, + IC: ic::Resolution + ic::Tier2Features +{ + /// Set comparator mode + pub fn set_comparator_mode(&mut self, mode: ComparatorMode) -> Result<(), Error> { + 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(()) + } + + /// Set comparator polarity + pub fn set_comparator_polarity(&mut self, polarity: ComparatorPolarity) -> Result<(), Error> { + 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(()) + } + + /// Set comparator latching + pub fn set_comparator_latching(&mut self, latching: ComparatorLatching) -> Result<(), Error> { + let config; + match latching { + ComparatorLatching::Nonlatching => config = self.config.with_low( BitFlags::COMP_LAT), + ComparatorLatching::Latching => config = self.config.with_high(BitFlags::COMP_LAT) + } + self.iface.write_register(Register::CONFIG, config.bits)?; + self.config = config; + Ok(()) + } +} -- cgit v1.2.3-54-g00ecf