Merge pull request #974 from embassy-rs/afit

Switch to async-fn-in-trait
This commit is contained in:
Dario Nieuwenhuis 2022-11-25 22:09:57 +01:00 committed by GitHub
commit fa37452359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 1153 additions and 1579 deletions

View File

@ -20,7 +20,7 @@ nightly = ["embedded-hal-async", "embedded-storage-async"]
embassy-sync = { version = "0.1.0", path = "../embassy-sync" } embassy-sync = { version = "0.1.0", path = "../embassy-sync" }
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" }
embedded-hal-async = { version = "=0.1.0-alpha.3", optional = true } embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true }
embedded-storage = "0.3.0" embedded-storage = "0.3.0"
embedded-storage-async = { version = "0.3.0", optional = true } embedded-storage-async = { version = "0.3.0", optional = true }
nb = "1.0.0" nb = "1.0.0"

View File

@ -38,32 +38,31 @@ where
E: embedded_hal_1::i2c::Error + 'static, E: embedded_hal_1::i2c::Error + 'static,
T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>, T: blocking::i2c::WriteRead<Error = E> + blocking::i2c::Read<Error = E> + blocking::i2c::Write<Error = E>,
{ {
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Result<(), Self::Error> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; self.wrapped.read(address, buffer)
type WriteReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
async move { self.wrapped.read(address, buffer) }
} }
fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { async fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Result<(), Self::Error> {
async move { self.wrapped.write(address, bytes) } self.wrapped.write(address, bytes)
} }
fn write_read<'a>(&'a mut self, address: u8, bytes: &'a [u8], buffer: &'a mut [u8]) -> Self::WriteReadFuture<'a> { async fn write_read<'a>(
async move { self.wrapped.write_read(address, bytes, buffer) } &'a mut self,
address: u8,
bytes: &'a [u8],
buffer: &'a mut [u8],
) -> Result<(), Self::Error> {
self.wrapped.write_read(address, bytes, buffer)
} }
type TransactionFuture<'a, 'b> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a, 'b: 'a; async fn transaction<'a, 'b>(
fn transaction<'a, 'b>(
&'a mut self, &'a mut self,
address: u8, address: u8,
operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], operations: &'a mut [embedded_hal_async::i2c::Operation<'b>],
) -> Self::TransactionFuture<'a, 'b> { ) -> Result<(), Self::Error> {
let _ = address; let _ = address;
let _ = operations; let _ = operations;
async move { todo!() } todo!()
} }
} }
@ -84,10 +83,7 @@ where
E: embedded_hal_1::spi::Error + 'static, E: embedded_hal_1::spi::Error + 'static,
T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>, T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>,
{ {
type TransferFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn transfer<'a>(&'a mut self, read: &'a mut [u8], write: &'a [u8]) -> Result<(), Self::Error> {
fn transfer<'a>(&'a mut self, read: &'a mut [u8], write: &'a [u8]) -> Self::TransferFuture<'a> {
async move {
// Ensure we write the expected bytes // Ensure we write the expected bytes
for i in 0..core::cmp::min(read.len(), write.len()) { for i in 0..core::cmp::min(read.len(), write.len()) {
read[i] = write[i].clone(); read[i] = write[i].clone();
@ -95,12 +91,9 @@ where
self.wrapped.transfer(read)?; self.wrapped.transfer(read)?;
Ok(()) Ok(())
} }
}
type TransferInPlaceFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn transfer_in_place<'a>(&'a mut self, _: &'a mut [u8]) -> Result<(), Self::Error> {
todo!()
fn transfer_in_place<'a>(&'a mut self, _: &'a mut [u8]) -> Self::TransferInPlaceFuture<'a> {
async move { todo!() }
} }
} }
@ -109,10 +102,8 @@ where
E: embedded_hal_1::spi::Error + 'static, E: embedded_hal_1::spi::Error + 'static,
T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>, T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>,
{ {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
async move { Ok(()) }
} }
} }
@ -121,14 +112,10 @@ where
E: embedded_hal_1::spi::Error + 'static, E: embedded_hal_1::spi::Error + 'static,
T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>, T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>,
{ {
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> {
fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> {
async move {
self.wrapped.write(data)?; self.wrapped.write(data)?;
Ok(()) Ok(())
} }
}
} }
impl<T, E> embedded_hal_async::spi::SpiBusRead<u8> for BlockingAsync<T> impl<T, E> embedded_hal_async::spi::SpiBusRead<u8> for BlockingAsync<T>
@ -136,14 +123,10 @@ where
E: embedded_hal_1::spi::Error + 'static, E: embedded_hal_1::spi::Error + 'static,
T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>, T: blocking::spi::Transfer<u8, Error = E> + blocking::spi::Write<u8, Error = E>,
{ {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read(&mut self, data: &mut [u8]) -> Result<(), Self::Error> {
fn read<'a>(&'a mut self, data: &'a mut [u8]) -> Self::ReadFuture<'a> {
async move {
self.wrapped.transfer(data)?; self.wrapped.transfer(data)?;
Ok(()) Ok(())
} }
}
} }
// Uart implementatinos // Uart implementatinos
@ -192,7 +175,7 @@ where
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where T: 'a; type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where T: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { fn flush(&mut self) -> Result<(), Self::Error> {
async move { self.wrapped.bflush() } async move { self.wrapped.bflush() }
} }
} }

View File

@ -1,5 +1,9 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] #![cfg_attr(
feature = "nightly",
feature(type_alias_impl_trait, async_fn_in_trait, impl_trait_projections)
)]
#![cfg_attr(feature = "nightly", allow(incomplete_features))]
#![warn(missing_docs)] #![warn(missing_docs)]
//! Utilities to use `embedded-hal` traits with Embassy. //! Utilities to use `embedded-hal` traits with Embassy.

View File

@ -22,7 +22,6 @@
//! let i2c_dev2 = I2cDevice::new(i2c_bus); //! let i2c_dev2 = I2cDevice::new(i2c_bus);
//! let mpu = Mpu6050::new(i2c_dev2); //! let mpu = Mpu6050::new(i2c_dev2);
//! ``` //! ```
use core::future::Future;
use embassy_sync::blocking_mutex::raw::RawMutex; use embassy_sync::blocking_mutex::raw::RawMutex;
use embassy_sync::mutex::Mutex; use embassy_sync::mutex::Mutex;
@ -55,53 +54,39 @@ where
M: RawMutex + 'static, M: RawMutex + 'static,
BUS: i2c::I2c + 'static, BUS: i2c::I2c + 'static,
{ {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Result<(), I2cDeviceError<BUS::Error>> {
fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
async move {
let mut bus = self.bus.lock().await; let mut bus = self.bus.lock().await;
bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?; bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?;
Ok(()) Ok(())
} }
}
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Result<(), I2cDeviceError<BUS::Error>> {
fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> {
async move {
let mut bus = self.bus.lock().await; let mut bus = self.bus.lock().await;
bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?; bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?;
Ok(()) Ok(())
} }
}
type WriteReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write_read<'a>(
fn write_read<'a>(
&'a mut self, &'a mut self,
address: u8, address: u8,
wr_buffer: &'a [u8], wr_buffer: &'a [u8],
rd_buffer: &'a mut [u8], rd_buffer: &'a mut [u8],
) -> Self::WriteReadFuture<'a> { ) -> Result<(), I2cDeviceError<BUS::Error>> {
async move {
let mut bus = self.bus.lock().await; let mut bus = self.bus.lock().await;
bus.write_read(address, wr_buffer, rd_buffer) bus.write_read(address, wr_buffer, rd_buffer)
.await .await
.map_err(I2cDeviceError::I2c)?; .map_err(I2cDeviceError::I2c)?;
Ok(()) Ok(())
} }
}
type TransactionFuture<'a, 'b> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a, 'b: 'a; async fn transaction<'a, 'b>(
fn transaction<'a, 'b>(
&'a mut self, &'a mut self,
address: u8, address: u8,
operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], operations: &'a mut [embedded_hal_async::i2c::Operation<'b>],
) -> Self::TransactionFuture<'a, 'b> { ) -> Result<(), I2cDeviceError<BUS::Error>> {
let _ = address; let _ = address;
let _ = operations; let _ = operations;
async move { todo!() } todo!()
} }
} }
@ -136,37 +121,26 @@ where
M: RawMutex + 'static, M: RawMutex + 'static,
BUS: i2c::I2c + SetConfig + 'static, BUS: i2c::I2c + SetConfig + 'static,
{ {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Result<(), I2cDeviceError<BUS::Error>> {
fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
async move {
let mut bus = self.bus.lock().await; let mut bus = self.bus.lock().await;
bus.set_config(&self.config); bus.set_config(&self.config);
bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?; bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?;
Ok(()) Ok(())
} }
}
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Result<(), I2cDeviceError<BUS::Error>> {
fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> {
async move {
let mut bus = self.bus.lock().await; let mut bus = self.bus.lock().await;
bus.set_config(&self.config); bus.set_config(&self.config);
bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?; bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?;
Ok(()) Ok(())
} }
}
type WriteReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write_read<'a>(
fn write_read<'a>(
&'a mut self, &'a mut self,
address: u8, address: u8,
wr_buffer: &'a [u8], wr_buffer: &'a [u8],
rd_buffer: &'a mut [u8], rd_buffer: &'a mut [u8],
) -> Self::WriteReadFuture<'a> { ) -> Result<(), I2cDeviceError<BUS::Error>> {
async move {
let mut bus = self.bus.lock().await; let mut bus = self.bus.lock().await;
bus.set_config(&self.config); bus.set_config(&self.config);
bus.write_read(address, wr_buffer, rd_buffer) bus.write_read(address, wr_buffer, rd_buffer)
@ -174,17 +148,14 @@ where
.map_err(I2cDeviceError::I2c)?; .map_err(I2cDeviceError::I2c)?;
Ok(()) Ok(())
} }
}
type TransactionFuture<'a, 'b> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a, 'b: 'a; async fn transaction<'a, 'b>(
fn transaction<'a, 'b>(
&'a mut self, &'a mut self,
address: u8, address: u8,
operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], operations: &'a mut [embedded_hal_async::i2c::Operation<'b>],
) -> Self::TransactionFuture<'a, 'b> { ) -> Result<(), I2cDeviceError<BUS::Error>> {
let _ = address; let _ = address;
let _ = operations; let _ = operations;
async move { todo!() } todo!()
} }
} }

View File

