Skip to content

Commit c949306

Browse files
author
Lucian Carata
committed
Change: embedded_hal dependency to 0.2.6 (stable)
1 parent c39a0c4 commit c949306

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sensor-temp-humidity-sht40"
3-
version = "0.2.0"
3+
version = "0.2.6"
44
authors = ["Lucian Carata <[email protected]>"]
55
license = "BSD-3-Clause OR Apache-2.0"
66
description = "Driver for SHT40 temperature and humidity sensor"
@@ -12,11 +12,12 @@ edition = "2021"
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15-
sensirion-i2c = { git="https://github.com/lc525/sensirion-i2c-rs", branch="hal-1.0.0-alpha.6" }
16-
embedded-hal = "1.0.0-alpha.6"
15+
sensirion-i2c = "0.1.1"
16+
embedded-hal = "0.2.6"
1717

1818
[dev-dependencies]
19-
embedded-hal-mock = { git="https://github.com/niclashoyer/embedded-hal-mock", branch="hal-1.0.0" }
19+
linux-embedded-hal = "0.3.2"
20+
embedded-hal-mock = "0.8.0"
2021
float-cmp = "0.9.0"
2122

2223
[profile.release]

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ driver for the Sensirion SHT40 temperature and relative-humidity sensor.
77

88
### Software
99

10-
The driver is developed against the unstable 1.0.0 version of
11-
embedded-hal (currently supporting embedded-hal-1.0.0-alpha.6). As such, it
12-
should also be considered unstable.
13-
14-
A release is planned for the older, stable version of embedded-hal.
10+
The driver is developed against the stable 0.2.6 version of
11+
embedded-hal. Please use the main branch for hal-1.0.0 support
1512

1613
### Hardware Features
1714

src/lib.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
///
1414
/// By depending on embedded-hal, this driver is platform-agnostic and can be
1515
/// used with any platform for which an implementation of the embedded-hal
16-
/// traits exists. Please note that this branch tracks the unstable development
17-
/// version of embedded-hal-1.0.0
18-
///
16+
/// traits exists.
17+
///
1918
/// The full details about the SHT40 sensor can be read in its datasheet:
2019
/// https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Datasheets/Sensirion_Humidity_Sensors_SHT4x_Datasheet.pdf
2120
///
@@ -28,7 +27,7 @@
2827
/// driver; For example, assuming you have connected a SH40 sensor to a linux
2928
/// machine and it is detected as an i2c device:
3029
///
31-
/// ```ignore
30+
/// ```no_run
3231
/// use linux_embedded_hal as hal;
3332
///
3433
/// use hal::{I2cdev, Delay};
@@ -50,8 +49,8 @@
5049
5150
use embedded_hal as hal;
5251

53-
use hal::delay::blocking::DelayUs;
54-
use hal::i2c::blocking::{Read, Write, WriteRead};
52+
use hal::blocking::delay::DelayMs;
53+
use hal::blocking::i2c::{Read, Write, WriteRead};
5554

5655
use sensirion_i2c::{crc8, i2c};
5756

@@ -158,8 +157,8 @@ pub enum TempUnit {
158157
/// SHT40Driver is the main structure with which a user of this driver
159158
/// interracts. It is generic over two parameters implementing embedded_hal
160159
/// traits for the specific platform you're using: I2c which must implement
161-
/// embedded_hal::i2c::blocking::{Read, Write, WriteRead} and Delay which must
162-
/// implement embedded_hal::delay::blocking::DelayUS.
160+
/// embedded_hal::blocking::i2c::{Read, Write, WriteRead} and Delay which must
161+
/// implement embedded_hal::blocking::delay::DelayMs.
163162
///
164163
/// Those implementations are needed for issuing I2C write commands to the
165164
/// sensor, waiting until the sensor has performed the actual measurement and
@@ -308,7 +307,7 @@ impl Command {
308307
impl<I2C, D, E> SHT40Driver<I2C, D>
309308
where
310309
I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,
311-
D: DelayUs
310+
D: DelayMs<u16>
312311
{
313312
/// Initialize a new instance of the driver. Any synchronization required
314313
/// for dealing with multiple instances needs to be managed externally to
@@ -377,11 +376,9 @@ where
377376
fn i2c_command_and_response(&mut self, cmd: Command, rx_bytes: Option<&mut [u8]>)
378377
-> Result<(), Error<E>>{
379378
let dev_cmd = cmd.as_device_command();
380-
i2c::write_command_u8(&mut self.i2c, self.address, dev_cmd.cmd_code)
379+
self.i2c.write(self.address, &dev_cmd.cmd_code.to_be_bytes())
381380
.map_err(|err| { Error::I2c(err) })?;
382-
if let Err(_) = self.delay.delay_ms(dev_cmd.max_duration_ms as u32) {
383-
return Err(Error::<E>::DelayError)
384-
}
381+
self.delay.delay_ms(dev_cmd.max_duration_ms);
385382
if let Some(rx_bytes) = rx_bytes {
386383
i2c::read_words_with_crc(&mut self.i2c, self.address, rx_bytes)?;
387384
};
@@ -544,7 +541,7 @@ where
544541
pub fn soft_reset_device(&mut self) -> Result<(), Error<E>> {
545542
let cmd = Command::SoftReset;
546543
let dev_cmd = cmd.as_device_command();
547-
i2c::write_command_u8(&mut self.i2c, self.address, dev_cmd.cmd_code)
544+
self.i2c.write(self.address, &dev_cmd.cmd_code.to_be_bytes())
548545
.map_err(|err| { Error::I2c(err) })?;
549546
Ok(())
550547
}

0 commit comments

Comments
 (0)