aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-07-03 16:00:23 +0000
committerGitHub <[email protected]>2025-07-03 16:00:23 +0000
commitb964bee302fc3631d14d73d9a9b406e7352cd550 (patch)
treeaa029cde4ffdf8d752e4206f90a60bf35d7a7326 /embassy-rp/src
parent4af2d9adc4494922058a48e4329c53eb305446bf (diff)
parentda6c4ff31a3ebc9995c695c0ad9bc260c5ccffed (diff)
Merge pull request #4366 from mattwigway/uart-line-break
Add note about UART line breaks being different from ASCII
Diffstat (limited to 'embassy-rp/src')
-rw-r--r--embassy-rp/src/uart/mod.rs34
1 files changed, 20 insertions, 14 deletions
diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs
index c3a15fda5..6f4e2ee07 100644
--- a/embassy-rp/src/uart/mod.rs
+++ b/embassy-rp/src/uart/mod.rs
@@ -495,52 +495,58 @@ impl<'d> UartRx<'d, Async> {
495 unreachable!("unrecognized rx error"); 495 unreachable!("unrecognized rx error");
496 } 496 }
497 497
498 /// Read from the UART, waiting for a line break. 498 /// Read from the UART, waiting for a break.
499 /// 499 ///
500 /// We read until one of the following occurs: 500 /// We read until one of the following occurs:
501 /// 501 ///
502 /// * We read `buffer.len()` bytes without a line break 502 /// * We read `buffer.len()` bytes without a break
503 /// * returns `Err(ReadToBreakError::MissingBreak(buffer.len()))` 503 /// * returns `Err(ReadToBreakError::MissingBreak(buffer.len()))`
504 /// * We read `n` bytes then a line break occurs 504 /// * We read `n` bytes then a break occurs
505 /// * returns `Ok(n)` 505 /// * returns `Ok(n)`
506 /// * We encounter some error OTHER than a line break 506 /// * We encounter some error OTHER than a break
507 /// * returns `Err(ReadToBreakError::Other(error))` 507 /// * returns `Err(ReadToBreakError::Other(error))`
508 /// 508 ///
509 /// **NOTE**: you MUST provide a buffer one byte larger than your largest expected 509 /// **NOTE**: you MUST provide a buffer one byte larger than your largest expected
510 /// message to reliably detect the framing on one single call to `read_to_break()`. 510 /// message to reliably detect the framing on one single call to `read_to_break()`.
511 /// 511 ///
512 /// * If you expect a message of 20 bytes + line break, and provide a 20-byte buffer: 512 /// * If you expect a message of 20 bytes + break, and provide a 20-byte buffer:
513 /// * The first call to `read_to_break()` will return `Err(ReadToBreakError::MissingBreak(20))` 513 /// * The first call to `read_to_break()` will return `Err(ReadToBreakError::MissingBreak(20))`
514 /// * The next call to `read_to_break()` will immediately return `Ok(0)`, from the "stale" line break 514 /// * The next call to `read_to_break()` will immediately return `Ok(0)`, from the "stale" break
515 /// * If you expect a message of 20 bytes + line break, and provide a 21-byte buffer: 515 /// * If you expect a message of 20 bytes + break, and provide a 21-byte buffer:
516 /// * The first call to `read_to_break()` will return `Ok(20)`. 516 /// * The first call to `read_to_break()` will return `Ok(20)`.
517 /// * The next call to `read_to_break()` will work as expected 517 /// * The next call to `read_to_break()` will work as expected
518 ///
519 /// **NOTE**: In the UART context, a break refers to a break condition (the line being held low for
520 /// for longer than a single character), not an ASCII line break.
518 pub async fn read_to_break(&mut self, buffer: &mut [u8]) -> Result<usize, ReadToBreakError> { 521 pub async fn read_to_break(&mut self, buffer: &mut [u8]) -> Result<usize, ReadToBreakError> {
519 self.read_to_break_with_count(buffer, 0).await 522 self.read_to_break_with_count(buffer, 0).await
520 } 523 }
521 524
522 /// Read from the UART, waiting for a line break as soon as at least `min_count` bytes have been read. 525 /// Read from the UART, waiting for a break as soon as at least `min_count` bytes have been read.
523 /// 526 ///
524 /// We read until one of the following occurs: 527 /// We read until one of the following occurs:
525 /// 528 ///
526 /// * We read `buffer.len()` bytes without a line break 529 /// * We read `buffer.len()` bytes without a break
527 /// * returns `Err(ReadToBreakError::MissingBreak(buffer.len()))` 530 /// * returns `Err(ReadToBreakError::MissingBreak(buffer.len()))`
528 /// * We read `n > min_count` bytes then a line break occurs 531 /// * We read `n > min_count` bytes then a break occurs
529 /// * returns `Ok(n)` 532 /// * returns `Ok(n)`
530 /// * We encounter some error OTHER than a line break 533 /// * We encounter some error OTHER than a break
531 /// * returns `Err(ReadToBreakError::Other(error))` 534 /// * returns `Err(ReadToBreakError::Other(error))`
532 /// 535 ///
533 /// If a line break occurs before `min_count` bytes have been read, the break will be ignored and the read will continue 536 /// If a break occurs before `min_count` bytes have been read, the break will be ignored and the read will continue
534 /// 537 ///
535 /// **NOTE**: you MUST provide a buffer one byte larger than your largest expected 538 /// **NOTE**: you MUST provide a buffer one byte larger than your largest expected
536 /// message to reliably detect the framing on one single call to `read_to_break()`. 539 /// message to reliably detect the framing on one single call to `read_to_break()`.
537 /// 540 ///
538 /// * If you expect a message of 20 bytes + line break, and provide a 20-byte buffer: 541 /// * If you expect a message of 20 bytes + break, and provide a 20-byte buffer:
539 /// * The first call to `read_to_break()` will return `Err(ReadToBreakError::MissingBreak(20))` 542 /// * The first call to `read_to_break()` will return `Err(ReadToBreakError::MissingBreak(20))`
540 /// * The next call to `read_to_break()` will immediately return `Ok(0)`, from the "stale" line break 543 /// * The next call to `read_to_break()` will immediately return `Ok(0)`, from the "stale" line break
541 /// * If you expect a message of 20 bytes + line break, and provide a 21-byte buffer: 544 /// * If you expect a message of 20 bytes + break, and provide a 21-byte buffer:
542 /// * The first call to `read_to_break()` will return `Ok(20)`. 545 /// * The first call to `read_to_break()` will return `Ok(20)`.
543 /// * The next call to `read_to_break()` will work as expected 546 /// * The next call to `read_to_break()` will work as expected
547 ///
548 /// **NOTE**: In the UART context, a break refers to a break condition (the line being held low for
549 /// for longer than a single character), not an ASCII line break.
544 pub async fn read_to_break_with_count( 550 pub async fn read_to_break_with_count(
545 &mut self, 551 &mut self,
546 buffer: &mut [u8], 552 buffer: &mut [u8],