@ -65,18 +65,11 @@ where
{ {
type Bus = BUS; type Bus = BUS;
type TransactionFuture<'a, R, F, Fut> = impl Future<Output = Result<R, Self::Error>> + 'a async fn transaction<R, F, Fut>(&mut self, f: F) -> Result<R, Self::Error>
where where
Self: 'a, R: 'a, F: FnOnce(*mut Self::Bus) -> Fut + 'a, F: FnOnce(*mut Self::Bus) -> Fut,
Fut: Future<Output = Result<R, <Self::Bus as ErrorType>::Error>> + 'a; Fut: Future<Output = Result<R, <Self::Bus as ErrorType>::Error>>,
fn transaction<'a, R, F, Fut>(&'a mut self, f: F) -> Self::TransactionFuture<'a, R, F, Fut>
where
R: 'a,
F: FnOnce(*mut Self::Bus) -> Fut + 'a,
Fut: Future<Output = Result<R, <Self::Bus as ErrorType>::Error>> + 'a,
{ {
async move {
let mut bus = self.bus.lock().await; let mut bus = self.bus.lock().await;
self.cs.set_low().map_err(SpiDeviceError::Cs)?; self.cs.set_low().map_err(SpiDeviceError::Cs)?;
@ -92,7 +85,6 @@ where
Ok(f_res) Ok(f_res)
} }
}
} }
/// SPI device on a shared bus, with its own configuration. /// SPI device on a shared bus, with its own configuration.
@ -130,18 +122,11 @@ where
{ {
type Bus = BUS; type Bus = BUS;
type TransactionFuture<'a, R, F, Fut> = impl Future<Output = Result<R, Self::Error>> + 'a async fn transaction<R, F, Fut>(&mut self, f: F) -> Result<R, Self::Error>
where where
Self: 'a, R: 'a, F: FnOnce(*mut Self::Bus) -> Fut + 'a, F: FnOnce(*mut Self::Bus) -> Fut,
Fut: Future<Output = Result<R, <Self::Bus as ErrorType>::Error>> + 'a; Fut: Future<Output = Result<R, <Self::Bus as ErrorType>::Error>>,
fn transaction<'a, R, F, Fut>(&'a mut self, f: F) -> Self::TransactionFuture<'a, R, F, Fut>
where
R: 'a,
F: FnOnce(*mut Self::Bus) -> Fut + 'a,
Fut: Future<Output = Result<R, <Self::Bus as ErrorType>::Error>> + 'a,
{ {
async move {
let mut bus = self.bus.lock().await; let mut bus = self.bus.lock().await;
bus.set_config(&self.config); bus.set_config(&self.config);
self.cs.set_low().map_err(SpiDeviceError::Cs)?; self.cs.set_low().map_err(SpiDeviceError::Cs)?;
@ -158,5 +143,4 @@ where
Ok(f_res) Ok(f_res)
} }
}
} }

View File

@ -32,7 +32,7 @@ embassy-time = { version = "0.1.0", path = "../embassy-time" }
embassy-sync = { version = "0.1.0", path = "../embassy-sync" } embassy-sync = { version = "0.1.0", path = "../embassy-sync" }
embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true } embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" }
embedded-hal-async = { version = "=0.1.0-alpha.3" } embedded-hal-async = { version = "=0.2.0-alpha.0" }
embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common", default-features = false } embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common", default-features = false }
futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] }
embedded-hal = { version = "0.2", features = ["unproven"] } embedded-hal = { version = "0.2", features = ["unproven"] }

View File

@ -42,7 +42,7 @@ log = { version = "0.4.14", optional = true }
embassy-time = { version = "0.1.0", path = "../embassy-time" } embassy-time = { version = "0.1.0", path = "../embassy-time" }
embassy-sync = { version = "0.1.0", path = "../embassy-sync" } embassy-sync = { version = "0.1.0", path = "../embassy-sync" }
embedded-io = { version = "0.3.1", optional = true } embedded-io = { version = "0.4.0", optional = true }
managed = { version = "0.8.0", default-features = false, features = [ "map" ] } managed = { version = "0.8.0", default-features = false, features = [ "map" ] }
heapless = { version = "0.7.5", default-features = false } heapless = { version = "0.7.5", default-features = false }
@ -52,7 +52,7 @@ stable_deref_trait = { version = "1.2.0", default-features = false }
futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] } futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] }
atomic-pool = "1.0" atomic-pool = "1.0"
atomic-polyfill = "1.0.1" atomic-polyfill = "1.0.1"
embedded-nal-async = { version = "0.2.0", optional = true } embedded-nal-async = { git = "https://github.com/embassy-rs/embedded-nal.git", rev = "691601e550449a53ab3a7c5eaa0411aee0a64ed0", optional = true }
[dependencies.smoltcp] [dependencies.smoltcp]
version = "0.8.0" version = "0.8.0"

View File

@ -1,5 +1,9 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] #![cfg_attr(
feature = "nightly",
feature(type_alias_impl_trait, async_fn_in_trait, impl_trait_projections)
)]
#![cfg_attr(feature = "nightly", allow(incomplete_features))]
// This mod MUST go first, so that the others see its macros. // This mod MUST go first, so that the others see its macros.
pub(crate) mod fmt; pub(crate) mod fmt;

View File

@ -271,8 +271,6 @@ impl<'d> TcpIo<'d> {
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
mod embedded_io_impls { mod embedded_io_impls {
use core::future::Future;
use super::*; use super::*;
impl embedded_io::Error for ConnectError { impl embedded_io::Error for ConnectError {
@ -292,30 +290,18 @@ mod embedded_io_impls {
} }
impl<'d> embedded_io::asynch::Read for TcpSocket<'d> { impl<'d> embedded_io::asynch::Read for TcpSocket<'d> {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where self.io.read(buf).await
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.io.read(buf)
} }
} }
impl<'d> embedded_io::asynch::Write for TcpSocket<'d> { impl<'d> embedded_io::asynch::Write for TcpSocket<'d> {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where self.io.write(buf).await
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
self.io.write(buf)
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where self.io.flush().await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
self.io.flush()
} }
} }
@ -324,12 +310,8 @@ mod embedded_io_impls {
} }
impl<'d> embedded_io::asynch::Read for TcpReader<'d> { impl<'d> embedded_io::asynch::Read for TcpReader<'d> {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where self.io.read(buf).await
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.io.read(buf)
} }
} }
@ -338,27 +320,18 @@ mod embedded_io_impls {
} }
impl<'d> embedded_io::asynch::Write for TcpWriter<'d> { impl<'d> embedded_io::asynch::Write for TcpWriter<'d> {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where self.io.write(buf).await
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
self.io.write(buf)
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where self.io.flush().await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
self.io.flush()
} }
} }
} }
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
pub mod client { pub mod client {
use core::future::Future;
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
use core::ptr::NonNull; use core::ptr::NonNull;
@ -385,12 +358,14 @@ pub mod client {
{ {
type Error = Error; type Error = Error;
type Connection<'m> = TcpConnection<'m, N, TX_SZ, RX_SZ> where Self: 'm; type Connection<'m> = TcpConnection<'m, N, TX_SZ, RX_SZ> where Self: 'm;
type ConnectFuture<'m> = impl Future<Output = Result<Self::Connection<'m>, Self::Error>> + 'm
where
Self: 'm;
fn connect<'m>(&'m self, remote: embedded_nal_async::SocketAddr) -> Self::ConnectFuture<'m> { async fn connect<'a>(
async move { &'a self,
remote: embedded_nal_async::SocketAddr,
) -> Result<Self::Connection<'a>, Self::Error>
where
Self: 'a,
{
let addr: crate::IpAddress = match remote.ip() { let addr: crate::IpAddress = match remote.ip() {
IpAddr::V4(addr) => crate::IpAddress::Ipv4(crate::Ipv4Address::from_bytes(&addr.octets())), IpAddr::V4(addr) => crate::IpAddress::Ipv4(crate::Ipv4Address::from_bytes(&addr.octets())),
#[cfg(feature = "proto-ipv6")] #[cfg(feature = "proto-ipv6")]
@ -408,7 +383,6 @@ pub mod client {
Ok(socket) Ok(socket)
} }
} }
}
pub struct TcpConnection<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> { pub struct TcpConnection<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> {
socket: TcpSocket<'d>, socket: TcpSocket<'d>,
@ -445,32 +419,20 @@ pub mod client {
impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::asynch::Read impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::asynch::Read
for TcpConnection<'d, N, TX_SZ, RX_SZ> for TcpConnection<'d, N, TX_SZ, RX_SZ>
{ {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where self.socket.read(buf).await
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.socket.read(buf)
} }
} }
impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::asynch::Write impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_io::asynch::Write
for TcpConnection<'d, N, TX_SZ, RX_SZ> for TcpConnection<'d, N, TX_SZ, RX_SZ>
{ {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where self.socket.write(buf).await
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
self.socket.write(buf)
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where self.socket.flush().await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
self.socket.flush()
} }
} }

View File

@ -75,8 +75,8 @@ embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optiona
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true}
embedded-hal-async = { version = "=0.1.0-alpha.3", optional = true} embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true}
embedded-io = { version = "0.3.1", features = ["async"], optional = true } embedded-io = { version = "0.4.0", features = ["async"], optional = true }
defmt = { version = "0.3", optional = true } defmt = { version = "0.3", optional = true }
log = { version = "0.4.14", optional = true } log = { version = "0.4.14", optional = true }

View File

@ -15,7 +15,7 @@
use core::cell::RefCell; use core::cell::RefCell;
use core::cmp::min; use core::cmp::min;
use core::future::{poll_fn, Future}; use core::future::poll_fn;
use core::sync::atomic::{compiler_fence, Ordering}; use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll; use core::task::Poll;
@ -341,32 +341,20 @@ impl<'u, 'd, U: UarteInstance, T: TimerInstance> embedded_io::Io for BufferedUar
} }
impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Read for BufferedUarte<'d, U, T> { impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Read for BufferedUarte<'d, U, T> {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where self.inner_read(buf).await
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.inner_read(buf)
} }
} }
impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Read for BufferedUarteRx<'u, 'd, U, T> { impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Read for BufferedUarteRx<'u, 'd, U, T> {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where self.inner.inner_read(buf).await
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.inner.inner_read(buf)
} }
} }
impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead for BufferedUarte<'d, U, T> { impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead for BufferedUarte<'d, U, T> {
type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> + 'a async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
where self.inner_fill_buf().await
Self: 'a;
fn fill_buf<'a>(&'a mut self) -> Self::FillBufFuture<'a> {
self.inner_fill_buf()
} }
fn consume(&mut self, amt: usize) { fn consume(&mut self, amt: usize) {
@ -375,12 +363,8 @@ impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead for Bu
} }
impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead for BufferedUarteRx<'u, 'd, U, T> { impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead for BufferedUarteRx<'u, 'd, U, T> {
type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> + 'a async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
where self.inner.inner_fill_buf().await
Self: 'a;
fn fill_buf<'a>(&'a mut self) -> Self::FillBufFuture<'a> {
self.inner.inner_fill_buf()
} }
fn consume(&mut self, amt: usize) { fn consume(&mut self, amt: usize) {
@ -389,38 +373,22 @@ impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRea
} }
impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write for BufferedUarte<'d, U, T> { impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write for BufferedUarte<'d, U, T> {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where self.inner_write(buf).await
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
self.inner_write(buf)
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where self.inner_flush().await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
self.inner_flush()
} }
} }
impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write for BufferedUarteTx<'u, 'd, U, T> { impl<'u, 'd: 'u, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write for BufferedUarteTx<'u, 'd, U, T> {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where self.inner.inner_write(buf).await
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
self.inner.inner_write(buf)
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where self.inner.inner_flush().await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
self.inner.inner_flush()
} }
} }

