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 /src/devices/mode/continuous.rs | |
parent | 0edd5527161809dfbc0c76e39c462e3a4f00beb7 (diff) | |
download | ads1x1x-async-cd403a91e6078956445aeb21d6509e863b0592ae.tar.gz ads1x1x-async-cd403a91e6078956445aeb21d6509e863b0592ae.tar.xz ads1x1x-async-cd403a91e6078956445aeb21d6509e863b0592ae.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?
Diffstat (limited to 'src/devices/mode/continuous.rs')
-rw-r--r-- | src/devices/mode/continuous.rs | 17 |
1 files changed, 10 insertions, 7 deletions
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(()) } |