diff options
Diffstat (limited to 'src/devices/mode/oneshot.rs')
-rw-r--r-- | src/devices/mode/oneshot.rs | 52 |
1 files changed, 18 insertions, 34 deletions
diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs index 957eba5..10cdadb 100644 --- a/src/devices/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -1,7 +1,7 @@ //! Common functions use crate::{ - conversion, devices::OperatingMode, mode, Ads1x1x, BitFlags, ChannelId, ChannelSelection, - Config, DynamicOneShot, Error, ModeChangeError, Register, + conversion, devices::OperatingMode, mode, Ads1x1x, BitFlags, ChannelId, Config, Error, + ModeChangeError, Register, }; use core::marker::PhantomData; @@ -40,14 +40,28 @@ where I2C: embedded_hal::i2c::I2c<Error = E>, CONV: conversion::ConvertMeasurement, { - fn read_inner(&mut self, channel: ChannelSelection) -> nb::Result<i16, Error<E>> { + /// Request that the ADC begin a conversion on the specified channel. + /// + /// The output value will be within `[2047..-2048]` for 12-bit devices + /// (`ADS101x`) and within `[32767..-32768]` for 16-bit devices (`ADS111x`). + /// The voltage that these values correspond to must be calculated using + /// the full-scale range selected. + /// See [`FullScaleRange`](enum.FullScaleRange.html). + /// + /// Returns `nb::Error::WouldBlock` while a measurement is in progress. + /// + /// In case a measurement was requested and after is it is finished a + /// measurement on a different channel is requested, a new measurement on + /// using the new channel selection is triggered. + #[allow(unused_variables)] + pub fn read<CH: ChannelId<Self>>(&mut self, channel: CH) -> nb::Result<i16, Error<E>> { if self .is_measurement_in_progress() .map_err(nb::Error::Other)? { return Err(nb::Error::WouldBlock); } - let config = self.config.with_mux_bits(channel); + let config = self.config.with_mux_bits(CH::channel_id()); let same_channel = self.config == config; if self.a_conversion_was_started && same_channel { // result is ready @@ -63,34 +77,4 @@ where self.a_conversion_was_started = true; Err(nb::Error::WouldBlock) } - - /// Request that the ADC begin a conversion on the specified channel. - /// - /// The output value will be within `[2047..-2048]` for 12-bit devices - /// (`ADS101x`) and within `[32767..-32768]` for 16-bit devices (`ADS111x`). - /// The voltage that these values correspond to must be calculated using - /// the full-scale range selected. - /// See [`FullScaleRange`](enum.FullScaleRange.html). - /// - /// Returns `nb::Error::WouldBlock` while a measurement is in progress. - /// - /// In case a measurement was requested and after is it is finished a - /// measurement on a different channel is requested, a new measurement on - /// using the new channel selection is triggered. - #[allow(unused_variables)] - pub fn read<CH: ChannelId<Self>>(&mut self, channel: CH) -> nb::Result<i16, Error<E>> { - self.read_inner(CH::channel_id()) - } -} - -impl<I2C, IC, CONV, E> DynamicOneShot for Ads1x1x<I2C, IC, CONV, mode::OneShot> -where - I2C: embedded_hal::i2c::I2c<Error = E>, - CONV: conversion::ConvertMeasurement, -{ - type Error = Error<E>; - - fn read(&mut self, channel: ChannelSelection) -> nb::Result<i16, Self::Error> { - self.read_inner(channel) - } } |