View File

@ -473,71 +473,49 @@ mod eh1 {
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod eha { mod eha {
use futures::FutureExt;
use super::*; use super::*;
impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for Input<'d, T> { impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for Input<'d, T> {
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_high().await)
fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> {
self.wait_for_high().map(Ok)
} }
type WaitForLowFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_low().await)
fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> {
self.wait_for_low().map(Ok)
} }
type WaitForRisingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_rising_edge().await)
fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> {
self.wait_for_rising_edge().map(Ok)
} }
type WaitForFallingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_falling_edge().await)
fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> {
self.wait_for_falling_edge().map(Ok)
} }
type WaitForAnyEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_any_edge().await)
fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> {
self.wait_for_any_edge().map(Ok)
} }
} }
impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for Flex<'d, T> { impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for Flex<'d, T> {
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_high().await)
fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> {
self.wait_for_high().map(Ok)
} }
type WaitForLowFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_low().await)
fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> {
self.wait_for_low().map(Ok)
} }
type WaitForRisingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_rising_edge().await)
fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> {
self.wait_for_rising_edge().map(Ok)
} }
type WaitForFallingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_falling_edge().await)
fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> {
self.wait_for_falling_edge().map(Ok)
} }
type WaitForAnyEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
Ok(self.wait_for_any_edge().await)
fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> {
self.wait_for_any_edge().map(Ok)
} }
} }
} }

View File

@ -43,7 +43,11 @@
//! mutable slices always reside in RAM. //! mutable slices always reside in RAM.
#![no_std] #![no_std]
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] #![cfg_attr(
feature = "nightly",
feature(type_alias_impl_trait, async_fn_in_trait, impl_trait_projections)
)]
#![cfg_attr(feature = "nightly", allow(incomplete_features))]
#[cfg(not(any( #[cfg(not(any(
feature = "nrf51", feature = "nrf51",

View File

@ -477,45 +477,34 @@ mod eh1 {
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod eha { mod eha {
use core::future::Future;
use super::*; use super::*;
impl<'d, T: Instance> embedded_hal_async::spi::SpiBusFlush for Spim<'d, T> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBusFlush for Spim<'d, T> {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn flush(&mut self) -> Result<(), Error> {
Ok(())
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
async move { Ok(()) }
} }
} }
impl<'d, T: Instance> embedded_hal_async::spi::SpiBusRead<u8> for Spim<'d, T> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBusRead<u8> for Spim<'d, T> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read(&mut self, words: &mut [u8]) -> Result<(), Error> {
self.read(words).await
fn read<'a>(&'a mut self, words: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.read(words)
} }
} }
impl<'d, T: Instance> embedded_hal_async::spi::SpiBusWrite<u8> for Spim<'d, T> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBusWrite<u8> for Spim<'d, T> {
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write(&mut self, data: &[u8]) -> Result<(), Error> {
self.write(data).await
fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> {
self.write(data)
} }
} }
impl<'d, T: Instance> embedded_hal_async::spi::SpiBus<u8> for Spim<'d, T> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBus<u8> for Spim<'d, T> {
type TransferFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn transfer(&mut self, rx: &mut [u8], tx: &[u8]) -> Result<(), Error> {
self.transfer(rx, tx).await
fn transfer<'a>(&'a mut self, rx: &'a mut [u8], tx: &'a [u8]) -> Self::TransferFuture<'a> {
self.transfer(rx, tx)
} }
type TransferInPlaceFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Error> {
self.transfer_in_place(words).await
fn transfer_in_place<'a>(&'a mut self, words: &'a mut [u8]) -> Self::TransferInPlaceFuture<'a> {
self.transfer_in_place(words)
} }
} }
} }

View File

@ -841,39 +841,31 @@ mod eh1 {
mod eha { mod eha {
use super::*; use super::*;
impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> { impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Result<(), Error> {
self.read(address, buffer).await
fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.read(address, buffer)
} }
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Result<(), Error> {
self.write(address, bytes).await
fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> {
self.write(address, bytes)
} }
type WriteReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write_read<'a>(
fn write_read<'a>(
&'a mut self, &'a mut self,
address: u8, address: u8,
wr_buffer: &'a [u8], wr_buffer: &'a [u8],
rd_buffer: &'a mut [u8], rd_buffer: &'a mut [u8],
) -> Self::WriteReadFuture<'a> { ) -> Result<(), Error> {
self.write_read(address, wr_buffer, rd_buffer) self.write_read(address, wr_buffer, rd_buffer).await
} }
type TransactionFuture<'a, 'b> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a, 'b: 'a; async fn transaction<'a, 'b>(
fn transaction<'a, 'b>(
&'a mut self, &'a mut self,
address: u8, address: u8,
operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], operations: &'a mut [embedded_hal_async::i2c::Operation<'b>],
) -> Self::TransactionFuture<'a, 'b> { ) -> Result<(), Error> {
let _ = address; let _ = address;
let _ = operations; let _ = operations;
async move { todo!() } todo!()
} }
} }
} }

View File

@ -986,7 +986,7 @@ mod eha {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { fn flush(&mut self) -> Result<(), Self::Error> {
async move { Ok(()) } async move { Ok(()) }
} }
} }
@ -1000,7 +1000,7 @@ mod eha {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { fn flush(&mut self) -> Result<(), Self::Error> {
async move { Ok(()) } async move { Ok(()) }
} }
} }
@ -1012,4 +1012,26 @@ mod eha {
self.read(buffer) self.read(buffer)
} }
} }
impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Read for UarteWithIdle<'d, U, T> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.read(buffer)
}
}
impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Write for UarteWithIdle<'d, U, T> {
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
self.write(buffer)
}
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn flush(&mut self) -> Result<(), Self::Error> {
async move { Ok(()) }
}
}
} }

View File

