#hal #io #spi #i2c #delay

dev embedded-hal-mock

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

15 releases (9 breaking)

new 0.10.0-rc.3 Nov 29, 2023
0.9.0 Jan 6, 2023
0.8.0 Aug 16, 2021
0.7.2 Jun 2, 2020
0.1.0 Mar 31, 2018

#86 in Embedded development

Download history 1252/week @ 2023-08-12 1262/week @ 2023-08-19 1068/week @ 2023-08-26 1123/week @ 2023-09-02 1296/week @ 2023-09-09 1310/week @ 2023-09-16 1181/week @ 2023-09-23 1248/week @ 2023-09-30 1103/week @ 2023-10-07 1706/week @ 2023-10-14 1501/week @ 2023-10-21 1464/week @ 2023-10-28 1574/week @ 2023-11-04 1381/week @ 2023-11-11 1282/week @ 2023-11-18 1294/week @ 2023-11-25

5,718 downloads per month
Used in 150 crates (149 directly)




GitHub Actions Minimum Rust Version Crates.io Version

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.



See module-level docs for more information.

embedded_hal version

This crate supports both version 0.x and version 1.x of embedded-hal. By default only support for version 0.x is enabled. To enable support for version 1.x, use the eh1 feature.

Cargo Features

There are currently the following cargo features:

  • eh0: Provide module eh0 that mocks embedded-hal version 0.x (enabled by default)
  • eh1: Provide module eh1 that mocks embedded-hal version 1.x
  • embedded-time: Enable the eh0::timer module (enabled by default)
  • embedded-hal-async: Provide mocks for embedded-hal-async in eh1


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


  • I²C
  • SPI
  • No-op delay
  • Actual delay
  • Serial
  • RNG
  • I/O pins (including PWM)
  • ADC
  • Timers (with embedded-time Cargo feature)
  • ...

Pull requests for more mock implementations are welcome! :)

Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.63 and up. It might compile with older versions but that may change in any new patch release.

Development Version of embedded-hal

If you would like to use the current development version of embedded-hal (or any other version), so long as they are API compatible you can use a patch field in your Cargo.toml file to override the dependency version.

eh0 = { git = "https://github.com/rust-embedded/embedded-hal" }


Licensed under either of


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.


~12K SLoC