aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src/uart
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-11-21 23:31:31 +0100
committerDario Nieuwenhuis <[email protected]>2022-11-25 21:02:06 +0100
commit1e2fb0459d8546ba658bb9fe150be5f1f537b48e (patch)
treeeb40a5027581896c7b78db58f509431ed6b11892 /embassy-rp/src/uart
parent758f5d7ea29f1df14d5ef59c82e4b7f22545d775 (diff)
Switch to async-fn-in-trait
Diffstat (limited to 'embassy-rp/src/uart')
-rw-r--r--embassy-rp/src/uart/buffered.rs60
1 files changed, 17 insertions, 43 deletions
diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs
index 4f0a55532..fa466c8a1 100644
--- a/embassy-rp/src/uart/buffered.rs
+++ b/embassy-rp/src/uart/buffered.rs
@@ -1,4 +1,4 @@
1use core::future::{poll_fn, Future}; 1use core::future::poll_fn;
2use core::task::{Poll, Waker}; 2use core::task::{Poll, Waker};
3 3
4use atomic_polyfill::{compiler_fence, Ordering}; 4use atomic_polyfill::{compiler_fence, Ordering};
@@ -355,11 +355,7 @@ impl<'d, T: Instance> embedded_io::Io for BufferedUartTx<'d, T> {
355} 355}
356 356
357impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUart<'d, T> { 357impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUart<'d, T> {
358 type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 358 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
359 where
360 Self: 'a;
361
362 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
363 poll_fn(move |cx| { 359 poll_fn(move |cx| {
364 let (res, do_pend) = self.inner.with(|state| { 360 let (res, do_pend) = self.inner.with(|state| {
365 compiler_fence(Ordering::SeqCst); 361 compiler_fence(Ordering::SeqCst);
@@ -372,15 +368,12 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUart<'d, T> {
372 368
373 res 369 res
374 }) 370 })
371 .await
375 } 372 }
376} 373}
377 374
378impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUartRx<'d, T> { 375impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUartRx<'d, T> {
379 type ReadFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 376 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
380 where
381 Self: 'a;
382
383 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
384 poll_fn(move |cx| { 377 poll_fn(move |cx| {
385 let (res, do_pend) = self.inner.with(|state| { 378 let (res, do_pend) = self.inner.with(|state| {
386 compiler_fence(Ordering::SeqCst); 379 compiler_fence(Ordering::SeqCst);
@@ -393,21 +386,19 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::Read for BufferedUartRx<'d, T> {
393 386
394 res 387 res
395 }) 388 })
389 .await
396 } 390 }
397} 391}
398 392
399impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUart<'d, T> { 393impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUart<'d, T> {
400 type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> + 'a 394 async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
401 where
402 Self: 'a;
403
404 fn fill_buf<'a>(&'a mut self) -> Self::FillBufFuture<'a> {
405 poll_fn(move |cx| { 395 poll_fn(move |cx| {
406 self.inner.with(|state| { 396 self.inner.with(|state| {
407 compiler_fence(Ordering::SeqCst); 397 compiler_fence(Ordering::SeqCst);
408 state.rx.fill_buf(cx.waker()) 398 state.rx.fill_buf(cx.waker())
409 }) 399 })
410 }) 400 })
401 .await
411 } 402 }
412 403
413 fn consume(&mut self, amt: usize) { 404 fn consume(&mut self, amt: usize) {
@@ -419,17 +410,14 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUart<'d, T>
419} 410}
420 411
421impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUartRx<'d, T> { 412impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUartRx<'d, T> {
422 type FillBufFuture<'a> = impl Future<Output = Result<&'a [u8], Self::Error>> + 'a 413 async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
423 where
424 Self: 'a;
425
426 fn fill_buf<'a>(&'a mut self) -> Self::FillBufFuture<'a> {
427 poll_fn(move |cx| { 414 poll_fn(move |cx| {
428 self.inner.with(|state| { 415 self.inner.with(|state| {
429 compiler_fence(Ordering::SeqCst); 416 compiler_fence(Ordering::SeqCst);
430 state.fill_buf(cx.waker()) 417 state.fill_buf(cx.waker())
431 }) 418 })
432 }) 419 })
420 .await
433 } 421 }
434 422
435 fn consume(&mut self, amt: usize) { 423 fn consume(&mut self, amt: usize) {
@@ -441,11 +429,7 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::BufRead for BufferedUartRx<'d, T
441} 429}
442 430
443impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUart<'d, T> { 431impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUart<'d, T> {
444 type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 432 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
445 where
446 Self: 'a;
447
448 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
449 poll_fn(move |cx| { 433 poll_fn(move |cx| {
450 let (poll, empty) = self.inner.with(|state| state.tx.write(buf, cx.waker())); 434 let (poll, empty) = self.inner.with(|state| state.tx.write(buf, cx.waker()));
451 if empty { 435 if empty {
@@ -453,23 +437,16 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUart<'d, T> {
453 } 437 }
454 poll 438 poll
455 }) 439 })
440 .await
456 } 441 }
457 442
458 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a 443 async fn flush(&mut self) -> Result<(), Self::Error> {
459 where 444 poll_fn(move |cx| self.inner.with(|state| state.tx.flush(cx.waker()))).await
460 Self: 'a;
461
462 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
463 poll_fn(move |cx| self.inner.with(|state| state.tx.flush(cx.waker())))
464 } 445 }
465} 446}
466 447
467impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUartTx<'d, T> { 448impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUartTx<'d, T> {
468 type WriteFuture<'a> = impl Future<Output = Result<usize, Self::Error>> + 'a 449 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
469 where
470 Self: 'a;
471
472 fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
473 poll_fn(move |cx| { 450 poll_fn(move |cx| {
474 let (poll, empty) = self.inner.with(|state| state.write(buf, cx.waker())); 451 let (poll, empty) = self.inner.with(|state| state.write(buf, cx.waker()));
475 if empty { 452 if empty {
@@ -477,13 +454,10 @@ impl<'d, T: Instance + 'd> embedded_io::asynch::Write for BufferedUartTx<'d, T>
477 } 454 }
478 poll 455 poll
479 }) 456 })
457 .await
480 } 458 }
481 459
482 type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a 460 async fn flush(&mut self) -> Result<(), Self::Error> {
483 where 461 poll_fn(move |cx| self.inner.with(|state| state.flush(cx.waker()))).await
484 Self: 'a;
485
486 fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> {
487 poll_fn(move |cx| self.inner.with(|state| state.flush(cx.waker())))
488 } 462 }
489} 463}