aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-11-27 23:13:41 +0000
committerGitHub <[email protected]>2022-11-27 23:13:41 +0000
commitcea29d7de3169cf2212128e0386e5d57053cc12d (patch)
tree920623238d8b5341f00720359a145b68c5519bd3
parent805b885de62f7028ffcec86b00014bf72749a871 (diff)
parent787e5d49078de4b09919711e6d9870a7c2a86b32 (diff)
Merge #1079
1079: Async function in trait cleanup r=Dirbaio a=yodaldevoid Some issues I ran across after the AFIT stuff was merged. Co-authored-by: Gabriel Smith <[email protected]> Co-authored-by: Dario Nieuwenhuis <[email protected]>
-rwxr-xr-xci.sh2
-rw-r--r--embassy-rp/src/rtc/mod.rs2
-rw-r--r--embassy-rp/src/usb.rs2
-rw-r--r--embassy-stm32/src/usb/usb.rs2
-rw-r--r--embassy-sync/src/lib.rs3
-rw-r--r--embassy-sync/src/pipe.rs74
-rw-r--r--embassy-time/src/delay.rs16
-rw-r--r--embassy-time/src/lib.rs3
-rw-r--r--embassy-usb-driver/src/lib.rs6
-rw-r--r--embassy-usb/src/class/hid.rs2
10 files changed, 35 insertions, 77 deletions
diff --git a/ci.sh b/ci.sh
index cd1c0786c..a99a5f323 100755
--- a/ci.sh
+++ b/ci.sh
@@ -36,6 +36,8 @@ cargo batch \
36 --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,log \ 36 --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,log \
37 --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,defmt \ 37 --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,defmt \
38 --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \ 38 --- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \
39 --- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \
40 --- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features nightly,unstable-traits,defmt,defmt-timestamp-uptime,tick-hz-32_768,generic-queue-8 \
39 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,pool-16 \ 41 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,pool-16 \
40 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,pool-16,unstable-traits \ 42 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,pool-16,unstable-traits \
41 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,pool-16,nightly \ 43 --- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,dhcpv4,medium-ethernet,pool-16,nightly \
diff --git a/embassy-rp/src/rtc/mod.rs b/embassy-rp/src/rtc/mod.rs
index e4b6f0b1d..c173909c7 100644
--- a/embassy-rp/src/rtc/mod.rs
+++ b/embassy-rp/src/rtc/mod.rs
@@ -164,7 +164,7 @@ impl<'d, T: Instance> RealTimeClock<'d, T> {
164 } 164 }
165} 165}
166 166
167/// Errors that can occur on methods on [RtcClock] 167/// Errors that can occur on methods on [RealTimeClock]
168#[derive(Clone, Debug, PartialEq, Eq)] 168#[derive(Clone, Debug, PartialEq, Eq)]
169pub enum RtcError { 169pub enum RtcError {
170 /// An invalid DateTime was given or stored on the hardware. 170 /// An invalid DateTime was given or stored on the hardware.
diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs
index 32fc2632d..dfc2e9da6 100644
--- a/embassy-rp/src/usb.rs
+++ b/embassy-rp/src/usb.rs
@@ -638,7 +638,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
638 64 638 64
639 } 639 }
640 640
641 async fn setup<'a>(&'a mut self) -> [u8; 8] { 641 async fn setup(&mut self) -> [u8; 8] {
642 loop { 642 loop {
643 trace!("SETUP read waiting"); 643 trace!("SETUP read waiting");
644 let regs = T::regs(); 644 let regs = T::regs();
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs
index 0ba06cce2..460abfe28 100644
--- a/embassy-stm32/src/usb/usb.rs
+++ b/embassy-stm32/src/usb/usb.rs
@@ -799,7 +799,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
799 usize::from(self.max_packet_size) 799 usize::from(self.max_packet_size)
800 } 800 }
801 801
802 async fn setup<'a>(&'a mut self) -> [u8; 8] { 802 async fn setup(&mut self) -> [u8; 8] {
803 loop { 803 loop {
804 trace!("SETUP read waiting"); 804 trace!("SETUP read waiting");
805 poll_fn(|cx| { 805 poll_fn(|cx| {
diff --git a/embassy-sync/src/lib.rs b/embassy-sync/src/lib.rs
index 80bb907a3..f9435ecff 100644
--- a/embassy-sync/src/lib.rs
+++ b/embassy-sync/src/lib.rs
@@ -1,5 +1,6 @@
1#![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] 1#![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)]
2#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] 2#![cfg_attr(feature = "nightly", feature(async_fn_in_trait, impl_trait_projections))]
3#![cfg_attr(feature = "nightly", allow(incomplete_features))]
3#![allow(clippy::new_without_default)] 4#![allow(clippy::new_without_default)]
4#![doc = include_str!("../README.md")] 5#![doc = include_str!("../README.md")]
5#![warn(missing_docs)] 6#![warn(missing_docs)]
diff --git a/embassy-sync/src/pipe.rs b/embassy-sync/src/pipe.rs
index cd577f34f..905686acd 100644
--- a/embassy-sync/src/pipe.rs
+++ b/embassy-sync/src/pipe.rs
@@ -352,8 +352,6 @@ where
352mod io_impls { 352mod io_impls {
353 use core::convert::Infallible; 353 use core::convert::Infallible;
354 354
355 use futures_util::FutureExt;
356
357 use super::*; 355 use super::*;
358 356
359 impl<M: RawMutex, const N: usize> embedded_io::Io for Pipe<M, N> { 357 impl<M: RawMutex, const N: usize> embedded_io::Io for Pipe<M, N> {
@@ -361,30 +359,18 @@ mod io_impls {
361 } 359 }
362 360
363 impl<M: RawMutex, const N: usize> embedded_io::asynch::Read for Pipe<M, N> { 361 impl<M: RawMutex, const N: usize> embedded_io::asynch::Read for Pipe<M, N> {
364 type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 362 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
365 where 363 Ok(Pipe::read(self, buf).await)
366 Self: 'a;
367
368 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
369 Pipe::read(self, buf).map(Ok)
370 } 364 }
371 } 365 }
372 366
373 impl<M: RawMutex, const N: usize> embedded_io::asynch::Write for Pipe<M, N> { 367 impl<M: RawMutex, const N: usize> embedded_io::asynch::Write for Pipe<M, N> {
374 type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 368 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
375 where 369 Ok(Pipe::write(self, buf).await)
376 Self: 'a;
377
378 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
379 Pipe::write(self, buf).map(Ok)
380 } 370 }
381 371
382 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a 372 async fn flush(&mut self) -> Result<(), Self::Error> {
383 where 373 Ok(())
384 Self: 'a;
385
386 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
387 futures_util::future::ready(Ok(()))
388 } 374 }
389 } 375 }
390 376
@@ -393,30 +379,18 @@ mod io_impls {
393 } 379 }
394 380
395 impl<M: RawMutex, const N: usize> embedded_io::asynch::Read for &Pipe<M, N> { 381 impl<M: RawMutex, const N: usize> embedded_io::asynch::Read for &Pipe<M, N> {
396 type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 382 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
397 where 383 Ok(Pipe::read(self, buf).await)
398 Self: 'a;
399
400 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
401 Pipe::read(self, buf).map(Ok)
402 } 384 }
403 } 385 }
404 386
405 impl<M: RawMutex, const N: usize> embedded_io::asynch::Write for &Pipe<M, N> { 387 impl<M: RawMutex, const N: usize> embedded_io::asynch::Write for &Pipe<M, N> {
406 type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 388 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
407 where 389 Ok(Pipe::write(self, buf).await)
408 Self: 'a;
409
410 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
411 Pipe::write(self, buf).map(Ok)
412 } 390 }
413 391
414 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a 392 async fn flush(&mut self) -> Result<(), Self::Error> {
415 where 393 Ok(())
416 Self: 'a;
417
418 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
419 futures_util::future::ready(Ok(()))
420 } 394 }
421 } 395 }
422 396
@@ -425,12 +399,8 @@ mod io_impls {
425 } 399 }
426 400
427 impl<M: RawMutex, const N: usize> embedded_io::asynch::Read for Reader<'_, M, N> { 401 impl<M: RawMutex, const N: usize> embedded_io::asynch::Read for Reader<'_, M, N> {
428 type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 402 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
429 where 403 Ok(Reader::read(self, buf).await)
430 Self: 'a;
431
432 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
433 Reader::read(self, buf).map(Ok)
434 } 404 }
435 } 405 }
436 406
@@ -439,20 +409,12 @@ mod io_impls {
439 } 409 }
440 410
441 impl<M: RawMutex, const N: usize> embedded_io::asynch::Write for Writer<'_, M, N> { 411 impl<M: RawMutex, const N: usize> embedded_io::asynch::Write for Writer<'_, M, N> {
442 type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 412 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
443 where 413 Ok(Writer::write(self, buf).await)
444 Self: 'a;
445
446 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
447 Writer::write(self, buf).map(Ok)
448 } 414 }
449 415
450 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a 416 async fn flush(&mut self) -> Result<(), Self::Error> {
451 where 417 Ok(())
452 Self: 'a;
453
454 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
455 futures_util::future::ready(Ok(()))
456 } 418 }
457 } 419 }
458} 420}
diff --git a/embassy-time/src/delay.rs b/embassy-time/src/delay.rs
index ff6b6869a..0ca176abd 100644
--- a/embassy-time/src/delay.rs
+++ b/embassy-time/src/delay.rs
@@ -33,26 +33,18 @@ mod eh1 {
33 33
34#[cfg(all(feature = "unstable-traits", feature = "nightly"))] 34#[cfg(all(feature = "unstable-traits", feature = "nightly"))]
35mod eha { 35mod eha {
36 use core::future::Future;
37
38 use futures_util::FutureExt;
39
40 use super::*; 36 use super::*;
41 use crate::Timer; 37 use crate::Timer;
42 38
43 impl embedded_hal_async::delay::DelayUs for Delay { 39 impl embedded_hal_async::delay::DelayUs for Delay {
44 type Error = core::convert::Infallible; 40 type Error = core::convert::Infallible;
45 41
46 type DelayUsFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; 42 async fn delay_us(&mut self, micros: u32) -> Result<(), Self::Error> {
47 43 Ok(Timer::after(Duration::from_micros(micros as _)).await)
48 fn delay_us(&mut self, micros: u32) -> Self::DelayUsFuture<'_> {
49 Timer::after(Duration::from_micros(micros as _)).map(Ok)
50 } 44 }
51 45
52 type DelayMsFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; 46 async fn delay_ms(&mut self, millis: u32) -> Result<(), Self::Error> {
53 47 Ok(Timer::after(Duration::from_millis(millis as _)).await)
54 fn delay_ms(&mut self, millis: u32) -> Self::DelayMsFuture<'_> {
55 Timer::after(Duration::from_millis(millis as _)).map(Ok)
56 } 48 }
57 } 49 }
58} 50}
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs
index 586aa28de..8b0aebe19 100644
--- a/embassy-time/src/lib.rs
+++ b/embassy-time/src/lib.rs
@@ -1,5 +1,6 @@
1#![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)] 1#![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)]
2#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] 2#![cfg_attr(feature = "nightly", feature(async_fn_in_trait))]
3#![cfg_attr(feature = "nightly", allow(incomplete_features))]
3#![doc = include_str!("../README.md")] 4#![doc = include_str!("../README.md")]
4#![allow(clippy::new_without_default)] 5#![allow(clippy::new_without_default)]
5#![warn(missing_docs)] 6#![warn(missing_docs)]
diff --git a/embassy-usb-driver/src/lib.rs b/embassy-usb-driver/src/lib.rs
index 85e9267d3..9300ff812 100644
--- a/embassy-usb-driver/src/lib.rs
+++ b/embassy-usb-driver/src/lib.rs
@@ -184,7 +184,7 @@ pub trait Bus {
184 /// 184 ///
185 /// # Errors 185 /// # Errors
186 /// 186 ///
187 /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support 187 /// * [`Unsupported`](crate::Unsupported) - This UsbBus implementation doesn't support
188 /// simulating a disconnect or it has not been enabled at creation time. 188 /// simulating a disconnect or it has not been enabled at creation time.
189 fn force_reset(&mut self) -> Result<(), Unsupported> { 189 fn force_reset(&mut self) -> Result<(), Unsupported> {
190 Err(Unsupported) 190 Err(Unsupported)
@@ -194,7 +194,7 @@ pub trait Bus {
194 /// 194 ///
195 /// # Errors 195 /// # Errors
196 /// 196 ///
197 /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support 197 /// * [`Unsupported`](crate::Unsupported) - This UsbBus implementation doesn't support
198 /// remote wakeup or it has not been enabled at creation time. 198 /// remote wakeup or it has not been enabled at creation time.
199 async fn remote_wakeup(&mut self) -> Result<(), Unsupported>; 199 async fn remote_wakeup(&mut self) -> Result<(), Unsupported>;
200} 200}
@@ -220,7 +220,7 @@ pub trait ControlPipe {
220 fn max_packet_size(&self) -> usize; 220 fn max_packet_size(&self) -> usize;
221 221
222 /// Reads a single setup packet from the endpoint. 222 /// Reads a single setup packet from the endpoint.
223 async fn setup<'a>(&'a mut self) -> [u8; 8]; 223 async fn setup(&mut self) -> [u8; 8];
224 224
225 /// Reads a DATA OUT packet into `buf` in response to a control write request. 225 /// Reads a DATA OUT packet into `buf` in response to a control write request.
226 /// 226 ///
diff --git a/embassy-usb/src/class/hid.rs b/embassy-usb/src/class/hid.rs
index 4d1fa995f..b967aba0e 100644
--- a/embassy-usb/src/class/hid.rs
+++ b/embassy-usb/src/class/hid.rs
@@ -299,7 +299,7 @@ impl<'d, D: Driver<'d>, const N: usize> HidReader<'d, D, N> {
299 /// **Note:** If `N` > the maximum packet size of the endpoint (i.e. output 299 /// **Note:** If `N` > the maximum packet size of the endpoint (i.e. output
300 /// reports may be split across multiple packets) and this method's future 300 /// reports may be split across multiple packets) and this method's future
301 /// is dropped after some packets have been read, the next call to `read()` 301 /// is dropped after some packets have been read, the next call to `read()`
302 /// will return a [`ReadError::SyncError()`]. The range in the sync error 302 /// will return a [`ReadError::Sync`]. The range in the sync error
303 /// indicates the portion `buf` that was filled by the current call to 303 /// indicates the portion `buf` that was filled by the current call to
304 /// `read()`. If the dropped future used the same `buf`, then `buf` will 304 /// `read()`. If the dropped future used the same `buf`, then `buf` will
305 /// contain the full report. 305 /// contain the full report.