Available on crate features eh0 and embedded-time only.
Expand description

Provides a mocked embedded_time::Clock that can be used for host-side testing crates that use embedded_hal::timer.

The provided embedded_time::Clock implementation is thread safe and can be freely skipped forward with nanosecond precision.

Usage

use embedded_hal::timer::CountDown;
use embedded_hal_mock::eh0::timer::MockClock;
use embedded_time::duration::*;

let mut clock = MockClock::new();
let mut timer = clock.get_timer();
timer.start(100.nanoseconds());
// hand over timer to embedded-hal based driver
// continue to tick clock
clock.tick(50.nanoseconds());
assert_eq!(timer.wait(), Err(nb::Error::WouldBlock));
clock.tick(50.nanoseconds());
assert_eq!(timer.wait(), Ok(()));
clock.tick(50.nanoseconds());
assert_eq!(timer.wait(), Err(nb::Error::WouldBlock));
clock.tick(50.nanoseconds());
assert_eq!(timer.wait(), Ok(()));

Structs

  • A simulated clock that can be used in tests.
  • A simulated timer that can be used in tests.

Traits

  • The Clock trait provides an abstraction for hardware-specific timer peripherals, external timer devices, RTCs, etc.