pub struct UartRx<'d, Dm: DriverMode> { /* private fields */ }unstable only.Expand description
UART (Receive)
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Implementations§
Source§impl<'d> UartRx<'d, Blocking>
impl<'d> UartRx<'d, Blocking>
Sourcepub fn new(
uart: impl Instance + 'd,
config: Config,
) -> Result<Self, ConfigError>
pub fn new( uart: impl Instance + 'd, config: Config, ) -> Result<Self, ConfigError>
Creates a new UART RX instance in Blocking mode.
§Examples
use esp_hal::uart::{Config, UartRx};
let rx = UartRx::new(peripherals.UART0, Config::default())?.with_rx(peripherals.GPIO2);§Errors
ConfigError when the configuration is not supported by the hardware
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn wait_for_break(&mut self)
pub fn wait_for_break(&mut self)
Waits for a break condition to be detected.
Polls the break-detection interrupt status and returns once the receiver has detected a break condition. After detection, the break status is automatically cleared.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn wait_for_break_with_timeout(&mut self, timeout: Duration) -> bool
pub fn wait_for_break_with_timeout(&mut self, timeout: Duration) -> bool
Waits for a break condition to be detected with a timeout.
Polls the break-detection interrupt status until a break is detected or the specified timeout expires. Returns whether a break was detected before the timeout expired. After successful detection, the break status is automatically cleared.
§Arguments
timeout- Maximum time to wait for a break condition
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§impl<'d> UartRx<'d, Async>
impl<'d> UartRx<'d, Async>
Sourcepub fn into_blocking(self) -> UartRx<'d, Blocking>
pub fn into_blocking(self) -> UartRx<'d, Blocking>
Sourcepub async fn read_async(&mut self, buf: &mut [u8]) -> Result<usize, RxError>
pub async fn read_async(&mut self, buf: &mut [u8]) -> Result<usize, RxError>
Reads data asynchronously.
Reads data from the UART receive buffer into the provided buffer. If the buffer is empty, waits asynchronously for data to become available, or for an error to occur.
Returns the number of bytes read into the buffer. This may be less than the length of the buffer.
May ignore the rx_fifo_full_threshold setting to ensure that it does not
wait for more data than the buffer can hold.
Upon an error, returns immediately and the contents of the internal FIFO are not modified.
§Cancellation Safety
Cancellation safe.
Sourcepub async fn read_exact_async(&mut self, buf: &mut [u8]) -> Result<(), RxError>
pub async fn read_exact_async(&mut self, buf: &mut [u8]) -> Result<(), RxError>
Fills buffer asynchronously.
Reads data into the provided buffer. If the internal FIFO does not contain enough data, waits asynchronously for data to become available, or for an error to occur.
May ignore the rx_fifo_full_threshold setting to ensure that it does not
wait for more data than the buffer can hold.
§Cancellation Safety
Not cancellation safe. If the future is dropped before it resolves, or if an error occurs during the read operation, previously read data may be lost.
Sourcepub async fn wait_for_break_async(&mut self)
pub async fn wait_for_break_async(&mut self)
Waits for a break condition to be detected asynchronously.
This is an async function that will await until a break condition is detected on the RX line. After detection, the break interrupt flag is automatically cleared.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§impl<'d, Dm> UartRx<'d, Dm>where
Dm: DriverMode,
impl<'d, Dm> UartRx<'d, Dm>where
Dm: DriverMode,
Sourcepub fn with_cts(self, cts: impl PeripheralInput<'d>) -> Self
pub fn with_cts(self, cts: impl PeripheralInput<'d>) -> Self
Assigns the CTS pin for UART instance.
Sets the specified pin to input and connects it to the UART CTS signal.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn with_rx(self, rx: impl PeripheralInput<'d>) -> Self
pub fn with_rx(self, rx: impl PeripheralInput<'d>) -> Self
Assigns the RX pin for UART instance.
Sets the specified pin to input and connects it to the UART RX signal.
When listening for the output of the UART peripheral, configure the driver side (the TX pin), or ensure that the line is initially high, to avoid receiving a non-data byte caused by an initial low signal level.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn is_break_detected(&self) -> bool
pub fn is_break_detected(&self) -> bool
Returns whether a break condition has been detected.
The returned status is sticky and remains set until
Self::clear_break_detected is called, or until one of the
wait_for_break methods observes and clears it.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn clear_break_detected(&mut self)
pub fn clear_break_detected(&mut self)
Clears the break-detection status.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>
pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>
Changes the configuration.
§Errors
ConfigError when the configuration is not supported by the hardware
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn enable_wakeup(
&mut self,
config: &WakeupConfig,
) -> Result<(), WakeConfigError>
pub fn enable_wakeup( &mut self, config: &WakeupConfig, ) -> Result<(), WakeConfigError>
Lets activity on the RX line wake the chip from light sleep.
The chip wakes when it counts the number of rising edges that
WakeupConfig::with_rising_edges gives. Deep sleep powers the UART down, so this source
ends a light sleep only.
The chip loses the bytes that cause the wake. It also loses the bytes that arrive during the wake, and at a typical baud rate that wake is long enough to lose several bytes. A sender must therefore first send data that the receiver can lose, and then send the data again. The first data after the wake also clears the internal wakeup indication. Without that write, the next wake occurs two edges early.
The peripheral counts the edges itself, so a light sleep keeps the high-performance peripherals powered instead of powering them down. This increases the sleep current.
The configuration stays after the driver is dropped, so that the UART continues to wake the
chip while no driver owns it. Call Self::disable_wakeup to remove it.
§Errors
WakeConfigError::NotAWakeupSource when this UART instance cannot wake the chip,
and WakeConfigError::EdgeCountUnsupported when the hardware cannot count the requested
number of edges.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn disable_wakeup(&mut self)
pub fn disable_wakeup(&mut self)
Stops the UART from waking the chip.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn check_for_errors(&mut self) -> Result<(), RxError>
pub fn check_for_errors(&mut self) -> Result<(), RxError>
Reads and clears RX error conditions set by received data.
Only errors enabled in RxConfig::with_reported_errors are returned;
disabled errors are cleared and ignored.
If a FIFO overflow is detected, the RX FIFO is reset.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn read_ready(&self) -> bool
pub fn read_ready(&self) -> bool
Returns whether the UART buffer has data.
If this function returns true, Self::read will not block.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn read(&mut self, buf: &mut [u8]) -> Result<usize, RxError>
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, RxError>
Reads bytes.
The UART hardware continuously receives bytes and stores them in the RX
FIFO. Reads the bytes from the RX FIFO and returns them in the provided
buffer. If the hardware buffer is empty, blocks until data is available.
Self::read_ready can be used to check if data is available without
blocking.
Returns the number of bytes read into the buffer. This may be less than the length of the buffer. Returns 0 only if the provided buffer is empty.
§Errors
RxError when a reported error occurred since
the last call to Self::check_for_errors, Self::read_buffered, or
this function.
If the error occurred before this function was called, the contents of the FIFO are not modified.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Sourcepub fn read_buffered(&mut self, buf: &mut [u8]) -> Result<usize, RxError>
pub fn read_buffered(&mut self, buf: &mut [u8]) -> Result<usize, RxError>
Reads already received bytes.
Reads the already received bytes from the FIFO into the provided buffer. Does not wait for the FIFO to actually contain any bytes.
Returns the number of bytes read into the buffer. This may be less than the length of the buffer, and it may also be 0.
§Errors
RxError when a reported error occurred since
the last call to Self::check_for_errors, Self::read, or this
function.
If the error occurred before this function was called, the contents of the FIFO are not modified.
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Trait Implementations§
Source§impl<Dm: DriverMode> ErrorType for UartRx<'_, Dm>
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl<Dm: DriverMode> ErrorType for UartRx<'_, Dm>
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§impl<Dm: DriverMode> ErrorType for UartRx<'_, Dm>
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl<Dm: DriverMode> ErrorType for UartRx<'_, Dm>
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§impl<Dm> Read for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl<Dm> Read for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read moreSource§impl<Dm> Read for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl<Dm> Read for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read moreSource§impl Read for UartRx<'_, Async>
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl Read for UartRx<'_, Async>
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§async fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read moreSource§impl Read for UartRx<'_, Async>
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl Read for UartRx<'_, Async>
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
Source§async fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read moreSource§impl<Dm> ReadReady for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl<Dm> ReadReady for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§impl<Dm> ReadReady for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl<Dm> ReadReady for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§impl<Dm> SetConfig for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
impl<Dm> SetConfig for UartRx<'_, Dm>where
Dm: DriverMode,
§Stability
This API is marked as unstable and is only available when the unstable
crate feature is enabled. This comes with no stability guarantees, and could be changed
or removed at any time.
Source§type ConfigError = ConfigError
type ConfigError = ConfigError
set_config fails.