@ -1,6 +1,6 @@
#![macro_use] #![macro_use]
use core::future::{poll_fn, Future}; use core::future::poll_fn;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU32, Ordering}; use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU32, Ordering};
@ -28,11 +28,7 @@ static READY_ENDPOINTS: AtomicU32 = AtomicU32::new(0);
/// here provides a hook into determining whether it is. /// here provides a hook into determining whether it is.
pub trait UsbSupply { pub trait UsbSupply {
fn is_usb_detected(&self) -> bool; fn is_usb_detected(&self) -> bool;
async fn wait_power_ready(&mut self) -> Result<(), ()>;
type UsbPowerReadyFuture<'a>: Future<Output = Result<(), ()>> + 'a
where
Self: 'a;
fn wait_power_ready(&mut self) -> Self::UsbPowerReadyFuture<'_>;
} }
pub struct Driver<'d, T: Instance, P: UsbSupply> { pub struct Driver<'d, T: Instance, P: UsbSupply> {
@ -102,8 +98,7 @@ impl UsbSupply for PowerUsb {
regs.usbregstatus.read().vbusdetect().is_vbus_present() regs.usbregstatus.read().vbusdetect().is_vbus_present()
} }
type UsbPowerReadyFuture<'a> = impl Future<Output = Result<(), ()>> + 'a where Self: 'a; async fn wait_power_ready(&mut self) -> Result<(), ()> {
fn wait_power_ready(&mut self) -> Self::UsbPowerReadyFuture<'_> {
poll_fn(move |cx| { poll_fn(move |cx| {
POWER_WAKER.register(cx.waker()); POWER_WAKER.register(cx.waker());
let regs = unsafe { &*pac::POWER::ptr() }; let regs = unsafe { &*pac::POWER::ptr() };
@ -116,6 +111,7 @@ impl UsbSupply for PowerUsb {
Poll::Pending Poll::Pending
} }
}) })
.await
} }
} }
@ -147,8 +143,7 @@ impl UsbSupply for &SignalledSupply {
self.usb_detected.load(Ordering::Relaxed) self.usb_detected.load(Ordering::Relaxed)
} }
type UsbPowerReadyFuture<'a> = impl Future<Output = Result<(), ()>> + 'a where Self: 'a; async fn wait_power_ready(&mut self) -> Result<(), ()> {
fn wait_power_ready(&mut self) -> Self::UsbPowerReadyFuture<'_> {
poll_fn(move |cx| { poll_fn(move |cx| {
POWER_WAKER.register(cx.waker()); POWER_WAKER.register(cx.waker());
@ -160,6 +155,7 @@ impl UsbSupply for &SignalledSupply {
Poll::Pending Poll::Pending
} }
}) })
.await
} }
} }
@ -289,13 +285,7 @@ pub struct Bus<'d, T: Instance, P: UsbSupply> {
} }
impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> { impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> {
type EnableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn enable(&mut self) {
type DisableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
type PollFuture<'a> = impl Future<Output = Event> + 'a where Self: 'a;
type RemoteWakeupFuture<'a> = impl Future<Output = Result<(), Unsupported>> + 'a where Self: 'a;
fn enable(&mut self) -> Self::EnableFuture<'_> {
async move {
let regs = T::regs(); let regs = T::regs();
errata::pre_enable(); errata::pre_enable();
@ -334,16 +324,13 @@ impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> {
trace!("usb power not ready due to usb removal"); trace!("usb power not ready due to usb removal");
} }
} }
}
fn disable(&mut self) -> Self::DisableFuture<'_> { async fn disable(&mut self) {
async move {
let regs = T::regs(); let regs = T::regs();
regs.enable.write(|x| x.enable().disabled()); regs.enable.write(|x| x.enable().disabled());
} }
}
fn poll<'a>(&'a mut self) -> Self::PollFuture<'a> { async fn poll(&mut self) -> Event {
poll_fn(move |cx| { poll_fn(move |cx| {
BUS_WAKER.register(cx.waker()); BUS_WAKER.register(cx.waker());
let regs = T::regs(); let regs = T::regs();
@ -401,6 +388,7 @@ impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> {
Poll::Pending Poll::Pending
}) })
.await
} }
#[inline] #[inline]
@ -493,8 +481,7 @@ impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> {
} }
#[inline] #[inline]
fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_> { async fn remote_wakeup(&mut self) -> Result<(), Unsupported> {
async move {
let regs = T::regs(); let regs = T::regs();
if regs.lowpower.read().lowpower().is_low_power() { if regs.lowpower.read().lowpower().is_low_power() {
@ -529,7 +516,6 @@ impl<'d, T: Instance, P: UsbSupply> driver::Bus for Bus<'d, T, P> {
Ok(()) Ok(())
} }
}
} }
pub enum Out {} pub enum Out {}
@ -594,9 +580,7 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir
&self.info &self.info
} }
type WaitEnabledFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn wait_enabled(&mut self) {
fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_> {
let i = self.info.addr.index(); let i = self.info.addr.index();
assert!(i != 0); assert!(i != 0);
@ -608,6 +592,7 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir
Poll::Pending Poll::Pending
} }
}) })
.await
} }
} }
@ -712,10 +697,7 @@ unsafe fn write_dma<T: Instance>(i: usize, buf: &[u8]) {
} }
impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
type ReadFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a; async fn read(&mut self, buf: &mut [u8]) -> Result<usize, EndpointError> {
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
async move {
let i = self.info.addr.index(); let i = self.info.addr.index();
assert!(i != 0); assert!(i != 0);
@ -723,14 +705,10 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
unsafe { read_dma::<T>(i, buf) } unsafe { read_dma::<T>(i, buf) }
} }
}
} }
impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> {
type WriteFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a; async fn write(&mut self, buf: &[u8]) -> Result<(), EndpointError> {
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
async move {
let i = self.info.addr.index(); let i = self.info.addr.index();
assert!(i != 0); assert!(i != 0);
@ -740,7 +718,6 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> {
Ok(()) Ok(())
} }
}
} }
pub struct ControlPipe<'d, T: Instance> { pub struct ControlPipe<'d, T: Instance> {
@ -749,18 +726,11 @@ pub struct ControlPipe<'d, T: Instance> {
} }
impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
type SetupFuture<'a> = impl Future<Output = [u8;8]> + 'a where Self: 'a;
type DataOutFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a;
type DataInFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a;
type AcceptFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
type RejectFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
fn max_packet_size(&self) -> usize { fn max_packet_size(&self) -> usize {
usize::from(self.max_packet_size) usize::from(self.max_packet_size)
} }
fn setup<'a>(&'a mut self) -> Self::SetupFuture<'a> { async fn setup(&mut self) -> [u8; 8] {
async move {
let regs = T::regs(); let regs = T::regs();
// Reset shorts // Reset shorts
@ -793,10 +763,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
buf buf
} }
}
fn data_out<'a>(&'a mut self, buf: &'a mut [u8], _first: bool, _last: bool) -> Self::DataOutFuture<'a> { async fn data_out(&mut self, buf: &mut [u8], _first: bool, _last: bool) -> Result<usize, EndpointError> {
async move {
let regs = T::regs(); let regs = T::regs();
regs.events_ep0datadone.reset(); regs.events_ep0datadone.reset();
@ -829,10 +797,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
unsafe { read_dma::<T>(0, buf) } unsafe { read_dma::<T>(0, buf) }
} }
}
fn data_in<'a>(&'a mut self, buf: &'a [u8], _first: bool, last: bool) -> Self::DataInFuture<'a> { async fn data_in(&mut self, buf: &[u8], _first: bool, last: bool) -> Result<(), EndpointError> {
async move {
let regs = T::regs(); let regs = T::regs();
regs.events_ep0datadone.reset(); regs.events_ep0datadone.reset();
@ -865,21 +831,16 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
}) })
.await .await
} }
}
fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> { async fn accept(&mut self) {
async move {
let regs = T::regs(); let regs = T::regs();
regs.tasks_ep0status.write(|w| w.tasks_ep0status().bit(true)); regs.tasks_ep0status.write(|w| w.tasks_ep0status().bit(true));
} }
}
fn reject<'a>(&'a mut self) -> Self::RejectFuture<'a> { async fn reject(&mut self) {
async move {
let regs = T::regs(); let regs = T::regs();
regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(true)); regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(true));
} }
}
} }
fn dma_start() { fn dma_start() {

View File

@ -53,7 +53,7 @@ cortex-m = "0.7.6"
critical-section = "1.1" critical-section = "1.1"
futures = { version = "0.3.17", default-features = false, features = ["async-await"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
chrono = { version = "0.4", default-features = false, optional = true } chrono = { version = "0.4", default-features = false, optional = true }
embedded-io = { version = "0.3.1", features = ["async"], optional = true } embedded-io = { version = "0.4.0", features = ["async"], optional = true }
embedded-storage = { version = "0.3" } embedded-storage = { version = "0.3" }
rp2040-pac2 = { git = "https://github.com/embassy-rs/rp2040-pac2", rev="017e3c9007b2d3b6965f0d85b5bf8ce3fa6d7364", features = ["rt"] } rp2040-pac2 = { git = "https://github.com/embassy-rs/rp2040-pac2", rev="017e3c9007b2d3b6965f0d85b5bf8ce3fa6d7364", features = ["rt"] }
@ -61,5 +61,5 @@ rp2040-pac2 = { git = "https://github.com/embassy-rs/rp2040-pac2", rev="017e3c90
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true}
embedded-hal-async = { version = "=0.1.0-alpha.3", optional = true} embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true}
embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true} embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true}

View File

@ -870,9 +870,6 @@ mod eh02 {
mod eh1 { mod eh1 {
use core::convert::Infallible; use core::convert::Infallible;
#[cfg(feature = "nightly")]
use futures::FutureExt;
use super::*; use super::*;
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {
@ -991,57 +988,57 @@ mod eh1 {
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
impl<'d, T: Pin> embedded_hal_async::digital::Wait for Flex<'d, T> { impl<'d, T: Pin> embedded_hal_async::digital::Wait for Flex<'d, T> {
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> { self.wait_for_high().await;
self.wait_for_high().map(Ok) Ok(())
} }
type WaitForLowFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> { self.wait_for_low().await;
self.wait_for_low().map(Ok) Ok(())
} }
type WaitForRisingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> { self.wait_for_rising_edge().await;
self.wait_for_rising_edge().map(Ok) Ok(())
} }
type WaitForFallingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> { self.wait_for_falling_edge().await;
self.wait_for_falling_edge().map(Ok) Ok(())
} }
type WaitForAnyEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> { self.wait_for_any_edge().await;
self.wait_for_any_edge().map(Ok) Ok(())
} }
} }
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
impl<'d, T: Pin> embedded_hal_async::digital::Wait for Input<'d, T> { impl<'d, T: Pin> embedded_hal_async::digital::Wait for Input<'d, T> {
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> { self.wait_for_high().await;
self.wait_for_high().map(Ok) Ok(())
} }
type WaitForLowFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> { self.wait_for_low().await;
self.wait_for_low().map(Ok) Ok(())
} }
type WaitForRisingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> { self.wait_for_rising_edge().await;
self.wait_for_rising_edge().map(Ok) Ok(())
} }
type WaitForFallingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> { self.wait_for_falling_edge().await;
self.wait_for_falling_edge().map(Ok) Ok(())
} }
type WaitForAnyEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> { self.wait_for_any_edge().await;
self.wait_for_any_edge().map(Ok) Ok(())
} }
} }
} }

View File

@ -717,8 +717,6 @@ mod eh1 {
} }
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod nightly { mod nightly {
use core::future::Future;
use embedded_hal_1::i2c::Operation; use embedded_hal_1::i2c::Operation;
use embedded_hal_async::i2c::AddressMode; use embedded_hal_async::i2c::AddressMode;
@ -729,56 +727,38 @@ mod nightly {
A: AddressMode + Into<u16> + 'static, A: AddressMode + Into<u16> + 'static,
T: Instance + 'd, T: Instance + 'd,
{ {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn read<'a>(&'a mut self, address: A, read: &'a mut [u8]) -> Result<(), Self::Error> {
where Self: 'a;
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a
where Self: 'a;
type WriteReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a
where Self: 'a;
type TransactionFuture<'a, 'b> = impl Future<Output = Result<(), Error>> + 'a
where Self: 'a, 'b: 'a;
fn read<'a>(&'a mut self, address: A, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
let addr: u16 = address.into(); let addr: u16 = address.into();
async move {
Self::setup(addr)?; Self::setup(addr)?;
self.read_async_internal(buffer, false, true).await self.read_async_internal(read, false, true).await
}
} }
fn write<'a>(&'a mut self, address: A, write: &'a [u8]) -> Self::WriteFuture<'a> { async fn write<'a>(&'a mut self, address: A, write: &'a [u8]) -> Result<(), Self::Error> {
let addr: u16 = address.into(); let addr: u16 = address.into();
async move {
Self::setup(addr)?; Self::setup(addr)?;
self.write_async_internal(write.iter().copied(), true).await self.write_async_internal(write.iter().copied(), true).await
} }
} async fn write_read<'a>(
fn write_read<'a>(
&'a mut self, &'a mut self,
address: A, address: A,
bytes: &'a [u8], write: &'a [u8],
buffer: &'a mut [u8], read: &'a mut [u8],
) -> Self::WriteReadFuture<'a> { ) -> Result<(), Self::Error> {
let addr: u16 = address.into(); let addr: u16 = address.into();
async move {
Self::setup(addr)?; Self::setup(addr)?;
self.write_async_internal(bytes.iter().cloned(), false).await?; self.write_async_internal(write.iter().cloned(), false).await?;
self.read_async_internal(buffer, false, true).await self.read_async_internal(read, false, true).await
} }
} async fn transaction<'a, 'b>(
fn transaction<'a, 'b>(
&'a mut self, &'a mut self,
address: A, address: A,
operations: &'a mut [Operation<'b>], operations: &'a mut [Operation<'b>],
) -> Self::TransactionFuture<'a, 'b> { ) -> Result<(), Self::Error> {
let addr: u16 = address.into(); let addr: u16 = address.into();
async move {
let mut iterator = operations.iter_mut(); let mut iterator = operations.iter_mut();
while let Some(op) = iterator.next() { while let Some(op) = iterator.next() {
@ -798,7 +778,6 @@ mod nightly {
Ok(()) Ok(())
} }
} }
}
} }
fn i2c_reserved_addr(addr: u16) -> bool { fn i2c_reserved_addr(addr: u16) -> bool {

View File

@ -1,5 +1,6 @@
#![no_std] #![no_std]
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] #![cfg_attr(feature = "nightly", feature(async_fn_in_trait, impl_trait_projections))]
#![cfg_attr(feature = "nightly", allow(incomplete_features))]
// This mod MUST go first, so that the others see its macros. // This mod MUST go first, so that the others see its macros.
pub(crate) mod fmt; pub(crate) mod fmt;

View File

@ -554,45 +554,33 @@ mod eh1 {
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod eha { mod eha {
use core::future::Future;
use super::*; use super::*;
impl<'d, T: Instance> embedded_hal_async::spi::SpiBusFlush for Spi<'d, T, Async> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBusFlush for Spi<'d, T, Async> {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
async { Ok(()) }
} }
} }
impl<'d, T: Instance> embedded_hal_async::spi::SpiBusWrite<u8> for Spi<'d, T, Async> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBusWrite<u8> for Spi<'d, T, Async> {
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write(&mut self, words: &[u8]) -> Result<(), Self::Error> {
self.write(words).await
fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> {
self.write(data)
} }
} }
impl<'d, T: Instance> embedded_hal_async::spi::SpiBusRead<u8> for Spi<'d, T, Async> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBusRead<u8> for Spi<'d, T, Async> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error> {
self.read(words).await
fn read<'a>(&'a mut self, data: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.read(data)
} }
} }
impl<'d, T: Instance> embedded_hal_async::spi::SpiBus<u8> for Spi<'d, T, Async> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBus<u8> for Spi<'d, T, Async> {
type TransferFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn transfer<'a>(&'a mut self, read: &'a mut [u8], write: &'a [u8]) -> Result<(), Self::Error> {
self.transfer(read, write).await
fn transfer<'a>(&'a mut self, rx: &'a mut [u8], tx: &'a [u8]) -> Self::TransferFuture<'a> {
self.transfer(rx, tx)
} }
type TransferInPlaceFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn transfer_in_place<'a>(&'a mut self, words: &'a mut [u8]) -> Result<(), Self::Error> {
self.transfer_in_place(words).await
fn transfer_in_place<'a>(&'a mut self, words: &'a mut [u8]) -> Self::TransferInPlaceFuture<'a> {
self.transfer_in_place(words)
} }
} }
} }

