Skip to content

Commit

Permalink
Merge pull request #34 from ATACAMA-Project/update-embedded-hal
Browse files Browse the repository at this point in the history
Update to embedded-hal 1.0.0
  • Loading branch information
ryankurte committed Feb 11, 2024
2 parents bec03f6 + 71e8967 commit c82531d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ helpers = [ "clap", "humantime", "std", "pcap-file", "libc", "byteorder", "rolli
default = [ ]

[dependencies]
embedded-hal = "1.0.0-rc.1"
embedded-hal-mock = { version = "0.9.0", optional = true }
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 }
Expand Down
18 changes: 9 additions & 9 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,7 +9,7 @@
use core::fmt::Debug;
use core::time::Duration;

use embedded_hal::delay::DelayUs;
use embedded_hal::delay::DelayNs;

#[cfg(feature = "defmt")]
use defmt::debug;
Expand Down Expand Up @@ -63,7 +63,7 @@ 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##"
Expand All @@ -75,7 +75,7 @@ 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 @@ -99,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 @@ -137,7 +137,7 @@ where
}

/// 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##"
Expand All @@ -152,7 +152,7 @@ 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 @@ -184,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 @@ -228,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
14 changes: 7 additions & 7 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use log::{debug, info};
use defmt::{debug, info};

use clap::Parser;
use embedded_hal::delay::DelayUs;
use embedded_hal::delay::DelayNs;
use humantime::Duration as HumanDuration;

use byteorder::{ByteOrder, NetworkEndian};
Expand Down Expand Up @@ -62,7 +62,7 @@ where
+ Receive<Info = I, Error = E>
+ Rssi<Error = E>
+ Power<Error = E>
+ DelayUs,
+ DelayNs,
I: ReceiveInfo + Default + std::fmt::Debug,
E: std::fmt::Debug,
{
Expand Down Expand Up @@ -102,7 +102,7 @@ pub struct TransmitOptions {

pub fn do_transmit<T, E>(radio: &mut T, options: TransmitOptions) -> Result<(), BlockingError<E>>
where
T: Transmit<Error = E> + Power<Error = E> + DelayUs,
T: Transmit<Error = E> + Power<Error = E> + DelayNs,
E: core::fmt::Debug,
{
// Set output power if specified
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn do_receive<T, I, E>(
options: ReceiveOptions,
) -> Result<usize, E>
where
T: Receive<Info = I, Error = E> + DelayUs,
T: Receive<Info = I, Error = E> + DelayNs,
I: std::fmt::Debug,
E: std::fmt::Debug,
{
Expand Down Expand Up @@ -282,7 +282,7 @@ pub struct RssiOptions {

pub fn do_rssi<T, I, E>(radio: &mut T, options: RssiOptions) -> Result<(), E>
where
T: Receive<Info = I, Error = E> + Rssi<Error = E> + DelayUs,
T: Receive<Info = I, Error = E> + Rssi<Error = E> + DelayNs,
I: std::fmt::Debug,
E: std::fmt::Debug,
{
Expand Down Expand Up @@ -336,7 +336,7 @@ pub fn do_echo<T, I, E>(
options: EchoOptions,
) -> Result<usize, BlockingError<E>>
where
T: Receive<Info = I, Error = E> + Transmit<Error = E> + Power<Error = E> + DelayUs,
T: Receive<Info = I, Error = E> + Transmit<Error = E> + Power<Error = E> + DelayNs,
I: ReceiveInfo + std::fmt::Debug,
E: std::fmt::Debug,
{
Expand Down Expand Up @@ -421,7 +421,7 @@ pub fn do_ping_pong<T, I, E>(
options: PingPongOptions,
) -> Result<LinkTestInfo, BlockingError<E>>
where
T: Receive<Info = I, Error = E> + Transmit<Error = E> + Power<Error = E> + DelayUs,
T: Receive<Info = I, Error = E> + Transmit<Error = E> + Power<Error = E> + DelayNs,
I: ReceiveInfo,
E: std::fmt::Debug,
{
Expand Down
16 changes: 8 additions & 8 deletions src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::vec::Vec;

use log::debug;

use embedded_hal::delay::DelayUs;
use embedded_hal::delay::DelayNs;

use embedded_hal_mock::common::Generic;

Expand Down Expand Up @@ -217,9 +217,9 @@ impl<St, Reg, Ch, Inf, Irq, E> Transaction<St, Reg, Ch, Inf, Irq, E> {
}

/// Delay for a certain time
pub fn delay_us(ms: u32) -> Self {
pub fn delay_ns(ns: u32) -> Self {
Self {
request: Request::DelayUs(ms),
request: Request::DelayNs(ns),
response: Response::Ok,
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ enum Request<St, Reg, Ch> {
CheckReceive(bool),
GetReceived,

DelayUs(u32),
DelayNs(u32),
}

#[derive(Debug, Clone, PartialEq)]
Expand All @@ -271,7 +271,7 @@ impl<St, Inf, Irq, E> From<Option<E>> for Response<St, Inf, Irq, E> {
}
}

impl<St, Reg, Ch, Inf, Irq, E> DelayUs for Radio<St, Reg, Ch, Inf, Irq, E>
impl<St, Reg, Ch, Inf, Irq, E> DelayNs for Radio<St, Reg, Ch, Inf, Irq, E>
where
St: PartialEq + Debug + Clone,
Reg: PartialEq + Debug + Clone,
Expand All @@ -280,10 +280,10 @@ where
Irq: PartialEq + Debug + Clone,
E: PartialEq + Debug + Clone,
{
fn delay_us(&mut self, ms: u32) {
let n = self.next().expect("no expectation for delay_us call");
fn delay_ns(&mut self, ns: u32) {
let n = self.next().expect("no expectation for delay_ns call");

assert_eq!(&n.request, &Request::DelayUs(ms));
assert_eq!(&n.request, &Request::DelayNs(ns));
}
}

Expand Down

0 comments on commit c82531d

Please sign in to comment.