aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2023-04-02 14:36:32 +0200
committerTimo Kröger <[email protected]>2023-04-02 14:36:32 +0200
commit7ef6a3cfb22ee1e497fcea37a019ca32d22298b7 (patch)
treedbd89d2ff0db653329cd04653bce1f815b2117dc
parentf78aa4f936b8bcdd8237f070125e60595f582eb3 (diff)
rp: Allow zero len writes for buffered uart
Prevents the write methods from getting stuck forever.
-rw-r--r--embassy-rp/src/uart/buffered.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs
index 9aa0b5714..c620ed08c 100644
--- a/embassy-rp/src/uart/buffered.rs
+++ b/embassy-rp/src/uart/buffered.rs
@@ -301,6 +301,10 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> {
301 301
302 fn write<'a>(buf: &'a [u8]) -> impl Future<Output = Result<usize, Error>> + 'a { 302 fn write<'a>(buf: &'a [u8]) -> impl Future<Output = Result<usize, Error>> + 'a {
303 poll_fn(move |cx| { 303 poll_fn(move |cx| {
304 if buf.is_empty() {
305 return Poll::Ready(Ok(0));
306 }
307
304 let state = T::state(); 308 let state = T::state();
305 let mut tx_writer = unsafe { state.tx_buf.writer() }; 309 let mut tx_writer = unsafe { state.tx_buf.writer() };
306 let n = tx_writer.push(|data| { 310 let n = tx_writer.push(|data| {
@@ -335,6 +339,10 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> {
335 } 339 }
336 340
337 pub fn blocking_write(&mut self, buf: &[u8]) -> Result<usize, Error> { 341 pub fn blocking_write(&mut self, buf: &[u8]) -> Result<usize, Error> {
342 if buf.is_empty() {
343 return Ok(0);
344 }
345
338 loop { 346 loop {
339 let state = T::state(); 347 let state = T::state();
340 let mut tx_writer = unsafe { state.tx_buf.writer() }; 348 let mut tx_writer = unsafe { state.tx_buf.writer() };