Skip to content

Commit 80e14f9

Browse files
niclashoyertommy-gilligan
authored andcommitted
Refactor for [email protected]
1 parent e920c96 commit 80e14f9

File tree

10 files changed

+315
-375
lines changed

10 files changed

+315
-375
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: rust:1.35
5+
- image: rust:1.46
66
steps:
77
- checkout
88

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ edition = "2021"
2121
rust-version = "1.60"
2222

2323
[dependencies]
24-
embedded-hal = "=1.0.0-alpha.4"
24+
embedded-hal = "=1.0.0-alpha.6"
2525
embedded-time = { version = "0.12", optional = true }
2626
void = { version = "^1.0", optional = true }
2727
nb = "0.1.1"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ embedded-hal = { git = "https://github.com/rust-embedded/embedded-hal" }
6767

6868
# Minimum Supported Rust Version (MSRV)
6969

70-
This crate is guaranteed to compile on stable Rust 1.35 and up. It *might*
70+
This crate is guaranteed to compile on stable Rust 1.46.0 and up. It *might*
7171
compile with older versions but that may change in any new patch release.
7272

7373

src/adc.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! ## Usage
44
//!
55
//! ```
6-
//! use embedded_hal::adc::OneShot;
6+
//! use embedded_hal::adc::nb::OneShot;
77
//! use embedded_hal_mock::adc::Mock;
88
//! use embedded_hal_mock::adc::Transaction;
99
//! use embedded_hal_mock::adc::{MockChan0, MockChan1};
@@ -28,7 +28,7 @@
2828
//! Attach an error to test error handling. An error is returned when such a transaction is executed.
2929
//!
3030
//! ```
31-
//! use embedded_hal::adc::OneShot;
31+
//! use embedded_hal::adc::nb::OneShot;
3232
//! use embedded_hal_mock::adc::Mock;
3333
//! use embedded_hal_mock::adc::Transaction;
3434
//! use embedded_hal_mock::adc::MockChan1;
@@ -49,8 +49,8 @@
4949
//! adc.done();
5050
//! ```
5151
52-
use embedded_hal::adc::Channel;
53-
use embedded_hal::adc::OneShot;
52+
use embedded_hal::adc::nb::Channel;
53+
use embedded_hal::adc::nb::OneShot;
5454
use nb;
5555
use std::fmt::Debug;
5656

@@ -100,7 +100,7 @@ macro_rules! mock_channel {
100100
impl Channel<$ADC> for $pin {
101101
type ID = u8;
102102

103-
fn channel() -> u8 { $chan }
103+
fn channel(&self) -> u8 { $chan }
104104
}
105105
)+
106106
};
@@ -126,9 +126,9 @@ where
126126
{
127127
type Error = MockError;
128128

129-
fn read(&mut self, _pin: &mut Pin) -> nb::Result<T, Self::Error> {
129+
fn read(&mut self, pin: &mut Pin) -> nb::Result<T, Self::Error> {
130130
let w = self.next().expect("unexpected read call");
131-
assert_eq!(w.expected_chan, Pin::channel(), "unexpected channel");
131+
assert_eq!(w.expected_chan, pin.channel(), "unexpected channel");
132132
match w.err {
133133
Some(e) => Err(nb::Error::Other(e)),
134134
None => Ok(w.response),
@@ -138,7 +138,7 @@ where
138138

139139
#[cfg(test)]
140140
mod test {
141-
use embedded_hal::adc::OneShot;
141+
use embedded_hal::adc::nb::OneShot;
142142

143143
use crate::adc::{Mock, MockChan0, MockChan1, MockChan2, Transaction};
144144
use crate::MockError;

src/delay.rs

Lines changed: 14 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use core::convert::Infallible;
1616
use std::thread;
1717
use std::time::Duration;
1818

19-
use embedded_hal::blocking::delay;
19+
use embedded_hal::delay::blocking as delay;
2020

2121
/// A `Delay` implementation that does not actually block.
2222
pub struct NoopDelay;
@@ -34,42 +34,15 @@ impl Default for NoopDelay {
3434
}
3535
}
3636

37-
macro_rules! impl_noop_delay_us {
38-
($type:ty) => {
39-
impl delay::DelayUs<$type> for NoopDelay {
40-
type Error = Infallible;
37+
impl delay::DelayUs for NoopDelay {
38+
type Error = Infallible;
4139

42-
/// A no-op delay implementation.
43-
fn try_delay_us(&mut self, _n: $type) -> Result<(), Self::Error> {
44-
Ok(())
45-
}
46-
}
47-
};
48-
}
49-
50-
impl_noop_delay_us!(u8);
51-
impl_noop_delay_us!(u16);
52-
impl_noop_delay_us!(u32);
53-
impl_noop_delay_us!(u64);
54-
55-
macro_rules! impl_noop_delay_ms {
56-
($type:ty) => {
57-
impl delay::DelayMs<$type> for NoopDelay {
58-
type Error = Infallible;
59-
60-
/// A no-op delay implementation.
61-
fn try_delay_ms(&mut self, _n: $type) -> Result<(), Self::Error> {
62-
Ok(())
63-
}
64-
}
65-
};
40+
/// A no-op delay implementation.
41+
fn delay_us(&mut self, _n: u32) -> Result<(), Self::Error> {
42+
Ok(())
43+
}
6644
}
6745

68-
impl_noop_delay_ms!(u8);
69-
impl_noop_delay_ms!(u16);
70-
impl_noop_delay_ms!(u32);
71-
impl_noop_delay_ms!(u64);
72-
7346
/// A `Delay` implementation that uses `std::thread::sleep`.
7447
pub struct StdSleep;
7548

@@ -86,40 +59,12 @@ impl Default for StdSleep {
8659
}
8760
}
8861

89-
macro_rules! impl_stdsleep_delay_us {
90-
($type:ty) => {
91-
impl delay::DelayUs<$type> for StdSleep {
92-
type Error = Infallible;
62+
impl delay::DelayUs for StdSleep {
63+
type Error = Infallible;
9364

94-
/// A `Delay` implementation that uses `std::thread::sleep`.
95-
fn try_delay_us(&mut self, n: $type) -> Result<(), Self::Error> {
96-
thread::sleep(Duration::from_micros(n as u64));
97-
Ok(())
98-
}
99-
}
100-
};
101-
}
102-
103-
impl_stdsleep_delay_us!(u8);
104-
impl_stdsleep_delay_us!(u16);
105-
impl_stdsleep_delay_us!(u32);
106-
impl_stdsleep_delay_us!(u64);
107-
108-
macro_rules! impl_stdsleep_delay_ms {
109-
($type:ty) => {
110-
impl delay::DelayMs<$type> for StdSleep {
111-
type Error = Infallible;
112-
113-
/// A `Delay` implementation that uses `std::thread::sleep`.
114-
fn try_delay_ms(&mut self, n: $type) -> Result<(), Self::Error> {
115-
thread::sleep(Duration::from_millis(n as u64));
116-
Ok(())
117-
}
118-
}
119-
};
65+
/// A `Delay` implementation that uses `std::thread::sleep`.
66+
fn delay_us(&mut self, n: u32) -> Result<(), Self::Error> {
67+
thread::sleep(Duration::from_micros(n as u64));
68+
Ok(())
69+
}
12070
}
121-
122-
impl_stdsleep_delay_ms!(u8);
123-
impl_stdsleep_delay_ms!(u16);
124-
impl_stdsleep_delay_ms!(u32);
125-
impl_stdsleep_delay_ms!(u64);

0 commit comments

Comments
 (0)