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/ads1x1x/mode/oneshot.rs | 66 ------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 src/devices/ads1x1x/mode/oneshot.rs (limited to 'src/devices/ads1x1x/mode/oneshot.rs') diff --git a/src/devices/ads1x1x/mode/oneshot.rs b/src/devices/ads1x1x/mode/oneshot.rs deleted file mode 100644 index 7ff9ac9..0000000 --- a/src/devices/ads1x1x/mode/oneshot.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! Common functions - -use core::marker::PhantomData; -use { Ads1x1x, mode, Error, Register, BitFlags, Config, ic }; -use { interface, hal, nb }; -use devices::ads1x1x::OperatingMode; -use devices::channels::ChannelSelection; -use super::convert_measurement; - -impl Ads1x1x -where - DI: interface::WriteData + interface::ReadData, - IC: ic::Resolution -{ - /// Change operating mode to Continuous - pub fn into_continuous(mut self) -> Result, Error> { - self.set_operating_mode(OperatingMode::Continuous)?; - Ok(Ads1x1x { - iface: self.iface, - config: self.config, - a_conversion_was_started: self.a_conversion_was_started, - _ic: PhantomData, - _mode: PhantomData - }) - } - - fn is_measurement_in_progress(&mut self) -> Result> { - let config = Config { - bits: self.iface.read_register(Register::CONFIG)? - }; - Ok(!config.is_high(BitFlags::OS)) - } - - fn trigger_measurement(&mut self, config: &Config) -> Result<(), Error> { - let config = config.with_high(BitFlags::OS); - self.iface.write_register(Register::CONFIG, config.bits) - } -} - -impl hal::adc::OneShot, i16, CH> for Ads1x1x -where - DI: interface::ReadData + interface::WriteData, - IC: ic::Resolution, - CH: hal::adc::Channel, ID = ChannelSelection> -{ - type Error = Error; - - /// Request that the ADC begin a conversion on the specified channel - fn read(&mut self, _channel: &mut CH) -> nb::Result { - //TODO for devices with MUX select channel, if it is the wrong one, return AlreadyInProgress or WrongChannel error - if self.is_measurement_in_progress().map_err(nb::Error::Other)? { - return Err(nb::Error::WouldBlock); - } - if self.a_conversion_was_started { - // result is ready - let value = self.iface.read_register(Register::CONVERSION).map_err(nb::Error::Other)?; - self.a_conversion_was_started = false; - return Ok(convert_measurement::(value)); - } - let config = self.config.with_mux_bits(CH::channel()); - self.trigger_measurement(&config).map_err(nb::Error::Other)?; - self.config = config; - self.a_conversion_was_started = true; - Err(nb::Error::WouldBlock) - } -} -- cgit v1.2.3-54-g00ecf