Skip to content

Commit da2649b

Browse files
authored
Merge pull request #104 from CBJamo/master
Bump embedded-hal to rc 2
2 parents c9b9809 + 7a2ab7a commit da2649b

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Changed
11+
- Updated to `embedded-hal` `1.0.0-rc.2` release ([API changes](https://github.com/rust-embedded/embedded-hal/blob/master/embedded-hal/CHANGELOG.md#v100-rc2---2023-11-28))
12+
- Updated to `embedded-hal-nb` `1.0.0-rc.2` release ([API changes](https://github.com/rust-embedded/embedded-hal/blob/master/embedded-hal-nb/CHANGELOG.md#v100-rc2---2023-11-28))
13+
14+
1015
## [v0.4.0-alpha.4] - 2023-11-10
1116

1217
### Changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ spi = ["spidev"]
2222
default = [ "gpio_cdev", "gpio_sysfs", "i2c", "spi" ]
2323

2424
[dependencies]
25-
embedded-hal = "=1.0.0-rc.1"
26-
embedded-hal-nb = "=1.0.0-rc.1"
25+
embedded-hal = "=1.0.0-rc.2"
26+
embedded-hal-nb = "=1.0.0-rc.2"
2727
gpio-cdev = { version = "0.5.1", optional = true }
2828
sysfs_gpio = { version = "0.6.1", optional = true }
2929
i2cdev = { version = "0.6.0", optional = true }

src/delay.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
//! [`embedded-hal`]: https://docs.rs/embedded-hal
44
55
use cast::u64;
6-
use embedded_hal::delay::DelayUs;
6+
use embedded_hal::delay::DelayNs;
77
use std::thread;
88
use std::time::Duration;
99

1010
/// Empty struct that provides delay functionality on top of `thread::sleep`
1111
pub struct Delay;
1212

13-
impl DelayUs for Delay {
14-
fn delay_us(&mut self, n: u32) {
15-
let secs = n / 1_000_000;
16-
let nsecs = (n % 1_000_000) * 1_000;
17-
18-
thread::sleep(Duration::new(u64(secs), nsecs));
13+
impl DelayNs for Delay {
14+
fn delay_ns(&mut self, n: u32) {
15+
thread::sleep(Duration::from_nanos(u64(n)));
1916
}
2017
}

src/spi.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,19 @@ mod embedded_hal_impl {
220220
};
221221
transfers.push(SpidevTransfer::read_write(tx, buf));
222222
}
223-
SpiOperation::DelayUs(us) => {
224-
let us = (*us).try_into().unwrap_or(u16::MAX);
223+
SpiOperation::DelayNs(ns) => {
224+
let us = {
225+
if *ns == 0 {
226+
0
227+
} else {
228+
let us = *ns / 1000;
229+
if us == 0 {
230+
1
231+
} else {
232+
(us).try_into().unwrap_or(u16::MAX)
233+
}
234+
}
235+
};
225236
transfers.push(SpidevTransfer::delay(us));
226237
}
227238
}

0 commit comments

Comments
 (0)