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>
Create a new UART RX instance in Blocking mode.
§Errors
This function returns a ConfigError if the configuration is not
supported by the hardware.
use esp_hal::uart::{Config, UartRx};
let rx = UartRx::new(peripherals.UART0, Config::default())?.with_rx(peripherals.GPIO2);§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.
This is a blocking function that will continuously check for a break condition. 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.
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.
This is a blocking function that will check for a break condition up to
the specified timeout. Returns true if a break was detected, false if
the timeout elapsed. After successful detection, the break interrupt flag
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>
Read data asynchronously.
This function reads data from the UART receive buffer into the provided buffer. If the buffer is empty, the function waits asynchronously for data to become available, or for an error to occur.
The function returns the number of bytes read into the buffer. This may be less than the length of the buffer.
Note that this function 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, the function returns immediately and the contents of the internal FIFO are not modified.
§Cancellation
This function is 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>
Fill buffer asynchronously.
This function reads data into the provided buffer. If the internal FIFO does not contain enough data, the function waits asynchronously for data to become available, or for an error to occur.
Note that this function may ignore the rx_fifo_full_threshold setting
to ensure that it does not wait for more data than the buffer can hold.
§Cancellation
This function is 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
Assign 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
Assign the RX pin for UART instance.
Sets the specified pin to input and connects it to the UART RX signal.
Note: when you listen for the output of the UART peripheral, you should configure the driver side (i.e. 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 enable_break_detection(&mut self)
pub fn enable_break_detection(&mut self)
Enable break detection.
This must be called before any breaks are expected to be received.
Break detection is enabled automatically by Self::wait_for_break
and Self::wait_for_break_with_timeout, but calling this method
explicitly ensures that breaks occurring before the first wait call
will be reliably detected.
§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>
Change the configuration.
§Errors
This function returns a ConfigError if 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 check_for_errors(&mut self) -> Result<(), RxError>
pub fn check_for_errors(&mut self) -> Result<(), RxError>
Reads and clears errors set by received data.
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>
Read bytes.
The UART hardware continuously receives bytes and stores them in the RX
FIFO. This function reads the bytes from the RX FIFO and returns
them in the provided buffer. If the hardware buffer is empty, this
function will block until data is available. The Self::read_ready
function can be used to check if data is available without blocking.
The function returns the number of bytes read into the buffer. This may be less than the length of the buffer. This function only returns 0 if the provided buffer is empty.
§Errors
This function returns an RxError if an 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>
Read already received bytes.
This function reads the already received bytes from the FIFO into the provided buffer. The function does not wait for the FIFO to actually contain any bytes.
The function 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
This function returns an RxError if an 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 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> 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<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§fn read_ready(&mut self) -> Result<bool, Self::Error>
fn read_ready(&mut self) -> Result<bool, Self::Error>
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§fn read_ready(&mut self) -> Result<bool, Self::Error>
fn read_ready(&mut self) -> Result<bool, Self::Error>
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.