Skip to content

Commit

Permalink
Update embedded-hal to 1.0.0-rc.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Nov 29, 2023
1 parent 80f0591 commit c5c4dca
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed

- Updated `embedded-hal` to `1.0.0-rc.2`.

## 0.10.0-rc.2 - 2023-11-23

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ default = ["eh0", "embedded-time"]

[dependencies]
eh0 = { package = "embedded-hal", version = "0.2.7", features = ["unproven"], optional = true }
eh1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = true }
embedded-hal-nb = { version = "=1.0.0-rc.1", optional = true }
embedded-hal-async = { version = "=1.0.0-rc.1", optional = true }
eh1 = { package = "embedded-hal", version = "=1.0.0-rc.2", optional = true }
embedded-hal-nb = { version = "=1.0.0-rc.2", optional = true }
embedded-hal-async = { version = "=1.0.0-rc.2", optional = true }
embedded-time = { version = "0.12", optional = true }
nb = { version = "0.1.1", optional = true}
void = { version = "^1.0", optional = true }
Expand Down
28 changes: 21 additions & 7 deletions src/eh1/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ impl Default for NoopDelay {
}
}

impl delay::DelayUs for NoopDelay {
/// A no-op delay implementation.
fn delay_us(&mut self, _n: u32) {
impl delay::DelayNs for NoopDelay {
fn delay_ns(&mut self, _ns: u32) {
// no-op
}

fn delay_us(&mut self, _us: u32) {
// no-op
}

fn delay_ms(&mut self, _ms: u32) {
// no-op
}
}
Expand All @@ -57,9 +64,16 @@ impl Default for StdSleep {
}
}

impl delay::DelayUs for StdSleep {
/// A `Delay` implementation that uses `std::thread::sleep`.
fn delay_us(&mut self, n: u32) {
thread::sleep(Duration::from_micros(n as u64));
impl delay::DelayNs for StdSleep {
fn delay_ns(&mut self, ns: u32) {
thread::sleep(Duration::from_nanos(ns as u64));
}

fn delay_us(&mut self, us: u32) {
thread::sleep(Duration::from_micros(us as u64));
}

fn delay_ms(&mut self, ms: u32) {
thread::sleep(Duration::from_millis(ms as u64));
}
}
4 changes: 2 additions & 2 deletions src/eh1/pin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Mock digital [`InputPin`] and [`OutputPin`] implementations
//!
//! [`InputPin`]: https://docs.rs/embedded-hal/1.0.0-rc.1/embedded_hal/digital/trait.InputPin.html
//! [`OutputPin`]: https://docs.rs/embedded-hal/1.0.0-rc.1/embedded_hal/digital/trait.OutputPin.html
//! [`InputPin`]: https://docs.rs/embedded-hal/1.0.0-rc.2/embedded_hal/digital/trait.InputPin.html
//! [`OutputPin`]: https://docs.rs/embedded-hal/1.0.0-rc.2/embedded_hal/digital/trait.OutputPin.html
//!
//! ```
//! # use eh1 as embedded_hal;
Expand Down
20 changes: 9 additions & 11 deletions src/eh1/pwm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Mock implementations for
//! [`embedded_hal::pwm`](https://docs.rs/embedded-hal/1.0.0-rc.1/embedded_hal/pwm/index.html).
//! [`embedded_hal::pwm`](https://docs.rs/embedded-hal/1.0.0-rc.2/embedded_hal/pwm/index.html).
//!
//! Usage example:
//! ```
Expand All @@ -14,7 +14,7 @@
//!
//! // Configure expectations
//! let expectations = [
//! PwmTransaction::get_max_duty_cycle(100),
//! PwmTransaction::max_duty_cycle(100),
//! PwmTransaction::set_duty_cycle(50),
//! PwmTransaction::set_duty_cycle(101).with_error(MockError::Io(ErrorKind::NotConnected)),
//! ];
Expand Down Expand Up @@ -51,8 +51,8 @@ impl Transaction {
Transaction { kind, err: None }
}

/// Create a new [`TransactionKind::GetMaxDutyCycle`] transaction for [`SetDutyCycle::get_max_duty_cycle`].
pub fn get_max_duty_cycle(duty: u16) -> Transaction {
/// Create a new [`TransactionKind::GetMaxDutyCycle`] transaction for [`SetDutyCycle::max_duty_cycle`].
pub fn max_duty_cycle(duty: u16) -> Transaction {
Transaction::new(TransactionKind::GetMaxDutyCycle(duty))
}

Expand All @@ -73,7 +73,7 @@ impl Transaction {
/// MockPwm transaction kind
#[derive(PartialEq, Clone, Debug)]
pub enum TransactionKind {
/// [`SetDutyCycle::get_max_duty_cycle`] which will return the defined duty.
/// [`SetDutyCycle::max_duty_cycle`] which will return the defined duty.
GetMaxDutyCycle(u16),
/// [`SetDutyCycle::set_duty_cycle`] with the expected duty.
SetDutyCycle(u16),
Expand All @@ -93,18 +93,16 @@ impl ErrorType for Mock {
}

impl SetDutyCycle for Mock {
fn get_max_duty_cycle(&self) -> u16 {
fn max_duty_cycle(&self) -> u16 {
let mut s = self.clone();

let Transaction { kind, err } = s
.next()
.expect("no expectation for get_max_duty_cycle call");
let Transaction { kind, err } = s.next().expect("no expectation for max_duty_cycle call");

assert_eq!(err, None, "error not supported by get_max_duty_cycle!");
assert_eq!(err, None, "error not supported by max_duty_cycle!");

match kind {
TransactionKind::GetMaxDutyCycle(duty) => duty,
other => panic!("expected get_max_duty_cycle, got {:?}", other),
other => panic!("expected max_duty_cycle, got {:?}", other),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/eh1/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl SpiDevice for Mock {
Operation::TransferInPlace(buffer) => {
SpiBus::transfer_in_place(self, buffer)?;
}
Operation::DelayUs(delay) => {
Operation::DelayNs(delay) => {
let w = self.next().expect("no expectation for spi::delay call");
assert_eq!(
w.expected_mode,
Expand Down Expand Up @@ -427,7 +427,7 @@ impl embedded_hal_async::spi::SpiDevice<u8> for Mock {
Operation::TransferInPlace(buffer) => {
SpiBus::transfer_in_place(self, buffer)?;
}
Operation::DelayUs(delay) => {
Operation::DelayNs(delay) => {
let w = self.next().expect("no expectation for spi::delay call");
assert_eq!(
w.expected_mode,
Expand Down Expand Up @@ -588,7 +588,7 @@ mod test {
spi.transaction(&mut [
Operation::Write(&[1, 2]),
Operation::Write(&[0x09]),
Operation::DelayUs(100),
Operation::DelayNs(100),
Operation::Read(&mut ans),
])
.unwrap();
Expand All @@ -610,7 +610,7 @@ mod test {
&mut [
Operation::Write(&[1, 2]),
Operation::Write(&[0x09]),
Operation::DelayUs(100),
Operation::DelayNs(100),
Operation::Read(&mut ans),
],
)
Expand Down

0 comments on commit c5c4dca

Please sign in to comment.