View File

@ -1,4 +1,4 @@
use core::future::{poll_fn, Future}; use core::future::poll_fn;
use core::task::{Poll, Waker}; use core::task::{Poll, Waker};
use atomic_polyfill::{compiler_fence, Ordering}; use atomic_polyfill::{compiler_fence, Ordering};
@ -355,11 +355,7 @@ impl<'d, T: Instance> embedded_io::Io for BufferedUartTx<'d, T> {
} }
impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUart<'d, T> { impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUart<'d, T> {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
poll_fn(move |cx| { poll_fn(move |cx| {
let (res, do_pend) = self.inner.with(|state| { let (res, do_pend) = self.inner.with(|state| {
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
@ -372,15 +368,12 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUart<'d, T> {
res res
}) })
.await
} }
} }
impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUartRx<'d, T> { impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUartRx<'d, T> {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
poll_fn(move |cx| { poll_fn(move |cx| {
let (res, do_pend) = self.inner.with(|state| { let (res, do_pend) = self.inner.with(|state| {
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
@ -393,21 +386,19 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUartRx<'d, T> {
res res
}) })
.await
} }
} }
impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUart<'d, T> { impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUart<'d, T> {
type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> + 'a async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
where
Self: 'a;
fn fill_buf<'a>(&'a mut self) -> Self::FillBufFuture<'a> {
poll_fn(move |cx| { poll_fn(move |cx| {
self.inner.with(|state| { self.inner.with(|state| {
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
state.rx.fill_buf(cx.waker()) state.rx.fill_buf(cx.waker())
}) })
}) })
.await
} }
fn consume(&mut self, amt: usize) { fn consume(&mut self, amt: usize) {
@ -419,17 +410,14 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUart<'d, T>
} }
impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUartRx<'d, T> { impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUartRx<'d, T> {
type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> + 'a async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
where
Self: 'a;
fn fill_buf<'a>(&'a mut self) -> Self::FillBufFuture<'a> {
poll_fn(move |cx| { poll_fn(move |cx| {
self.inner.with(|state| { self.inner.with(|state| {
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
state.fill_buf(cx.waker()) state.fill_buf(cx.waker())
}) })
}) })
.await
} }
fn consume(&mut self, amt: usize) { fn consume(&mut self, amt: usize) {
@ -441,11 +429,7 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUartRx<'d, T
} }
impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUart<'d, T> { impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUart<'d, T> {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
poll_fn(move |cx| { poll_fn(move |cx| {
let (poll, empty) = self.inner.with(|state| state.tx.write(buf, cx.waker())); let (poll, empty) = self.inner.with(|state| state.tx.write(buf, cx.waker()));
if empty { if empty {
@ -453,23 +437,16 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUart<'d, T> {
} }
poll poll
}) })
.await
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where poll_fn(move |cx| self.inner.with(|state| state.tx.flush(cx.waker()))).await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
poll_fn(move |cx| self.inner.with(|state| state.tx.flush(cx.waker())))
} }
} }
impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUartTx<'d, T> { impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUartTx<'d, T> {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
poll_fn(move |cx| { poll_fn(move |cx| {
let (poll, empty) = self.inner.with(|state| state.write(buf, cx.waker())); let (poll, empty) = self.inner.with(|state| state.write(buf, cx.waker()));
if empty { if empty {
@ -477,13 +454,10 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUartTx<'d, T>
} }
poll poll
}) })
.await
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where poll_fn(move |cx| self.inner.with(|state| state.flush(cx.waker()))).await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
poll_fn(move |cx| self.inner.with(|state| state.flush(cx.waker())))
} }
} }

View File

@ -1,4 +1,4 @@
use core::future::{poll_fn, Future}; use core::future::poll_fn;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::slice; use core::slice;
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
@ -352,9 +352,7 @@ pub struct Bus<'d, T: Instance> {
} }
impl<'d, T: Instance> driver::Bus for Bus<'d, T> { impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
type PollFuture<'a> = impl Future<Output = Event> + 'a where Self: 'a; async fn poll(&mut self) -> Event {
fn poll<'a>(&'a mut self) -> Self::PollFuture<'a> {
poll_fn(move |cx| unsafe { poll_fn(move |cx| unsafe {
BUS_WAKER.register(cx.waker()); BUS_WAKER.register(cx.waker());
@ -406,6 +404,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
}); });
Poll::Pending Poll::Pending
}) })
.await
} }
#[inline] #[inline]
@ -456,22 +455,12 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
} }
} }
type EnableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn enable(&mut self) {}
fn enable(&mut self) -> Self::EnableFuture<'_> { async fn disable(&mut self) {}
async move {}
}
type DisableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn remote_wakeup(&mut self) -> Result<(), Unsupported> {
Err(Unsupported)
fn disable(&mut self) -> Self::DisableFuture<'_> {
async move {}
}
type RemoteWakeupFuture<'a> = impl Future<Output = Result<(), Unsupported>> + 'a where Self: 'a;
fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_> {
async move { Err(Unsupported) }
} }
} }
@ -515,10 +504,7 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> {
&self.info &self.info
} }
type WaitEnabledFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn wait_enabled(&mut self) {
fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_> {
async move {
trace!("wait_enabled IN WAITING"); trace!("wait_enabled IN WAITING");
let index = self.info.addr.index(); let index = self.info.addr.index();
poll_fn(|cx| { poll_fn(|cx| {
@ -533,7 +519,6 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> {
.await; .await;
trace!("wait_enabled IN OK"); trace!("wait_enabled IN OK");
} }
}
} }
impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> { impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> {
@ -541,10 +526,7 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> {
&self.info &self.info
} }
type WaitEnabledFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn wait_enabled(&mut self) {
fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_> {
async move {
trace!("wait_enabled OUT WAITING"); trace!("wait_enabled OUT WAITING");
let index = self.info.addr.index(); let index = self.info.addr.index();
poll_fn(|cx| { poll_fn(|cx| {
@ -559,14 +541,10 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> {
.await; .await;
trace!("wait_enabled OUT OK"); trace!("wait_enabled OUT OK");
} }
}
} }
impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
type ReadFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a; async fn read(&mut self, buf: &mut [u8]) -> Result<usize, EndpointError> {
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
async move {
trace!("READ WAITING, buf.len() = {}", buf.len()); trace!("READ WAITING, buf.len() = {}", buf.len());
let index = self.info.addr.index(); let index = self.info.addr.index();
let val = poll_fn(|cx| unsafe { let val = poll_fn(|cx| unsafe {
@ -604,14 +582,10 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
Ok(rx_len) Ok(rx_len)
} }
}
} }
impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> {
type WriteFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a; async fn write(&mut self, buf: &[u8]) -> Result<(), EndpointError> {
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
async move {
if buf.len() > self.info.max_packet_size as usize { if buf.len() > self.info.max_packet_size as usize {
return Err(EndpointError::BufferOverflow); return Err(EndpointError::BufferOverflow);
} }
@ -652,7 +626,6 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> {
Ok(()) Ok(())
} }
}
} }
pub struct ControlPipe<'d, T: Instance> { pub struct ControlPipe<'d, T: Instance> {
@ -661,18 +634,11 @@ pub struct ControlPipe<'d, T: Instance> {
} }
impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
type SetupFuture<'a> = impl Future<Output = [u8;8]> + 'a where Self: 'a;
type DataOutFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a;
type DataInFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a;
type AcceptFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
type RejectFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
fn max_packet_size(&self) -> usize { fn max_packet_size(&self) -> usize {
64 64
} }
fn setup<'a>(&'a mut self) -> Self::SetupFuture<'a> { async fn setup<'a>(&'a mut self) -> [u8; 8] {
async move {
loop { loop {
trace!("SETUP read waiting"); trace!("SETUP read waiting");
let regs = T::regs(); let regs = T::regs();
@ -705,10 +671,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
return buf; return buf;
} }
} }
}
fn data_out<'a>(&'a mut self, buf: &'a mut [u8], _first: bool, _last: bool) -> Self::DataOutFuture<'a> { async fn data_out(&mut self, buf: &mut [u8], first: bool, last: bool) -> Result<usize, EndpointError> {
async move {
unsafe { unsafe {
let bufcontrol = T::dpram().ep_out_buffer_control(0); let bufcontrol = T::dpram().ep_out_buffer_control(0);
let pid = !bufcontrol.read().pid(0); let pid = !bufcontrol.read().pid(0);
@ -724,7 +688,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
}); });
} }
trace!("control: data_out len={} first={} last={}", buf.len(), _first, _last); trace!("control: data_out len={} first={} last={}", buf.len(), first, last);
let val = poll_fn(|cx| unsafe { let val = poll_fn(|cx| unsafe {
EP_OUT_WAKERS[0].register(cx.waker()); EP_OUT_WAKERS[0].register(cx.waker());
let val = T::dpram().ep_out_buffer_control(0).read(); let val = T::dpram().ep_out_buffer_control(0).read();
@ -746,28 +710,26 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
Ok(rx_len) Ok(rx_len)
} }
}
fn data_in<'a>(&'a mut self, buf: &'a [u8], _first: bool, _last: bool) -> Self::DataInFuture<'a> { async fn data_in(&mut self, data: &[u8], first: bool, last: bool) -> Result<(), EndpointError> {
async move { trace!("control: data_in len={} first={} last={}", data.len(), first, last);
trace!("control: data_in len={} first={} last={}", buf.len(), _first, _last);
if buf.len() > 64 { if data.len() > 64 {
return Err(EndpointError::BufferOverflow); return Err(EndpointError::BufferOverflow);
} }
EndpointBuffer::<T>::new(0x100, 64).write(buf); EndpointBuffer::<T>::new(0x100, 64).write(data);
unsafe { unsafe {
let bufcontrol = T::dpram().ep_in_buffer_control(0); let bufcontrol = T::dpram().ep_in_buffer_control(0);
let pid = !bufcontrol.read().pid(0); let pid = !bufcontrol.read().pid(0);
bufcontrol.write(|w| { bufcontrol.write(|w| {
w.set_length(0, buf.len() as _); w.set_length(0, data.len() as _);
w.set_pid(0, pid); w.set_pid(0, pid);
w.set_full(0, true); w.set_full(0, true);
}); });
cortex_m::asm::delay(12); cortex_m::asm::delay(12);
bufcontrol.write(|w| { bufcontrol.write(|w| {
w.set_length(0, buf.len() as _); w.set_length(0, data.len() as _);
w.set_pid(0, pid); w.set_pid(0, pid);
w.set_full(0, true); w.set_full(0, true);
w.set_available(0, true); w.set_available(0, true);
@ -786,7 +748,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
.await; .await;
trace!("control: data_in DONE"); trace!("control: data_in DONE");
if _last { if last {
// prepare status phase right away. // prepare status phase right away.
unsafe { unsafe {
let bufcontrol = T::dpram().ep_out_buffer_control(0); let bufcontrol = T::dpram().ep_out_buffer_control(0);
@ -805,10 +767,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
Ok(()) Ok(())
} }
}
fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> { async fn accept(&mut self) {
async move {
trace!("control: accept"); trace!("control: accept");
let bufcontrol = T::dpram().ep_in_buffer_control(0); let bufcontrol = T::dpram().ep_in_buffer_control(0);
@ -839,10 +799,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
}) })
.await; .await;
} }
}
fn reject<'a>(&'a mut self) -> Self::RejectFuture<'a> { async fn reject(&mut self) {
async move {
trace!("control: reject"); trace!("control: reject");
let regs = T::regs(); let regs = T::regs();
@ -855,5 +813,4 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
T::dpram().ep_in_buffer_control(0).write(|w| w.set_stall(true)); T::dpram().ep_in_buffer_control(0).write(|w| w.set_stall(true));
} }
} }
}
} }

View File

@ -44,7 +44,7 @@ embassy-usb-driver = {version = "0.1.0", path = "../embassy-usb-driver", optiona
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true}
embedded-hal-async = { version = "=0.1.0-alpha.3", optional = true} embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true}
embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true} embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true}
embedded-storage = "0.3.0" embedded-storage = "0.3.0"
@ -67,7 +67,7 @@ nb = "1.0.0"
stm32-fmc = "0.2.4" stm32-fmc = "0.2.4"
seq-macro = "0.3.0" seq-macro = "0.3.0"
cfg-if = "1.0.0" cfg-if = "1.0.0"
embedded-io = { version = "0.3.1", features = ["async"], optional = true } embedded-io = { version = "0.4.0", features = ["async"], optional = true }
[build-dependencies] [build-dependencies]
proc-macro2 = "1.0.36" proc-macro2 = "1.0.36"

