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, Dm> UartRx<'d, Dm>where
Dm: DriverMode,
impl<'d, Dm> UartRx<'d, Dm>where
Dm: DriverMode,
Sourcepub fn with_cts(
self,
cts: impl Peripheral<P = impl PeripheralInput> + 'd,
) -> Self
pub fn with_cts( self, cts: impl Peripheral<P = impl PeripheralInput> + 'd, ) -> Self
Configure CTS pin
§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 Peripheral<P = impl PeripheralInput> + 'd) -> Self
pub fn with_rx(self, rx: impl Peripheral<P = 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 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.
§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, 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.
Source§impl<'d> UartRx<'d, Blocking>
impl<'d> UartRx<'d, Blocking>
Sourcepub fn new(
uart: impl Peripheral<P = impl Instance> + 'd,
config: Config,
) -> Result<Self, ConfigError>
pub fn new( uart: impl Peripheral<P = 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.
let rx = UartRx::new(
peripherals.UART1,
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.
Source§impl UartRx<'_, Async>
impl UartRx<'_, Async>
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.
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 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> 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.