Merge pull request #30 from embassy-rs/afit
feat: use async fn in trait
This commit is contained in:
commit
432240162a
@ -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 }
|
||||
|
@ -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
|
||||
|
@ -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,74 +156,58 @@ 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;
|
||||
async fn read(&mut self, words: &mut [u32]) -> Result<(), Self::Error> {
|
||||
self.dio.set_as_input();
|
||||
for word in words {
|
||||
let mut w = 0;
|
||||
for _ in 0..32 {
|
||||
w = w << 1;
|
||||
|
||||
fn read<'a>(&'a mut self, words: &'a mut [u32]) -> Self::ReadFuture<'a> {
|
||||
async move {
|
||||
self.dio.set_as_input();
|
||||
for word in words {
|
||||
let mut w = 0;
|
||||
for _ in 0..32 {
|
||||
w = w << 1;
|
||||
|
||||
// rising edge, sample data
|
||||
if self.dio.is_high() {
|
||||
w |= 0x01;
|
||||
}
|
||||
self.clk.set_high();
|
||||
|
||||
// falling edge
|
||||
self.clk.set_low();
|
||||
// rising edge, sample data
|
||||
if self.dio.is_high() {
|
||||
w |= 0x01;
|
||||
}
|
||||
*word = w
|
||||
}
|
||||
self.clk.set_high();
|
||||
|
||||
Ok(())
|
||||
// falling edge
|
||||
self.clk.set_low();
|
||||
}
|
||||
*word = w
|
||||
}
|
||||
|
||||
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 {
|
||||
self.dio.set_as_output();
|
||||
for word in words {
|
||||
let mut word = *word;
|
||||
for _ in 0..32 {
|
||||
// falling edge, setup data
|
||||
self.clk.set_low();
|
||||
if word & 0x8000_0000 == 0 {
|
||||
self.dio.set_low();
|
||||
} else {
|
||||
self.dio.set_high();
|
||||
}
|
||||
|
||||
// rising edge
|
||||
self.clk.set_high();
|
||||
|
||||
word = word << 1;
|
||||
async fn write(&mut self, words: &[u32]) -> Result<(), Self::Error> {
|
||||
self.dio.set_as_output();
|
||||
for word in words {
|
||||
let mut word = *word;
|
||||
for _ in 0..32 {
|
||||
// falling edge, setup data
|
||||
self.clk.set_low();
|
||||
if word & 0x8000_0000 == 0 {
|
||||
self.dio.set_low();
|
||||
} else {
|
||||
self.dio.set_high();
|
||||
}
|
||||
}
|
||||
self.clk.set_low();
|
||||
|
||||
self.dio.set_as_input();
|
||||
Ok(())
|
||||
// rising edge
|
||||
self.clk.set_high();
|
||||
|
||||
word = word << 1;
|
||||
}
|
||||
}
|
||||
self.clk.set_low();
|
||||
|
||||
self.dio.set_as_input();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user