Skip to content

Commit

Permalink
feat: Support embedded_hal 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nathaniel-brough committed Jan 13, 2024
1 parent 01c0cd0 commit 1bd0932
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "embedded-hal-fuzz"
version = "1.0.0-rc.1"
version = "1.0.0"
edition = "2021"
authors = ["Nathaniel Brough"]
repository = "https://github.com/silvergasp/embedded-hal-fuzz"
Expand All @@ -11,7 +11,7 @@ license = "MIT"

[dependencies]
arbitrary = { version = "1.3.2", features = ["derive"] }
embedded-hal = {version = "1.0.0-rc.1"}
embedded-hal = {version = "1.0.0"}
nb = "1.0.0"
thiserror = "1.0.50"

Expand Down
14 changes: 7 additions & 7 deletions src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
//! this in as a value from the fuzz_target macro e.g.
//! ```rust
//! use libfuzzer_sys::fuzz_target;
//! use embedded_hal_fuzz::delay::ArbitraryDelayUs;
//! use embedded_hal::delay::DelayUs;
//! fuzz_target!(|delay_handle: ArbitraryDelayUs| {
//! use embedded_hal_fuzz::delay::ArbitraryDelayNs;
//! use embedded_hal::delay::DelayNs;
//! fuzz_target!(|delay_handle: ArbitraryDelayNs| {
//! let mut delay_handle = delay_handle;
//! delay_handle.delay_us(10);
//! });
//! ```
use arbitrary::Arbitrary;
use embedded_hal::delay::DelayUs;
use embedded_hal::delay::DelayNs;

/// An arbitrary delay implmentation that is a no-op
/// when we are fuzzing we typically don't want to
Expand All @@ -19,10 +19,10 @@ use embedded_hal::delay::DelayUs;
/// delays to avoid race-conditions as this is poor
/// design.
#[derive(Debug, Arbitrary)]
pub struct ArbitraryDelayUs;
pub struct ArbitraryDelayNs;

impl DelayUs for ArbitraryDelayUs {
fn delay_us(&mut self, _us: u32) {
impl DelayNs for ArbitraryDelayNs {
fn delay_ns(&mut self, _us: u32) {
// no-op
}
fn delay_ms(&mut self, _ms: u32) {
Expand Down
8 changes: 4 additions & 4 deletions src/digital.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl ErrorType for ArbitraryInputPin {
}

impl InputPin for ArbitraryInputPin {
fn is_high(&self) -> Result<bool, Self::Error> {
fn is_high(&mut self) -> Result<bool, Self::Error> {
match self.pin_states.try_borrow_mut() {
Ok(mut pin_states) => match pin_states.pop() {
Some(result) => result,
Expand All @@ -59,7 +59,7 @@ impl InputPin for ArbitraryInputPin {
Err(_) => Err(Error),
}
}
fn is_low(&self) -> Result<bool, Self::Error> {
fn is_low(&mut self) -> Result<bool, Self::Error> {
self.is_high().map(|x| !x)
}
}
Expand Down Expand Up @@ -102,14 +102,14 @@ impl OutputPin for ArbitraryOutputPin {
}

impl StatefulOutputPin for ArbitraryOutputPin {
fn is_set_high(&self) -> Result<bool, Self::Error> {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
match self.maybe_error.try_borrow_mut().map_err(|_| Error)?.pop() {
Some(Some(error)) => Err(error),
_ => Ok(self.state == PinState::High),
}
}

fn is_set_low(&self) -> Result<bool, Self::Error> {
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
match self.maybe_error.try_borrow_mut().map_err(|_| Error)?.pop() {
Some(Some(error)) => Err(error),
_ => Ok(self.state == PinState::Low),
Expand Down
2 changes: 1 addition & 1 deletion src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl ErrorType for ArbitraryPwm {
}

impl SetDutyCycle for ArbitraryPwm {
fn get_max_duty_cycle(&self) -> u16 {
fn max_duty_cycle(&self) -> u16 {
self.max_duty_cycle
}

Expand Down

0 comments on commit 1bd0932

Please sign in to comment.