summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2019-03-30 13:36:06 +0200
committerDiego Barrios Romero <eldruin@gmail.com>2019-03-31 13:41:26 +0200
commit50223ad02e2f487540107e320c8bef40a9849582 (patch)
tree58b4e44e2261940d07aba96b8d8e83457e641f53 /src
parentab1221e175f2da577c7a3fb510b5ae5cf41b0697 (diff)
downloadads1x1x-async-50223ad02e2f487540107e320c8bef40a9849582.tar.gz
ads1x1x-async-50223ad02e2f487540107e320c8bef40a9849582.tar.xz
ads1x1x-async-50223ad02e2f487540107e320c8bef40a9849582.zip
Format code
Diffstat (limited to 'src')
-rw-r--r--src/channels.rs40
-rw-r--r--src/conversion.rs13
-rw-r--r--src/devices/features/tier2.rs12
-rw-r--r--src/devices/mod.rs4
-rw-r--r--src/devices/mode/mod.rs2
-rw-r--r--src/devices/mode/oneshot.rs10
-rw-r--r--src/lib.rs55
7 files changed, 85 insertions, 51 deletions
diff --git a/src/channels.rs b/src/channels.rs
index d5ae7bc..90b9b5d 100644
--- a/src/channels.rs
+++ b/src/channels.rs
@@ -74,14 +74,38 @@ 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),
+ 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),
}
}
}
diff --git a/src/conversion.rs b/src/conversion.rs
index fef80ac..2be9f1e 100644
--- a/src/conversion.rs
+++ b/src/conversion.rs
@@ -44,25 +44,24 @@ impl ConvertMeasurement for ic::Resolution16Bit {
}
}
-
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn convert_measurement_12_bits() {
- assert_eq!( 0, ic::Resolution12Bit::convert_measurement(0));
- assert_eq!( 2047, ic::Resolution12Bit::convert_measurement(0x7FFF));
+ assert_eq!(0, ic::Resolution12Bit::convert_measurement(0));
+ assert_eq!(2047, ic::Resolution12Bit::convert_measurement(0x7FFF));
assert_eq!(-2048, ic::Resolution12Bit::convert_measurement(0x8000));
- assert_eq!( -1, ic::Resolution12Bit::convert_measurement(0xFFFF));
+ assert_eq!(-1, ic::Resolution12Bit::convert_measurement(0xFFFF));
}
#[test]
fn convert_measurement_16_bits() {
- assert_eq!( 0, ic::Resolution16Bit::convert_measurement(0));
- assert_eq!( 32767, ic::Resolution16Bit::convert_measurement(0x7FFF));
+ assert_eq!(0, ic::Resolution16Bit::convert_measurement(0));
+ assert_eq!(32767, ic::Resolution16Bit::convert_measurement(0x7FFF));
assert_eq!(-32768, ic::Resolution16Bit::convert_measurement(0x8000));
- assert_eq!( -1, ic::Resolution16Bit::convert_measurement(0xFFFF));
+ assert_eq!(-1, ic::Resolution16Bit::convert_measurement(0xFFFF));
}
fn assert_invalid_input_data<E>(result: Result<u16, Error<E>>) {
diff --git a/src/devices/features/tier2.rs b/src/devices/features/tier2.rs
index 48e4eb9..0b0b92c 100644
--- a/src/devices/features/tier2.rs
+++ b/src/devices/features/tier2.rs
@@ -128,7 +128,10 @@ where
/// The comparator can be enabled by setting the comparator queue.
/// See [`set_comparator_queue()`](struct.Ads1x1x.html#method.set_comparator_queue)
pub fn disable_comparator(&mut self) -> Result<(), Error<E>> {
- let config = self.config.with_high(BF::COMP_QUE1).with_high(BF::COMP_QUE0);
+ let config = self
+ .config
+ .with_high(BF::COMP_QUE1)
+ .with_high(BF::COMP_QUE0);
self.iface.write_register(Register::CONFIG, config.bits)?;
self.config = config;
Ok(())
@@ -142,7 +145,12 @@ where
///
/// When calling this the comparator will be disabled and the thresholds will be cleared.
pub fn use_alert_rdy_pin_as_ready(&mut self) -> Result<(), Error<E>> {
- if self.config != self.config.with_high(BF::COMP_QUE1).with_high(BF::COMP_QUE0) {
+ if self.config
+ != self
+ .config
+ .with_high(BF::COMP_QUE1)
+ .with_high(BF::COMP_QUE0)
+ {
self.disable_comparator()?;
}
self.iface.write_register(Register::HIGH_TH, 0x8000)?;
diff --git a/src/devices/mod.rs b/src/devices/mod.rs
index 5b87738..01efeba 100644
--- a/src/devices/mod.rs
+++ b/src/devices/mod.rs
@@ -4,6 +4,6 @@ enum OperatingMode {
Continuous,
}
-mod mode;
-mod features;
mod common;
+mod features;
+mod mode;
diff --git a/src/devices/mode/mod.rs b/src/devices/mode/mod.rs
index 9625465..670ebe9 100644
--- a/src/devices/mode/mod.rs
+++ b/src/devices/mode/mod.rs
@@ -1,4 +1,4 @@
//! Functions for all devices specific to each operating mode
-mod oneshot;
mod continuous;
+mod oneshot;
diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs
index 612d5a4..5901292 100644
--- a/src/devices/mode/oneshot.rs
+++ b/src/devices/mode/oneshot.rs
@@ -58,13 +58,19 @@ where
/// 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> {
- if self.is_measurement_in_progress().map_err(nb::Error::Other)? {
+ 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(CH::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)?;
+ 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));
}
diff --git a/src/lib.rs b/src/lib.rs
index c6716b9..b5abe4d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -388,9 +388,7 @@ impl SlaveAddr {
fn addr(self, default: u8) -> u8 {
match self {
SlaveAddr::Default => default,
- SlaveAddr::Alternative(a1, a0) => default |
- ((a1 as u8) << 1) |
- a0 as u8
+ SlaveAddr::Alternative(a1, a0) => default | ((a1 as u8) << 1) | a0 as u8,
}
}
}
@@ -398,33 +396,32 @@ impl SlaveAddr {
struct Register;
impl Register {
- const CONVERSION : u8 = 0x00;
- const CONFIG : u8 = 0x01;
- const LOW_TH : u8 = 0x02;
- const HIGH_TH : u8 = 0x03;
+ const CONVERSION: u8 = 0x00;
+ const CONFIG: u8 = 0x01;
+ const LOW_TH: u8 = 0x02;
+ const HIGH_TH: u8 = 0x03;
}
struct BitFlags;
impl BitFlags {
- const OS : u16 = 0b1000_0000_0000_0000;
- const MUX2 : u16 = 0b0100_0000_0000_0000;
- const MUX1 : u16 = 0b0010_0000_0000_0000;
- const MUX0 : u16 = 0b0001_0000_0000_0000;
- const PGA2 : u16 = 0b0000_1000_0000_0000;
- const PGA1 : u16 = 0b0000_0100_0000_0000;
- const PGA0 : u16 = 0b0000_0010_0000_0000;
- const OP_MODE : u16 = 0b0000_0001_0000_0000;
- const DR2 : u16 = 0b0000_0000_1000_0000;
- const DR1 : u16 = 0b0000_0000_0100_0000;
- const DR0 : u16 = 0b0000_0000_0010_0000;
- const COMP_MODE : u16 = 0b0000_0000_0001_0000;
- const COMP_POL : u16 = 0b0000_0000_0000_1000;
- const COMP_LAT : u16 = 0b0000_0000_0000_0100;
- const COMP_QUE1 : u16 = 0b0000_0000_0000_0010;
- const COMP_QUE0 : u16 = 0b0000_0000_0000_0001;
+ const OS: u16 = 0b1000_0000_0000_0000;
+ const MUX2: u16 = 0b0100_0000_0000_0000;
+ const MUX1: u16 = 0b0010_0000_0000_0000;
+ const MUX0: u16 = 0b0001_0000_0000_0000;
+ const PGA2: u16 = 0b0000_1000_0000_0000;
+ const PGA1: u16 = 0b0000_0100_0000_0000;
+ const PGA0: u16 = 0b0000_0010_0000_0000;
+ const OP_MODE: u16 = 0b0000_0001_0000_0000;
+ const DR2: u16 = 0b0000_0000_1000_0000;
+ const DR1: u16 = 0b0000_0000_0100_0000;
+ const DR0: u16 = 0b0000_0000_0010_0000;
+ const COMP_MODE: u16 = 0b0000_0000_0001_0000;
+ const COMP_POL: u16 = 0b0000_0000_0000_1000;
+ const COMP_LAT: u16 = 0b0000_0000_0000_0100;
+ const COMP_QUE1: u16 = 0b0000_0000_0000_0010;
+ const COMP_QUE0: u16 = 0b0000_0000_0000_0001;
}
-
#[derive(Debug, Clone, PartialEq)]
struct Config {
bits: u16,
@@ -471,17 +468,17 @@ pub struct Ads1x1x<DI, IC, CONV, MODE> {
_mode: PhantomData<MODE>,
}
-#[doc(hidden)]
-pub mod interface;
+mod channels;
#[doc(hidden)]
pub mod ic;
-mod channels;
+#[doc(hidden)]
+pub mod interface;
pub use channels::channel;
-mod devices;
mod construction;
mod conversion;
-pub use conversion::ConvertThreshold;
+mod devices;
pub use conversion::ConvertMeasurement;
+pub use conversion::ConvertThreshold;
mod private {
use super::{ic, interface};