summaryrefslogtreecommitdiffstats
path: root/src/devices
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-21 09:35:37 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-21 09:35:37 +0100
commit5485d9655e2ab3a6d04e5f69b246f5db4d2c5936 (patch)
tree84bb1e825656d4c523b65edc5d7780fbb060c8cc /src/devices
parente4a1ac5a04d021ef026c559354e9913ae59864d8 (diff)
downloadads1x1x-async-5485d9655e2ab3a6d04e5f69b246f5db4d2c5936.tar.gz
ads1x1x-async-5485d9655e2ab3a6d04e5f69b246f5db4d2c5936.tar.xz
ads1x1x-async-5485d9655e2ab3a6d04e5f69b246f5db4d2c5936.zip
Code formatting
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/common.rs4
-rw-r--r--src/devices/features/tier1.rs34
-rw-r--r--src/devices/features/tier2.rs42
-rw-r--r--src/devices/mod.rs2
-rw-r--r--src/devices/mode/continuous.rs11
-rw-r--r--src/devices/mode/oneshot.rs15
6 files changed, 59 insertions, 49 deletions
diff --git a/src/devices/common.rs b/src/devices/common.rs
index 92b4f9e..57d67b9 100644
--- a/src/devices/common.rs
+++ b/src/devices/common.rs
@@ -1,7 +1,7 @@
//! Common functions
-use { Ads1x1x, Error, Register, BitFlags, interface, Config };
use super::OperatingMode;
+use {interface, Ads1x1x, BitFlags, Config, Error, Register};
impl<DI, IC, CONV, MODE, E> Ads1x1x<DI, IC, CONV, MODE>
where
@@ -21,7 +21,7 @@ where
/// Read whether a measurement is currently in progress.
pub fn is_measurement_in_progress(&mut self) -> Result<bool, Error<E>> {
let config = Config {
- bits: self.iface.read_register(Register::CONFIG)?
+ bits: self.iface.read_register(Register::CONFIG)?,
};
Ok(!config.is_high(BitFlags::OS))
}
diff --git a/src/devices/features/tier1.rs b/src/devices/features/tier1.rs
index 16ed96c..6bd1a99 100644
--- a/src/devices/features/tier1.rs
+++ b/src/devices/features/tier1.rs
@@ -1,6 +1,6 @@
//! Common functions
-use { Ads1x1x, DataRate12Bit, DataRate16Bit, Error, Register, BitFlags, interface, ic };
+use {ic, interface, Ads1x1x, BitFlags as BF, DataRate12Bit, DataRate16Bit, Error, Register};
impl<DI, IC, MODE, E> Ads1x1x<DI, IC, ic::Resolution12Bit, MODE>
where
@@ -8,15 +8,16 @@ where
{
/// Set data rate
pub fn set_data_rate(&mut self, rate: DataRate12Bit) -> Result<(), Error<E>> {
+ use DataRate12Bit as DR;
let config;
match rate {
- DataRate12Bit::Sps128 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0),
- DataRate12Bit::Sps250 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0),
- DataRate12Bit::Sps490 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0),
- DataRate12Bit::Sps920 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0),
- DataRate12Bit::Sps1600 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0),
- DataRate12Bit::Sps2400 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0),
- DataRate12Bit::Sps3300 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0),
+ DR::Sps128 => config = self.config.with_low( BF::DR2).with_low( BF::DR1).with_low( BF::DR0),
+ DR::Sps250 => config = self.config.with_low( BF::DR2).with_low( BF::DR1).with_high(BF::DR0),
+ DR::Sps490 => config = self.config.with_low( BF::DR2).with_high(BF::DR1).with_low( BF::DR0),
+ DR::Sps920 => config = self.config.with_low( BF::DR2).with_high(BF::DR1).with_high(BF::DR0),
+ DR::Sps1600 => config = self.config.with_high(BF::DR2).with_low( BF::DR1).with_low( BF::DR0),
+ DR::Sps2400 => config = self.config.with_high(BF::DR2).with_low( BF::DR1).with_high(BF::DR0),
+ DR::Sps3300 => config = self.config.with_high(BF::DR2).with_high(BF::DR1).with_low( BF::DR0),
}
self.iface.write_register(Register::CONFIG, config.bits)?;
self.config = config;
@@ -30,16 +31,17 @@ where
{
/// Set data rate
pub fn set_data_rate(&mut self, rate: DataRate16Bit) -> Result<(), Error<E>> {
+ use DataRate16Bit as DR;
let config;
match rate {
- DataRate16Bit::Sps8 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0),
- DataRate16Bit::Sps16 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0),
- DataRate16Bit::Sps32 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0),
- DataRate16Bit::Sps64 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0),
- DataRate16Bit::Sps128 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0),
- DataRate16Bit::Sps250 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0),
- DataRate16Bit::Sps475 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0),
- DataRate16Bit::Sps860 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0),
+ DR::Sps8 => config = self.config.with_low( BF::DR2).with_low( BF::DR1).with_low( BF::DR0),
+ DR::Sps16 => config = self.config.with_low( BF::DR2).with_low( BF::DR1).with_high(BF::DR0),
+ DR::Sps32 => config = self.config.with_low( BF::DR2).with_high(BF::DR1).with_low( BF::DR0),
+ DR::Sps64 => config = self.config.with_low( BF::DR2).with_high(BF::DR1).with_high(BF::DR0),
+ DR::Sps128 => config = self.config.with_high(BF::DR2).with_low( BF::DR1).with_low( BF::DR0),
+ DR::Sps250 => config = self.config.with_high(BF::DR2).with_low( BF::DR1).with_high(BF::DR0),
+ DR::Sps475 => config = self.config.with_high(BF::DR2).with_high(BF::DR1).with_low( BF::DR0),
+ DR::Sps860 => config = self.config.with_high(BF::DR2).with_high(BF::DR1).with_high(BF::DR0),
}
self.iface.write_register(Register::CONFIG, config.bits)?;
self.config = config;
diff --git a/src/devices/features/tier2.rs b/src/devices/features/tier2.rs
index 6047572..3f8d7b4 100644
--- a/src/devices/features/tier2.rs
+++ b/src/devices/features/tier2.rs
@@ -2,21 +2,21 @@
//!
//! These are the features included only in ADS1x14, ADS1x15
-use { Ads1x1x, Error, interface, ic, FullScaleRange, ComparatorMode,
- ComparatorPolarity, ComparatorLatching, ComparatorQueue, Register,
- BitFlags, conversion };
+use {
+ conversion, ic, interface, Ads1x1x, BitFlags as BF, ComparatorLatching, ComparatorMode,
+ ComparatorPolarity, ComparatorQueue, Error, FullScaleRange, Register,
+};
impl<DI, IC, CONV, MODE, E> Ads1x1x<DI, IC, CONV, MODE>
where
DI: interface::WriteData<Error = E>,
IC: ic::Tier2Features,
- CONV: conversion::ConvertThreshold<E>
+ CONV: conversion::ConvertThreshold<E>,
{
/// Set the input voltage measurable range
///
/// This configures the programmable gain amplifier and determines the measurable input voltage range.
pub fn set_full_scale_range(&mut self, range: FullScaleRange) -> Result<(), Error<E>> {
- use BitFlags as BF;
let config;
match range {
FullScaleRange::Within6_144V => config = self.config.with_low( BF::PGA2).with_low( BF::PGA1).with_low( BF::PGA0),
@@ -57,8 +57,8 @@ where
pub fn set_comparator_mode(&mut self, mode: ComparatorMode) -> Result<(), Error<E>> {
let config;
match mode {
- ComparatorMode::Traditional => config = self.config.with_low(BitFlags::COMP_MODE),
- ComparatorMode::Window => config = self.config.with_high(BitFlags::COMP_MODE)
+ ComparatorMode::Traditional => config = self.config.with_low( BF::COMP_MODE),
+ ComparatorMode::Window => config = self.config.with_high(BF::COMP_MODE),
}
self.iface.write_register(Register::CONFIG, config.bits)?;
self.config = config;
@@ -66,11 +66,14 @@ where
}
/// Set comparator polarity
- pub fn set_comparator_polarity(&mut self, polarity: ComparatorPolarity) -> Result<(), Error<E>> {
+ pub fn set_comparator_polarity(
+ &mut self,
+ polarity: ComparatorPolarity,
+ ) -> Result<(), Error<E>> {
let config;
match polarity {
- ComparatorPolarity::ActiveLow => config = self.config.with_low( BitFlags::COMP_POL),
- ComparatorPolarity::ActiveHigh => config = self.config.with_high(BitFlags::COMP_POL)
+ ComparatorPolarity::ActiveLow => config = self.config.with_low( BF::COMP_POL),
+ ComparatorPolarity::ActiveHigh => config = self.config.with_high(BF::COMP_POL),
}
self.iface.write_register(Register::CONFIG, config.bits)?;
self.config = config;
@@ -78,11 +81,14 @@ where
}
/// Set comparator latching
- pub fn set_comparator_latching(&mut self, latching: ComparatorLatching) -> Result<(), Error<E>> {
+ pub fn set_comparator_latching(
+ &mut self,
+ latching: ComparatorLatching,
+ ) -> Result<(), Error<E>> {
let config;
match latching {
- ComparatorLatching::Nonlatching => config = self.config.with_low( BitFlags::COMP_LAT),
- ComparatorLatching::Latching => config = self.config.with_high(BitFlags::COMP_LAT)
+ ComparatorLatching::Nonlatching => config = self.config.with_low( BF::COMP_LAT),
+ ComparatorLatching::Latching => config = self.config.with_high(BF::COMP_LAT),
}
self.iface.write_register(Register::CONFIG, config.bits)?;
self.config = config;
@@ -95,9 +101,9 @@ where
pub fn set_comparator_queue(&mut self, queue: ComparatorQueue) -> Result<(), Error<E>> {
let config;
match queue {
- ComparatorQueue::One => config = self.config.with_low( BitFlags::COMP_QUE1).with_low( BitFlags::COMP_QUE0),
- ComparatorQueue::Two => config = self.config.with_low( BitFlags::COMP_QUE1).with_high(BitFlags::COMP_QUE0),
- ComparatorQueue::Four => config = self.config.with_high(BitFlags::COMP_QUE1).with_low( BitFlags::COMP_QUE0)
+ ComparatorQueue::One => config = self.config.with_low( BF::COMP_QUE1).with_low( BF::COMP_QUE0),
+ ComparatorQueue::Two => config = self.config.with_low( BF::COMP_QUE1).with_high(BF::COMP_QUE0),
+ ComparatorQueue::Four => config = self.config.with_high(BF::COMP_QUE1).with_low( BF::COMP_QUE0),
}
self.iface.write_register(Register::CONFIG, config.bits)?;
self.config = config;
@@ -110,7 +116,7 @@ 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(BitFlags::COMP_QUE1).with_high(BitFlags::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(())
@@ -124,7 +130,7 @@ 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(BitFlags::COMP_QUE1).with_high(BitFlags::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 e5124e1..5b87738 100644
--- a/src/devices/mod.rs
+++ b/src/devices/mod.rs
@@ -1,7 +1,7 @@
#[derive(Debug, Clone, Copy)]
enum OperatingMode {
OneShot,
- Continuous
+ Continuous,
}
mod mode;
diff --git a/src/devices/mode/continuous.rs b/src/devices/mode/continuous.rs
index 35cfd7b..cb4757c 100644
--- a/src/devices/mode/continuous.rs
+++ b/src/devices/mode/continuous.rs
@@ -1,9 +1,9 @@
//! Continuous measurement mode
-use core::marker::PhantomData;
-use { Ads1x1x, conversion, Error, hal, interface, mode, Register };
-use channels::ChannelSelection;
use super::super::OperatingMode;
+use channels::ChannelSelection;
+use core::marker::PhantomData;
+use {conversion, hal, interface, mode, Ads1x1x, Error, Register};
impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous>
where
@@ -20,7 +20,7 @@ where
a_conversion_was_started: false,
_conv: PhantomData,
_ic: PhantomData,
- _mode: PhantomData
+ _mode: PhantomData,
})
}
@@ -58,7 +58,8 @@ where
/// 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> {
+ 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;
diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs
index a03d8d2..3595c26 100644
--- a/src/devices/mode/oneshot.rs
+++ b/src/devices/mode/oneshot.rs
@@ -1,14 +1,14 @@
//! Common functions
-use core::marker::PhantomData;
-use { Ads1x1x, mode, Error, Register, BitFlags, Config };
-use { interface, conversion, hal, nb };
use channels::ChannelSelection;
+use core::marker::PhantomData;
+use {conversion, hal, interface, nb};
+use {mode, Ads1x1x, BitFlags, Config, Error, Register};
impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::OneShot>
where
DI: interface::WriteData<Error = E> + interface::ReadData<Error = E>,
- CONV: conversion::ConvertMeasurement
+ CONV: conversion::ConvertMeasurement,
{
/// Change operating mode to Continuous
pub fn into_continuous(self) -> Result<Ads1x1x<DI, IC, CONV, mode::Continuous>, Error<E>> {
@@ -19,7 +19,7 @@ where
a_conversion_was_started: self.a_conversion_was_started,
_conv: PhantomData,
_ic: PhantomData,
- _mode: PhantomData
+ _mode: PhantomData,
})
}
@@ -34,7 +34,7 @@ impl<DI, IC, CONV, E, CH> hal::adc::OneShot<Ads1x1x<DI, IC, CONV, mode::OneShot>
where
DI: interface::ReadData<Error = E> + interface::WriteData<Error = E>,
CONV: conversion::ConvertMeasurement,
- CH: hal::adc::Channel<Ads1x1x<DI, IC, CONV, mode::OneShot>, ID = ChannelSelection>
+ CH: hal::adc::Channel<Ads1x1x<DI, IC, CONV, mode::OneShot>, ID = ChannelSelection>,
{
type Error = Error<E>;
@@ -63,7 +63,8 @@ where
return Ok(CONV::convert_measurement(value));
}
let config = self.config.with_mux_bits(CH::channel());
- self.trigger_measurement(&config).map_err(nb::Error::Other)?;
+ self.trigger_measurement(&config)
+ .map_err(nb::Error::Other)?;
self.config = config;
self.a_conversion_was_started = true;
Err(nb::Error::WouldBlock)