Module digital

Source
Available on crate feature eh0 only.
Expand description

Mock digital InputPin, OutputPin, and ToggleableOutputPin v2 implementations

use std::io::ErrorKind;

use embedded_hal::digital::v2::{InputPin, OutputPin, ToggleableOutputPin};
use embedded_hal_mock::eh0::{
    digital::{Mock as PinMock, State as PinState, Transaction as PinTransaction},
    MockError,
};

let err = MockError::Io(ErrorKind::NotConnected);

// Configure expectations
let expectations = [
    PinTransaction::get(PinState::High),
    PinTransaction::get(PinState::High),
    PinTransaction::set(PinState::Low),
    PinTransaction::set(PinState::High).with_error(err.clone()),
    PinTransaction::toggle(),
];

// Create pin
let mut pin = PinMock::new(&expectations);

// Run and test
assert_eq!(pin.is_high().unwrap(), true);
assert_eq!(pin.is_low().unwrap(), false);

pin.set_low().unwrap();
pin.set_high().expect_err("expected error return");

pin.toggle().unwrap();

pin.done();

// Update expectations
pin.update_expectations(&[]);
// ...
pin.done();

Structs§

Transaction
MockPin transaction

Enums§

State
Digital pin value enumeration
TransactionKind
MockPin transaction kind.

Type Aliases§

Mock
Mock Pin implementation
PwmDuty
The type used for the duty of the PwmPin mock.