feat: use async fn in trait

This commit is contained in:
Ulf Lilleengen 2022-12-01 22:09:45 +01:00
parent 8a81114baf
commit f4c9014fe4
Failed to extract signature
4 changed files with 50 additions and 65 deletions

View file

@ -22,5 +22,5 @@ cortex-m-rt = "0.7.0"
futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] }
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" }
num_enum = { version = "0.5.7", default-features = false }

View file

@ -22,18 +22,18 @@ cortex-m-rt = "0.7.0"
futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] }
embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.9" }
embedded-hal-async = { version = "0.1.0-alpha.3" }
embedded-io = { version = "0.3.0", features = ["async", "defmt"] }
embedded-hal-async = { version = "0.2.0-alpha.0" }
embedded-io = { version = "0.4.0", features = ["async", "defmt"] }
heapless = "0.7.15"
[patch.crates-io]
embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "c53614f057cd7d9ac6e86aebd1fb6c1a1055d8b6" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "c53614f057cd7d9ac6e86aebd1fb6c1a1055d8b6" }
embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "c53614f057cd7d9ac6e86aebd1fb6c1a1055d8b6" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "c53614f057cd7d9ac6e86aebd1fb6c1a1055d8b6" }
embassy-rp = { git = "https://github.com/embassy-rs/embassy", rev = "c53614f057cd7d9ac6e86aebd1fb6c1a1055d8b6" }
embassy-net = { git = "https://github.com/embassy-rs/embassy", rev = "c53614f057cd7d9ac6e86aebd1fb6c1a1055d8b6" }
embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "645fb66a5122bdc8180e0e65d076ca103431a426" }
embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "645fb66a5122bdc8180e0e65d076ca103431a426" }
embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "645fb66a5122bdc8180e0e65d076ca103431a426" }
embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "645fb66a5122bdc8180e0e65d076ca103431a426" }
embassy-rp = { git = "https://github.com/embassy-rs/embassy", rev = "645fb66a5122bdc8180e0e65d076ca103431a426" }
embassy-net = { git = "https://github.com/embassy-rs/embassy", rev = "645fb66a5122bdc8180e0e65d076ca103431a426" }
[profile.dev]
debug = 2

View file

@ -1,9 +1,10 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]
use core::convert::Infallible;
use core::future::Future;
use defmt::*;
use embassy_executor::Spawner;
@ -155,22 +156,13 @@ impl ErrorType for MySpi {
}
impl SpiBusFlush for MySpi {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>>
where
Self: 'a;
fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
async move { Ok(()) }
async fn flush(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
impl SpiBusRead<u32> for MySpi {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a
where
Self: 'a;
fn read<'a>(&'a mut self, words: &'a mut [u32]) -> Self::ReadFuture<'a> {
async move {
async fn read(&mut self, words: &mut [u32]) -> Result<(), Self::Error> {
self.dio.set_as_input();
for word in words {
let mut w = 0;
@ -191,16 +183,10 @@ impl SpiBusRead<u32> for MySpi {
Ok(())
}
}
}
impl SpiBusWrite<u32> for MySpi {
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a
where
Self: 'a;
fn write<'a>(&'a mut self, words: &'a [u32]) -> Self::WriteFuture<'a> {
async move {
async fn write(&mut self, words: &[u32]) -> Result<(), Self::Error> {
self.dio.set_as_output();
for word in words {
let mut word = *word;
@ -224,5 +210,4 @@ impl SpiBusWrite<u32> for MySpi {
self.dio.set_as_input();
Ok(())
}
}
}

View file

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