@@ -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