summaryrefslogtreecommitdiffstats
path: root/src/devices/mode
diff options
context:
space:
mode:
authorMarkus Reiter <me@reitermark.us>2024-01-12 20:24:51 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2024-01-19 11:23:31 +0100
commitb3ca672f70c71194da40a7670549a8264c13d971 (patch)
tree1f316806351a059ca5b5fccbcf4d790b94c0b471 /src/devices/mode
parented4cc1dbc5b048332b68a0ebc1d7113d482a74a2 (diff)
downloadads1x1x-async-b3ca672f70c71194da40a7670549a8264c13d971.tar.gz
ads1x1x-async-b3ca672f70c71194da40a7670549a8264c13d971.tar.xz
ads1x1x-async-b3ca672f70c71194da40a7670549a8264c13d971.zip
Update to `embedded-hal` 1.0.
Diffstat (limited to 'src/devices/mode')
-rw-r--r--src/devices/mode/continuous.rs13
-rw-r--r--src/devices/mode/oneshot.rs62
2 files changed, 36 insertions, 39 deletions
diff --git a/src/devices/mode/continuous.rs b/src/devices/mode/continuous.rs
index 64aa179..b3b4807 100644
--- a/src/devices/mode/continuous.rs
+++ b/src/devices/mode/continuous.rs
@@ -1,11 +1,10 @@
//! Continuous measurement mode
use crate::{
- channels::ChannelSelection, conversion, devices::OperatingMode, interface, mode, Ads1x1x,
- Error, ModeChangeError, Register,
+ conversion, devices::OperatingMode, interface, mode, Ads1x1x, ChannelId, Error,
+ ModeChangeError, Register,
};
use core::marker::PhantomData;
-use embedded_hal::adc;
impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous>
where
@@ -41,11 +40,9 @@ where
/// Note that when changing the channel in continuous conversion mode, the
/// ongoing conversion will be completed.
/// The following conversions will use the new channel configuration.
- pub fn select_channel<CH>(&mut self, _channel: &mut CH) -> Result<(), Error<E>>
- where
- CH: adc::Channel<Ads1x1x<DI, IC, CONV, mode::OneShot>, ID = ChannelSelection>,
- {
- let config = self.config.with_mux_bits(CH::channel());
+ #[allow(unused_variables)]
+ pub fn select_channel<CH: ChannelId<Self>>(&mut self, channel: CH) -> Result<(), Error<E>> {
+ let config = self.config.with_mux_bits(CH::channel_id());
self.iface.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs
index fa4d3b8..0663e4b 100644
--- a/src/devices/mode/oneshot.rs
+++ b/src/devices/mode/oneshot.rs
@@ -1,10 +1,9 @@
//! Common functions
use crate::{
- conversion, devices::OperatingMode, interface, mode, Ads1x1x, BitFlags, ChannelSelection,
- Config, DynamicOneShot, Error, ModeChangeError, Register,
+ conversion, devices::OperatingMode, interface, mode, Ads1x1x, BitFlags, ChannelId,
+ ChannelSelection, Config, DynamicOneShot, Error, ModeChangeError, Register,
};
use core::marker::PhantomData;
-use embedded_hal::adc;
impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::OneShot>
where
@@ -35,14 +34,35 @@ where
}
}
-impl<DI, IC, CONV, E, CH> adc::OneShot<Ads1x1x<DI, IC, CONV, mode::OneShot>, i16, CH>
- for Ads1x1x<DI, IC, CONV, mode::OneShot>
+impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::OneShot>
where
DI: interface::ReadData<Error = E> + interface::WriteData<Error = E>,
CONV: conversion::ConvertMeasurement,
- CH: adc::Channel<Ads1x1x<DI, IC, CONV, mode::OneShot>, ID = ChannelSelection>,
{
- type Error = Error<E>;
+ fn read_inner(&mut self, channel: ChannelSelection) -> 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 same_channel = self.config == config;
+ if self.a_conversion_was_started && same_channel {
+ // result is ready
+ let value = self
+ .iface
+ .read_register(Register::CONVERSION)
+ .map_err(nb::Error::Other)?;
+ self.a_conversion_was_started = false;
+ return Ok(CONV::convert_measurement(value));
+ }
+ self.trigger_measurement(&config)
+ .map_err(nb::Error::Other)?;
+ self.config = config;
+ self.a_conversion_was_started = true;
+ Err(nb::Error::WouldBlock)
+ }
/// Request that the ADC begin a conversion on the specified channel.
///
@@ -57,8 +77,9 @@ where
/// 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.
- fn read(&mut self, _channel: &mut CH) -> nb::Result<i16, Self::Error> {
- <Self as DynamicOneShot>::read(self, CH::channel())
+ #[allow(unused_variables)]
+ pub fn read<CH: ChannelId<Self>>(&mut self, channel: CH) -> nb::Result<i16, Error<E>> {
+ self.read_inner(CH::channel_id())
}
}
@@ -70,27 +91,6 @@ where
type Error = Error<E>;
fn read(&mut self, channel: ChannelSelection) -> nb::Result<i16, Self::Error> {
- if self
- .is_measurement_in_progress()
- .map_err(nb::Error::Other)?
- {
- return Err(nb::Error::WouldBlock);
- }
- let same_channel = self.config == self.config.with_mux_bits(channel);
- if self.a_conversion_was_started && same_channel {
- // result is ready
- let value = self
- .iface
- .read_register(Register::CONVERSION)
- .map_err(nb::Error::Other)?;
- self.a_conversion_was_started = false;
- return Ok(CONV::convert_measurement(value));
- }
- let config = self.config.with_mux_bits(channel);
- self.trigger_measurement(&config)
- .map_err(nb::Error::Other)?;
- self.config = config;
- self.a_conversion_was_started = true;
- Err(nb::Error::WouldBlock)
+ self.read_inner(channel)
}
}