diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2024-12-08 12:01:31 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2024-12-08 12:01:31 +0000 |
commit | cd403a91e6078956445aeb21d6509e863b0592ae (patch) | |
tree | b1bb59ed526081be31494544f8920c39f0588711 | |
parent | 0edd5527161809dfbc0c76e39c462e3a4f00beb7 (diff) | |
download | ads1x1x-async-async.tar.gz ads1x1x-async-async.tar.xz ads1x1x-async-async.zip |
Modify to use asyncasync
A changeover from embedded_hal::i2c::I2c to embedded_hal_async::i2c::I2c
including changes to all the relevant functions into async functions.
Tests have been updated to work using futures-test and embedded-hal-mock
with the embedded-hal-async feature.
Examples have been kept the same meaning they no longer compile.
Currently it doesn't _seem_ like the linux embedded hal can do async
i2c so maybe these should be re-written to use embassy?
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | src/construction.rs | 2 | ||||
-rw-r--r-- | src/devices/common.rs | 20 | ||||
-rw-r--r-- | src/devices/features/tier1.rs | 12 | ||||
-rw-r--r-- | src/devices/features/tier2.rs | 43 | ||||
-rw-r--r-- | src/devices/mode/continuous.rs | 17 | ||||
-rw-r--r-- | src/devices/mode/oneshot.rs | 17 | ||||
-rw-r--r-- | tests/mux.rs | 22 | ||||
-rw-r--r-- | tests/tier1.rs | 58 | ||||
-rw-r--r-- | tests/tier2.rs | 28 |
10 files changed, 119 insertions, 105 deletions
@@ -22,10 +22,11 @@ edition = "2021" [dependencies] nb = "1" -embedded-hal = "1" +embedded-hal-async = "1.0.0" [dev-dependencies] -embedded-hal-mock = { version = "0.10", default-features = false, features = ["eh1"] } +embedded-hal-mock = { version = "0.11.1", default-features = false, features = ["eh1", "embedded-hal-async"] } +futures-test = "0.3.31" [target.'cfg(target_os = "linux")'.dev-dependencies] linux-embedded-hal = "0.4" diff --git a/src/construction.rs b/src/construction.rs index 84ee8ad..cd9d779 100644 --- a/src/construction.rs +++ b/src/construction.rs @@ -7,7 +7,7 @@ macro_rules! impl_new_destroy { ( $IC:ident, $create:ident, $destroy:ident, $conv:ty ) => { impl<I2C, E> Ads1x1x<I2C, ic::$IC, $conv, mode::OneShot> where - I2C: embedded_hal::i2c::I2c<Error = E>, + I2C: embedded_hal_async::i2c::I2c<Error = E>, { /// Create a new instance of the device in OneShot mode. pub fn $create(i2c: I2C, address: TargetAddr) -> Self { diff --git a/src/devices/common.rs b/src/devices/common.rs index 66a6d97..865d0c5 100644 --- a/src/devices/common.rs +++ b/src/devices/common.rs @@ -4,36 +4,40 @@ use crate::{devices::OperatingMode, Ads1x1x, BitFlags, Config, Error, Register}; impl<I2C, IC, CONV, MODE, E> Ads1x1x<I2C, IC, CONV, MODE> where - I2C: embedded_hal::i2c::I2c<Error = E>, + I2C: embedded_hal_async::i2c::I2c<Error = E>, { - pub(super) fn write_register(&mut self, register: u8, data: u16) -> Result<(), Error<E>> { + pub(super) async fn write_register(&mut self, register: u8, data: u16) -> Result<(), Error<E>> { let data = data.to_be_bytes(); let payload: [u8; 3] = [register, data[0], data[1]]; - self.i2c.write(self.address, &payload).map_err(Error::I2C) + self.i2c + .write(self.address, &payload) + .await + .map_err(Error::I2C) } - pub(super) fn read_register(&mut self, register: u8) -> Result<u16, Error<E>> { + pub(super) async fn read_register(&mut self, register: u8) -> Result<u16, Error<E>> { let mut data = [0, 0]; self.i2c .write_read(self.address, &[register], &mut data) + .await .map_err(Error::I2C) .and(Ok(u16::from_be_bytes(data))) } - pub(super) fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error<E>> { + pub(super) async fn set_operating_mode(&mut self, mode: OperatingMode) -> Result<(), Error<E>> { let config = match mode { OperatingMode::OneShot => self.config.with_high(BitFlags::OP_MODE), OperatingMode::Continuous => self.config.with_low(BitFlags::OP_MODE), }; - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } /// Checks whether a measurement is currently in progress. - pub fn is_measurement_in_progress(&mut self) -> Result<bool, Error<E>> { + pub async fn is_measurement_in_progress(&mut self) -> Result<bool, Error<E>> { let config = Config { - bits: self.read_register(Register::CONFIG)?, + bits: self.read_register(Register::CONFIG).await?, }; Ok(!config.is_high(BitFlags::OS)) } diff --git a/src/devices/features/tier1.rs b/src/devices/features/tier1.rs index 3a8beb9..17da990 100644 --- a/src/devices/features/tier1.rs +++ b/src/devices/features/tier1.rs @@ -4,10 +4,10 @@ use crate::{ic, Ads1x1x, BitFlags as BF, DataRate12Bit, DataRate16Bit, Error, Re impl<I2C, IC, MODE, E> Ads1x1x<I2C, IC, ic::Resolution12Bit, MODE> where - I2C: embedded_hal::i2c::I2c<Error = E>, + I2C: embedded_hal_async::i2c::I2c<Error = E>, { /// Sets the data rate. - pub fn set_data_rate(&mut self, rate: DataRate12Bit) -> Result<(), Error<E>> { + pub async fn set_data_rate(&mut self, rate: DataRate12Bit) -> Result<(), Error<E>> { use crate::DataRate12Bit as DR; let cfg = self.config.clone(); let config = match rate { @@ -19,7 +19,7 @@ where DR::Sps2400 => cfg.with_high(BF::DR2).with_low(BF::DR1).with_high(BF::DR0), DR::Sps3300 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_low(BF::DR0), }; - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } @@ -27,10 +27,10 @@ where impl<I2C, IC, MODE, E> Ads1x1x<I2C, IC, ic::Resolution16Bit, MODE> where - I2C: embedded_hal::i2c::I2c<Error = E>, + I2C: embedded_hal_async::i2c::I2c<Error = E>, { /// Sets the data rate. - pub fn set_data_rate(&mut self, rate: DataRate16Bit) -> Result<(), Error<E>> { + pub async fn set_data_rate(&mut self, rate: DataRate16Bit) -> Result<(), Error<E>> { use crate::DataRate16Bit as DR; let cfg = self.config.clone(); let config = match rate { @@ -43,7 +43,7 @@ where DR::Sps475 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_low(BF::DR0), DR::Sps860 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_high(BF::DR0), }; - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } diff --git a/src/devices/features/tier2.rs b/src/devices/features/tier2.rs index fe36a72..8a9a3cc 100644 --- a/src/devices/features/tier2.rs +++ b/src/devices/features/tier2.rs @@ -7,14 +7,14 @@ use crate::{ impl<I2C, IC, CONV, MODE, E> Ads1x1x<I2C, IC, CONV, MODE> where - I2C: embedded_hal::i2c::I2c<Error = E>, + I2C: embedded_hal_async::i2c::I2c<Error = E>, IC: ic::Tier2Features, CONV: conversion::ConvertThreshold<E>, { /// Sets the input voltage measurable range. /// /// This configures the programmable gain amplifier (PGA) and determines the measurable input voltage range. - pub fn set_full_scale_range(&mut self, range: FullScaleRange) -> Result<(), Error<E>> { + pub async fn set_full_scale_range(&mut self, range: FullScaleRange) -> Result<(), Error<E>> { use crate::FullScaleRange as FSR; let cfg = self.config.clone(); let config = match range { @@ -40,7 +40,7 @@ where .with_low(BF::PGA1) .with_high(BF::PGA0), }; - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } @@ -52,9 +52,9 @@ where /// /// The input value must be within `[2047..-2048]` for 12-bit devices (`ADS101x`) /// and within `[32767..-32768]` for 16-bit devices (`ADS111x`). - pub fn set_low_threshold_raw(&mut self, value: i16) -> Result<(), Error<E>> { + pub async fn set_low_threshold_raw(&mut self, value: i16) -> Result<(), Error<E>> { let register_value = CONV::convert_threshold(value)?; - self.write_register(Register::LOW_TH, register_value) + self.write_register(Register::LOW_TH, register_value).await } /// Sets the raw comparator upper threshold. @@ -64,24 +64,24 @@ where /// /// The input value must be within `[2047..-2048]` for 12-bit devices (`ADS101x`) /// and within `[32767..-32768]` for 16-bit devices (`ADS111x`). - pub fn set_high_threshold_raw(&mut self, value: i16) -> Result<(), Error<E>> { + pub async fn set_high_threshold_raw(&mut self, value: i16) -> Result<(), Error<E>> { let register_value = CONV::convert_threshold(value)?; - self.write_register(Register::HIGH_TH, register_value) + self.write_register(Register::HIGH_TH, register_value).await } /// Sets the comparator mode. - pub fn set_comparator_mode(&mut self, mode: ComparatorMode) -> Result<(), Error<E>> { + pub async fn set_comparator_mode(&mut self, mode: ComparatorMode) -> Result<(), Error<E>> { let config = match mode { ComparatorMode::Traditional => self.config.with_low(BF::COMP_MODE), ComparatorMode::Window => self.config.with_high(BF::COMP_MODE), }; - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } /// Sets the comparator polarity. - pub fn set_comparator_polarity( + pub async fn set_comparator_polarity( &mut self, polarity: ComparatorPolarity, ) -> Result<(), Error<E>> { @@ -89,13 +89,13 @@ where ComparatorPolarity::ActiveLow => self.config.with_low(BF::COMP_POL), ComparatorPolarity::ActiveHigh => self.config.with_high(BF::COMP_POL), }; - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } /// Sets the comparator latching. - pub fn set_comparator_latching( + pub async fn set_comparator_latching( &mut self, latching: ComparatorLatching, ) -> Result<(), Error<E>> { @@ -103,7 +103,7 @@ where ComparatorLatching::Nonlatching => self.config.with_low(BF::COMP_LAT), ComparatorLatching::Latching => self.config.with_high(BF::COMP_LAT), }; - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } @@ -111,13 +111,13 @@ where /// Activates the comparator and sets the alert queue. /// /// The comparator can be disabled with [`disable_comparator`](Self::disable_comparator). - pub fn set_comparator_queue(&mut self, queue: ComparatorQueue) -> Result<(), Error<E>> { + pub async fn set_comparator_queue(&mut self, queue: ComparatorQueue) -> Result<(), Error<E>> { let config = match queue { ComparatorQueue::One => self.config.with_low(BF::COMP_QUE1).with_low(BF::COMP_QUE0), ComparatorQueue::Two => self.config.with_low(BF::COMP_QUE1).with_high(BF::COMP_QUE0), ComparatorQueue::Four => self.config.with_high(BF::COMP_QUE1).with_low(BF::COMP_QUE0), }; - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } @@ -128,12 +128,12 @@ where /// /// The comparator can be enabled by setting the comparator queue using /// the [`set_comparator_queue`](Self::set_comparator_queue) method. - pub fn disable_comparator(&mut self) -> Result<(), Error<E>> { + pub async fn disable_comparator(&mut self) -> Result<(), Error<E>> { let config = self .config .with_high(BF::COMP_QUE1) .with_high(BF::COMP_QUE0); - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } @@ -144,16 +144,17 @@ where /// in continuous-conversion mode, provides a continuous-conversion ready pulse. /// /// When calling this the comparator will be reset to default and any thresholds will be cleared. - pub fn use_alert_rdy_pin_as_ready(&mut self) -> Result<(), Error<E>> { + pub async fn use_alert_rdy_pin_as_ready(&mut self) -> Result<(), Error<E>> { if self.config != self .config .with_high(BF::COMP_QUE1) .with_high(BF::COMP_QUE0) { - self.set_comparator_queue(ComparatorQueue::default())?; + self.set_comparator_queue(ComparatorQueue::default()) + .await?; } - self.write_register(Register::HIGH_TH, 0x8000)?; - self.write_register(Register::LOW_TH, 0) + self.write_register(Register::HIGH_TH, 0x8000).await?; + self.write_register(Register::LOW_TH, 0).await } } diff --git a/src/devices/mode/continuous.rs b/src/devices/mode/continuous.rs index d514a9a..a7a94b3 100644 --- a/src/devices/mode/continuous.rs +++ b/src/devices/mode/continuous.rs @@ -7,14 +7,14 @@ use core::marker::PhantomData; impl<I2C, IC, CONV, E> Ads1x1x<I2C, IC, CONV, mode::Continuous> where - I2C: embedded_hal::i2c::I2c<Error = E>, + I2C: embedded_hal_async::i2c::I2c<Error = E>, CONV: conversion::ConvertMeasurement, { /// Changes to one-shot operating mode. - pub fn into_one_shot( + pub async fn into_one_shot( mut self, ) -> Result<Ads1x1x<I2C, IC, CONV, mode::OneShot>, ModeChangeError<E, Self>> { - if let Err(Error::I2C(e)) = self.set_operating_mode(OperatingMode::OneShot) { + if let Err(Error::I2C(e)) = self.set_operating_mode(OperatingMode::OneShot).await { return Err(ModeChangeError::I2C(e, self)); } Ok(Ads1x1x { @@ -30,8 +30,8 @@ where } /// Reads the most recent measurement. - pub fn read(&mut self) -> Result<i16, Error<E>> { - let value = self.read_register(Register::CONVERSION)?; + pub async fn read(&mut self) -> Result<i16, Error<E>> { + let value = self.read_register(Register::CONVERSION).await?; Ok(CONV::convert_measurement(value)) } @@ -41,9 +41,12 @@ where /// ongoing conversion will be completed. /// The following conversions will use the new channel configuration. #[allow(unused_variables)] - pub fn select_channel<CH: ChannelId<Self>>(&mut self, channel: CH) -> Result<(), Error<E>> { + pub async fn select_channel<CH: ChannelId<Self>>( + &mut self, + channel: CH, + ) -> Result<(), Error<E>> { let config = self.config.with_mux_bits(CH::channel_id()); - self.write_register(Register::CONFIG, config.bits)?; + self.write_register(Register::CONFIG, config.bits).await?; self.config = config; Ok(()) } diff --git a/src/devices/mode/oneshot.rs b/src/devices/mode/oneshot.rs index 22b6d51..ba78c84 100644 --- a/src/devices/mode/oneshot.rs +++ b/src/devices/mode/oneshot.rs @@ -9,14 +9,14 @@ use crate::{ impl<I2C, IC, CONV, E> Ads1x1x<I2C, IC, CONV, mode::OneShot> where - I2C: embedded_hal::i2c::I2c<Error = E>, + I2C: embedded_hal_async::i2c::I2c<Error = E>, CONV: conversion::ConvertMeasurement, { /// Changes to continuous operating mode. - pub fn into_continuous( + pub async fn into_continuous( mut self, ) -> Result<Ads1x1x<I2C, IC, CONV, mode::Continuous>, ModeChangeError<E, Self>> { - if let Err(Error::I2C(e)) = self.set_operating_mode(OperatingMode::Continuous) { + if let Err(Error::I2C(e)) = self.set_operating_mode(OperatingMode::Continuous).await { return Err(ModeChangeError::I2C(e, self)); } Ok(Ads1x1x { @@ -31,15 +31,15 @@ where }) } - fn trigger_measurement(&mut self, config: &Config) -> Result<(), Error<E>> { + async fn trigger_measurement(&mut self, config: &Config) -> Result<(), Error<E>> { let config = config.with_high(BitFlags::OS); - self.write_register(Register::CONFIG, config.bits) + self.write_register(Register::CONFIG, config.bits).await } } impl<I2C, IC, CONV, E> Ads1x1x<I2C, IC, CONV, mode::OneShot> where - I2C: embedded_hal::i2c::I2c<Error = E>, + I2C: embedded_hal_async::i2c::I2c<Error = E>, CONV: conversion::ConvertMeasurement, { /// Requests that the ADC begins a conversion on the specified channel. @@ -55,9 +55,10 @@ where /// measurement on a different channel is requested, a new measurement on /// using the new channel selection is triggered. #[allow(unused_variables)] - pub fn read<CH: ChannelId<Self>>(&mut self, channel: CH) -> nb::Result<i16, Error<E>> { + pub async fn read<CH: ChannelId<Self>>(&mut self, channel: CH) -> nb::Result<i16, Error<E>> { if self .is_measurement_in_progress() + .await .map_err(nb::Error::Other)? { return Err(nb::Error::WouldBlock); @@ -68,11 +69,13 @@ where // result is ready let value = self .read_register(Register::CONVERSION) + .await .map_err(nb::Error::Other)?; self.a_conversion_was_started = false; return Ok(CONV::convert_measurement(value)); } self.trigger_measurement(&config) + .await .map_err(nb::Error::Other)?; self.config = config; self.a_conversion_was_started = true; diff --git a/tests/mux.rs b/tests/mux.rs index ac335b5..1b2575b 100644 --- a/tests/mux.rs +++ b/tests/mux.rs @@ -13,8 +13,8 @@ macro_rules! mux_test { mod $name { use super::*; - #[test] - fn can_read() { + #[futures_test::test] + async fn can_read() { let default_config = Config::default(); let config = Config::default().with_high(BF::OS).with_high($config_bits); let transactions = [ @@ -32,13 +32,13 @@ 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(channel::$CS)).unwrap(); + let measurement = block!(dev.read(channel::$CS).await).unwrap(); assert_eq!(-2048, measurement); destroy(dev); } - #[test] - fn read_then_read_different_triggers_new_measurement() { + #[futures_test::test] + async fn read_then_read_different_triggers_new_measurement() { let default_config = Config::default(); let config = Config::default().with_high(BF::OS).with_high($config_bits); let other_config = Config::default().with_high($other_config_bits); @@ -66,14 +66,14 @@ 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(channel::$CS)); - let measurement = block!(dev.read(channel::$other_CS)).unwrap(); + assert_would_block!(dev.read(channel::$CS).await); + let measurement = block!(dev.read(channel::$other_CS).await).unwrap(); assert_eq!(-2048, measurement); destroy(dev); } - #[test] - fn continuous_can_select_channel() { + #[futures_test::test] + async fn continuous_can_select_channel() { let config1 = Config::default().with_low(BF::OP_MODE); let config2 = config1.with_high($config_bits); let transactions = [ @@ -87,8 +87,8 @@ macro_rules! mux_test { ), ]; let dev = new(&transactions); - let mut dev = dev.into_continuous().ok().unwrap(); - dev.select_channel(channel::$CS).unwrap(); + let mut dev = dev.into_continuous().await.ok().unwrap(); + dev.select_channel(channel::$CS).await.unwrap(); destroy(dev); } } diff --git a/tests/tier1.rs b/tests/tier1.rs index bbe9d6f..fe5f1b4 100644 --- a/tests/tier1.rs +++ b/tests/tier1.rs @@ -16,8 +16,8 @@ macro_rules! measure_tests { mod would_block { use super::*; - #[test] - fn read_if_measurement_in_progress() { + #[futures_test::test] + async fn read_if_measurement_in_progress() { let config = Config::default().with_low(BF::OS); let transactions = [I2cTrans::write_read( DEV_ADDR, @@ -25,13 +25,13 @@ macro_rules! measure_tests { vec![config.msb(), config.lsb()], )]; let mut dev = $create(&transactions); - assert_would_block!(dev.read(channel::DifferentialA0A1)); + assert_would_block!(dev.read(channel::DifferentialA0A1).await); $destroy(dev); } } - #[test] - fn can_measure() { + #[futures_test::test] + async fn can_measure() { let default_config = Config::default(); let config_with_os = Config::default().with_high(BF::OS); let transactions = [ @@ -52,21 +52,21 @@ 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(channel::DifferentialA0A1)).unwrap(); + let measurement = block!(dev.read(channel::DifferentialA0A1).await).unwrap(); assert_eq!($expected, measurement); $destroy(dev); } - #[test] - fn can_measure_continuous() { + #[futures_test::test] + async fn can_measure_continuous() { let config = Config::default().with_low(BF::OP_MODE); let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()]), I2cTrans::write_read(DEV_ADDR, vec![Register::CONVERSION], vec![0x80, 0x00]), ]; let dev = $create(&transactions); - let mut dev = dev.into_continuous().ok().unwrap(); - let measurement = dev.read().unwrap(); + let mut dev = dev.into_continuous().await.ok().unwrap(); + let measurement = dev.read().await.unwrap(); assert_eq!($expected, measurement); $destroy(dev); } @@ -82,14 +82,14 @@ mod data_rate_12bit { macro_rules! test { ($name:ident, $variant:ident, $config:expr) => { - #[test] - fn $name() { + #[futures_test::test] + async fn $name() { let transactions = [I2cTrans::write( DEV_ADDR, vec![Register::CONFIG, $config.msb(), $config.lsb()], )]; let mut dev = new_ads1013(&transactions); - dev.set_data_rate(DataRate12Bit::$variant).unwrap(); + dev.set_data_rate(DataRate12Bit::$variant).await.unwrap(); destroy_ads1013(dev); } }; @@ -158,14 +158,14 @@ mod data_rate_16bit { macro_rules! test { ($name:ident, $variant:ident, $config:expr) => { - #[test] - fn $name() { + #[futures_test::test] + async fn $name() { let transactions = [I2cTrans::write( DEV_ADDR, vec![Register::CONFIG, $config.msb(), $config.lsb()], )]; let mut dev = new_ads1113(&transactions); - dev.set_data_rate(DataRate16Bit::$variant).unwrap(); + dev.set_data_rate(DataRate16Bit::$variant).await.unwrap(); destroy_ads1113(dev); } }; @@ -237,8 +237,8 @@ mod data_rate_16bit { ); } -#[test] -fn can_read_measurement_in_progress() { +#[futures_test::test] +async fn can_read_measurement_in_progress() { let config_os = Config::default().with_low(BF::OS); let transactions = [I2cTrans::write_read( DEV_ADDR, @@ -246,12 +246,12 @@ fn can_read_measurement_in_progress() { vec![config_os.msb(), config_os.lsb()], )]; let mut dev = new_ads1013(&transactions); - assert!(dev.is_measurement_in_progress().unwrap()); + assert!(dev.is_measurement_in_progress().await.unwrap()); destroy_ads1013(dev); } -#[test] -fn can_read_measurement_not_in_progress() { +#[futures_test::test] +async fn can_read_measurement_not_in_progress() { let config_os = Config::default().with_high(BF::OS); let transactions = [I2cTrans::write_read( DEV_ADDR, @@ -259,24 +259,24 @@ fn can_read_measurement_not_in_progress() { vec![config_os.msb(), config_os.lsb()], )]; let mut dev = new_ads1013(&transactions); - assert!(!dev.is_measurement_in_progress().unwrap()); + assert!(!dev.is_measurement_in_progress().await.unwrap()); destroy_ads1013(dev); } -#[test] -fn can_convert_to_continuous() { +#[futures_test::test] +async fn can_convert_to_continuous() { let config = Config::default().with_low(BF::OP_MODE); let transactions = [I2cTrans::write( DEV_ADDR, vec![Register::CONFIG, config.msb(), config.lsb()], )]; let dev = new_ads1013(&transactions); - let dev = dev.into_continuous().ok().unwrap(); + let dev = dev.into_continuous().await.ok().unwrap(); destroy_ads1013(dev); } -#[test] -fn can_convert_to_one_shot() { +#[futures_test::test] +async fn can_convert_to_one_shot() { let config_cont = Config::default().with_low(BF::OP_MODE); let config_os = Config::default(); let transactions = [ @@ -290,7 +290,7 @@ fn can_convert_to_one_shot() { ), ]; let dev = new_ads1013(&transactions); - let dev = dev.into_continuous().ok().unwrap(); - let dev = dev.into_one_shot().ok().unwrap(); + let dev = dev.into_continuous().await.ok().unwrap(); + let dev = dev.into_one_shot().await.ok().unwrap(); destroy_ads1013(dev); } diff --git a/tests/tier2.rs b/tests/tier2.rs index e29b67b..270d3ce 100644 --- a/tests/tier2.rs +++ b/tests/tier2.rs @@ -10,11 +10,11 @@ use crate::common::{ macro_rules! set_value_test { ($name:ident, $method:ident, $value:expr, $reg:ident, $msb:expr, $lsb:expr) => { - #[test] - fn $name() { + #[futures_test::test] + async fn $name() { let transactions = [I2cTrans::write(DEV_ADDR, vec![Register::$reg, $msb, $lsb])]; let mut dev = new_ads1014(&transactions); - dev.$method($value).unwrap(); + dev.$method($value).await.unwrap(); destroy_ads1014(dev); } }; @@ -80,8 +80,8 @@ mod can_set_comparator_latching { ); } -#[test] -fn can_disable_comparator() { +#[futures_test::test] +async fn can_disable_comparator() { let config = Config::default() .with_high(BF::COMP_QUE1) .with_high(BF::COMP_QUE0); @@ -90,7 +90,7 @@ fn can_disable_comparator() { vec![Register::CONFIG, config.msb(), config.lsb()], )]; let mut dev = new_ads1014(&transactions); - dev.disable_comparator().unwrap(); + dev.disable_comparator().await.unwrap(); destroy_ads1014(dev); } @@ -122,19 +122,19 @@ mod can_set_comparator_queue { ); } -#[test] -fn can_use_alert_rdy_pin_as_rdy_does_not_disable_comparator_if_already_disabled() { +#[futures_test::test] +async fn can_use_alert_rdy_pin_as_rdy_does_not_disable_comparator_if_already_disabled() { let transactions = [ I2cTrans::write(DEV_ADDR, vec![Register::HIGH_TH, 0b1000_0000, 0]), I2cTrans::write(DEV_ADDR, vec![Register::LOW_TH, 0, 0]), ]; let mut dev = new_ads1014(&transactions); - dev.use_alert_rdy_pin_as_ready().unwrap(); + dev.use_alert_rdy_pin_as_ready().await.unwrap(); destroy_ads1014(dev); } -#[test] -fn can_use_alert_rdy_pin_as_rdy_disabled_comparator() { +#[futures_test::test] +async fn can_use_alert_rdy_pin_as_rdy_disabled_comparator() { let config = Config::default() .with_low(BF::COMP_QUE1) .with_low(BF::COMP_QUE0); @@ -155,8 +155,10 @@ fn can_use_alert_rdy_pin_as_rdy_disabled_comparator() { I2cTrans::write(DEV_ADDR, vec![Register::LOW_TH, 0, 0]), ]; let mut dev = new_ads1014(&transactions); - dev.set_comparator_queue(ComparatorQueue::One).unwrap(); - dev.use_alert_rdy_pin_as_ready().unwrap(); + dev.set_comparator_queue(ComparatorQueue::One) + .await + .unwrap(); + dev.use_alert_rdy_pin_as_ready().await.unwrap(); destroy_ads1014(dev); } |