Skip to content

Commit b9d055b

Browse files
committed
update to embedded-hal=1.0.0-alpha.10
there were various breaking changes in alpha.9 and alpha.10 which have been applied here. see [their changelog][embedded-hal-1.0.0-alpha.10] for further details. important: this is completely untested beyond "it compiles", please test this carefully! compilation has been tested with the `stm32f401` feature, the CI will show whether it'll also compile for all others. note that this does only the bare minimum to make it build against the new version - it does not implement any of the newly added APIs. this can be done in subsequent commits. this fixes #602 [embedded-hal-1.0.0-alpha.10]: https://github.com/rust-embedded/embedded-hal/blob/v1.0.0-alpha.10/embedded-hal/CHANGELOG.md
1 parent 3ff3b69 commit b9d055b

File tree

11 files changed

+36
-144
lines changed

11 files changed

+36
-144
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111

1212
- move gpio impls in subdir, remove unused `From` impls
13+
- Bump `embedded-hal` to `1.0.0-alpha.10`. See [their changelog][embedded-hal-1.0.0-alpha.10] for further details. Note that this included breaking changes to the previous alpha APIs. [#663]
14+
15+
[#663]: https://github.com/stm32-rs/stm32f4xx-hal/pull/663
16+
[embedded-hal-1.0.0-alpha.10]: https://github.com/rust-embedded/embedded-hal/blob/v1.0.0-alpha.10/embedded-hal/CHANGELOG.md
1317

1418
## [v0.16.2] - 2023-06-27
1519

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ embedded-dma = "0.2.0"
4040
bare-metal = { version = "1" }
4141
void = { default-features = false, version = "1.0.2" }
4242
embedded-hal = { features = ["unproven"], version = "0.2.7" }
43+
embedded-hal-nb = "1.0.0-alpha.2"
4344
display-interface = { version = "0.4.1", optional = true }
4445
fugit = "0.3.6"
4546
fugit-timer = "0.1.3"
@@ -53,7 +54,7 @@ version = "0.3.14"
5354
default-features = false
5455

5556
[dependencies.embedded-hal-one]
56-
version = "=1.0.0-alpha.8"
57+
version = "=1.0.0-alpha.10"
5758
package = "embedded-hal"
5859

5960
[dependencies.stm32_i2s_v12x]

src/dwt.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,19 @@ impl<T: Into<u64>> embedded_hal::blocking::delay::DelayMs<T> for Delay {
114114
}
115115
}
116116

117-
impl embedded_hal_one::delay::blocking::DelayUs for Delay {
118-
type Error = core::convert::Infallible;
119-
120-
fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> {
117+
impl embedded_hal_one::delay::DelayUs for Delay {
118+
fn delay_us(&mut self, us: u32) {
121119
// Convert us to ticks
122120
let start = DWT::cycle_count();
123121
let ticks = (us as u64 * self.clock.raw() as u64) / 1_000_000;
124122
Delay::delay_ticks(start, ticks);
125-
Ok(())
126123
}
127124

128-
fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> {
125+
fn delay_ms(&mut self, ms: u32) {
129126
// Convert ms to ticks
130127
let start = DWT::cycle_count();
131128
let ticks = (ms as u64 * self.clock.raw() as u64) / 1_000;
132129
Delay::delay_ticks(start, ticks);
133-
Ok(())
134130
}
135131
}
136132

src/fmpi2c/hal_1.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ impl<I2C: Instance> ErrorType for super::FMPI2c<I2C> {
99
mod blocking {
1010
use super::super::{fmpi2c1, FMPI2c, Instance};
1111
use core::ops::Deref;
12-
use embedded_hal_one::i2c::blocking::Operation;
12+
use embedded_hal_one::i2c::Operation;
1313

14-
impl<I2C: Instance> embedded_hal_one::i2c::blocking::I2c for FMPI2c<I2C>
14+
impl<I2C: Instance> embedded_hal_one::i2c::I2c for FMPI2c<I2C>
1515
where
1616
I2C: Deref<Target = fmpi2c1::RegisterBlock>,
1717
{
@@ -23,13 +23,6 @@ mod blocking {
2323
self.write(addr, bytes)
2424
}
2525

26-
fn write_iter<B>(&mut self, _addr: u8, _bytes: B) -> Result<(), Self::Error>
27-
where
28-
B: IntoIterator<Item = u8>,
29-
{
30-
todo!()
31-
}
32-
3326
fn write_read(
3427
&mut self,
3528
addr: u8,
@@ -39,31 +32,12 @@ mod blocking {
3932
self.write_read(addr, bytes, buffer)
4033
}
4134

42-
fn write_iter_read<B>(
43-
&mut self,
44-
_addr: u8,
45-
_bytes: B,
46-
_buffer: &mut [u8],
47-
) -> Result<(), Self::Error>
48-
where
49-
B: IntoIterator<Item = u8>,
50-
{
51-
todo!()
52-
}
53-
5435
fn transaction(
5536
&mut self,
5637
_addr: u8,
5738
_operations: &mut [Operation<'_>],
5839
) -> Result<(), Self::Error> {
5940
todo!()
6041
}
61-
62-
fn transaction_iter<'a, O>(&mut self, _addr: u8, _operations: O) -> Result<(), Self::Error>
63-
where
64-
O: IntoIterator<Item = Operation<'a>>,
65-
{
66-
todo!()
67-
}
6842
}
6943
}

src/gpio/dynamic.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::*;
2+
use embedded_hal_one::digital::ErrorKind;
23

34
/// Pin type with dynamic mode
45
///
@@ -30,6 +31,12 @@ pub enum PinModeError {
3031
IncorrectMode,
3132
}
3233

34+
impl embedded_hal_one::digital::Error for PinModeError {
35+
fn kind(&self) -> ErrorKind {
36+
ErrorKind::Other
37+
}
38+
}
39+
3340
impl Dynamic {
3441
/// Is pin in readable mode
3542
pub fn is_input(&self) -> bool {

src/gpio/hal_1.rs

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
11
use core::convert::Infallible;
22

33
use super::{
4-
dynamic::PinModeError, marker, DynamicPin, ErasedPin, Input, OpenDrain, Output,
5-
PartiallyErasedPin, Pin, PinMode,
4+
dynamic::PinModeError, marker, DynamicPin, ErasedPin, Output, PartiallyErasedPin, Pin,
65
};
76

87
pub use embedded_hal_one::digital::PinState;
98
use embedded_hal_one::digital::{
10-
blocking::{InputPin, IoPin, OutputPin, StatefulOutputPin, ToggleableOutputPin},
11-
ErrorType,
9+
ErrorType, InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
1210
};
1311

14-
fn into_state(state: PinState) -> super::PinState {
15-
match state {
16-
PinState::Low => super::PinState::Low,
17-
PinState::High => super::PinState::High,
18-
}
19-
}
20-
2112
// Implementations for `Pin`
2213
impl<const P: char, const N: u8, MODE> ErrorType for Pin<P, N, MODE> {
2314
type Error = Infallible;
@@ -72,45 +63,6 @@ where
7263
}
7364
}
7465

75-
impl<const P: char, const N: u8> IoPin<Self, Self> for Pin<P, N, Output<OpenDrain>> {
76-
type Error = Infallible;
77-
fn into_input_pin(self) -> Result<Self, Self::Error> {
78-
Ok(self)
79-
}
80-
fn into_output_pin(mut self, state: PinState) -> Result<Self, Self::Error> {
81-
self.set_state(into_state(state));
82-
Ok(self)
83-
}
84-
}
85-
86-
impl<const P: char, const N: u8, Otype> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Output<Otype>>
87-
where
88-
Output<Otype>: PinMode,
89-
{
90-
type Error = Infallible;
91-
fn into_input_pin(self) -> Result<Pin<P, N, Input>, Self::Error> {
92-
Ok(self.into_input())
93-
}
94-
fn into_output_pin(mut self, state: PinState) -> Result<Self, Self::Error> {
95-
self.set_state(into_state(state));
96-
Ok(self)
97-
}
98-
}
99-
100-
impl<const P: char, const N: u8, Otype> IoPin<Self, Pin<P, N, Output<Otype>>> for Pin<P, N, Input>
101-
where
102-
Output<Otype>: PinMode,
103-
{
104-
type Error = Infallible;
105-
fn into_input_pin(self) -> Result<Self, Self::Error> {
106-
Ok(self)
107-
}
108-
fn into_output_pin(mut self, state: PinState) -> Result<Pin<P, N, Output<Otype>>, Self::Error> {
109-
self._set_state(into_state(state));
110-
Ok(self.into_mode())
111-
}
112-
}
113-
11466
// Implementations for `ErasedPin`
11567
impl<MODE> ErrorType for ErasedPin<MODE> {
11668
type Error = core::convert::Infallible;

src/i2c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::rcc::{Enable, Reset};
66
use crate::gpio;
77

88
use crate::rcc::Clocks;
9-
use embedded_hal_one::i2c::blocking::Operation;
9+
use embedded_hal_one::i2c::Operation;
1010
use fugit::{HertzU32 as Hertz, RateExtU32};
1111

1212
mod hal_02;

src/i2c/hal_1.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ impl<I2C: super::Instance> ErrorType for super::I2c<I2C> {
1818

1919
mod blocking {
2020
use super::super::{I2c, Instance};
21-
use embedded_hal_one::i2c::blocking::Operation;
21+
use embedded_hal_one::i2c::Operation;
2222

23-
impl<I2C: Instance> embedded_hal_one::i2c::blocking::I2c for I2c<I2C> {
23+
impl<I2C: Instance> embedded_hal_one::i2c::I2c for I2c<I2C> {
2424
fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
2525
self.read(addr, buffer)
2626
}
@@ -29,13 +29,6 @@ mod blocking {
2929
self.write(addr, bytes)
3030
}
3131

32-
fn write_iter<B>(&mut self, addr: u8, bytes: B) -> Result<(), Self::Error>
33-
where
34-
B: IntoIterator<Item = u8>,
35-
{
36-
self.write_iter(addr, bytes)
37-
}
38-
3932
fn write_read(
4033
&mut self,
4134
addr: u8,
@@ -45,32 +38,12 @@ mod blocking {
4538
self.write_read(addr, bytes, buffer)
4639
}
4740

48-
fn write_iter_read<B>(
49-
&mut self,
50-
addr: u8,
51-
bytes: B,
52-
buffer: &mut [u8],
53-
) -> Result<(), Self::Error>
54-
where
55-
B: IntoIterator<Item = u8>,
56-
{
57-
self.write_iter_read(addr, bytes, buffer)
58-
}
59-
6041
fn transaction(
6142
&mut self,
6243
addr: u8,
6344
operations: &mut [Operation<'_>],
6445
) -> Result<(), Self::Error> {
6546
self.transaction_slice(addr, operations)
6647
}
67-
68-
fn transaction_iter<'a, O>(&mut self, addr: u8, operations: O) -> Result<(), Self::Error>
69-
where
70-
O: IntoIterator<Item = Operation<'a>>,
71-
{
72-
let it = operations.into_iter();
73-
self.transaction(addr, it)
74-
}
7548
}
7649
}

src/serial/hal_1.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ mod nb {
1818
use core::ops::Deref;
1919

2020
use super::super::{Error, Instance, RegisterBlockImpl, Rx, Serial, Tx};
21-
use embedded_hal_one::serial::{
22-
nb::{Read, Write},
23-
ErrorType,
24-
};
21+
use embedded_hal_nb::serial::{ErrorType, Read, Write};
2522

2623
impl<USART: Instance, WORD: Copy> Read<WORD> for Serial<USART, WORD>
2724
where
@@ -107,7 +104,7 @@ mod blocking {
107104

108105
use super::super::{Instance, RegisterBlockImpl, Serial, Tx};
109106
use super::ErrorType;
110-
use embedded_hal_one::serial::blocking::Write;
107+
use embedded_hal_one::serial::Write;
111108

112109
impl<USART: Instance, WORD: Copy> Write<WORD> for Serial<USART, WORD>
113110
where

src/spi/hal_1.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<SPI: Instance, const BIDI: bool, W> ErrorType for super::Spi<SPI, BIDI, W>
4545

4646
mod nb {
4747
use super::super::{Error, FrameSize, Instance, Spi};
48-
use embedded_hal_one::spi::nb::FullDuplex;
48+
use embedded_hal_nb::spi::FullDuplex;
4949

5050
impl<SPI, const BIDI: bool, W: FrameSize> FullDuplex<W> for Spi<SPI, BIDI, W>
5151
where
@@ -63,10 +63,7 @@ mod nb {
6363

6464
mod blocking {
6565
use super::super::{FrameSize, Instance, Spi};
66-
use embedded_hal_one::spi::{
67-
blocking::{SpiBus, SpiBusFlush, SpiBusRead, SpiBusWrite},
68-
nb::FullDuplex,
69-
};
66+
use embedded_hal_one::spi::{SpiBus, SpiBusFlush, SpiBusRead, SpiBusWrite};
7067

7168
impl<SPI, const BIDI: bool, W: FrameSize + 'static> SpiBus<W> for Spi<SPI, BIDI, W>
7269
where
@@ -112,8 +109,8 @@ mod blocking {
112109
{
113110
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
114111
for word in words {
115-
nb::block!(<Self as FullDuplex<W>>::write(self, W::default()))?;
116-
*word = nb::block!(<Self as FullDuplex<W>>::read(self))?;
112+
nb::block!(self.write_nonblocking(W::default()))?;
113+
*word = nb::block!(self.read_nonblocking())?;
117114
}
118115

119116
Ok(())

0 commit comments

Comments
 (0)