pub struct UartDriver<'d> { /* private fields */ }Expand description
Serial abstraction
Implementations§
Source§impl<'d> UartDriver<'d>
impl<'d> UartDriver<'d>
Sourcepub fn new<UART: Uart>(
uart: impl Peripheral<P = UART> + 'd,
tx: impl Peripheral<P = impl OutputPin> + 'd,
rx: impl Peripheral<P = impl InputPin> + 'd,
cts: Option<impl Peripheral<P = impl InputPin> + 'd>,
rts: Option<impl Peripheral<P = impl OutputPin> + 'd>,
config: &Config,
) -> Result<Self, EspError>
pub fn new<UART: Uart>( uart: impl Peripheral<P = UART> + 'd, tx: impl Peripheral<P = impl OutputPin> + 'd, rx: impl Peripheral<P = impl InputPin> + 'd, cts: Option<impl Peripheral<P = impl InputPin> + 'd>, rts: Option<impl Peripheral<P = impl OutputPin> + 'd>, config: &Config, ) -> Result<Self, EspError>
Create a new serial driver
Sourcepub fn event_queue(&self) -> Option<&Queue<UartEvent>>
pub fn event_queue(&self) -> Option<&Queue<UartEvent>>
Retrieves the event queue for this UART. Returns None if
the config specified 0 for queue_size.
Sourcepub fn change_stop_bits(&self, stop_bits: StopBits) -> Result<&Self, EspError>
pub fn change_stop_bits(&self, stop_bits: StopBits) -> Result<&Self, EspError>
Change the number of stop bits
Sourcepub fn change_data_bits(&self, data_bits: DataBits) -> Result<&Self, EspError>
pub fn change_data_bits(&self, data_bits: DataBits) -> Result<&Self, EspError>
Change the number of data bits
Sourcepub fn change_parity(&self, parity: Parity) -> Result<&Self, EspError>
pub fn change_parity(&self, parity: Parity) -> Result<&Self, EspError>
Change the type of parity checking
Sourcepub fn change_baudrate<T: Into<Hertz> + Copy>(
&self,
baudrate: T,
) -> Result<&Self, EspError>
pub fn change_baudrate<T: Into<Hertz> + Copy>( &self, baudrate: T, ) -> Result<&Self, EspError>
Change the baudrate.
Will automatically select the clock source. When possible the reference clock (1MHz) will be used, because this is constant when the clock source/frequency changes. However if one of the clock frequencies is below 10MHz or if the baudrate is above the reference clock or if the baudrate cannot be set within 1.5% then use the APB clock.
Sourcepub fn split(&mut self) -> (UartTxDriver<'_>, UartRxDriver<'_>)
pub fn split(&mut self) -> (UartTxDriver<'_>, UartRxDriver<'_>)
Split the serial driver in separate TX and RX drivers
Sourcepub fn into_split(self) -> (UartTxDriver<'d>, UartRxDriver<'d>)
pub fn into_split(self) -> (UartTxDriver<'d>, UartRxDriver<'d>)
Split the serial driver in separate TX and RX drivers.
Unlike [split], the halves are owned and reference counted.
Sourcepub fn read(
&self,
buf: &mut [u8],
timeout: TickType_t,
) -> Result<usize, EspError>
pub fn read( &self, buf: &mut [u8], timeout: TickType_t, ) -> Result<usize, EspError>
Read multiple bytes into a slice
Sourcepub fn write_nb(&self, bytes: &[u8]) -> Result<usize, EspError>
pub fn write_nb(&self, bytes: &[u8]) -> Result<usize, EspError>
Write multiple bytes from a slice directly to the TX FIFO hardware. Returns the number of bytes written, where 0 would mean that the TX FIFO is full.
NOTE: In case the UART TX buffer is enabled, this method might have unpredictable results
when used together with method write, as the latter will push the data to be sent to the
TX buffer first.
To avoid this, always call wait_done after the last call to write and before
calling this method.
Sourcepub fn flush_read(&self) -> Result<(), EspError>
👎Deprecated since 0.41.3: Use UartDriver::clear_rx instead
pub fn flush_read(&self) -> Result<(), EspError>
Clears the receive buffer.
Sourcepub fn flush_write(&self) -> Result<(), EspError>
👎Deprecated since 0.41.3: Use UartDriver::wait_tx_done instead
pub fn flush_write(&self) -> Result<(), EspError>
Waits for the transmission to complete.
Sourcepub fn wait_tx_done(&self, timeout: TickType_t) -> Result<(), EspError>
pub fn wait_tx_done(&self, timeout: TickType_t) -> Result<(), EspError>
Waits until the transmission is complete or until the specified timeout expires.
pub fn port(&self) -> uart_port_t
Sourcepub fn remaining_read(&self) -> Result<usize, EspError>
pub fn remaining_read(&self) -> Result<usize, EspError>
Get count of remaining bytes in the receive ring buffer
Sourcepub fn remaining_write(&self) -> Result<usize, EspError>
pub fn remaining_write(&self) -> Result<usize, EspError>
Get count of remaining capacity in the transmit ring buffer
Trait Implementations§
Source§impl Drop for UartDriver<'_>
impl Drop for UartDriver<'_>
Source§impl ErrorType for UartDriver<'_>
impl ErrorType for UartDriver<'_>
Source§type Error = EspIOError
type Error = EspIOError
Source§impl ErrorType for UartDriver<'_>
impl ErrorType for UartDriver<'_>
Source§type Error = SerialError
type Error = SerialError
Source§impl Read for UartDriver<'_>
impl Read for UartDriver<'_>
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 more