diff options
| author | Markus Reiter <me@reitermark.us> | 2024-01-12 20:24:51 +0100 | 
|---|---|---|
| committer | Diego Barrios Romero <eldruin@gmail.com> | 2024-01-19 11:23:31 +0100 | 
| commit | b3ca672f70c71194da40a7670549a8264c13d971 (patch) | |
| tree | 1f316806351a059ca5b5fccbcf4d790b94c0b471 | |
| parent | ed4cc1dbc5b048332b68a0ebc1d7113d482a74a2 (diff) | |
| download | ads1x1x-async-b3ca672f70c71194da40a7670549a8264c13d971.tar.gz ads1x1x-async-b3ca672f70c71194da40a7670549a8264c13d971.tar.xz ads1x1x-async-b3ca672f70c71194da40a7670549a8264c13d971.zip | |
Update to `embedded-hal` 1.0.
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | Cargo.toml | 8 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | examples/all_channels.rs | 9 | ||||
| -rw-r--r-- | examples/linux.rs | 3 | ||||
| -rw-r--r-- | examples/typed.rs | 5 | ||||
| -rw-r--r-- | src/channel.rs | 98 | ||||
| -rw-r--r-- | src/channels.rs | 121 | ||||
| -rw-r--r-- | src/construction.rs | 3 | ||||
| -rw-r--r-- | src/conversion.rs | 2 | ||||
| -rw-r--r-- | src/devices/common.rs | 9 | ||||
| -rw-r--r-- | src/devices/mode/continuous.rs | 13 | ||||
| -rw-r--r-- | src/devices/mode/oneshot.rs | 62 | ||||
| -rw-r--r-- | src/interface.rs | 7 | ||||
| -rw-r--r-- | src/lib.rs | 9 | ||||
| -rw-r--r-- | src/types.rs | 3 | ||||
| -rw-r--r-- | tests/common/mod.rs | 6 | ||||
| -rw-r--r-- | tests/mux.rs | 11 | ||||
| -rw-r--r-- | tests/tier1.rs | 7 | ||||
| -rw-r--r-- | tests/tier2.rs | 2 | 
20 files changed, 173 insertions, 210 deletions
| diff --git a/CHANGELOG.md b/CHANGELOG.md index cbee377..2c50ecc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.  ## [Unreleased] -... +- Updated `embedded-hal` to version `1`, `read` in one-shot mode is therefore only an inherent method.  ## [0.2.2] - 2021-07-29 @@ -18,18 +18,18 @@ include = [      "/LICENSE-MIT",      "/LICENSE-APACHE",  ] -edition = "2018" +edition = "2021"  [badges]  coveralls = { repository = "eldruin/ads1x1x-rs", branch = "master", service = "github" }  [dependencies]  nb = "1" -embedded-hal = { version = "0.2.2", features = ["unproven"] } +embedded-hal = "1"  [dev-dependencies] -linux-embedded-hal = "0.3" -embedded-hal-mock = "0.7" +embedded-hal-mock = { version = "0.10", default-features = false, features = ["eh1"] } +linux-embedded-hal = "0.4"  [profile.release]  lto = true @@ -77,7 +77,6 @@ Please find additional examples using hardware in this repository: [driver-examp  [driver-examples]: https://github.com/eldruin/driver-examples  ```rust -use embedded_hal::adc::OneShot;  use linux_embedded_hal::I2cdev;  use nb::block; @@ -87,7 +86,7 @@ fn main() {      let dev = I2cdev::new("/dev/i2c-1").unwrap();      let address = SlaveAddr::default();      let mut adc = Ads1x1x::new_ads1013(dev, address); -    let value = block!(adc.read(&mut channel::DifferentialA0A1)).unwrap(); +    let value = block!(adc.read(channel::DifferentialA0A1)).unwrap();      println!("Measurement: {}", value);      // get I2C device back      let _dev = adc.destroy_ads1013(); diff --git a/examples/all_channels.rs b/examples/all_channels.rs index 888737c..ddf8326 100644 --- a/examples/all_channels.rs +++ b/examples/all_channels.rs @@ -1,4 +1,3 @@ -use embedded_hal::adc::OneShot;  use linux_embedded_hal::I2cdev;  use nb::block; @@ -9,10 +8,10 @@ fn main() {      let address = SlaveAddr::default();      let mut adc = Ads1x1x::new_ads1015(dev, address);      let values = [ -        block!(adc.read(&mut channel::SingleA0)).unwrap(), -        block!(adc.read(&mut channel::SingleA1)).unwrap(), -        block!(adc.read(&mut channel::SingleA2)).unwrap(), -        block!(adc.read(&mut channel::SingleA3)).unwrap(), +        block!(adc.read(channel::SingleA0)).unwrap(), +        block!(adc.read(channel::SingleA1)).unwrap(), +        block!(adc.read(channel::SingleA2)).unwrap(), +        block!(adc.read(channel::SingleA3)).unwrap(),      ];      for (channel, value) in values.iter().enumerate() {          println!("Channel {}: {}", channel, value); diff --git a/examples/linux.rs b/examples/linux.rs index 7364816..55eab64 100644 --- a/examples/linux.rs +++ b/examples/linux.rs @@ -1,4 +1,3 @@ -use embedded_hal::adc::OneShot;  use linux_embedded_hal::I2cdev;  use nb::block; @@ -8,7 +7,7 @@ fn main() {      let dev = I2cdev::new("/dev/i2c-1").unwrap();      let address = SlaveAddr::default();      let mut adc = Ads1x1x::new_ads1013(dev, address); -    let value = block!(adc.read(&mut channel::DifferentialA0A1)).unwrap(); +    let value = block!(adc.read(channel::DifferentialA0A1)).unwrap();      println!("Measurement: {}", value);      // get I2C device back      let _dev = adc.destroy_ads1013(); diff --git a/examples/typed.rs b/examples/typed.rs index 61268cf..6d6961c 100644 --- a/examples/typed.rs +++ b/examples/typed.rs @@ -1,12 +1,11 @@  // This example demonstrates the use of a type alias for the `Ads1x1x` struct  // to ease usage in signatures. -use embedded_hal::adc::OneShot;  use linux_embedded_hal::I2cdev;  use nb::block;  use ads1x1x::{ -    channel::SingleA0, +    channel,      ic::{Ads1115, Resolution16Bit},      interface::I2cInterface,      Ads1x1x, SlaveAddr, @@ -18,7 +17,7 @@ type Adc = Ads1x1x<I2cInterface<I2cdev>, Ads1115, Resolution16Bit, ads1x1x::mode  /// Read a single value from channel A.  /// Returns 0 on Error.  pub fn read(adc: &mut Adc) -> i16 { -    block!(adc.read(&mut SingleA0)).unwrap_or(0) +    block!(adc.read(channel::SingleA0)).unwrap_or(0)  }  fn main() { diff --git a/src/channel.rs b/src/channel.rs new file mode 100644 index 0000000..df23c39 --- /dev/null +++ b/src/channel.rs @@ -0,0 +1,98 @@ +//! ADC input channels +use crate::{ic, Ads1x1x, BitFlags as BF, Config}; + +mod private { +    pub trait Sealed {} +} + +/// Marker type for an ADC input channel. +pub trait ChannelId<T>: private::Sealed { +    /// Get the channel. +    fn channel_id() -> ChannelSelection; +} + +macro_rules! impl_channels { +    ($(#[doc = $doc:expr] $CH:ident => [$($IC:ident),+]),+ $(,)?) => { +        #[derive(Debug, Clone, Copy)] +        /// ADC input channel selection. +        pub enum ChannelSelection { +            $( +                #[doc = $doc] +                $CH, +            )+ +        } + +        $( +            #[doc = $doc] +            pub struct $CH; + +            impl private::Sealed for $CH {} + +            $( +                impl<DI, CONV, MODE> ChannelId<Ads1x1x<DI, ic::$IC, CONV, MODE>> for $CH { +                    fn channel_id() -> ChannelSelection { +                        ChannelSelection::$CH +                    } +                } +            )+ +        )+ +    }; +} + +impl_channels!( +    /// Measure signal on input channel 0 differentially to signal on input channel 1. +    DifferentialA0A1 => [Ads1013, Ads1014, Ads1015, Ads1113, Ads1114,  Ads1115], +    /// Measure signal on input channel 0 differentially to signal on input channel 3. +    DifferentialA0A3 => [Ads1015, Ads1115], +    /// Measure signal on input channel 1 differentially to signal on input channel 3. +    DifferentialA1A3 => [Ads1015, Ads1115], +    /// Measure signal on input channel 3 differentially to signal on input channel 3. +    DifferentialA2A3 => [Ads1015, Ads1115], +    /// Measure single-ended signal on input channel 0. +    SingleA0 => [Ads1015, Ads1115], +    /// Measure single-ended signal on input channel 1. +    SingleA1 => [Ads1015, Ads1115], +    /// Measure single-ended signal on input channel 2. +    SingleA2 => [Ads1015, Ads1115], +    /// Measure single-ended signal on input channel 3. +    SingleA3 => [Ads1015, Ads1115] +); + +impl Config { +    pub(crate) fn with_mux_bits(&self, ch: ChannelSelection) -> Self { +        match ch { +            ChannelSelection::DifferentialA0A1 => self +                .with_low(BF::MUX2) +                .with_low(BF::MUX1) +                .with_low(BF::MUX0), +            ChannelSelection::DifferentialA0A3 => self +                .with_low(BF::MUX2) +                .with_low(BF::MUX1) +                .with_high(BF::MUX0), +            ChannelSelection::DifferentialA1A3 => self +                .with_low(BF::MUX2) +                .with_high(BF::MUX1) +                .with_low(BF::MUX0), +            ChannelSelection::DifferentialA2A3 => self +                .with_low(BF::MUX2) +                .with_high(BF::MUX1) +                .with_high(BF::MUX0), +            ChannelSelection::SingleA0 => self +                .with_high(BF::MUX2) +                .with_low(BF::MUX1) +                .with_low(BF::MUX0), +            ChannelSelection::SingleA1 => self +                .with_high(BF::MUX2) +                .with_low(BF::MUX1) +                .with_high(BF::MUX0), +            ChannelSelection::SingleA2 => self +                .with_high(BF::MUX2) +                .with_high(BF::MUX1) +                .with_low(BF::MUX0), +            ChannelSelection::SingleA3 => self +                .with_high(BF::MUX2) +                .with_high(BF::MUX1) +                .with_high(BF::MUX0), +        } +    } +} diff --git a/src/channels.rs b/src/channels.rs deleted file mode 100644 index a4c806c..0000000 --- a/src/channels.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! ADC input channels -use crate::{ic, Ads1x1x, BitFlags as BF, Config}; -use embedded_hal::adc; - -/// 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; -} - -/// ADC input channel selection -#[derive(Debug, Clone, Copy)] -pub enum ChannelSelection { -    /// Measure single-ended signal on input channel 0 -    SingleA0, -    /// Measure single-ended signal on input channel 1 -    SingleA1, -    /// Measure single-ended signal on input channel 2 -    SingleA2, -    /// Measure single-ended signal on input channel 3 -    SingleA3, -    /// Measure signal on input channel 0 differentially to signal on input channel 1 -    DifferentialA0A1, -    /// Measure signal on input channel 0 differentially to signal on input channel 3 -    DifferentialA0A3, -    /// Measure signal on input channel 1 differentially to signal on input channel 3 -    DifferentialA1A3, -    /// Measure signal on input channel 2 differentially to signal on input channel 3 -    DifferentialA2A3, -} - -macro_rules! impl_channel { -    ( $IC:ident, $CH:ident ) => { -        impl<DI, CONV, MODE> adc::Channel<Ads1x1x<DI, ic::$IC, CONV, 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/construction.rs b/src/construction.rs index e217c85..d6463df 100644 --- a/src/construction.rs +++ b/src/construction.rs @@ -5,13 +5,12 @@ use crate::{      DEVICE_BASE_ADDRESS,  };  use core::marker::PhantomData; -use embedded_hal::blocking;  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: embedded_hal::i2c::I2c<Error = E>,          {              /// Create a new instance of the device in OneShot mode.              pub fn $create(i2c: I2C, address: SlaveAddr) -> Self { diff --git a/src/conversion.rs b/src/conversion.rs index d6aea82..142de0e 100644 --- a/src/conversion.rs +++ b/src/conversion.rs @@ -7,7 +7,7 @@ pub trait ConvertThreshold<E>: private::Sealed {  impl<E> ConvertThreshold<E> for ic::Resolution12Bit {      fn convert_threshold(value: i16) -> Result<u16, Error<E>> { -        if value < -2048 || value > 2047 { +        if !(-2048..=2047).contains(&value) {              return Err(Error::InvalidInputData);          }          Ok((value << 4) as u16) diff --git a/src/devices/common.rs b/src/devices/common.rs index 2234d93..f1509d3 100644 --- a/src/devices/common.rs +++ b/src/devices/common.rs @@ -7,11 +7,10 @@ where      DI: interface::WriteData<Error = E> + interface::ReadData<Error = E>,  {      pub(super) fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error<E>> { -        let config; -        match mode { -            OperatingMode::OneShot => config = self.config.with_high(BitFlags::OP_MODE), -            OperatingMode::Continuous => config = self.config.with_low(BitFlags::OP_MODE), -        } +        let config = match mode { +            OperatingMode::OneShot => self.config.with_high(BitFlags::OP_MODE), +            OperatingMode::Continuous => self.config.with_low(BitFlags::OP_MODE), +        };          self.iface.write_register(Register::CONFIG, config.bits)?;          self.config = config;          Ok(()) diff --git a/src/devices/mode/continuous.rs b/src/devices/mode/continuous.rs index 64aa179..b3b4807 100644 --- a/src/devices/mode/continuous.rs +++ b/src/devices/mode/continuous.rs @@ -1,11 +1,10 @@  //! Continuous measurement mode  use crate::{ -    channels::ChannelSelection, conversion, devices::OperatingMode, interface, mode, Ads1x1x, -    Error, ModeChangeError, Register, +    conversion, devices::OperatingMode, interface, mode, Ads1x1x, ChannelId, Error, +    ModeChangeError, Register,  };  use core::marker::PhantomData; -use embedded_hal::adc;  impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous>  where @@ -41,11 +40,9 @@ where      /// Note that when changing the channel in continuous conversion mode, the      /// ongoing conversion will be completed.      /// The following conversions will use the new channel configuration. -    pub fn select_channel<CH>(&mut self, _channel: &mut CH) -> Result<(), Error<E>> -    where -        CH: adc::Channel<Ads1x1x<DI, IC, CONV, mode::OneShot>, ID = ChannelSelection>, -    { -        let config = self.config.with_mux_bits(CH::channel()); +    #[allow(unused_variables)] +    pub fn select_channel<CH: ChannelId<Self>>(&mut self, channel: CH) -> Result<(), Error<E>> { +        let config = self.config.with_mux_bits(CH::channel_id());          self.iface.write_register(Register::CONFIG, config.bits)?;          self.config = config;          Ok(()) diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs index fa4d3b8..0663e4b 100644 --- a/src/devices/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -1,10 +1,9 @@  //! Common functions  use crate::{ -    conversion, devices::OperatingMode, interface, mode, Ads1x1x, BitFlags, ChannelSelection, -    Config, DynamicOneShot, Error, ModeChangeError, Register, +    conversion, devices::OperatingMode, interface, mode, Ads1x1x, BitFlags, ChannelId, +    ChannelSelection, Config, DynamicOneShot, Error, ModeChangeError, Register,  };  use core::marker::PhantomData; -use embedded_hal::adc;  impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::OneShot>  where @@ -35,14 +34,35 @@ where      }  } -impl<DI, IC, CONV, E, CH> adc::OneShot<Ads1x1x<DI, IC, CONV, mode::OneShot>, i16, CH> -    for Ads1x1x<DI, IC, CONV, mode::OneShot> +impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::OneShot>  where      DI: interface::ReadData<Error = E> + interface::WriteData<Error = E>,      CONV: conversion::ConvertMeasurement, -    CH: adc::Channel<Ads1x1x<DI, IC, CONV, mode::OneShot>, ID = ChannelSelection>,  { -    type Error = Error<E>; +    fn read_inner(&mut self, channel: ChannelSelection) -> nb::Result<i16, Error<E>> { +        if self +            .is_measurement_in_progress() +            .map_err(nb::Error::Other)? +        { +            return Err(nb::Error::WouldBlock); +        } +        let config = self.config.with_mux_bits(channel); +        let same_channel = self.config == config; +        if self.a_conversion_was_started && same_channel { +            // result is ready +            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)); +        } +        self.trigger_measurement(&config) +            .map_err(nb::Error::Other)?; +        self.config = config; +        self.a_conversion_was_started = true; +        Err(nb::Error::WouldBlock) +    }      /// Request that the ADC begin a conversion on the specified channel.      /// @@ -57,8 +77,9 @@ where      /// In case a measurement was requested and after is it is finished a      /// 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> { -        <Self as DynamicOneShot>::read(self, CH::channel()) +    #[allow(unused_variables)] +    pub fn read<CH: ChannelId<Self>>(&mut self, channel: CH) -> nb::Result<i16, Error<E>> { +        self.read_inner(CH::channel_id())      }  } @@ -70,27 +91,6 @@ where      type Error = Error<E>;      fn read(&mut self, channel: ChannelSelection) -> nb::Result<i16, Self::Error> { -        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(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)?; -            self.a_conversion_was_started = false; -            return Ok(CONV::convert_measurement(value)); -        } -        let config = self.config.with_mux_bits(channel); -        self.trigger_measurement(&config) -            .map_err(nb::Error::Other)?; -        self.config = config; -        self.a_conversion_was_started = true; -        Err(nb::Error::WouldBlock) +        self.read_inner(channel)      }  } diff --git a/src/interface.rs b/src/interface.rs index 960c7ef..0e665a3 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1,7 +1,6 @@  //! I2C interface  use crate::{private, Error}; -use embedded_hal::blocking;  /// I2C interface  #[derive(Debug, Default)] @@ -14,13 +13,14 @@ pub struct I2cInterface<I2C> {  pub trait WriteData: private::Sealed {      /// Error type      type Error; +      /// Write to an u16 register      fn write_register(&mut self, register: u8, data: u16) -> Result<(), Error<Self::Error>>;  }  impl<I2C, E> WriteData for I2cInterface<I2C>  where -    I2C: blocking::i2c::Write<Error = E>, +    I2C: embedded_hal::i2c::I2c<Error = E>,  {      type Error = E;      fn write_register(&mut self, register: u8, data: u16) -> Result<(), Error<E>> { @@ -33,13 +33,14 @@ where  pub trait ReadData: private::Sealed {      /// Error type      type Error; +      /// Read an u16 register      fn read_register(&mut self, register: u8) -> Result<u16, Error<Self::Error>>;  }  impl<I2C, E> ReadData for I2cInterface<I2C>  where -    I2C: blocking::i2c::WriteRead<Error = E>, +    I2C: embedded_hal::i2c::I2c<Error = E>,  {      type Error = E;      fn read_register(&mut self, register: u8) -> Result<u16, Error<E>> { @@ -129,13 +129,12 @@  //! ### Make a one-shot measurement  //! ```no_run  //! use ads1x1x::{channel, Ads1x1x, SlaveAddr}; -//! use embedded_hal::adc::OneShot;  //! use linux_embedded_hal::I2cdev;  //! use nb::block;  //!  //! let dev = I2cdev::new("/dev/i2c-1").unwrap();  //! let mut adc = Ads1x1x::new_ads1013(dev, SlaveAddr::default()); -//! let measurement = block!(adc.read(&mut channel::DifferentialA0A1)).unwrap(); +//! let measurement = block!(adc.read(channel::DifferentialA0A1)).unwrap();  //! println!("Measurement: {}", measurement);  //! let _dev = adc.destroy_ads1013(); // get I2C device back  //! ``` @@ -201,8 +200,6 @@  //! adc.set_high_threshold_raw(1500).unwrap();  //! adc.set_comparator_latching(ComparatorLatching::Latching).unwrap();  //! ``` - -#![doc(html_root_url = "https://docs.rs/ads1x1x/0.2.2")]  #![deny(unsafe_code)]  #![deny(missing_docs)]  #![no_std] @@ -237,8 +234,8 @@ impl BitFlags {      const COMP_QUE0: u16 = 0b0000_0000_0000_0001;  } -mod channels; -pub use crate::channels::{channel, ChannelSelection}; +pub mod channel; +pub use channel::{ChannelId, ChannelSelection};  mod construction;  mod conversion;  pub use crate::conversion::{ConvertMeasurement, ConvertThreshold}; diff --git a/src/types.rs b/src/types.rs index 957825e..e4402fe 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,8 +1,9 @@  //! Type definitions. -use crate::{channels::ChannelSelection, private};  use core::marker::PhantomData; +use crate::{private, ChannelSelection}; +  /// Errors in this crate  #[derive(Debug)]  pub enum Error<E> { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index c9ca2a1..429479c 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,7 +1,5 @@ -extern crate embedded_hal_mock as hal; -use self::hal::i2c::{Mock as I2cMock, Transaction as I2cTrans}; -extern crate ads1x1x; -use self::ads1x1x::{ic, interface, mode, Ads1x1x, SlaveAddr}; +use ads1x1x::{ic, interface, mode, Ads1x1x, SlaveAddr}; +use embedded_hal_mock::eh1::i2c::{Mock as I2cMock, Transaction as I2cTrans};  #[allow(unused)]  pub const DEVICE_ADDRESS: u8 = 0b100_1000; diff --git a/tests/mux.rs b/tests/mux.rs index b539ebe..ac335b5 100644 --- a/tests/mux.rs +++ b/tests/mux.rs @@ -1,5 +1,5 @@  use ads1x1x::channel; -use embedded_hal_mock::i2c::Transaction as I2cTrans; +use embedded_hal_mock::eh1::i2c::Transaction as I2cTrans;  use nb::block;  mod common; @@ -12,7 +12,6 @@ macro_rules! mux_test {      ($name:ident, $CS:ident, $config_bits:expr, $other_CS:ident, $other_config_bits:expr) => {          mod $name {              use super::*; -            use embedded_hal::adc::OneShot;              #[test]              fn can_read() { @@ -33,7 +32,7 @@ macro_rules! mux_test {                      I2cTrans::write_read(DEV_ADDR, vec![Register::CONVERSION], vec![0x80, 0x00]),                  ];                  let mut dev = new(&transactions); -                let measurement = block!(dev.read(&mut channel::$CS)).unwrap(); +                let measurement = block!(dev.read(channel::$CS)).unwrap();                  assert_eq!(-2048, measurement);                  destroy(dev);              } @@ -67,8 +66,8 @@ macro_rules! mux_test {                      I2cTrans::write_read(DEV_ADDR, vec![Register::CONVERSION], vec![0x80, 0x00]),                  ];                  let mut dev = new(&transactions); -                assert_would_block!(dev.read(&mut channel::$CS)); -                let measurement = block!(dev.read(&mut channel::$other_CS)).unwrap(); +                assert_would_block!(dev.read(channel::$CS)); +                let measurement = block!(dev.read(channel::$other_CS)).unwrap();                  assert_eq!(-2048, measurement);                  destroy(dev);              } @@ -89,7 +88,7 @@ macro_rules! mux_test {                  ];                  let dev = new(&transactions);                  let mut dev = dev.into_continuous().ok().unwrap(); -                dev.select_channel(&mut channel::$CS).unwrap(); +                dev.select_channel(channel::$CS).unwrap();                  destroy(dev);              }          } diff --git a/tests/tier1.rs b/tests/tier1.rs index 1f1a542..bbe9d6f 100644 --- a/tests/tier1.rs +++ b/tests/tier1.rs @@ -1,5 +1,5 @@  use ads1x1x::{channel, DataRate12Bit, DataRate16Bit}; -use embedded_hal_mock::i2c::Transaction as I2cTrans; +use embedded_hal_mock::eh1::i2c::Transaction as I2cTrans;  use nb::block;  mod common; @@ -12,7 +12,6 @@ macro_rules! measure_tests {      ($IC:ident, $create:ident, $destroy:ident, $expected:expr) => {          mod $IC {              use super::*; -            use embedded_hal::adc::OneShot;              mod would_block {                  use super::*; @@ -26,7 +25,7 @@ macro_rules! measure_tests {                          vec![config.msb(), config.lsb()],                      )];                      let mut dev = $create(&transactions); -                    assert_would_block!(dev.read(&mut channel::DifferentialA0A1)); +                    assert_would_block!(dev.read(channel::DifferentialA0A1));                      $destroy(dev);                  }              } @@ -53,7 +52,7 @@ macro_rules! measure_tests {                      I2cTrans::write_read(DEV_ADDR, vec![Register::CONVERSION], vec![0x80, 0x00]),                  ];                  let mut dev = $create(&transactions); -                let measurement = block!(dev.read(&mut channel::DifferentialA0A1)).unwrap(); +                let measurement = block!(dev.read(channel::DifferentialA0A1)).unwrap();                  assert_eq!($expected, measurement);                  $destroy(dev);              } diff --git a/tests/tier2.rs b/tests/tier2.rs index 15a7865..7d3a54f 100644 --- a/tests/tier2.rs +++ b/tests/tier2.rs @@ -1,7 +1,7 @@  use ads1x1x::{      ComparatorLatching, ComparatorMode, ComparatorPolarity, ComparatorQueue, FullScaleRange,  }; -use embedded_hal_mock::i2c::Transaction as I2cTrans; +use embedded_hal_mock::eh1::i2c::Transaction as I2cTrans;  mod common;  use crate::common::{ | 
