Module embedded_hal_mock::eh0::pin
source · Available on crate feature
eh0
only.Expand description
Mock digital InputPin
and OutputPin
v2 implementations
use std::io::ErrorKind;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use embedded_hal_mock::eh0::{
pin::{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()),
];
// 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.done();
// Update expectations
pin.update_expectations(&[]);
// ...
pin.done();
Structs
- MockPin transaction
Enums
- Digital pin value enumeration
- MockPin transaction kind.
Type Aliases
- Mock Pin implementation
- The type used for the duty of the
PwmPin
mock.