Skip to main content

UartRx

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> UartRx<'d, Blocking>

Source

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.

Source

pub fn wait_for_break(&mut self)

Waits for a break condition to be detected.

This function 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.

Source

pub fn wait_for_break_with_timeout(&mut self, timeout: Duration) -> bool

Waits for a break condition to be detected with a timeout.

This function polls the break-detection interrupt status until a break is detected or the specified timeout expires. Returns true if a break was detected, false if the timeout elapsed. 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

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

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.

Source

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,

Source

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.

Source

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.

Source

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.

Source

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.

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

Returns WakeConfigError::NotAWakeupSource if this UART instance cannot wake the chip, and WakeConfigError::EdgeCountUnsupported if 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.

Source

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.

Source

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.

Source

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.

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

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

Source§

type Error = RxError

Error type of all the IO operations on this type.
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 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> 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> 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> UnsafeUnpin for UartRx<'d, Dm>

§

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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.