From cd403a91e6078956445aeb21d6509e863b0592ae Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sun, 8 Dec 2024 12:01:31 +0000 Subject: Modify to use async 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? --- src/devices/mode/continuous.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/devices/mode/continuous.rs') 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 Ads1x1x where - I2C: embedded_hal::i2c::I2c, + I2C: embedded_hal_async::i2c::I2c, CONV: conversion::ConvertMeasurement, { /// Changes to one-shot operating mode. - pub fn into_one_shot( + pub async fn into_one_shot( mut self, ) -> Result, ModeChangeError> { - 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> { - let value = self.read_register(Register::CONVERSION)?; + pub async fn read(&mut self) -> Result> { + 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>(&mut self, channel: CH) -> Result<(), Error> { + pub async fn select_channel>( + &mut self, + channel: CH, + ) -> Result<(), Error> { 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(()) } -- cgit v1.2.3-54-g00ecf