Use async fn instead of impl Future

This commit is contained in:
Ulf Lilleengen 2021-10-19 20:48:46 +02:00
parent e807a9eaec
commit 69953a78f1

View File

@ -4,7 +4,6 @@ use crate::interrupt;
use crate::pac; use crate::pac;
use crate::peripherals::TEMP; use crate::peripherals::TEMP;
use core::future::Future;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::task::Poll; use core::task::Poll;
use embassy::interrupt::InterruptExt; use embassy::interrupt::InterruptExt;
@ -54,7 +53,7 @@ impl<'d> Temp<'d> {
/// let mut t = Temp::new(p.TEMP, interrupt::take!(TEMP)); /// let mut t = Temp::new(p.TEMP, interrupt::take!(TEMP));
/// let v: u16 = t.read().await.to_num::<u16>(); /// let v: u16 = t.read().await.to_num::<u16>();
/// ``` /// ```
pub fn read(&mut self) -> impl Future<Output = I30F2> { pub async fn read(&mut self) -> I30F2 {
// In case the future is dropped, stop the task and reset events. // In case the future is dropped, stop the task and reset events.
let on_drop = OnDrop::new(|| { let on_drop = OnDrop::new(|| {
let t = Self::regs(); let t = Self::regs();
@ -66,7 +65,6 @@ impl<'d> Temp<'d> {
t.intenset.write(|w| w.datardy().set()); t.intenset.write(|w| w.datardy().set());
unsafe { t.tasks_start.write(|w| w.bits(1)) }; unsafe { t.tasks_start.write(|w| w.bits(1)) };
async move {
let value = poll_fn(|cx| { let value = poll_fn(|cx| {
WAKER.register(cx.waker()); WAKER.register(cx.waker());
if t.events_datardy.read().bits() == 0 { if t.events_datardy.read().bits() == 0 {
@ -81,7 +79,6 @@ impl<'d> Temp<'d> {
on_drop.defuse(); on_drop.defuse();
value value
} }
}
fn regs() -> &'static pac::temp::RegisterBlock { fn regs() -> &'static pac::temp::RegisterBlock {
unsafe { &*pac::TEMP::ptr() } unsafe { &*pac::TEMP::ptr() }