pub struct UartRx<'d, T: Instance, M: Mode> { /* private fields */ }
Expand description
UART RX driver.
Implementations§
Source§impl<'d, T: Instance, M: Mode> UartRx<'d, T, M>
impl<'d, T: Instance, M: Mode> UartRx<'d, T, M>
Sourcepub fn new(
_uart: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>>,
rx_dma: impl Peripheral<P = impl Channel> + 'd,
config: Config,
) -> Self
pub fn new( _uart: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>>, rx_dma: impl Peripheral<P = impl Channel> + 'd, config: Config, ) -> Self
Create a new DMA-enabled UART which can only receive data
Source§impl<'d, T: Instance> UartRx<'d, T, Blocking>
impl<'d, T: Instance> UartRx<'d, T, Blocking>
Sourcepub fn new_blocking(
_uart: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
config: Config,
) -> Self
pub fn new_blocking( _uart: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, config: Config, ) -> Self
Create a new UART RX instance for blocking mode operations.
Sourcepub fn into_buffered(
self,
irq: impl Binding<T::Interrupt, BufferedInterruptHandler<T>>,
rx_buffer: &'d mut [u8],
) -> BufferedUartRx<'d, T>
pub fn into_buffered( self, irq: impl Binding<T::Interrupt, BufferedInterruptHandler<T>>, rx_buffer: &'d mut [u8], ) -> BufferedUartRx<'d, T>
Convert this uart RX instance into a buffered uart using the provided irq and receive buffer.
Source§impl<'d, T: Instance> UartRx<'d, T, Async>
impl<'d, T: Instance> UartRx<'d, T, Async>
Sourcepub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
Read from UART RX into the provided buffer.
Sourcepub async fn read_to_break(
&mut self,
buffer: &mut [u8],
) -> Result<usize, ReadToBreakError>
pub async fn read_to_break( &mut self, buffer: &mut [u8], ) -> Result<usize, ReadToBreakError>
Read from the UART, waiting for a line break.
We read until one of the following occurs:
- We read
buffer.len()
bytes without a line break- returns
Err(ReadToBreakError::MissingBreak(buffer.len()))
- returns
- We read
n
bytes then a line break occurs- returns
Ok(n)
- returns
- We encounter some error OTHER than a line break
- returns
Err(ReadToBreakError::Other(error))
- returns
NOTE: you MUST provide a buffer one byte larger than your largest expected
message to reliably detect the framing on one single call to read_to_break()
.
- If you expect a message of 20 bytes + line break, and provide a 20-byte buffer:
- The first call to
read_to_break()
will returnErr(ReadToBreakError::MissingBreak(20))
- The next call to
read_to_break()
will immediately returnOk(0)
, from the “stale” line break
- The first call to
- If you expect a message of 20 bytes + line break, and provide a 21-byte buffer:
- The first call to
read_to_break()
will returnOk(20)
. - The next call to
read_to_break()
will work as expected
- The first call to
Sourcepub async fn read_to_break_with_count(
&mut self,
buffer: &mut [u8],
min_count: usize,
) -> Result<usize, ReadToBreakError>
pub async fn read_to_break_with_count( &mut self, buffer: &mut [u8], min_count: usize, ) -> Result<usize, ReadToBreakError>
Read from the UART, waiting for a line break as soon as at least min_count
bytes have been read.
We read until one of the following occurs:
- We read
buffer.len()
bytes without a line break- returns
Err(ReadToBreakError::MissingBreak(buffer.len()))
- returns
- We read
n > min_count
bytes then a line break occurs- returns
Ok(n)
- returns
- We encounter some error OTHER than a line break
- returns
Err(ReadToBreakError::Other(error))
- returns
If a line break occurs before min_count
bytes have been read, the break will be ignored and the read will continue
NOTE: you MUST provide a buffer one byte larger than your largest expected
message to reliably detect the framing on one single call to read_to_break()
.
- If you expect a message of 20 bytes + line break, and provide a 20-byte buffer:
- The first call to
read_to_break()
will returnErr(ReadToBreakError::MissingBreak(20))
- The next call to
read_to_break()
will immediately returnOk(0)
, from the “stale” line break
- The first call to
- If you expect a message of 20 bytes + line break, and provide a 21-byte buffer:
- The first call to
read_to_break()
will returnOk(20)
. - The next call to
read_to_break()
will work as expected
- The first call to