Skip to content

Commit

Permalink
Merge pull request #33 from rust-iot/update-embedded-hal
Browse files Browse the repository at this point in the history
update embedded hal to 1.0.0
  • Loading branch information
ryankurte authored Feb 11, 2024
2 parents caef935 + c82531d commit 7aade85
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 108 deletions.
18 changes: 6 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,26 @@ features = [ "std", "nonblocking", "mock", "helpers" ]
std = [ ]
nonblocking = [ ]
mock = [ "embedded-hal-mock" ]
helpers = [ "structopt", "humantime", "std", "pcap-file", "libc", "byteorder", "rolling-stats" ]
helpers = [ "clap", "humantime", "std", "pcap-file", "libc", "byteorder", "rolling-stats" ]
default = [ ]

[dependencies]
embedded-hal = "1.0.0-alpha.7"
embedded-hal = "1.0.0"
embedded-hal-mock = { version = "0.10.0", optional = true }
nb = "1.0.0"

log = { version = "0.4.14", default_features = false }
defmt = { version = "0.3.0", optional = true }

chrono = { version = "0.4.19", default_features = false }
humantime = { version = "2.0.1", optional = true }
pcap-file = { version = "1.1.1", optional = true }
structopt = { version = "0.3.14", optional = true }
async-std = { version = "1.4.0", optional = true }
libc = { version = "0.2.71", optional = true }
byteorder = { version = "1.3.4", optional = true }
rolling-stats = { version = "0.5.0", optional = true }
rolling-stats = { version = "0.7.0", optional = true }
thiserror = { version = "1.0.30", optional = true }

[dependencies.chrono]
version = "0.4.19"
default_features = false

[dependencies.embedded-hal-mock]
version = "0.8.0"
optional = true
clap = { version = "4.4.7", optional = true, features = [ "derive" ] }

[dev-dependencies]
anyhow = "1.0.44"
41 changes: 19 additions & 22 deletions src/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Blocking APIs on top of the base radio traits
//!
//! These implementations use the radio's DelayUs implementation to
//! These implementations use the radio's DelayNs implementation to
//! poll on completion of operations.
//!
//! ## <https://github.com/rust-iot/radio-hal>
Expand All @@ -9,16 +9,13 @@
use core::fmt::Debug;
use core::time::Duration;

use embedded_hal::delay::blocking::DelayUs;

#[cfg(not(feature = "defmt"))]
use log::debug;
use embedded_hal::delay::DelayNs;

#[cfg(feature = "defmt")]
use defmt::debug;

#[cfg(feature = "structopt")]
use structopt::StructOpt;
#[cfg(feature = "clap")]
use clap::Parser;

#[cfg(feature = "std")]
use std::string::ToString;
Expand All @@ -27,15 +24,15 @@ use crate::{Receive, State, Transmit};

/// BlockingOptions for blocking radio functions
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "structopt", derive(StructOpt))]
#[cfg_attr(feature = "clap", derive(Parser))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BlockingOptions {
/// Interval for polling for device state
#[cfg_attr(feature="structopt", structopt(long, default_value="100us", parse(try_from_str=crate::duration_from_str)))]
#[cfg_attr(feature="clap", clap(long, default_value="100us", value_parser=crate::duration_from_str))]
pub poll_interval: Duration,

/// Timeout for blocking operation
#[cfg_attr(feature="structopt", structopt(long, default_value="100ms", parse(try_from_str=crate::duration_from_str)))]
#[cfg_attr(feature="clap", clap(long, default_value="100ms", value_parser=crate::duration_from_str))]
pub timeout: Duration,
}

Expand Down Expand Up @@ -66,19 +63,19 @@ impl<E> From<E> for BlockingError<E> {
}

/// Blocking transmit function implemented over `radio::Transmit` and `radio::Power` using the provided
/// `BlockingOptions` and radio-internal `DelayUs` impl to poll for completion
/// `BlockingOptions` and radio-internal `DelayNs` impl to poll for completion
#[cfg_attr(
feature = "mock",
doc = r##"
```
# use radio::*;
# use radio::mock::*;
use radio::blocking::{BlockingTransmit, BlockingOptions};
use radio::{BlockingTransmit, BlockingOptions};
# let mut radio = MockRadio::new(&[
# Transaction::start_transmit(vec![0xaa, 0xbb], None),
# Transaction::check_transmit(Ok(false)),
# Transaction::delay_us(100),
# Transaction::delay_ns(100000),
# Transaction::check_transmit(Ok(true)),
# ]);
#
Expand All @@ -102,7 +99,7 @@ pub trait BlockingTransmit<E: Debug> {

impl<T, E> BlockingTransmit<E> for T
where
T: Transmit<Error = E> + DelayUs,
T: Transmit<Error = E> + DelayNs,
E: Debug,
{
fn do_transmit(
Expand Down Expand Up @@ -132,30 +129,30 @@ where
}

// Wait for next poll
let _ = self.delay_us(tx_options.poll_interval.as_micros() as u32);
self.delay_us(tx_options.poll_interval.as_micros() as u32);
}

Ok(())
}
}

/// Blocking receive function implemented over `radio::Receive` using the provided `BlockingOptions`
/// and radio-internal `DelayUs` impl to poll for completion
/// and radio-internal `DelayNs` impl to poll for completion
#[cfg_attr(
feature = "mock",
doc = r##"
```
# use radio::*;
# use radio::mock::*;
use radio::blocking::{BlockingReceive, BlockingOptions};
use radio::{BlockingReceive, BlockingOptions};
let data = [0xaa, 0xbb];
let info = BasicInfo::new(-81, 0);
# let mut radio = MockRadio::new(&[
# Transaction::start_receive(None),
# Transaction::check_receive(true, Ok(false)),
# Transaction::delay_us(100),
# Transaction::delay_ns(100000),
# Transaction::check_receive(true, Ok(true)),
# Transaction::get_received(Ok((data.to_vec(), info.clone()))),
# ]);
Expand Down Expand Up @@ -187,7 +184,7 @@ pub trait BlockingReceive<I, E> {

impl<T, I, E> BlockingReceive<I, E> for T
where
T: Receive<Info = I, Error = E> + DelayUs,
T: Receive<Info = I, Error = E> + DelayNs,
<T as Receive>::Info: Debug,
I: Debug,
E: Debug,
Expand Down Expand Up @@ -215,7 +212,7 @@ where
return Err(BlockingError::Timeout);
}

let _ = self.delay_us(rx_options.poll_interval.as_micros() as u32);
self.delay_us(rx_options.poll_interval.as_micros() as u32);
}
}
}
Expand All @@ -231,7 +228,7 @@ pub trait BlockingSetState<S, E> {

impl<T, S, E> BlockingSetState<S, E> for T
where
T: State<State = S, Error = E> + DelayUs,
T: State<State = S, Error = E> + DelayNs,
S: Debug + core::cmp::PartialEq + Copy,
E: Debug,
{
Expand Down Expand Up @@ -264,7 +261,7 @@ where
}

// Delay before next loop
let _ = self.delay_us(options.poll_interval.as_micros() as u32);
self.delay_us(options.poll_interval.as_micros() as u32);
}
}
}
Loading

0 comments on commit 7aade85

Please sign in to comment.