Struct UartRx

Source
pub struct UartRx<'d, Dm: DriverMode> { /* private fields */ }
Available on crate feature 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,

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source

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

pub fn into_async(self) -> UartRx<'d, Async>

Reconfigures the driver to operate in Async mode.

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

Source

pub fn into_blocking(self) -> UartRx<'d, Blocking>

Reconfigures the driver to operate in Blocking mode.

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

Source

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.

Source

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.

Source§

type Error = RxError

Error type of all the IO operations on this type.
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.

Source§

async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
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.

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
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.

Source§

fn read_ready(&mut self) -> Result<bool, Self::Error>

Get whether the reader is ready for immediately reading. Read more
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.

Source§

type Config = Config

The configuration type used by this driver.
Source§

type ConfigError = ConfigError

The error type that can occur if set_config fails.
Source§

fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError>

Set the configuration of the driver.

Auto Trait Implementations§

§

impl<'d, Dm> Freeze for UartRx<'d, Dm>

§

impl<'d, Dm> RefUnwindSafe for UartRx<'d, Dm>
where Dm: RefUnwindSafe,

§

impl<'d, Dm> Send for UartRx<'d, Dm>
where Dm: Send,

§

impl<'d, Dm> Sync for UartRx<'d, Dm>
where Dm: Sync,

§

impl<'d, Dm> Unpin for UartRx<'d, Dm>
where Dm: Unpin,

§

impl<'d, Dm> !UnwindSafe for UartRx<'d, Dm>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.