View File

@ -167,39 +167,33 @@ mod eh1 {
} }
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod eha { mod eha {
use futures::FutureExt;
use super::*; use super::*;
impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> { impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> {
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
self.wait_for_high().await;
fn wait_for_high<'a>(&'a mut self) -> Self::WaitForHighFuture<'a> { Ok(())
self.wait_for_high().map(Ok)
} }
type WaitForLowFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
self.wait_for_low().await;
fn wait_for_low<'a>(&'a mut self) -> Self::WaitForLowFuture<'a> { Ok(())
self.wait_for_low().map(Ok)
} }
type WaitForRisingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
self.wait_for_rising_edge().await;
fn wait_for_rising_edge<'a>(&'a mut self) -> Self::WaitForRisingEdgeFuture<'a> { Ok(())
self.wait_for_rising_edge().map(Ok)
} }
type WaitForFallingEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
self.wait_for_falling_edge().await;
fn wait_for_falling_edge<'a>(&'a mut self) -> Self::WaitForFallingEdgeFuture<'a> { Ok(())
self.wait_for_falling_edge().map(Ok)
} }
type WaitForAnyEdgeFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
self.wait_for_any_edge().await;
fn wait_for_any_edge<'a>(&'a mut self) -> Self::WaitForAnyEdgeFuture<'a> { Ok(())
self.wait_for_any_edge().map(Ok)
} }
} }
} }

View File

@ -1048,43 +1048,35 @@ mod eh1 {
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod eha { mod eha {
use core::future::Future;
use super::super::{RxDma, TxDma}; use super::super::{RxDma, TxDma};
use super::*; use super::*;
impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> { impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read<'a>(&'a mut self, address: u8, read: &'a mut [u8]) -> Result<(), Self::Error> {
self.read(address, read).await
fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.read(address, buffer)
} }
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write<'a>(&'a mut self, address: u8, write: &'a [u8]) -> Result<(), Self::Error> {
fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { self.write(address, write).await
self.write(address, bytes)
} }
type WriteReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write_read<'a>(
fn write_read<'a>(
&'a mut self, &'a mut self,
address: u8, address: u8,
bytes: &'a [u8], write: &'a [u8],
buffer: &'a mut [u8], read: &'a mut [u8],
) -> Self::WriteReadFuture<'a> { ) -> Result<(), Self::Error> {
self.write_read(address, bytes, buffer) self.write_read(address, write, read).await
} }
type TransactionFuture<'a, 'b> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a, 'b: 'a; async fn transaction<'a, 'b>(
fn transaction<'a, 'b>(
&'a mut self, &'a mut self,
address: u8, address: u8,
operations: &'a mut [embedded_hal_async::i2c::Operation<'b>], operations: &'a mut [embedded_hal_1::i2c::Operation<'b>],
) -> Self::TransactionFuture<'a, 'b> { ) -> Result<(), Self::Error> {
let _ = address; let _ = address;
let _ = operations; let _ = operations;
async move { todo!() } todo!()
} }
} }
} }

View File

@ -1,5 +1,9 @@
#![no_std] #![no_std]
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))] #![cfg_attr(
feature = "nightly",
feature(type_alias_impl_trait, async_fn_in_trait, impl_trait_projections)
)]
#![cfg_attr(feature = "nightly", allow(incomplete_features))]
// This must go FIRST so that all the other modules see its macros. // This must go FIRST so that all the other modules see its macros.
pub mod fmt; pub mod fmt;

View File

@ -885,46 +885,34 @@ mod eh1 {
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod eha { mod eha {
use core::future::Future;
use super::*; use super::*;
impl<'d, T: Instance, Tx, Rx> embedded_hal_async::spi::SpiBusFlush for Spi<'d, T, Tx, Rx> { impl<'d, T: Instance, Tx, Rx> embedded_hal_async::spi::SpiBusFlush for Spi<'d, T, Tx, Rx> {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
async { Ok(()) }
} }
} }
impl<'d, T: Instance, Tx: TxDma<T>, Rx, W: Word> embedded_hal_async::spi::SpiBusWrite<W> for Spi<'d, T, Tx, Rx> { impl<'d, T: Instance, Tx: TxDma<T>, Rx, W: Word> embedded_hal_async::spi::SpiBusWrite<W> for Spi<'d, T, Tx, Rx> {
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn write(&mut self, words: &[W]) -> Result<(), Self::Error> {
self.write(words).await
fn write<'a>(&'a mut self, data: &'a [W]) -> Self::WriteFuture<'a> {
self.write(data)
} }
} }
impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBusRead<W> impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBusRead<W>
for Spi<'d, T, Tx, Rx> for Spi<'d, T, Tx, Rx>
{ {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
self.read(words).await
fn read<'a>(&'a mut self, data: &'a mut [W]) -> Self::ReadFuture<'a> {
self.read(data)
} }
} }
impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBus<W> for Spi<'d, T, Tx, Rx> { impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBus<W> for Spi<'d, T, Tx, Rx> {
type TransferFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn transfer<'a>(&'a mut self, read: &'a mut [W], write: &'a [W]) -> Result<(), Self::Error> {
self.transfer(read, write).await
fn transfer<'a>(&'a mut self, rx: &'a mut [W], tx: &'a [W]) -> Self::TransferFuture<'a> {
self.transfer(rx, tx)
} }
type TransferInPlaceFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; async fn transfer_in_place<'a>(&'a mut self, words: &'a mut [W]) -> Result<(), Self::Error> {
self.transfer_in_place(words).await
fn transfer_in_place<'a>(&'a mut self, words: &'a mut [W]) -> Self::TransferInPlaceFuture<'a> {
self.transfer_in_place(words)
} }
} }
} }

View File

@ -1,5 +1,5 @@
use core::cell::RefCell; use core::cell::RefCell;
use core::future::{poll_fn, Future}; use core::future::poll_fn;
use core::task::Poll; use core::task::Poll;
use atomic_polyfill::{compiler_fence, Ordering}; use atomic_polyfill::{compiler_fence, Ordering};
@ -339,32 +339,20 @@ impl<'u, 'd, T: BasicInstance> embedded_io::Io for BufferedUartTx<'u, 'd, T> {
} }
impl<'d, T: BasicInstance> embedded_io::asynch::Read for BufferedUart<'d, T> { impl<'d, T: BasicInstance> embedded_io::asynch::Read for BufferedUart<'d, T> {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where self.inner_read(buf).await
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.inner_read(buf)
} }
} }
impl<'u, 'd, T: BasicInstance> embedded_io::asynch::Read for BufferedUartRx<'u, 'd, T> { impl<'u, 'd, T: BasicInstance> embedded_io::asynch::Read for BufferedUartRx<'u, 'd, T> {
type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
where self.inner.inner_read(buf).await
Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.inner.inner_read(buf)
} }
} }
impl<'d, T: BasicInstance> embedded_io::asynch::BufRead for BufferedUart<'d, T> { impl<'d, T: BasicInstance> embedded_io::asynch::BufRead for BufferedUart<'d, T> {
type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> + 'a async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
where self.inner_fill_buf().await
Self: 'a;
fn fill_buf<'a>(&'a mut self) -> Self::FillBufFuture<'a> {
self.inner_fill_buf()
} }
fn consume(&mut self, amt: usize) { fn consume(&mut self, amt: usize) {
@ -373,12 +361,8 @@ impl<'d, T: BasicInstance> embedded_io::asynch::BufRead for BufferedUart<'d, T>
} }
impl<'u, 'd, T: BasicInstance> embedded_io::asynch::BufRead for BufferedUartRx<'u, 'd, T> { impl<'u, 'd, T: BasicInstance> embedded_io::asynch::BufRead for BufferedUartRx<'u, 'd, T> {
type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> + 'a async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
where self.inner.inner_fill_buf().await
Self: 'a;
fn fill_buf<'a>(&'a mut self) -> Self::FillBufFuture<'a> {
self.inner.inner_fill_buf()
} }
fn consume(&mut self, amt: usize) { fn consume(&mut self, amt: usize) {
@ -387,37 +371,21 @@ impl<'u, 'd, T: BasicInstance> embedded_io::asynch::BufRead for BufferedUartRx<'
} }
impl<'d, T: BasicInstance> embedded_io::asynch::Write for BufferedUart<'d, T> { impl<'d, T: BasicInstance> embedded_io::asynch::Write for BufferedUart<'d, T> {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where self.inner_write(buf).await
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
self.inner_write(buf)
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where self.inner_flush().await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
self.inner_flush()
} }
} }
impl<'u, 'd, T: BasicInstance> embedded_io::asynch::Write for BufferedUartTx<'u, 'd, T> { impl<'u, 'd, T: BasicInstance> embedded_io::asynch::Write for BufferedUartTx<'u, 'd, T> {
type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
where self.inner.inner_write(buf).await
Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
self.inner.inner_write(buf)
} }
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a async fn flush(&mut self) -> Result<(), Self::Error> {
where self.inner.inner_flush().await
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
self.inner.inner_flush()
} }
} }

