Skip to content

Commit 6c02337

Browse files
committed
Expand read_ready documentation
1 parent 42f18d2 commit 6c02337

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

esp-hal/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

1919
### Changed
2020

21-
- UART: `fn read_ready` is now stable (#4586)
2221
- RMT: `SingleShotTxTransaction` has been renamed to `TxTransaction`. (#4302)
2322
- RMT: `ChannelCreator::configure_tx` and `ChannelCreator::configure_rx` now take the configuration by reference. (#4302)
2423
- RMT: `ChannelCreator::configure_tx` and `ChannelCreator::configure_rx` don't take a pin anymore, instead `Channel::with_pin` has been added. (#4302)

esp-hal/src/uart/mod.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,9 +1867,31 @@ where
18671867
self.tx.send_break(bits)
18681868
}
18691869

1870-
/// Returns whether the UART buffer has data.
1870+
#[procmacros::doc_replace]
1871+
/// Returns whether the UART receive buffer has at least one byte of data.
18711872
///
1872-
/// If this function returns `true`, [`Self::read`] will not block.
1873+
/// If this function returns `true`, [`Self::read`] and [`Self::read_async`]
1874+
/// will not block. Otherwise, they will not return until data is available.
1875+
///
1876+
/// Data that does not get stored due to an error will be lost and does not count
1877+
/// towards the number of bytes in the receive buffer.
1878+
// TODO: once we add support for UART_ERR_WR_MASK it needs to be documented here.
1879+
/// ## Example
1880+
///
1881+
/// ```rust, no_run
1882+
/// # {before_snippet}
1883+
/// use esp_hal::uart::{Config, Uart};
1884+
/// let mut uart = Uart::new(peripherals.UART0, Config::default())?;
1885+
///
1886+
/// while !uart.read_ready() {
1887+
/// // Do something else while waiting for data to be available.
1888+
/// }
1889+
///
1890+
/// let mut buf = [0u8; 32];
1891+
/// uart.read(&mut buf[..])?;
1892+
///
1893+
/// # {after_snippet}
1894+
/// ```
18731895
#[instability::unstable]
18741896
pub fn read_ready(&mut self) -> bool {
18751897
self.rx.read_ready()
@@ -1881,7 +1903,8 @@ where
18811903
/// The UART hardware continuously receives bytes and stores them in the RX
18821904
/// FIFO. This function reads the bytes from the RX FIFO and returns
18831905
/// them in the provided buffer. If the hardware buffer is empty, this
1884-
/// function will block until data is available.
1906+
/// function will block until data is available. The [`Self::read_ready`]
1907+
/// function can be used to check if data is available without blocking.
18851908
///
18861909
/// The function returns the number of bytes read into the buffer. This may
18871910
/// be less than the length of the buffer. This function only returns 0

0 commit comments

Comments
 (0)