aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/buffered_uarte.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-nrf/src/buffered_uarte.rs')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index 159b4db8f..6d39597c6 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -358,6 +358,11 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> {
358 self.tx.write(buf).await 358 self.tx.write(buf).await
359 } 359 }
360 360
361 /// Try writing a buffer without waiting, returning how many bytes were written.
362 pub fn try_write(&mut self, buf: &[u8]) -> Result<usize, Error> {
363 self.tx.try_write(buf)
364 }
365
361 /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination. 366 /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
362 pub async fn flush(&mut self) -> Result<(), Error> { 367 pub async fn flush(&mut self) -> Result<(), Error> {
363 self.tx.flush().await 368 self.tx.flush().await
@@ -482,6 +487,29 @@ impl<'d, U: UarteInstance> BufferedUarteTx<'d, U> {
482 .await 487 .await
483 } 488 }
484 489
490 /// Try writing a buffer without waiting, returning how many bytes were written.
491 pub fn try_write(&mut self, buf: &[u8]) -> Result<usize, Error> {
492 //trace!("poll_write: {:?}", buf.len());
493 let s = U::buffered_state();
494 let mut tx = unsafe { s.tx_buf.writer() };
495
496 let tx_buf = tx.push_slice();
497 if tx_buf.is_empty() {
498 return Ok(0);
499 }
500
501 let n = min(tx_buf.len(), buf.len());
502 tx_buf[..n].copy_from_slice(&buf[..n]);
503 tx.push_done(n);
504
505 //trace!("poll_write: queued {:?}", n);
506
507 compiler_fence(Ordering::SeqCst);
508 U::Interrupt::pend();
509
510 Ok(n)
511 }
512
485 /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination. 513 /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
486 pub async fn flush(&mut self) -> Result<(), Error> { 514 pub async fn flush(&mut self) -> Result<(), Error> {
487 poll_fn(move |cx| { 515 poll_fn(move |cx| {