View File

@ -1,6 +1,6 @@
#![macro_use] #![macro_use]
use core::future::{poll_fn, Future}; use core::future::poll_fn;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
use core::task::Poll; use core::task::Poll;
@ -429,9 +429,7 @@ pub struct Bus<'d, T: Instance> {
} }
impl<'d, T: Instance> driver::Bus for Bus<'d, T> { impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
type PollFuture<'a> = impl Future<Output = Event> + 'a where Self: 'a; async fn poll(&mut self) -> Event {
fn poll<'a>(&'a mut self) -> Self::PollFuture<'a> {
poll_fn(move |cx| unsafe { poll_fn(move |cx| unsafe {
BUS_WAKER.register(cx.waker()); BUS_WAKER.register(cx.waker());
@ -488,6 +486,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
return Poll::Ready(Event::PowerDetected); return Poll::Ready(Event::PowerDetected);
} }
}) })
.await
} }
#[inline] #[inline]
@ -598,22 +597,11 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
trace!("EPR after: {:04x}", unsafe { reg.read() }.0); trace!("EPR after: {:04x}", unsafe { reg.read() }.0);
} }
type EnableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn enable(&mut self) {}
async fn disable(&mut self) {}
fn enable(&mut self) -> Self::EnableFuture<'_> { async fn remote_wakeup(&mut self) -> Result<(), Unsupported> {
async move {} Err(Unsupported)
}
type DisableFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
fn disable(&mut self) -> Self::DisableFuture<'_> {
async move {}
}
type RemoteWakeupFuture<'a> = impl Future<Output = Result<(), Unsupported>> + 'a where Self: 'a;
fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_> {
async move { Err(Unsupported) }
} }
} }
@ -676,10 +664,7 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> {
&self.info &self.info
} }
type WaitEnabledFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn wait_enabled(&mut self) {
fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_> {
async move {
trace!("wait_enabled OUT WAITING"); trace!("wait_enabled OUT WAITING");
let index = self.info.addr.index(); let index = self.info.addr.index();
poll_fn(|cx| { poll_fn(|cx| {
@ -694,7 +679,6 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, In> {
.await; .await;
trace!("wait_enabled OUT OK"); trace!("wait_enabled OUT OK");
} }
}
} }
impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> { impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> {
@ -702,10 +686,7 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> {
&self.info &self.info
} }
type WaitEnabledFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a; async fn wait_enabled(&mut self) {
fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_> {
async move {
trace!("wait_enabled OUT WAITING"); trace!("wait_enabled OUT WAITING");
let index = self.info.addr.index(); let index = self.info.addr.index();
poll_fn(|cx| { poll_fn(|cx| {
@ -720,14 +701,10 @@ impl<'d, T: Instance> driver::Endpoint for Endpoint<'d, T, Out> {
.await; .await;
trace!("wait_enabled OUT OK"); trace!("wait_enabled OUT OK");
} }
}
} }
impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
type ReadFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a; async fn read(&mut self, buf: &mut [u8]) -> Result<usize, EndpointError> {
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
async move {
trace!("READ WAITING, buf.len() = {}", buf.len()); trace!("READ WAITING, buf.len() = {}", buf.len());
let index = self.info.addr.index(); let index = self.info.addr.index();
let stat = poll_fn(|cx| { let stat = poll_fn(|cx| {
@ -763,14 +740,10 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
Ok(rx_len) Ok(rx_len)
} }
}
} }
impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> {
type WriteFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a; async fn write(&mut self, buf: &[u8]) -> Result<(), EndpointError> {
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
async move {
if buf.len() > self.info.max_packet_size as usize { if buf.len() > self.info.max_packet_size as usize {
return Err(EndpointError::BufferOverflow); return Err(EndpointError::BufferOverflow);
} }
@ -812,7 +785,6 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> {
Ok(()) Ok(())
} }
}
} }
pub struct ControlPipe<'d, T: Instance> { pub struct ControlPipe<'d, T: Instance> {
@ -823,18 +795,11 @@ pub struct ControlPipe<'d, T: Instance> {
} }
impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
type SetupFuture<'a> = impl Future<Output = [u8;8]> + 'a where Self: 'a;
type DataOutFuture<'a> = impl Future<Output = Result<usize, EndpointError>> + 'a where Self: 'a;
type DataInFuture<'a> = impl Future<Output = Result<(), EndpointError>> + 'a where Self: 'a;
type AcceptFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
type RejectFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
fn max_packet_size(&self) -> usize { fn max_packet_size(&self) -> usize {
usize::from(self.max_packet_size) usize::from(self.max_packet_size)
} }
fn setup<'a>(&'a mut self) -> Self::SetupFuture<'a> { async fn setup<'a>(&'a mut self) -> [u8; 8] {
async move {
loop { loop {
trace!("SETUP read waiting"); trace!("SETUP read waiting");
poll_fn(|cx| { poll_fn(|cx| {
@ -860,10 +825,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
return buf; return buf;
} }
} }
}
fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a> { async fn data_out(&mut self, buf: &mut [u8], first: bool, last: bool) -> Result<usize, EndpointError> {
async move {
let regs = T::regs(); let regs = T::regs();
// When a SETUP is received, Stat/Stat is set to NAK. // When a SETUP is received, Stat/Stat is set to NAK.
@ -931,13 +894,11 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
Ok(rx_len) Ok(rx_len)
} }
}
fn data_in<'a>(&'a mut self, buf: &'a [u8], first: bool, last: bool) -> Self::DataInFuture<'a> { async fn data_in(&mut self, data: &[u8], first: bool, last: bool) -> Result<(), EndpointError> {
async move {
trace!("control: data_in"); trace!("control: data_in");
if buf.len() > self.ep_in.info.max_packet_size as usize { if data.len() > self.ep_in.info.max_packet_size as usize {
return Err(EndpointError::BufferOverflow); return Err(EndpointError::BufferOverflow);
} }
@ -987,7 +948,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
return Err(EndpointError::Disabled); return Err(EndpointError::Disabled);
} }
self.ep_in.write_data(buf); self.ep_in.write_data(data);
let regs = T::regs(); let regs = T::regs();
unsafe { unsafe {
@ -1004,10 +965,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
Ok(()) Ok(())
} }
}
fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> { async fn accept(&mut self) {
async move {
let regs = T::regs(); let regs = T::regs();
trace!("control: accept"); trace!("control: accept");
@ -1041,10 +1000,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
trace!("control: accept OK"); trace!("control: accept OK");
} }
}
fn reject<'a>(&'a mut self) -> Self::RejectFuture<'a> { async fn reject(&mut self) {
async move {
let regs = T::regs(); let regs = T::regs();
trace!("control: reject"); trace!("control: reject");
@ -1060,5 +1017,4 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> {
}); });
} }
} }
}
} }

View File

@ -35,7 +35,7 @@ atomic-polyfill = "1.0.1"
critical-section = "1.1" critical-section = "1.1"
heapless = "0.7.5" heapless = "0.7.5"
cfg-if = "1.0.0" cfg-if = "1.0.0"
embedded-io = "0.3.1" embedded-io = "0.4.0"
[dev-dependencies] [dev-dependencies]
futures-executor = { version = "0.3.17", features = [ "thread-pool" ] } futures-executor = { version = "0.3.17", features = [ "thread-pool" ] }

View File

@ -134,7 +134,7 @@ log = { version = "0.4.14", optional = true }
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" } embedded-hal-02 = { package = "embedded-hal", version = "0.2.6" }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true} embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true}
embedded-hal-async = { version = "=0.1.0-alpha.3", optional = true} embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true}
futures-util = { version = "0.3.17", default-features = false } futures-util = { version = "0.3.17", default-features = false }
embassy-sync = { version = "0.1", path = "../embassy-sync" } embassy-sync = { version = "0.1", path = "../embassy-sync" }

View File

