summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-20 19:07:16 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-20 19:07:16 +0100
commit2a2f25b35c8411a5932e576b5d0969d3928c7209 (patch)
tree337989e345dc44d83e6dfcc08742d6781b6e405c
parentea48b456d5045cd136c08829d40708eef1cab67a (diff)
downloadads1x1x-async-2a2f25b35c8411a5932e576b5d0969d3928c7209.tar.gz
ads1x1x-async-2a2f25b35c8411a5932e576b5d0969d3928c7209.tar.xz
ads1x1x-async-2a2f25b35c8411a5932e576b5d0969d3928c7209.zip
Add function to select the measurement channel in continuous mode
-rw-r--r--src/devices/mode/continuous.rs21
-rw-r--r--tests/mux_i2c.rs10
2 files changed, 29 insertions, 2 deletions
diff --git a/src/devices/mode/continuous.rs b/src/devices/mode/continuous.rs
index 6bf5201..cd3edee 100644
--- a/src/devices/mode/continuous.rs
+++ b/src/devices/mode/continuous.rs
@@ -1,7 +1,8 @@
-//! Common functions
+//! Continuous measurement mode
use core::marker::PhantomData;
-use { Ads1x1x, mode, Error, interface };
+use { Ads1x1x, conversion, Error, hal, interface, mode, Register };
+use channels::ChannelSelection;
use super::super::OperatingMode;
impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous>
@@ -29,3 +30,19 @@ where
Ok(())
}
}
+
+impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous>
+where
+ DI: interface::ReadData<Error = E> + interface::WriteData<Error = E>,
+ CONV: conversion::ConvertMeasurement,
+{
+ /// Select the channel for measurements.
+ pub fn select_channel<CH>(&mut self, _channel: &mut CH) -> Result<(), Error<E>>
+ where
+ CH: hal::adc::Channel<Ads1x1x<DI, IC, CONV, mode::OneShot>, ID = ChannelSelection> {
+ let config = self.config.with_mux_bits(CH::channel());
+ self.iface.write_register(Register::CONFIG, config.bits)?;
+ self.config = config;
+ Ok(())
+ }
+}
diff --git a/tests/mux_i2c.rs b/tests/mux_i2c.rs
index ca10673..f448f04 100644
--- a/tests/mux_i2c.rs
+++ b/tests/mux_i2c.rs
@@ -49,6 +49,16 @@ macro_rules! mux_test {
assert_eq!(-2048, measurement);
destroy(dev);
}
+
+ #[test]
+ fn continuous_can_select_channel() {
+ let config = Config::default().with_high($config_bits);
+ let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]) ];
+ let dev = new(&transactions);
+ let mut dev = dev.into_continuous().unwrap();
+ dev.select_channel(&mut channel::$CS).unwrap();
+ destroy(dev);
+ }
}
};
}