diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-11 08:04:42 +0100 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-11 08:04:42 +0100 |
commit | 3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a (patch) | |
tree | 8cf40e43cb93b15a774696c3af639d504addce8c /src/devices/common.rs | |
parent | 8b9e9ecdb85a30ac1c57fe6b96498cae6ad9f7cc (diff) | |
download | ads1x1x-async-3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a.tar.gz ads1x1x-async-3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a.tar.xz ads1x1x-async-3e3a790d9f70bfd6cb4210dfe09560d0385fdf5a.zip |
Reorganize modules
Diffstat (limited to 'src/devices/common.rs')
-rw-r--r-- | src/devices/common.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/devices/common.rs b/src/devices/common.rs new file mode 100644 index 0000000..5abb99c --- /dev/null +++ b/src/devices/common.rs @@ -0,0 +1,36 @@ +//! Common functions + +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>, + IC: ic::Resolution +{ + pub(super) fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error<E>> { + let config; + match mode { + OperatingMode::OneShot => config = self.config.with_high(BitFlags::OP_MODE), + OperatingMode::Continuous => config = self.config.with_low(BitFlags::OP_MODE), + } + 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(); + } +} |