Skip to content

Commit fd07a6e

Browse files
committed
Expand write_ready documentation
1 parent 6c02337 commit fd07a6e

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

esp-hal/src/uart/mod.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,9 +1804,32 @@ where
18041804
self.tx.uart.info().regs()
18051805
}
18061806

1807-
/// Returns whether the UART buffer is ready to accept more data.
1807+
#[procmacros::doc_replace]
1808+
/// Returns whether the UART TX buffer is ready to accept more data.
18081809
///
1809-
/// If this function returns `true`, [`Self::write`] will not block.
1810+
/// If this function returns `true`, [`Self::write`] and [`Self::write_async`]
1811+
/// will not block. Otherwise, the functions will not return until the buffer is
1812+
/// ready.
1813+
///
1814+
/// ## Example
1815+
///
1816+
/// ```rust, no_run
1817+
/// # {before_snippet}
1818+
/// use esp_hal::uart::{Config, Uart};
1819+
/// let mut uart = Uart::new(peripherals.UART0, Config::default())?;
1820+
///
1821+
/// if uart.write_ready() {
1822+
/// // Because write_ready has returned true, the following call will immediately
1823+
/// // copy some bytes into the FIFO and return a non-zero value.
1824+
/// let written = uart.write(b"Hello")?;
1825+
/// // ... handle written bytes
1826+
/// } else {
1827+
/// // Calling write would have blocked, but here we can do something useful
1828+
/// // instead of waiting for the buffer to become ready.
1829+
/// }
1830+
}
1831+
/// # {after_snippet}
1832+
/// ```
18101833
#[instability::unstable]
18111834
pub fn write_ready(&mut self) -> bool {
18121835
self.tx.write_ready()

0 commit comments

Comments
 (0)