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/features/tier1.rs | |
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?
Diffstat (limited to 'src/devices/features/tier1.rs')
-rw-r--r-- | src/devices/features/tier1.rs | 12 |
1 files changed, 6 insertions, 6 deletions
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(()) } |