Skip to content

Commit ed53656

Browse files
committed
Stabilize read_ready
1 parent 167fec7 commit ed53656

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

esp-hal/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Unsafely expose GPIO pins that are only available on certain chip/module variants (#4520)
1717

1818
### Changed
19+
20+
- UART: `fn read_ready` is now stable (#?)
1921
- RMT: `SingleShotTxTransaction` has been renamed to `TxTransaction`. (#4302)
2022
- RMT: `ChannelCreator::configure_tx` and `ChannelCreator::configure_rx` now take the configuration by reference. (#4302)
2123
- 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: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,8 @@ where
13011301
/// The UART hardware continuously receives bytes and stores them in the RX
13021302
/// FIFO. This function reads the bytes from the RX FIFO and returns
13031303
/// them in the provided buffer. If the hardware buffer is empty, this
1304-
/// function will block until data is available.
1304+
/// function will block until data is available. The [`Self::read_ready`]
1305+
/// function can be used to check if data is available without blocking.
13051306
///
13061307
/// The function returns the number of bytes read into the buffer. This may
13071308
/// be less than the length of the buffer. This function only returns 0
@@ -1862,10 +1863,30 @@ where
18621863
self.tx.send_break(bits)
18631864
}
18641865

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

0 commit comments

Comments
 (0)