aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/buffered_uarte.rs
diff options
context:
space:
mode:
authorDániel Buga <[email protected]>2024-12-30 12:13:13 +0100
committerDániel Buga <[email protected]>2024-12-30 12:13:13 +0100
commit44217aa0924e7590aa0afabdf17babd5c2ea5b82 (patch)
treee42f5d02f9b560610b870d802cf390518180c3c6 /embassy-nrf/src/buffered_uarte.rs
parenta4f8fddd696ca2e3705827ba4b3806cbadcb3134 (diff)
Desugar some async fns
Diffstat (limited to 'embassy-nrf/src/buffered_uarte.rs')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs11
1 files changed, 4 insertions, 7 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`.