From 5485d9655e2ab3a6d04e5f69b246f5db4d2c5936 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Wed, 21 Nov 2018 09:35:37 +0100 Subject: Code formatting --- src/devices/common.rs | 4 ++-- src/devices/features/tier1.rs | 34 ++++++++++++++++++---------------- src/devices/features/tier2.rs | 42 ++++++++++++++++++++++++------------------ src/devices/mod.rs | 2 +- src/devices/mode/continuous.rs | 11 ++++++----- src/devices/mode/oneshot.rs | 15 ++++++++------- 6 files changed, 59 insertions(+), 49 deletions(-) (limited to 'src/devices') 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 Ads1x1x where @@ -21,7 +21,7 @@ where /// Read whether a measurement is currently in progress. pub fn is_measurement_in_progress(&mut self) -> Result> { 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 Ads1x1x where @@ -8,15 +8,16 @@ where { /// Set data rate pub fn set_data_rate(&mut self, rate: DataRate12Bit) -> Result<(), Error> { + 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> { + 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 Ads1x1x where DI: interface::WriteData, IC: ic::Tier2Features, - CONV: conversion::ConvertThreshold + CONV: conversion::ConvertThreshold, { /// 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> { - 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> { 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> { + pub fn set_comparator_polarity( + &mut self, + polarity: ComparatorPolarity, + ) -> Result<(), Error> { 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> { + pub fn set_comparator_latching( + &mut self, + latching: ComparatorLatching, + ) -> Result<(), Error> { 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> { 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> { - 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> { - 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 Ads1x1x 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(&mut self, _channel: &mut CH) -> Result<(), Error> where - CH: hal::adc::Channel, ID = ChannelSelection> { + CH: hal::adc::Channel, 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 Ads1x1x where DI: interface::WriteData + interface::ReadData, - CONV: conversion::ConvertMeasurement + CONV: conversion::ConvertMeasurement, { /// Change operating mode to Continuous pub fn into_continuous(self) -> Result, Error> { @@ -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 hal::adc::OneShot where DI: interface::ReadData + interface::WriteData, CONV: conversion::ConvertMeasurement, - CH: hal::adc::Channel, ID = ChannelSelection> + CH: hal::adc::Channel, ID = ChannelSelection>, { type Error = Error; @@ -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) -- cgit v1.2.3-54-g00ecf