aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs11
-rwxr-xr-xembassy-nrf/src/qspi.rs5
-rw-r--r--embassy-nrf/src/usb/mod.rs14
-rw-r--r--embassy-nrf/src/usb/vbus_detect.rs10
4 files changed, 16 insertions, 24 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index b55e70a36..c3fcfd06e 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -9,7 +9,7 @@
9//! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. 9//! Please also see [crate::uarte] to understand when [BufferedUarte] should be used.
10 10
11use core::cmp::min; 11use core::cmp::min;
12use core::future::poll_fn; 12use core::future::{poll_fn, Future};
13use core::marker::PhantomData; 13use core::marker::PhantomData;
14use core::slice; 14use core::slice;
15use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU8, AtomicUsize, Ordering}; 15use core::sync::atomic::{compiler_fence, AtomicBool, AtomicU8, AtomicUsize, Ordering};
@@ -452,7 +452,7 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> {
452 } 452 }
453 453
454 /// Write a buffer into this writer, returning how many bytes were written. 454 /// Write a buffer into this writer, returning how many bytes were written.
455 pub async fn write(&mut self, buf: &[u8]) -> Result<usize, Error> { 455 pub fn write<'a>(&'a mut self, buf: &'a [u8]) -> impl Future<Output = Result<usize, Error>> + 'a {
456 poll_fn(move |cx| { 456 poll_fn(move |cx| {
457 //trace!("poll_write: {:?}", buf.len()); 457 //trace!("poll_write: {:?}", buf.len());
458 let ss = U::state(); 458 let ss = U::state();
@@ -477,7 +477,6 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> {
477 477
478 Poll::Ready(Ok(n)) 478 Poll::Ready(Ok(n))
479 }) 479 })
480 .await
481 } 480 }
482 481
483 /// Try writing a buffer without waiting, returning how many bytes were written. 482 /// Try writing a buffer without waiting, returning how many bytes were written.
@@ -504,7 +503,7 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> {
504 } 503 }
505 504
506 /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination. 505 /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
507 pub async fn flush(&mut self) -> Result<(), Error> { 506 pub fn flush(&mut self) -> impl Future<Output = Result<(), Error>> + '_ {
508 poll_fn(move |cx| { 507 poll_fn(move |cx| {
509 //trace!("poll_flush"); 508 //trace!("poll_flush");
510 let ss = U::state(); 509 let ss = U::state();
@@ -517,7 +516,6 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> {
517 516
518 Poll::Ready(Ok(())) 517 Poll::Ready(Ok(()))
519 }) 518 })
520 .await
521 } 519 }
522} 520}
523 521
@@ -721,7 +719,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> {
721 } 719 }
722 720
723 /// Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. 721 /// Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
724 pub async fn fill_buf(&mut self) -> Result<&[u8], Error> { 722 pub fn fill_buf(&mut self) -> impl Future<Output = Result<&'_ [u8], Error>> {
725 poll_fn(move |cx| { 723 poll_fn(move |cx| {
726 compiler_fence(Ordering::SeqCst); 724 compiler_fence(Ordering::SeqCst);
727 //trace!("poll_read"); 725 //trace!("poll_read");
@@ -771,7 +769,6 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> {
771 let buf = s.rx_buf.buf.load(Ordering::Relaxed); 769 let buf = s.rx_buf.buf.load(Ordering::Relaxed);
772 Poll::Ready(Ok(unsafe { slice::from_raw_parts(buf.add(start), n) })) 770 Poll::Ready(Ok(unsafe { slice::from_raw_parts(buf.add(start), n) }))
773 }) 771 })
774 .await
775 } 772 }
776 773
777 /// Tell this buffer that `amt` bytes have been consumed from the buffer, so they should no longer be returned in calls to `fill_buf`. 774 /// Tell this buffer that `amt` bytes have been consumed from the buffer, so they should no longer be returned in calls to `fill_buf`.
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index 255b43c33..17e127700 100755
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -2,7 +2,7 @@
2 2
3#![macro_use] 3#![macro_use]
4 4
5use core::future::poll_fn; 5use core::future::{poll_fn, Future};
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::ptr; 7use core::ptr;
8use core::task::Poll; 8use core::task::Poll;
@@ -314,7 +314,7 @@ impl<'d, T: Instance> Qspi<'d, T> {
314 Ok(()) 314 Ok(())
315 } 315 }
316 316
317 async fn wait_ready(&mut self) { 317 fn wait_ready(&mut self) -> impl Future<Output = ()> {
318 poll_fn(move |cx| { 318 poll_fn(move |cx| {
319 let r = T::regs(); 319 let r = T::regs();
320 let s = T::state(); 320 let s = T::state();
@@ -324,7 +324,6 @@ impl<'d, T: Instance> Qspi<'d, T> {
324 } 324 }
325 Poll::Pending 325 Poll::Pending
326 }) 326 })
327 .await
328 } 327 }
329 328
330 fn blocking_wait_ready() { 329 fn blocking_wait_ready() {
diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs
index a9bf16708..06dae694b 100644
--- a/embassy-nrf/src/usb/mod.rs
+++ b/embassy-nrf/src/usb/mod.rs
@@ -4,7 +4,7 @@
4 4
5pub mod vbus_detect; 5pub mod vbus_detect;
6 6
7use core::future::poll_fn; 7use core::future::{poll_fn, Future};
8use core::marker::PhantomData; 8use core::marker::PhantomData;
9use core::mem::MaybeUninit; 9use core::mem::MaybeUninit;
10use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; 10use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
@@ -219,8 +219,8 @@ impl<'d, T: Instance, V: VbusDetect> driver::Bus for Bus<'d, T, V> {
219 regs.enable().write(|x| x.set_enable(false)); 219 regs.enable().write(|x| x.set_enable(false));
220 } 220 }
221 221
222 async fn poll(&mut self) -> Event { 222 fn poll(&mut self) -> impl Future<Output = Event> {
223 poll_fn(move |cx| { 223 poll_fn(|cx| {
224 BUS_WAKER.register(cx.waker()); 224 BUS_WAKER.register(cx.waker());
225 let regs = T::regs(); 225 let regs = T::regs();
226 226
@@ -277,7 +277,6 @@ impl<'d, T: Instance, V: VbusDetect> driver::Bus for Bus<'d, T, V> {
277 277
278 Poll::Pending 278 Poll::Pending
279 }) 279 })
280 .await
281 } 280 }
282 281
283 fn endpoint_set_stalled(&mut self, ep_addr: EndpointAddress, stalled: bool) { 282 fn endpoint_set_stalled(&mut self, ep_addr: EndpointAddress, stalled: bool) {
@@ -468,7 +467,7 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir
468 467
469#[allow(private_bounds)] 468#[allow(private_bounds)]
470impl<'d, T: Instance, Dir: EndpointDir> Endpoint<'d, T, Dir> { 469impl<'d, T: Instance, Dir: EndpointDir> Endpoint<'d, T, Dir> {
471 async fn wait_enabled_state(&mut self, state: bool) { 470 fn wait_enabled_state(&mut self, state: bool) -> impl Future<Output = ()> {
472 let i = self.info.addr.index(); 471 let i = self.info.addr.index();
473 assert!(i != 0); 472 assert!(i != 0);
474 473
@@ -480,12 +479,11 @@ impl<'d, T: Instance, Dir: EndpointDir> Endpoint<'d, T, Dir> {
480 Poll::Pending 479 Poll::Pending
481 } 480 }
482 }) 481 })
483 .await
484 } 482 }
485 483
486 /// Wait for the endpoint to be disabled 484 /// Wait for the endpoint to be disabled
487 pub async fn wait_disabled(&mut self) { 485 pub fn wait_disabled(&mut self) -> impl Future<Output = ()> {
488 self.wait_enabled_state(false).await 486 self.wait_enabled_state(false)
489 } 487 }
490} 488}
491 489
diff --git a/embassy-nrf/src/usb/vbus_detect.rs b/embassy-nrf/src/usb/vbus_detect.rs
index bdc088dcb..8794beb2d 100644
--- a/embassy-nrf/src/usb/vbus_detect.rs
+++ b/embassy-nrf/src/usb/vbus_detect.rs
@@ -1,6 +1,6 @@
1//! Trait and implementations for performing VBUS detection. 1//! Trait and implementations for performing VBUS detection.
2 2
3use core::future::poll_fn; 3use core::future::{poll_fn, Future};
4use core::sync::atomic::{AtomicBool, Ordering}; 4use core::sync::atomic::{AtomicBool, Ordering};
5use core::task::Poll; 5use core::task::Poll;
6 6
@@ -99,8 +99,8 @@ impl VbusDetect for HardwareVbusDetect {
99 regs.usbregstatus().read().vbusdetect() 99 regs.usbregstatus().read().vbusdetect()
100 } 100 }
101 101
102 async fn wait_power_ready(&mut self) -> Result<(), ()> { 102 fn wait_power_ready(&mut self) -> impl Future<Output = Result<(), ()>> {
103 poll_fn(move |cx| { 103 poll_fn(|cx| {
104 POWER_WAKER.register(cx.waker()); 104 POWER_WAKER.register(cx.waker());
105 let regs = USB_REG_PERI; 105 let regs = USB_REG_PERI;
106 106
@@ -112,7 +112,6 @@ impl VbusDetect for HardwareVbusDetect {
112 Poll::Pending 112 Poll::Pending
113 } 113 }
114 }) 114 })
115 .await
116 } 115 }
117} 116}
118 117
@@ -163,7 +162,7 @@ impl VbusDetect for &SoftwareVbusDetect {
163 self.usb_detected.load(Ordering::Relaxed) 162 self.usb_detected.load(Ordering::Relaxed)
164 } 163 }
165 164
166 async fn wait_power_ready(&mut self) -> Result<(), ()> { 165 fn wait_power_ready(&mut self) -> impl Future<Output = Result<(), ()>> {
167 poll_fn(move |cx| { 166 poll_fn(move |cx| {
168 POWER_WAKER.register(cx.waker()); 167 POWER_WAKER.register(cx.waker());
169 168
@@ -175,6 +174,5 @@ impl VbusDetect for &SoftwareVbusDetect {
175 Poll::Pending 174 Poll::Pending
176 } 175 }
177 }) 176 })
178 .await
179 } 177 }
180} 178}