Skip to content

Commit 5034eda

Browse files
committed
hal-async: fix warnings for latest nightly (1.75.0)
Fixes `cargo check` warnings for the latest nightly version (`1.75.0`). Recommended public API signatures for async trait functions has changed to recommending the desugared version for compatibility with different `async` runtimes.
1 parent 129282e commit 5034eda

File tree

4 files changed

+142
-84
lines changed

4 files changed

+142
-84
lines changed

embedded-hal-async/src/delay.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
//! Delays.
22
3+
use core::future::Future;
4+
35
/// Microsecond delay.
46
pub trait DelayUs {
57
/// Pauses execution for at minimum `us` microseconds. Pause can be longer
68
/// if the implementation requires it due to precision/timing issues.
7-
async fn delay_us(&mut self, us: u32);
9+
fn delay_us(&mut self, us: u32) -> impl Future<Output = ()>;
810

911
/// Pauses execution for at minimum `ms` milliseconds. Pause can be longer
1012
/// if the implementation requires it due to precision/timing issues.
11-
async fn delay_ms(&mut self, ms: u32);
13+
fn delay_ms(&mut self, ms: u32) -> impl Future<Output = ()>;
1214
}
1315

1416
impl<T> DelayUs for &mut T
1517
where
1618
T: DelayUs + ?Sized,
1719
{
1820
#[inline]
19-
async fn delay_us(&mut self, us: u32) {
20-
T::delay_us(self, us).await;
21+
fn delay_us(&mut self, us: u32) -> impl Future<Output = ()> {
22+
async move {
23+
T::delay_us(self, us).await;
24+
}
2125
}
2226

2327
#[inline]
24-
async fn delay_ms(&mut self, ms: u32) {
25-
T::delay_ms(self, ms).await;
28+
fn delay_ms(&mut self, ms: u32) -> impl Future<Output = ()> {
29+
async move {
30+
T::delay_ms(self, ms).await;
31+
}
2632
}
2733
}

embedded-hal-async/src/digital.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,63 @@
1616
//! }
1717
//! ```
1818
19+
use core::future::Future;
20+
1921
/// Asynchronously wait for GPIO pin state.
2022
pub trait Wait: embedded_hal::digital::ErrorType {
2123
/// Wait until the pin is high. If it is already high, return immediately.
2224
///
2325
/// # Note for implementers
2426
/// The pin may have switched back to low before the task was run after
2527
/// being woken. The future should still resolve in that case.
26-
async fn wait_for_high(&mut self) -> Result<(), Self::Error>;
28+
fn wait_for_high(&mut self) -> impl Future<Output = Result<(), Self::Error>>;
2729

2830
/// Wait until the pin is low. If it is already low, return immediately.
2931
///
3032
/// # Note for implementers
3133
/// The pin may have switched back to high before the task was run after
3234
/// being woken. The future should still resolve in that case.
33-
async fn wait_for_low(&mut self) -> Result<(), Self::Error>;
35+
fn wait_for_low(&mut self) -> impl Future<Output = Result<(), Self::Error>>;
3436

3537
/// Wait for the pin to undergo a transition from low to high.
3638
///
3739
/// If the pin is already high, this does *not* return immediately, it'll wait for the
3840
/// pin to go low and then high again.
39-
async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error>;
41+
fn wait_for_rising_edge(&mut self) -> impl Future<Output = Result<(), Self::Error>>;
4042

4143
/// Wait for the pin to undergo a transition from high to low.
4244
///
4345
/// If the pin is already low, this does *not* return immediately, it'll wait for the
4446
/// pin to go high and then low again.
45-
async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error>;
47+
fn wait_for_falling_edge(&mut self) -> impl Future<Output = Result<(), Self::Error>>;
4648

4749
/// Wait for the pin to undergo any transition, i.e low to high OR high to low.
48-
async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error>;
50+
fn wait_for_any_edge(&mut self) -> impl Future<Output = Result<(), Self::Error>>;
4951
}
5052

5153
impl<T: Wait + ?Sized> Wait for &mut T {
5254
#[inline]
53-
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
54-
T::wait_for_high(self).await
55+
fn wait_for_high(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
56+
async move { T::wait_for_high(self).await }
5557
}
5658

5759
#[inline]
58-
async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
59-
T::wait_for_low(self).await
60+
fn wait_for_low(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
61+
async move { T::wait_for_low(self).await }
6062
}
6163

6264
#[inline]
63-
async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
64-
T::wait_for_rising_edge(self).await
65+
fn wait_for_rising_edge(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
66+
async move { T::wait_for_rising_edge(self).await }
6567
}
6668

6769
#[inline]
68-
async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
69-
T::wait_for_falling_edge(self).await
70+
fn wait_for_falling_edge(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
71+
async move { T::wait_for_falling_edge(self).await }
7072
}
7173

7274
#[inline]
73-
async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
74-
T::wait_for_any_edge(self).await
75+
fn wait_for_any_edge(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
76+
async move { T::wait_for_any_edge(self).await }
7577
}
7678
}

embedded-hal-async/src/i2c.rs

+41-25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
//! Since 7-bit addressing is the mode of the majority of I2C devices,
1717
//! `SevenBitAddress` has been set as default mode and thus can be omitted if desired.
1818
19+
use core::future::Future;
20+
1921
pub use embedded_hal::i2c::Operation;
2022
pub use embedded_hal::i2c::{
2123
AddressMode, Error, ErrorKind, ErrorType, NoAcknowledgeSource, SevenBitAddress, TenBitAddress,
@@ -42,9 +44,15 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
4244
/// - `NMAK` = master no acknowledge
4345
/// - `SP` = stop condition
4446
#[inline]
45-
async fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error> {
46-
self.transaction(address, &mut [Operation::Read(read)])
47-
.await
47+
fn read(
48+
&mut self,
49+
address: A,
50+
read: &mut [u8],
51+
) -> impl Future<Output = Result<(), Self::Error>> {
52+
async move {
53+
self.transaction(address, &mut [Operation::Read(read)])
54+
.await
55+
}
4856
}
4957

5058
/// Writes bytes to slave with address `address`.
@@ -64,9 +72,11 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
6472
/// - `Bi` = ith byte of data
6573
/// - `SP` = stop condition
6674
#[inline]
67-
async fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error> {
68-
self.transaction(address, &mut [Operation::Write(write)])
69-
.await
75+
fn write(&mut self, address: A, write: &[u8]) -> impl Future<Output = Result<(), Self::Error>> {
76+
async move {
77+
self.transaction(address, &mut [Operation::Write(write)])
78+
.await
79+
}
7080
}
7181

7282
/// Writes bytes to slave with address `address` and then reads enough bytes to fill `read` *in a
@@ -92,17 +102,19 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
92102
/// - `NMAK` = master no acknowledge
93103
/// - `SP` = stop condition
94104
#[inline]
95-
async fn write_read(
105+
fn write_read(
96106
&mut self,
97107
address: A,
98108
write: &[u8],
99109
read: &mut [u8],
100-
) -> Result<(), Self::Error> {
101-
self.transaction(
102-
address,
103-
&mut [Operation::Write(write), Operation::Read(read)],
104-
)
105-
.await
110+
) -> impl Future<Output = Result<(), Self::Error>> {
111+
async move {
112+
self.transaction(
113+
address,
114+
&mut [Operation::Write(write), Operation::Read(read)],
115+
)
116+
.await
117+
}
106118
}
107119

108120
/// Execute the provided operations on the I2C bus as a single transaction.
@@ -118,40 +130,44 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
118130
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
119131
/// - `SR` = repeated start condition
120132
/// - `SP` = stop condition
121-
async fn transaction(
133+
fn transaction(
122134
&mut self,
123135
address: A,
124136
operations: &mut [Operation<'_>],
125-
) -> Result<(), Self::Error>;
137+
) -> impl Future<Output = Result<(), Self::Error>>;
126138
}
127139

128140
impl<A: AddressMode, T: I2c<A> + ?Sized> I2c<A> for &mut T {
129141
#[inline]
130-
async fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error> {
131-
T::read(self, address, read).await
142+
fn read(
143+
&mut self,
144+
address: A,
145+
read: &mut [u8],
146+
) -> impl Future<Output = Result<(), Self::Error>> {
147+
async move { T::read(self, address, read).await }
132148
}
133149

134150
#[inline]
135-
async fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error> {
136-
T::write(self, address, write).await
151+
fn write(&mut self, address: A, write: &[u8]) -> impl Future<Output = Result<(), Self::Error>> {
152+
async move { T::write(self, address, write).await }
137153
}
138154

139155
#[inline]
140-
async fn write_read(
156+
fn write_read(
141157
&mut self,
142158
address: A,
143159
write: &[u8],
144160
read: &mut [u8],
145-
) -> Result<(), Self::Error> {
146-
T::write_read(self, address, write, read).await
161+
) -> impl Future<Output = Result<(), Self::Error>> {
162+
async move { T::write_read(self, address, write, read).await }
147163
}
148164

149165
#[inline]
150-
async fn transaction(
166+
fn transaction(
151167
&mut self,
152168
address: A,
153169
operations: &mut [Operation<'_>],
154-
) -> Result<(), Self::Error> {
155-
T::transaction(self, address, operations).await
170+
) -> impl Future<Output = Result<(), Self::Error>> {
171+
async move { T::transaction(self, address, operations).await }
156172
}
157173
}

0 commit comments

Comments
 (0)