@ -1,6 +1,6 @@
#![no_std] #![no_std]
#![feature(async_fn_in_trait)]
use core::future::Future; #![allow(incomplete_features)]
/// Direction of USB traffic. Note that in the USB standard the direction is always indicated from /// Direction of USB traffic. Note that in the USB standard the direction is always indicated from
/// the perspective of the host, which is backward for devices, but the standard directions are used /// the perspective of the host, which is backward for devices, but the standard directions are used
@ -155,27 +155,14 @@ pub trait Driver<'a> {
} }
pub trait Bus { pub trait Bus {
type EnableFuture<'a>: Future<Output = ()> + 'a
where
Self: 'a;
type DisableFuture<'a>: Future<Output = ()> + 'a
where
Self: 'a;
type PollFuture<'a>: Future<Output = Event> + 'a
where
Self: 'a;
type RemoteWakeupFuture<'a>: Future<Output = Result<(), Unsupported>> + 'a
where
Self: 'a;
/// Enables the USB peripheral. Soon after enabling the device will be reset, so /// Enables the USB peripheral. Soon after enabling the device will be reset, so
/// there is no need to perform a USB reset in this method. /// there is no need to perform a USB reset in this method.
fn enable(&mut self) -> Self::EnableFuture<'_>; async fn enable(&mut self);
/// Disables and powers down the USB peripheral. /// Disables and powers down the USB peripheral.
fn disable(&mut self) -> Self::DisableFuture<'_>; async fn disable(&mut self);
fn poll<'a>(&'a mut self) -> Self::PollFuture<'a>; async fn poll(&mut self) -> Event;
/// Sets the device USB address to `addr`. /// Sets the device USB address to `addr`.
fn set_address(&mut self, addr: u8); fn set_address(&mut self, addr: u8);
@ -209,85 +196,57 @@ pub trait Bus {
/// ///
/// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support /// * [`Unsupported`](crate::driver::Unsupported) - This UsbBus implementation doesn't support
/// remote wakeup or it has not been enabled at creation time. /// remote wakeup or it has not been enabled at creation time.
fn remote_wakeup(&mut self) -> Self::RemoteWakeupFuture<'_>; async fn remote_wakeup(&mut self) -> Result<(), Unsupported>;
} }
pub trait Endpoint { pub trait Endpoint {
type WaitEnabledFuture<'a>: Future<Output = ()> + 'a
where
Self: 'a;
/// Get the endpoint address /// Get the endpoint address
fn info(&self) -> &EndpointInfo; fn info(&self) -> &EndpointInfo;
/// Waits for the endpoint to be enabled. /// Waits for the endpoint to be enabled.
fn wait_enabled(&mut self) -> Self::WaitEnabledFuture<'_>; async fn wait_enabled(&mut self);
} }
pub trait EndpointOut: Endpoint { pub trait EndpointOut: Endpoint {
type ReadFuture<'a>: Future<Output = Result<usize, EndpointError>> + 'a
where
Self: 'a;
/// Reads a single packet of data from the endpoint, and returns the actual length of /// Reads a single packet of data from the endpoint, and returns the actual length of
/// the packet. /// the packet.
/// ///
/// This should also clear any NAK flags and prepare the endpoint to receive the next packet. /// This should also clear any NAK flags and prepare the endpoint to receive the next packet.
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a>; async fn read(&mut self, buf: &mut [u8]) -> Result<usize, EndpointError>;
} }
pub trait ControlPipe { pub trait ControlPipe {
type SetupFuture<'a>: Future<Output = [u8; 8]> + 'a
where
Self: 'a;
type DataOutFuture<'a>: Future<Output = Result<usize, EndpointError>> + 'a
where
Self: 'a;
type DataInFuture<'a>: Future<Output = Result<(), EndpointError>> + 'a
where
Self: 'a;
type AcceptFuture<'a>: Future<Output = ()> + 'a
where
Self: 'a;
type RejectFuture<'a>: Future<Output = ()> + 'a
where
Self: 'a;
/// Maximum packet size for the control pipe /// Maximum packet size for the control pipe
fn max_packet_size(&self) -> usize; fn max_packet_size(&self) -> usize;
/// Reads a single setup packet from the endpoint. /// Reads a single setup packet from the endpoint.
fn setup<'a>(&'a mut self) -> Self::SetupFuture<'a>; async fn setup<'a>(&'a mut self) -> [u8; 8];
/// Reads a DATA OUT packet into `buf` in response to a control write request. /// Reads a DATA OUT packet into `buf` in response to a control write request.
/// ///
/// Must be called after `setup()` for requests with `direction` of `Out` /// Must be called after `setup()` for requests with `direction` of `Out`
/// and `length` greater than zero. /// and `length` greater than zero.
fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a>; async fn data_out(&mut self, buf: &mut [u8], first: bool, last: bool) -> Result<usize, EndpointError>;
/// Sends a DATA IN packet with `data` in response to a control read request. /// Sends a DATA IN packet with `data` in response to a control read request.
/// ///
/// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`.
fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) -> Self::DataInFuture<'a>; async fn data_in(&mut self, data: &[u8], first: bool, last: bool) -> Result<(), EndpointError>;
/// Accepts a control request. /// Accepts a control request.
/// ///
/// Causes the STATUS packet for the current request to be ACKed. /// Causes the STATUS packet for the current request to be ACKed.
fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a>; async fn accept(&mut self);
/// Rejects a control request. /// Rejects a control request.
/// ///
/// Sets a STALL condition on the pipe to indicate an error. /// Sets a STALL condition on the pipe to indicate an error.
fn reject<'a>(&'a mut self) -> Self::RejectFuture<'a>; async fn reject(&mut self);
} }
pub trait EndpointIn: Endpoint { pub trait EndpointIn: Endpoint {
type WriteFuture<'a>: Future<Output = Result<(), EndpointError>> + 'a
where
Self: 'a;
/// Writes a single packet of data to the endpoint. /// Writes a single packet of data to the endpoint.
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a>; async fn write(&mut self, buf: &[u8]) -> Result<(), EndpointError>;
} }
#[derive(Copy, Clone, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Debug)]

View File

@ -17,7 +17,7 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true } embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "pool-16"], optional = true }
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true }
embedded-io = "0.3.1" embedded-io = "0.4.0"
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx126x", "time", "defmt"], optional = true } embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx126x", "time", "defmt"], optional = true }
lorawan-device = { version = "0.8.0", default-features = false, features = ["async"], optional = true } lorawan-device = { version = "0.8.0", default-features = false, features = ["async"], optional = true }

View File

@ -29,8 +29,8 @@ display-interface = "0.4.1"
byte-slice-cast = { version = "1.2.0", default-features = false } byte-slice-cast = { version = "1.2.0", default-features = false }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" }
embedded-hal-async = { version = "0.1.0-alpha.3" } embedded-hal-async = "0.2.0-alpha.0"
embedded-io = { version = "0.3.1", features = ["async", "defmt"] } embedded-io = { version = "0.4.0", features = ["async", "defmt"] }
embedded-storage = { version = "0.3" } embedded-storage = { version = "0.3" }
static_cell = "1.0.0" static_cell = "1.0.0"
log = "0.4" log = "0.4"

View File

@ -9,7 +9,7 @@ embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["lo
embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] } embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["log", "std", "nightly", "integrated-timers"] }
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] } embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["log", "std", "nightly"] }
embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] } embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "tcp", "udp", "dhcpv4", "pool-16"] }
embedded-io = { version = "0.3.1", features = ["async", "std", "futures"] } embedded-io = { version = "0.4.0", features = ["async", "std", "futures"] }
critical-section = { version = "1.1", features = ["std"] } critical-section = { version = "1.1", features = ["std"] }
async-io = "1.6.0" async-io = "1.6.0"

View File

@ -17,7 +17,7 @@ defmt-rtt = "0.3"
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.0" cortex-m-rt = "0.7.0"
embedded-hal = "0.2.6" embedded-hal = "0.2.6"
embedded-io = "0.3.1" embedded-io = "0.4.0"
panic-probe = { version = "0.3", features = ["print-defmt"] } panic-probe = { version = "0.3", features = ["print-defmt"] }
futures = { version = "0.3.17", default-features = false, features = ["async-await"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
heapless = { version = "0.7.5", default-features = false } heapless = { version = "0.7.5", default-features = false }

View File

@ -10,7 +10,7 @@ embassy-executor = { version = "0.1.0", path = "../../embassy-executor", feature
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-any", "exti"] }
embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] } embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16"] }
embedded-io = { version = "0.3.1", features = ["async"] } embedded-io = { version = "0.4.0", features = ["async"] }
defmt = "0.3" defmt = "0.3"
defmt-rtt = "0.3" defmt-rtt = "0.3"

View File

@ -10,7 +10,7 @@ embassy-executor = { version = "0.1.0", path = "../../embassy-executor", feature
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] } embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16", "unstable-traits"] } embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "pool-16", "unstable-traits"] }
embedded-io = { version = "0.3.1", features = ["async"] } embedded-io = { version = "0.4.0", features = ["async"] }
defmt = "0.3" defmt = "0.3"
defmt-rtt = "0.3" defmt-rtt = "0.3"
@ -19,8 +19,8 @@ cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.0" cortex-m-rt = "0.7.0"
embedded-hal = "0.2.6" embedded-hal = "0.2.6"
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" }
embedded-hal-async = { version = "=0.1.0-alpha.3" } embedded-hal-async = { version = "=0.2.0-alpha.0" }
embedded-nal-async = "0.2.0" embedded-nal-async = { git = "https://github.com/embassy-rs/embedded-nal.git", rev = "691601e550449a53ab3a7c5eaa0411aee0a64ed0" }
panic-probe = { version = "0.3", features = ["print-defmt"] } panic-probe = { version = "0.3", features = ["print-defmt"] }
futures = { version = "0.3.17", default-features = false, features = ["async-await"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
heapless = { version = "0.7.5", default-features = false } heapless = { version = "0.7.5", default-features = false }

View File

@ -22,7 +22,7 @@ defmt = "0.3"
defmt-rtt = "0.3" defmt-rtt = "0.3"
embedded-storage = "0.3.0" embedded-storage = "0.3.0"
embedded-io = "0.3.1" embedded-io = "0.4.0"
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.0" cortex-m-rt = "0.7.0"

View File

@ -20,7 +20,7 @@ cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.0" cortex-m-rt = "0.7.0"
embedded-hal = "0.2.6" embedded-hal = "0.2.6"
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" }
embedded-hal-async = { version = "=0.1.0-alpha.3" } embedded-hal-async = { version = "=0.2.0-alpha.0" }
panic-probe = { version = "0.3", features = ["print-defmt"] } panic-probe = { version = "0.3", features = ["print-defmt"] }
futures = { version = "0.3.17", default-features = false, features = ["async-await"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
heapless = { version = "0.7.5", default-features = false } heapless = { version = "0.7.5", default-features = false }

View File

@ -26,5 +26,5 @@ embedded-hal = "0.2.6"
futures = { version = "0.3.17", default-features = false, features = ["async-await"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
heapless = { version = "0.7.5", default-features = false } heapless = { version = "0.7.5", default-features = false }
rand_core = { version = "0.6.3", default-features = false } rand_core = { version = "0.6.3", default-features = false }
embedded-io = { version = "0.3.1", features = ["async"] } embedded-io = { version = "0.4.0", features = ["async"] }
static_cell = "1.0" static_cell = "1.0"

View File

@ -21,8 +21,3 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa
heapless = { version = "0.7.5", default-features = false } heapless = { version = "0.7.5", default-features = false }
micromath = "2.0.0" micromath = "2.0.0"
#[patch.crates-io]
#defmt = { git="https://github.com/knurling-rs/defmt.git" }
#defmt-rtt = { git="https://github.com/knurling-rs/defmt.git" }

View File

@ -1,7 +1,7 @@
# Before upgrading check that everything is available on all tier1 targets here: # Before upgrading check that everything is available on all tier1 targets here:
# https://rust-lang.github.io/rustup-components-history # https://rust-lang.github.io/rustup-components-history
[toolchain] [toolchain]
channel = "nightly-2022-10-25" channel = "nightly-2022-11-22"
components = [ "rust-src", "rustfmt" ] components = [ "rust-src", "rustfmt" ]
targets = [ targets = [
"thumbv7em-none-eabi", "thumbv7em-none-eabi",

View File

@ -18,10 +18,10 @@ cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.0" cortex-m-rt = "0.7.0"
embedded-hal = "0.2.6" embedded-hal = "0.2.6"
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" }
embedded-hal-async = { version = "=0.1.0-alpha.3" } embedded-hal-async = { version = "=0.2.0-alpha.0" }
panic-probe = { version = "0.3.0", features = ["print-defmt"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] }
futures = { version = "0.3.17", default-features = false, features = ["async-await"] } futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
embedded-io = { version = "0.3.1", features = ["async"] } embedded-io = { version = "0.4.0", features = ["async"] }
embedded-storage = { version = "0.3" } embedded-storage = { version = "0.3" }
[profile.dev] [profile.dev]

View File

@ -26,7 +26,7 @@ cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7.0" cortex-m-rt = "0.7.0"
embedded-hal = "0.2.6" embedded-hal = "0.2.6"
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" } embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9" }
embedded-hal-async = { version = "=0.1.0-alpha.3" } embedded-hal-async = { version = "=0.2.0-alpha.0" }
panic-probe = { version = "0.3.0", features = ["print-defmt"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] }
[profile.dev] [profile.dev]