From 50b28f8cf4eb1c6185ed296ef4f35ccd8f6d3ed4 Mon Sep 17 00:00:00 2001 From: Brian Bustin Date: Fri, 15 Mar 2024 10:36:22 -0700 Subject: [PATCH] changes to work with embedded-hal 1.0.0 --- Cargo.toml | 9 +++------ src/commands.rs | 2 +- src/error.rs | 10 +++++----- src/sht4x.rs | 9 +++------ 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb84d20..e68fb41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,17 +15,14 @@ documentation = "https://docs.rs/sht4x" repository = "https://github.com/sirhcel/sht4x" readme = "README.md" -exclude = [ - "/.github/", - ".gitignore", -] +exclude = ["/.github/", ".gitignore"] [dependencies] defmt = { version = "0.3.2", optional = true } -embedded-hal = "0.2.7" +embedded-hal = "1.0.0" fixed = "1.20.0" -sensirion-i2c = "0.2" +sensirion-i2c = "0.3" [features] defmt = ["dep:defmt"] diff --git a/src/commands.rs b/src/commands.rs index 132e12f..3d78617 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -31,7 +31,7 @@ impl Command { } } - pub(crate) fn duration_ms(&self) -> u16 { + pub(crate) fn duration_ms(&self) -> u32 { // Values rounded up from the maximum durations given in the datasheet // table 4, 'System timing specifications'. match self { diff --git a/src/error.rs b/src/error.rs index c4af875..8d85b1a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,5 @@ -use embedded_hal::blocking::i2c::{Read, Write}; +use embedded_hal::i2c::I2c; +use embedded_hal::i2c::SevenBitAddress; use sensirion_i2c::i2c; /// Error conditions from accessing SHT4x sensors. @@ -12,12 +13,11 @@ pub enum Error { Crc, } -impl From> for Error +impl From> for Error where - W: Write, - R: Read, + I: I2c, { - fn from(err: i2c::Error) -> Self { + fn from(err: i2c::Error) -> Self { match err { i2c::Error::Crc => Error::Crc, i2c::Error::I2cRead(e) => Error::I2c(e), diff --git a/src/sht4x.rs b/src/sht4x.rs index a49bf7d..1072471 100644 --- a/src/sht4x.rs +++ b/src/sht4x.rs @@ -4,10 +4,7 @@ use crate::{ types::{Address, HeatingDuration, HeatingPower, Measurement, Precision, SensorData}, }; use core::marker::PhantomData; -use embedded_hal::blocking::{ - delay::DelayMs, - i2c::{Read, Write, WriteRead}, -}; +use embedded_hal::{delay::DelayNs, i2c::I2c, i2c::SevenBitAddress}; use sensirion_i2c::i2c; const RESPONSE_LEN: usize = 6; @@ -48,8 +45,8 @@ impl From for Command { impl Sht4x where - I: Read + Write + WriteRead, - D: DelayMs, + I: I2c, + D: DelayNs, { /// Creates a new driver instance using the given I2C bus. It configures the default I2C /// address 0x44 used by most family members.