Skip to content

Commit 46f6b64

Browse files
committed
Update embedded-hal dependency to 1.0.0-alpha.7
1 parent a397344 commit 46f6b64

10 files changed

+440
-226
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "ISC"
1010
edition = "2018"
1111

1212
[dependencies]
13-
embedded-hal = "=1.0.0-alpha.1"
13+
embedded-hal = "=1.0.0-alpha.7"
1414
nb = "1.0.0"
1515
riscv = "0.7.0"
1616
e310x = { version = "0.9.0", features = ["rt"] }

src/delay.rs

Lines changed: 6 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::clock::Clocks;
44
use crate::core::clint::{MTIME, MTIMECMP};
55
use core::convert::Infallible;
6-
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
6+
use embedded_hal::delay::blocking::DelayUs;
77
use riscv::register::{mie, mip};
88

99
/// Machine timer (mtime) as a busyloop delay provider
@@ -18,10 +18,10 @@ impl Delay {
1818
}
1919
}
2020

21-
impl DelayUs<u32> for Delay {
21+
impl DelayUs for Delay {
2222
type Error = Infallible;
2323

24-
fn try_delay_us(&mut self, us: u32) -> Result<(), Infallible> {
24+
fn delay_us(&mut self, us: u32) -> Result<(), Infallible> {
2525
let ticks = (us as u64) * TICKS_PER_SECOND / 1_000_000;
2626

2727
let mtime = MTIME;
@@ -31,72 +31,6 @@ impl DelayUs<u32> for Delay {
3131
}
3232
}
3333

34-
// This is a workaround to allow `delay_us(42)` construction without specifying a type.
35-
impl DelayUs<i32> for Delay {
36-
type Error = Infallible;
37-
38-
#[inline(always)]
39-
fn try_delay_us(&mut self, us: i32) -> Result<(), Infallible> {
40-
assert!(us >= 0);
41-
self.try_delay_us(us as u32)
42-
}
43-
}
44-
45-
impl DelayUs<u16> for Delay {
46-
type Error = Infallible;
47-
48-
#[inline(always)]
49-
fn try_delay_us(&mut self, us: u16) -> Result<(), Infallible> {
50-
self.try_delay_us(u32::from(us))
51-
}
52-
}
53-
54-
impl DelayUs<u8> for Delay {
55-
type Error = Infallible;
56-
57-
#[inline(always)]
58-
fn try_delay_us(&mut self, us: u8) -> Result<(), Infallible> {
59-
self.try_delay_us(u32::from(us))
60-
}
61-
}
62-
63-
impl DelayMs<u32> for Delay {
64-
type Error = Infallible;
65-
66-
fn try_delay_ms(&mut self, ms: u32) -> Result<(), Infallible> {
67-
self.try_delay_us(ms * 1000)
68-
}
69-
}
70-
71-
// This is a workaround to allow `delay_ms(42)` construction without specifying a type.
72-
impl DelayMs<i32> for Delay {
73-
type Error = Infallible;
74-
75-
#[inline(always)]
76-
fn try_delay_ms(&mut self, ms: i32) -> Result<(), Infallible> {
77-
assert!(ms >= 0);
78-
self.try_delay_ms(ms as u32)
79-
}
80-
}
81-
82-
impl DelayMs<u16> for Delay {
83-
type Error = Infallible;
84-
85-
#[inline(always)]
86-
fn try_delay_ms(&mut self, ms: u16) -> Result<(), Infallible> {
87-
self.try_delay_ms(u32::from(ms))
88-
}
89-
}
90-
91-
impl DelayMs<u8> for Delay {
92-
type Error = Infallible;
93-
94-
#[inline(always)]
95-
fn try_delay_ms(&mut self, ms: u8) -> Result<(), Infallible> {
96-
self.try_delay_ms(u32::from(ms))
97-
}
98-
}
99-
10034
/// Machine timer (mtime) as a sleep delay provider using mtimecmp
10135
pub struct Sleep {
10236
clock_freq: u32,
@@ -113,11 +47,11 @@ impl Sleep {
11347
}
11448
}
11549

116-
impl DelayMs<u32> for Sleep {
50+
impl DelayUs for Sleep {
11751
type Error = Infallible;
11852

119-
fn try_delay_ms(&mut self, ms: u32) -> Result<(), Infallible> {
120-
let ticks = (ms as u64) * (self.clock_freq as u64) / 1000;
53+
fn delay_us(&mut self, us: u32) -> Result<(), Infallible> {
54+
let ticks = (us as u64) * (self.clock_freq as u64) / 1_000_000;
12155
let t = MTIME.mtime() + ticks;
12256

12357
self.mtimecmp.set_mtimecmp(t);
@@ -150,32 +84,3 @@ impl DelayMs<u32> for Sleep {
15084
Ok(())
15185
}
15286
}
153-
154-
// This is a workaround to allow `delay_ms(42)` construction without specifying a type.
155-
impl DelayMs<i32> for Sleep {
156-
type Error = Infallible;
157-
158-
#[inline(always)]
159-
fn try_delay_ms(&mut self, ms: i32) -> Result<(), Infallible> {
160-
assert!(ms >= 0);
161-
self.try_delay_ms(ms as u32)
162-
}
163-
}
164-
165-
impl DelayMs<u16> for Sleep {
166-
type Error = Infallible;
167-
168-
#[inline(always)]
169-
fn try_delay_ms(&mut self, ms: u16) -> Result<(), Infallible> {
170-
self.try_delay_ms(u32::from(ms))
171-
}
172-
}
173-
174-
impl DelayMs<u8> for Sleep {
175-
type Error = Infallible;
176-
177-
#[inline(always)]
178-
fn try_delay_ms(&mut self, ms: u8) -> Result<(), Infallible> {
179-
self.try_delay_ms(u32::from(ms))
180-
}
181-
}

src/gpio.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ macro_rules! gpio {
142142
use core::marker::PhantomData;
143143
use core::convert::Infallible;
144144

145-
use embedded_hal::digital::{InputPin, OutputPin, StatefulOutputPin,
145+
use embedded_hal::digital::ErrorType;
146+
use embedded_hal::digital::blocking::{InputPin, OutputPin, StatefulOutputPin,
146147
ToggleableOutputPin};
147148
use e310x::$GPIOX;
148149
use super::{Unknown, IOF0, IOF1, Drive, Floating, GpioExt, Input, Invert,
@@ -275,48 +276,50 @@ macro_rules! gpio {
275276
}
276277
}
277278

278-
impl<MODE> InputPin for $PXi<Input<MODE>> {
279+
impl<MODE> ErrorType for $PXi<Input<MODE>> {
279280
type Error = Infallible;
281+
}
280282

281-
fn try_is_high(&self) -> Result<bool, Infallible> {
283+
impl<MODE> InputPin for $PXi<Input<MODE>> {
284+
fn is_high(&self) -> Result<bool, Infallible> {
282285
Ok($GPIOX::input_value(Self::INDEX))
283286

284287
}
285288

286-
fn try_is_low(&self) -> Result<bool, Infallible> {
287-
Ok(!self.try_is_high()?)
289+
fn is_low(&self) -> Result<bool, Infallible> {
290+
Ok(!self.is_high()?)
288291
}
289292
}
290293

291294
impl<MODE> StatefulOutputPin for $PXi<Output<MODE>> {
292-
fn try_is_set_high(&self) -> Result<bool, Infallible> {
295+
fn is_set_high(&self) -> Result<bool, Infallible> {
293296
Ok($GPIOX::input_value(Self::INDEX))
294297
}
295298

296-
fn try_is_set_low(&self) -> Result<bool, Infallible> {
297-
Ok(!self.try_is_set_high()?)
299+
fn is_set_low(&self) -> Result<bool, Infallible> {
300+
Ok(!self.is_set_high()?)
298301
}
299302
}
300303

301-
impl<MODE> OutputPin for $PXi<Output<MODE>> {
304+
impl<MODE> ErrorType for $PXi<Output<MODE>> {
302305
type Error = Infallible;
306+
}
303307

304-
fn try_set_high(&mut self) -> Result<(), Infallible> {
308+
impl<MODE> OutputPin for $PXi<Output<MODE>> {
309+
fn set_high(&mut self) -> Result<(), Infallible> {
305310
$GPIOX::set_output_value(Self::INDEX, true);
306311
Ok(())
307312
}
308313

309-
fn try_set_low(&mut self) -> Result<(), Infallible> {
314+
fn set_low(&mut self) -> Result<(), Infallible> {
310315
$GPIOX::set_output_value(Self::INDEX, false);
311316
Ok(())
312317
}
313318
}
314319

315320
impl<MODE> ToggleableOutputPin for $PXi<Output<MODE>> {
316-
type Error = Infallible;
317-
318321
/// Toggles the pin state.
319-
fn try_toggle(&mut self) -> Result<(), Infallible> {
322+
fn toggle(&mut self) -> Result<(), Infallible> {
320323
$GPIOX::toggle_pin(Self::INDEX);
321324
Ok(())
322325
}

0 commit comments

Comments
 (0)