diff options
Diffstat (limited to 'src/devices')
-rw-r--r-- | src/devices/ads1x1x/mod.rs | 10 | ||||
-rw-r--r-- | src/devices/channels.rs | 86 | ||||
-rw-r--r-- | src/devices/common.rs (renamed from src/devices/ads1x1x/common.rs) | 0 | ||||
-rw-r--r-- | src/devices/construction/i2c.rs | 45 | ||||
-rw-r--r-- | src/devices/construction/mod.rs | 3 | ||||
-rw-r--r-- | src/devices/features/mod.rs (renamed from src/devices/ads1x1x/features/mod.rs) | 0 | ||||
-rw-r--r-- | src/devices/features/tier1.rs (renamed from src/devices/ads1x1x/features/tier1.rs) | 0 | ||||
-rw-r--r-- | src/devices/features/tier2.rs (renamed from src/devices/ads1x1x/features/tier2.rs) | 0 | ||||
-rw-r--r-- | src/devices/ic.rs | 42 | ||||
-rw-r--r-- | src/devices/mod.rs | 16 | ||||
-rw-r--r-- | src/devices/mode/continuous.rs (renamed from src/devices/ads1x1x/mode/continuous.rs) | 0 | ||||
-rw-r--r-- | src/devices/mode/mod.rs (renamed from src/devices/ads1x1x/mode/mod.rs) | 0 | ||||
-rw-r--r-- | src/devices/mode/oneshot.rs (renamed from src/devices/ads1x1x/mode/oneshot.rs) | 4 |
13 files changed, 12 insertions, 194 deletions
diff --git a/src/devices/ads1x1x/mod.rs b/src/devices/ads1x1x/mod.rs deleted file mode 100644 index 95d8907..0000000 --- a/src/devices/ads1x1x/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Functions for all devices - -enum OperatingMode { - OneShot, - Continuous -} - -mod common; -mod mode; -mod features; diff --git a/src/devices/channels.rs b/src/devices/channels.rs deleted file mode 100644 index c202ad3..0000000 --- a/src/devices/channels.rs +++ /dev/null @@ -1,86 +0,0 @@ -//! ADC input channels -use { Ads1x1x, ic, hal, Config, BitFlags as BF }; - -/// ADC input channel selection -#[allow(dead_code)] -pub mod channel { - /// Measure single-ended signal on input channel 0 - pub struct SingleA0; - /// Measure single-ended signal on input channel 1 - pub struct SingleA1; - /// Measure single-ended signal on input channel 2 - pub struct SingleA2; - /// Measure single-ended signal on input channel 3 - pub struct SingleA3; - /// Measure signal on input channel 0 differentially to signal on input channel 1 - pub struct DifferentialA0A1; - /// Measure signal on input channel 0 differentially to signal on input channel 3 - pub struct DifferentialA0A3; - /// Measure signal on input channel 1 differentially to signal on input channel 3 - pub struct DifferentialA1A3; - /// Measure signal on input channel 3 differentially to signal on input channel 3 - pub struct DifferentialA2A3; -} - -pub enum ChannelSelection { - SingleA0, - SingleA1, - SingleA2, - SingleA3, - DifferentialA0A1, - DifferentialA0A3, - DifferentialA1A3, - DifferentialA2A3, -} - -macro_rules! impl_channel { - ( $IC:ident, $CH:ident ) => { - impl<DI, MODE> hal::adc::Channel<Ads1x1x<DI, ic::$IC, MODE>> for channel::$CH { - type ID = ChannelSelection; - - fn channel() -> Self::ID { - ChannelSelection::$CH - } - } - } -} - -impl_channel!(Ads1013, DifferentialA0A1); -impl_channel!(Ads1113, DifferentialA0A1); - -impl_channel!(Ads1014, DifferentialA0A1); -impl_channel!(Ads1114, DifferentialA0A1); - -impl_channel!(Ads1015, DifferentialA0A1); -impl_channel!(Ads1015, DifferentialA0A3); -impl_channel!(Ads1015, DifferentialA1A3); -impl_channel!(Ads1015, DifferentialA2A3); -impl_channel!(Ads1015, SingleA0); -impl_channel!(Ads1015, SingleA1); -impl_channel!(Ads1015, SingleA2); -impl_channel!(Ads1015, SingleA3); - -impl_channel!(Ads1115, DifferentialA0A1); -impl_channel!(Ads1115, DifferentialA0A3); -impl_channel!(Ads1115, DifferentialA1A3); -impl_channel!(Ads1115, DifferentialA2A3); -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), - } - } -} diff --git a/src/devices/ads1x1x/common.rs b/src/devices/common.rs index 5abb99c..5abb99c 100644 --- a/src/devices/ads1x1x/common.rs +++ b/src/devices/common.rs diff --git a/src/devices/construction/i2c.rs b/src/devices/construction/i2c.rs deleted file mode 100644 index 9ef18eb..0000000 --- a/src/devices/construction/i2c.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! Constructor/destructor functions for devices using I2C interface. - -extern crate embedded_hal as hal; -use hal::blocking; -use core::marker::PhantomData; -use { Ads1x1x, DEVICE_BASE_ADDRESS, SlaveAddr, ic, Config, mode }; -use interface::I2cInterface; - - -macro_rules! impl_new_destroy { - ( $IC:ident, $create:ident, $destroy:ident ) => { - impl<I2C, E> Ads1x1x<I2cInterface<I2C>, ic::$IC, mode::OneShot> - where - 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) - }, - config: Config::default(), - a_conversion_was_started: false, - _ic: PhantomData, - _mode: PhantomData - } - } - } - impl<I2C, MODE> Ads1x1x<I2cInterface<I2C>, ic::$IC, 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); -impl_new_destroy!(Ads1113, new_ads1113, destroy_ads1113); -impl_new_destroy!(Ads1014, new_ads1014, destroy_ads1014); -impl_new_destroy!(Ads1114, new_ads1114, destroy_ads1114); -impl_new_destroy!(Ads1015, new_ads1015, destroy_ads1015); -impl_new_destroy!(Ads1115, new_ads1115, destroy_ads1115); diff --git a/src/devices/construction/mod.rs b/src/devices/construction/mod.rs deleted file mode 100644 index 0873d88..0000000 --- a/src/devices/construction/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Construction / destruction functions - -mod i2c; diff --git a/src/devices/ads1x1x/features/mod.rs b/src/devices/features/mod.rs index c24b7b4..c24b7b4 100644 --- a/src/devices/ads1x1x/features/mod.rs +++ b/src/devices/features/mod.rs diff --git a/src/devices/ads1x1x/features/tier1.rs b/src/devices/features/tier1.rs index 9f72b77..9f72b77 100644 --- a/src/devices/ads1x1x/features/tier1.rs +++ b/src/devices/features/tier1.rs diff --git a/src/devices/ads1x1x/features/tier2.rs b/src/devices/features/tier2.rs index 43dce5c..43dce5c 100644 --- a/src/devices/ads1x1x/features/tier2.rs +++ b/src/devices/features/tier2.rs diff --git a/src/devices/ic.rs b/src/devices/ic.rs deleted file mode 100644 index 7b30f85..0000000 --- a/src/devices/ic.rs +++ /dev/null @@ -1,42 +0,0 @@ -/// ICs -use private; - -#[derive(PartialEq)] -pub enum ResolutionBits { - _12, - _16 -} - -pub trait Resolution : private::Sealed { - const BITS : ResolutionBits; -} - -macro_rules! ic_marker { - ($name:ident, $resolution:ident) => { - /// IC marker - pub struct $name(()); - impl Resolution for $name { - const BITS: ResolutionBits = ResolutionBits::$resolution; - } - }; -} - -ic_marker!(Ads1013, _12); -ic_marker!(Ads1113, _16); -ic_marker!(Ads1014, _12); -ic_marker!(Ads1114, _16); -ic_marker!(Ads1015, _12); -ic_marker!(Ads1115, _16); - -pub trait Tier2Features : private::Sealed { } - -macro_rules! tier2_features { - ($name:ident) => { - impl Tier2Features for $name {} - } -} - -tier2_features!(Ads1014); -tier2_features!(Ads1114); -tier2_features!(Ads1015); -tier2_features!(Ads1115); diff --git a/src/devices/mod.rs b/src/devices/mod.rs index c73d344..95d8907 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -1,6 +1,10 @@ -#[doc(hidden)] -pub mod ic; -mod ads1x1x; -mod construction; -mod channels; -pub use self::channels::channel; +//! Functions for all devices + +enum OperatingMode { + OneShot, + Continuous +} + +mod common; +mod mode; +mod features; diff --git a/src/devices/ads1x1x/mode/continuous.rs b/src/devices/mode/continuous.rs index 1472478..1472478 100644 --- a/src/devices/ads1x1x/mode/continuous.rs +++ b/src/devices/mode/continuous.rs diff --git a/src/devices/ads1x1x/mode/mod.rs b/src/devices/mode/mod.rs index 8e0e012..8e0e012 100644 --- a/src/devices/ads1x1x/mode/mod.rs +++ b/src/devices/mode/mod.rs diff --git a/src/devices/ads1x1x/mode/oneshot.rs b/src/devices/mode/oneshot.rs index 7ff9ac9..30958ab 100644 --- a/src/devices/ads1x1x/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -3,8 +3,8 @@ use core::marker::PhantomData; use { Ads1x1x, mode, Error, Register, BitFlags, Config, ic }; use { interface, hal, nb }; -use devices::ads1x1x::OperatingMode; -use devices::channels::ChannelSelection; +use devices::OperatingMode; +use channels::ChannelSelection; use super::convert_measurement; impl<DI, IC, E> Ads1x1x<DI, IC, mode::OneShot> |