summaryrefslogtreecommitdiffstats
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
parente4a1ac5a04d021ef026c559354e9913ae59864d8 (diff)
downloadads1x1x-async-5485d9655e2ab3a6d04e5f69b246f5db4d2c5936.tar.gz
ads1x1x-async-5485d9655e2ab3a6d04e5f69b246f5db4d2c5936.tar.xz
ads1x1x-async-5485d9655e2ab3a6d04e5f69b246f5db4d2c5936.zip
Code formatting
-rw-r--r--examples/linux.rs2
-rw-r--r--src/channels.rs4
-rw-r--r--src/construction.rs16
-rw-r--r--src/conversion.rs11
-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
-rw-r--r--src/ic.rs9
-rw-r--r--src/interface.rs17
-rw-r--r--src/lib.rs33
-rw-r--r--tests/common/mod.rs23
-rw-r--r--tests/construction.rs10
15 files changed, 122 insertions, 111 deletions
diff --git a/examples/linux.rs b/examples/linux.rs
index 7f65c52..df2ab58 100644
--- a/examples/linux.rs
+++ b/examples/linux.rs
@@ -5,8 +5,8 @@ extern crate linux_embedded_hal;
extern crate nb;
extern crate ads1x1x;
+use ads1x1x::{channel, Ads1x1x, SlaveAddr};
use linux_embedded_hal::I2cdev;
-use ads1x1x::{ Ads1x1x, SlaveAddr, channel };
fn main() {
let dev = I2cdev::new("/dev/i2c-1").unwrap();
diff --git a/src/channels.rs b/src/channels.rs
index f88e10e..d5ae7bc 100644
--- a/src/channels.rs
+++ b/src/channels.rs
@@ -1,5 +1,5 @@
//! ADC input channels
-use { Ads1x1x, ic, hal, Config, BitFlags as BF };
+use {hal, ic, Ads1x1x, BitFlags as BF, Config};
/// ADC input channel selection
#[allow(dead_code)]
@@ -43,7 +43,7 @@ macro_rules! impl_channel {
ChannelSelection::$CH
}
}
- }
+ };
}
impl_channel!(Ads1013, DifferentialA0A1);
diff --git a/src/construction.rs b/src/construction.rs
index ab100fd..61abb06 100644
--- a/src/construction.rs
+++ b/src/construction.rs
@@ -1,42 +1,40 @@
//! Constructor/destructor functions.
extern crate embedded_hal as hal;
-use hal::blocking;
use core::marker::PhantomData;
-use { Ads1x1x, DEVICE_BASE_ADDRESS, SlaveAddr, ic, Config, mode, FullScaleRange };
+use hal::blocking;
use interface::I2cInterface;
-
+use {ic, mode, Ads1x1x, Config, FullScaleRange, SlaveAddr, DEVICE_BASE_ADDRESS};
macro_rules! impl_new_destroy {
( $IC:ident, $create:ident, $destroy:ident, $conv:ty ) => {
impl<I2C, E> Ads1x1x<I2cInterface<I2C>, ic::$IC, $conv, mode::OneShot>
where
- I2C: blocking::i2c::Write<Error = E> + blocking::i2c::WriteRead<Error = E>
+ I2C: blocking::i2c::Write<Error = E> + blocking::i2c::WriteRead<Error = E>,
{
/// Create a new instance of the device in OneShot mode.
pub fn $create(i2c: I2C, address: SlaveAddr) -> Self {
Ads1x1x {
iface: I2cInterface {
i2c,
- address: address.addr(DEVICE_BASE_ADDRESS)
+ address: address.addr(DEVICE_BASE_ADDRESS),
},
config: Config::default(),
fsr: FullScaleRange::default(),
a_conversion_was_started: false,
_conv: PhantomData,
_ic: PhantomData,
- _mode: PhantomData
+ _mode: PhantomData,
}
}
}
- impl<I2C, CONV, MODE> Ads1x1x<I2cInterface<I2C>, ic::$IC, CONV, MODE>
- {
+ impl<I2C, CONV, MODE> Ads1x1x<I2cInterface<I2C>, ic::$IC, CONV, MODE> {
/// Destroy driver instance, return I²C bus instance.
pub fn $destroy(self) -> I2C {
self.iface.i2c
}
}
- }
+ };
}
impl_new_destroy!(Ads1013, new_ads1013, destroy_ads1013, ic::Resolution12Bit);
diff --git a/src/conversion.rs b/src/conversion.rs
index 5e7751c..644ed4a 100644
--- a/src/conversion.rs
+++ b/src/conversion.rs
@@ -1,7 +1,7 @@
-use { ic, private, Error };
+use {ic, private, Error};
#[doc(hidden)]
-pub trait ConvertThreshold<E> : private::Sealed {
+pub trait ConvertThreshold<E>: private::Sealed {
fn convert_threshold(value: i16) -> Result<u16, Error<E>>;
}
@@ -21,7 +21,7 @@ impl<E> ConvertThreshold<E> for ic::Resolution16Bit {
}
#[doc(hidden)]
-pub trait ConvertMeasurement : private::Sealed {
+pub trait ConvertMeasurement: private::Sealed {
fn convert_measurement(register_data: u16) -> i16;
}
@@ -32,8 +32,7 @@ impl ConvertMeasurement for ic::Resolution12Bit {
if is_negative {
let value = 0b1111_0000_0000_0000 | (value >> 4);
value as i16
- }
- else {
+ } else {
(value >> 4) as i16
}
}
@@ -69,7 +68,7 @@ mod tests {
fn assert_invalid_input_data<E>(result: Result<u16, Error<E>>) {
match result {
Err(Error::InvalidInputData) => (),
- _ => panic!("InvalidInputData error was not returned.")
+ _ => panic!("InvalidInputData error was not returned."),
}
}
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)
diff --git a/src/ic.rs b/src/ic.rs
index a09cb72..4ed42d9 100644
--- a/src/ic.rs
+++ b/src/ic.rs
@@ -1,9 +1,8 @@
/// ICs
use private;
-pub struct Resolution12Bit(pub(crate)());
-pub struct Resolution16Bit(pub(crate)());
-
+pub struct Resolution12Bit(pub(crate) ());
+pub struct Resolution16Bit(pub(crate) ());
macro_rules! ic_marker {
($name:ident) => {
@@ -19,12 +18,12 @@ ic_marker!(Ads1114);
ic_marker!(Ads1015);
ic_marker!(Ads1115);
-pub trait Tier2Features : private::Sealed { }
+pub trait Tier2Features: private::Sealed {}
macro_rules! tier2_features {
($name:ident) => {
impl Tier2Features for $name {}
- }
+ };
}
tier2_features!(Ads1014);
diff --git a/src/interface.rs b/src/interface.rs
index 2ef42fc..36458b4 100644
--- a/src/interface.rs
+++ b/src/interface.rs
@@ -2,18 +2,17 @@
extern crate embedded_hal as hal;
use hal::blocking;
-use { private, Error };
-
+use {private, Error};
/// I2C interface
#[derive(Debug, Default)]
pub struct I2cInterface<I2C> {
pub(crate) i2c: I2C,
- pub(crate) address : u8,
+ pub(crate) address: u8,
}
/// Write data
-pub trait WriteData : private::Sealed {
+pub trait WriteData: private::Sealed {
/// Error type
type Error;
/// Write to an u16 register
@@ -22,19 +21,17 @@ pub trait WriteData : private::Sealed {
impl<I2C, E> WriteData for I2cInterface<I2C>
where
- I2C: blocking::i2c::Write<Error = E>
+ I2C: blocking::i2c::Write<Error = E>,
{
type Error = E;
fn write_register(&mut self, register: u8, data: u16) -> Result<(), Error<E>> {
let payload: [u8; 3] = [register, (data >> 8) as u8, data as u8];
- self.i2c
- .write(self.address, &payload)
- .map_err(Error::I2C)
+ self.i2c.write(self.address, &payload).map_err(Error::I2C)
}
}
/// Read data
-pub trait ReadData : private::Sealed {
+pub trait ReadData: private::Sealed {
/// Error type
type Error;
/// Read an u16 register
@@ -43,7 +40,7 @@ pub trait ReadData : private::Sealed {
impl<I2C, E> ReadData for I2cInterface<I2C>
where
- I2C: blocking::i2c::WriteRead<Error = E>
+ I2C: blocking::i2c::WriteRead<Error = E>,
{
type Error = E;
fn read_register(&mut self, register: u8) -> Result<u16, Error<E>> {
diff --git a/src/lib.rs b/src/lib.rs
index 7e829be..0faa50b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -204,8 +204,8 @@
#![deny(warnings)]
#![no_std]
-extern crate nb;
extern crate embedded_hal as hal;
+extern crate nb;
use core::marker::PhantomData;
/// All possible errors in this crate
@@ -219,7 +219,7 @@ pub enum Error<E> {
NotStarted,
}
-const DEVICE_BASE_ADDRESS : u8 = 0b100_1000;
+const DEVICE_BASE_ADDRESS: u8 = 0b100_1000;
/// Mode marker types
pub mod mode {
@@ -246,10 +246,9 @@ pub enum DataRate12Bit {
/// 2400 SPS
Sps2400,
/// 3300 SPS
- Sps3300
+ Sps3300,
}
-
/// Data rate for ADS1113, ADS1114, ADS1115
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DataRate16Bit {
@@ -268,7 +267,7 @@ pub enum DataRate16Bit {
/// 475 SPS
Sps475,
/// 860 SPS
- Sps860
+ Sps860,
}
/// Comparator mode (only for ADS1x14, ADS1x15)
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -285,7 +284,7 @@ pub enum ComparatorMode {
/// In this mode the ALERT/RDY pin asserts (according to selected active
/// polarity) when the conversion data exceeds the value set as *high*
/// threshold or goes below the value set as *low* temperature threshold.
- Window
+ Window,
}
/// Comparator polarity (only for ADS1x14, ADS1x15)
@@ -294,7 +293,7 @@ pub enum ComparatorPolarity {
/// Active low (default)
ActiveLow,
/// Active high
- ActiveHigh
+ ActiveHigh,
}
/// Comparator polarity (only for ADS1x14, ADS1x15)
@@ -314,7 +313,7 @@ pub enum ComparatorLatching {
/// read by the master or an appropriate SMBus alert response is sent by
/// the master. The device responds with its address, and it is the lowest
/// address currently asserting the ALERT/RDY bus line.
- Latching
+ Latching,
}
/// Comparator alert queue (only for ADS1x14, ADS1x15)
@@ -358,7 +357,7 @@ pub enum SlaveAddr {
/// Default slave address
Default,
/// Alternative slave address providing bit values for A1 and A0
- Alternative(bool, bool)
+ Alternative(bool, bool),
}
impl Default for SlaveAddr {
@@ -411,19 +410,23 @@ impl BitFlags {
#[derive(Debug, Clone, PartialEq)]
struct Config {
- bits: u16
+ bits: u16,
}
impl Config {
- fn is_high(&self, mask : u16) -> bool {
+ fn is_high(&self, mask: u16) -> bool {
(self.bits & mask) != 0
}
fn with_high(&self, mask: u16) -> Self {
- Config { bits: self.bits | mask }
+ Config {
+ bits: self.bits | mask,
+ }
}
fn with_low(&self, mask: u16) -> Self {
- Config { bits: self.bits & !mask }
+ Config {
+ bits: self.bits & !mask,
+ }
}
}
@@ -448,7 +451,7 @@ pub struct Ads1x1x<DI, IC, CONV, MODE> {
a_conversion_was_started: bool,
_conv: PhantomData<CONV>,
_ic: PhantomData<IC>,
- _mode: PhantomData<MODE>
+ _mode: PhantomData<MODE>,
}
#[doc(hidden)]
@@ -464,7 +467,7 @@ pub use conversion::ConvertThreshold;
pub use conversion::ConvertMeasurement;
mod private {
- use super::{ ic, interface };
+ use super::{ic, interface};
pub trait Sealed {}
impl<I2C> Sealed for interface::I2cInterface<I2C> {}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index d81494f..509dbd8 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,10 +1,10 @@
extern crate embedded_hal_mock as hal;
-use self::hal::i2c::{ Mock as I2cMock, Transaction as I2cTrans };
+use self::hal::i2c::{Mock as I2cMock, Transaction as I2cTrans};
extern crate ads1x1x;
-use self::ads1x1x::{ Ads1x1x, interface, ic, SlaveAddr, mode };
+use self::ads1x1x::{ic, interface, mode, Ads1x1x, SlaveAddr};
#[allow(unused)]
-pub const DEVICE_ADDRESS : u8 = 0b100_1000;
+pub const DEVICE_ADDRESS: u8 = 0b100_1000;
pub struct Register;
#[allow(unused)]
@@ -37,16 +37,20 @@ impl BitFlags {
}
pub struct Config {
- pub bits: u16
+ pub bits: u16,
}
#[allow(dead_code)]
impl Config {
pub fn with_high(&self, mask: u16) -> Self {
- Config { bits: self.bits | mask }
+ Config {
+ bits: self.bits | mask,
+ }
}
pub fn with_low(&self, mask: u16) -> Self {
- Config { bits: self.bits & !mask }
+ Config {
+ bits: self.bits & !mask,
+ }
}
pub fn msb(&self) -> u8 {
@@ -75,7 +79,7 @@ macro_rules! impl_new_destroy {
pub fn $destroy<MODE>(dev: Ads1x1x<$iface, ic::$ic, $conv, MODE>) {
dev.$destroy().done();
}
- }
+ };
}
impl_new_destroy!(Ads1013, new_ads1013, destroy_ads1013, ic::Resolution12Bit, I2cTrans, interface::I2cInterface<I2cMock>);
@@ -90,8 +94,7 @@ macro_rules! assert_would_block {
($result: expr) => {
match $result {
Err(nb::Error::WouldBlock) => (),
- _ => panic!("Would not block.")
+ _ => panic!("Would not block."),
}
- }
+ };
}
-
diff --git a/tests/construction.rs b/tests/construction.rs
index 459e5a8..698d06a 100644
--- a/tests/construction.rs
+++ b/tests/construction.rs
@@ -1,7 +1,9 @@
mod common;
-use common::{ new_ads1013, destroy_ads1013, new_ads1113, destroy_ads1113,
- new_ads1014, destroy_ads1014, new_ads1114, destroy_ads1114,
- new_ads1015, destroy_ads1015, new_ads1115, destroy_ads1115 };
+use common::{
+ new_ads1013, destroy_ads1013, new_ads1113, destroy_ads1113,
+ new_ads1014, destroy_ads1014, new_ads1114, destroy_ads1114,
+ new_ads1015, destroy_ads1015, new_ads1115, destroy_ads1115
+};
macro_rules! impl_tests {
($IC:ident, $create:ident, $destroy:ident) => {
@@ -13,7 +15,7 @@ macro_rules! impl_tests {
$destroy(dev);
}
}
- }
+ };
}
impl_tests!(ads1013, new_ads1013, destroy_ads1013);