aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-04-02 18:33:36 +0000
committerGitHub <[email protected]>2023-04-02 18:33:36 +0000
commit08f911d25e83266b03bd1ebd37eee50cf2c53dd4 (patch)
tree597d1c59b8258f90485e3ac93ce66797a62b38f8
parentcd2ed065dc50e8540b17bfaecbf421679d2ab60d (diff)
parent7ef6a3cfb22ee1e497fcea37a019ca32d22298b7 (diff)
Merge #1318
1318: rp: Allow zero len reads for buffered uart r=Dirbaio a=timokroeger Prevents the read methods from getting stuck forever. cc `@MathiasKoch` can you test if this fixes the problem you described in the chat? Co-authored-by: Timo Kröger <[email protected]>
-rw-r--r--embassy-rp/src/uart/buffered.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs
index 1a573b311..c620ed08c 100644
--- a/embassy-rp/src/uart/buffered.rs
+++ b/embassy-rp/src/uart/buffered.rs
@@ -175,6 +175,10 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> {
175 175
176 fn read<'a>(buf: &'a mut [u8]) -> impl Future<Output = Result<usize, Error>> + 'a { 176 fn read<'a>(buf: &'a mut [u8]) -> impl Future<Output = Result<usize, Error>> + 'a {
177 poll_fn(move |cx| { 177 poll_fn(move |cx| {
178 if buf.is_empty() {
179 return Poll::Ready(Ok(0));
180 }
181
178 let state = T::state(); 182 let state = T::state();
179 let mut rx_reader = unsafe { state.rx_buf.reader() }; 183 let mut rx_reader = unsafe { state.rx_buf.reader() };
180 let n = rx_reader.pop(|data| { 184 let n = rx_reader.pop(|data| {
@@ -202,6 +206,10 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> {
202 } 206 }
203 207
204 pub fn blocking_read(&mut self, buf: &mut [u8]) -> Result<usize, Error> { 208 pub fn blocking_read(&mut self, buf: &mut [u8]) -> Result<usize, Error> {
209 if buf.is_empty() {
210 return Ok(0);
211 }
212
205 loop { 213 loop {
206 let state = T::state(); 214 let state = T::state();
207 let mut rx_reader = unsafe { state.rx_buf.reader() }; 215 let mut rx_reader = unsafe { state.rx_buf.reader() };
@@ -293,6 +301,10 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> {
293 301
294 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 {
295 poll_fn(move |cx| { 303 poll_fn(move |cx| {
304 if buf.is_empty() {
305 return Poll::Ready(Ok(0));
306 }
307
296 let state = T::state(); 308 let state = T::state();
297 let mut tx_writer = unsafe { state.tx_buf.writer() }; 309 let mut tx_writer = unsafe { state.tx_buf.writer() };
298 let n = tx_writer.push(|data| { 310 let n = tx_writer.push(|data| {
@@ -327,6 +339,10 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> {
327 } 339 }
328 340
329 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
330 loop { 346 loop {
331 let state = T::state(); 347 let state = T::state();
332 let mut tx_writer = unsafe { state.tx_buf.writer() }; 348 let mut tx_writer = unsafe { state.tx_buf.writer() };