embedded-hal-mock 0.2.0

A collection of mocked devices that implement the embedded-hal traits
Documentation

embedded-hal-mock

This is a collection of types that implement the embedded-hal traits.

The implementations never access real hardware. Instead, the hardware is mocked or no-op implementations are used.

The goal of the crate is to be able to test drivers in CI without having access to hardware.

Status

  • Simple I2C implementation
  • No-op Delay implementation

no_std

Currently this crate is not no_std. If you think this is important, let me know.

Usage

I2C

use embedded_hal::blocking::i2c::Read;
use embedded_hal_mock::I2cMock;

let mut i2c = I2cMock::new();

// Reading
let mut buf = [0; 3];
i2c.set_read_data(&[1, 2]);
i2c.read(0, &mut buf).unwrap();
assert_eq!(buf, [1, 2, 0]);
assert_eq!(i2c.get_last_address(), Some(0));

// Writing
let buf = [1, 2, 4];
i2c.write(42, &buf).unwrap();
assert_eq!(i2c.get_last_address(), Some(42));
assert_eq!(i2c.get_write_data(), &[1, 2, 4]);

Delay

Just create an instance of embedded_hal_mock::DelayMockNoop. There will be no actual delay. This is useful for fast tests, where you don't actually need to wait for the hardware.

License

Licensed under either of

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.