|
13 | 13 | ///
|
14 | 14 | /// By depending on embedded-hal, this driver is platform-agnostic and can be
|
15 | 15 | /// 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 | +/// |
19 | 18 | /// The full details about the SHT40 sensor can be read in its datasheet:
|
20 | 19 | /// https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Datasheets/Sensirion_Humidity_Sensors_SHT4x_Datasheet.pdf
|
21 | 20 | ///
|
|
28 | 27 | /// driver; For example, assuming you have connected a SH40 sensor to a linux
|
29 | 28 | /// machine and it is detected as an i2c device:
|
30 | 29 | ///
|
31 |
| -/// ```ignore |
| 30 | +/// ```no_run |
32 | 31 | /// use linux_embedded_hal as hal;
|
33 | 32 | ///
|
34 | 33 | /// use hal::{I2cdev, Delay};
|
|
50 | 49 |
|
51 | 50 | use embedded_hal as hal;
|
52 | 51 |
|
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}; |
55 | 54 |
|
56 | 55 | use sensirion_i2c::{crc8, i2c};
|
57 | 56 |
|
@@ -158,8 +157,8 @@ pub enum TempUnit {
|
158 | 157 | /// SHT40Driver is the main structure with which a user of this driver
|
159 | 158 | /// interracts. It is generic over two parameters implementing embedded_hal
|
160 | 159 | /// 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. |
163 | 162 | ///
|
164 | 163 | /// Those implementations are needed for issuing I2C write commands to the
|
165 | 164 | /// sensor, waiting until the sensor has performed the actual measurement and
|
@@ -308,7 +307,7 @@ impl Command {
|
308 | 307 | impl<I2C, D, E> SHT40Driver<I2C, D>
|
309 | 308 | where
|
310 | 309 | I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,
|
311 |
| - D: DelayUs |
| 310 | + D: DelayMs<u16> |
312 | 311 | {
|
313 | 312 | /// Initialize a new instance of the driver. Any synchronization required
|
314 | 313 | /// for dealing with multiple instances needs to be managed externally to
|
@@ -377,11 +376,9 @@ where
|
377 | 376 | fn i2c_command_and_response(&mut self, cmd: Command, rx_bytes: Option<&mut [u8]>)
|
378 | 377 | -> Result<(), Error<E>>{
|
379 | 378 | 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()) |
381 | 380 | .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); |
385 | 382 | if let Some(rx_bytes) = rx_bytes {
|
386 | 383 | i2c::read_words_with_crc(&mut self.i2c, self.address, rx_bytes)?;
|
387 | 384 | };
|
@@ -544,7 +541,7 @@ where
|
544 | 541 | pub fn soft_reset_device(&mut self) -> Result<(), Error<E>> {
|
545 | 542 | let cmd = Command::SoftReset;
|
546 | 543 | 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()) |
548 | 545 | .map_err(|err| { Error::I2c(err) })?;
|
549 | 546 | Ok(())
|
550 | 547 | }
|
|
0 commit comments