summaryrefslogtreecommitdiffstats
path: root/src/devices/channels.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/channels.rs')
-rw-r--r--src/devices/channels.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/devices/channels.rs b/src/devices/channels.rs
index 2482df5..c202ad3 100644
--- a/src/devices/channels.rs
+++ b/src/devices/channels.rs
@@ -1,5 +1,5 @@
//! ADC input channels
-use { Ads1x1x, ic, hal };
+use { Ads1x1x, ic, hal, Config, BitFlags as BF };
/// ADC input channel selection
#[allow(dead_code)]
@@ -68,3 +68,19 @@ impl_channel!(Ads1115, SingleA0);
impl_channel!(Ads1115, SingleA1);
impl_channel!(Ads1115, SingleA2);
impl_channel!(Ads1115, SingleA3);
+
+impl Config {
+ pub(crate) fn with_mux_bits(&self, ch: ChannelSelection) -> Self {
+ use self::ChannelSelection as CS;
+ match ch {
+ CS::DifferentialA0A1 => self.with_low( BF::MUX2).with_low( BF::MUX1).with_low( BF::MUX0),
+ CS::DifferentialA0A3 => self.with_low( BF::MUX2).with_low( BF::MUX1).with_high(BF::MUX0),
+ CS::DifferentialA1A3 => self.with_low( BF::MUX2).with_high(BF::MUX1).with_low( BF::MUX0),
+ CS::DifferentialA2A3 => self.with_low( BF::MUX2).with_high(BF::MUX1).with_high(BF::MUX0),
+ CS::SingleA0 => self.with_high(BF::MUX2).with_low( BF::MUX1).with_low( BF::MUX0),
+ CS::SingleA1 => self.with_high(BF::MUX2).with_low( BF::MUX1).with_high(BF::MUX0),
+ CS::SingleA2 => self.with_high(BF::MUX2).with_high(BF::MUX1).with_low( BF::MUX0),
+ CS::SingleA3 => self.with_high(BF::MUX2).with_high(BF::MUX1).with_high(BF::MUX0),
+ }
+ }
+}