diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-08 18:56:15 +0100 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-08 18:56:15 +0100 |
commit | 2f4284b914fb187ae485918b3f64c0ff2360ddb1 (patch) | |
tree | 353d282a81277e2bfb0a89b9babc02122cde1b55 /src/devices/ads1x1x/common.rs | |
parent | 4905c13ae1e77cad1a325d66000de930c1e4abbb (diff) | |
download | ads1x1x-async-2f4284b914fb187ae485918b3f64c0ff2360ddb1.tar.gz ads1x1x-async-2f4284b914fb187ae485918b3f64c0ff2360ddb1.tar.xz ads1x1x-async-2f4284b914fb187ae485918b3f64c0ff2360ddb1.zip |
Split common functions into tier1 features module
Diffstat (limited to 'src/devices/ads1x1x/common.rs')
-rw-r--r-- | src/devices/ads1x1x/common.rs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/devices/ads1x1x/common.rs b/src/devices/ads1x1x/common.rs index ce8a67a..5abb99c 100644 --- a/src/devices/ads1x1x/common.rs +++ b/src/devices/ads1x1x/common.rs @@ -1,11 +1,12 @@ //! Common functions -use { Ads1x1x, DataRate, Error, Register, BitFlags, interface }; +use { Ads1x1x, Error, Register, BitFlags, interface, Config, ic }; use super::OperatingMode; impl<DI, IC, MODE, E> Ads1x1x<DI, IC, MODE> where - DI: interface::WriteData<Error = E> + DI: interface::WriteData<Error = E>, + IC: ic::Resolution { pub(super) fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error<E>> { let config; @@ -18,20 +19,18 @@ where Ok(()) } - /// Set data rate - pub fn set_data_rate(&mut self, rate: DataRate) -> Result<(), Error<E>> { - let config; - match rate { - DataRate::Sps128 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), - DataRate::Sps250 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), - DataRate::Sps490 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), - DataRate::Sps920 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0), - DataRate::Sps1600 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), - DataRate::Sps2400 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), - DataRate::Sps3300 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), - } - self.iface.write_register(Register::CONFIG, config.bits)?; - self.config = config; - Ok(()) + /// Reset the internal state of this driver to the default values. + /// + /// *Note:* This does not alter the state or configuration of the device. + /// + /// This resets the cached configuration register value in this driver to + /// the power-up (reset) configuration of the device. + /// + /// This needs to be called after performing a reset on the device, for + /// example through an I2C general-call Reset command, which was not done + /// through this driver to ensure that the configurations in the device + /// and in the driver match. + pub fn reset_internal_driver_state(&mut self) { + self.config = Config::default(); } } |