Skip to content

Commit

Permalink
Merge pull request rust-embedded#104 from CBJamo/master
Browse files Browse the repository at this point in the history
Bump embedded-hal to rc 2
  • Loading branch information
eldruin authored Dec 9, 2023
2 parents c9b9809 + 7a2ab7a commit da2649b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- 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))
- 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))


## [v0.4.0-alpha.4] - 2023-11-10

### Changed
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ spi = ["spidev"]
default = [ "gpio_cdev", "gpio_sysfs", "i2c", "spi" ]

[dependencies]
embedded-hal = "=1.0.0-rc.1"
embedded-hal-nb = "=1.0.0-rc.1"
embedded-hal = "=1.0.0-rc.2"
embedded-hal-nb = "=1.0.0-rc.2"
gpio-cdev = { version = "0.5.1", optional = true }
sysfs_gpio = { version = "0.6.1", optional = true }
i2cdev = { version = "0.6.0", optional = true }
Expand Down
11 changes: 4 additions & 7 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
//! [`embedded-hal`]: https://docs.rs/embedded-hal

use cast::u64;
use embedded_hal::delay::DelayUs;
use embedded_hal::delay::DelayNs;
use std::thread;
use std::time::Duration;

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

impl DelayUs for Delay {
fn delay_us(&mut self, n: u32) {
let secs = n / 1_000_000;
let nsecs = (n % 1_000_000) * 1_000;

thread::sleep(Duration::new(u64(secs), nsecs));
impl DelayNs for Delay {
fn delay_ns(&mut self, n: u32) {
thread::sleep(Duration::from_nanos(u64(n)));
}
}
15 changes: 13 additions & 2 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,19 @@ mod embedded_hal_impl {
};
transfers.push(SpidevTransfer::read_write(tx, buf));
}
SpiOperation::DelayUs(us) => {
let us = (*us).try_into().unwrap_or(u16::MAX);
SpiOperation::DelayNs(ns) => {
let us = {
if *ns == 0 {
0
} else {
let us = *ns / 1000;
if us == 0 {
1
} else {
(us).try_into().unwrap_or(u16::MAX)
}
}
};
transfers.push(SpidevTransfer::delay(us));
}
}
Expand Down

0 comments on commit da2649b

Please sign in to comment.