Struct esp_idf_svc::hal::uart::UartDriver
source · 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: 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<UartDriver<'d>, EspError>where
UART: Uart,
pub fn new<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<UartDriver<'d>, EspError>where
UART: Uart,
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<&UartDriver<'d>, EspError>
pub fn change_stop_bits( &self, stop_bits: StopBits, ) -> Result<&UartDriver<'d>, EspError>
Change the number of stop bits
sourcepub fn change_data_bits(
&self,
data_bits: DataBits,
) -> Result<&UartDriver<'d>, EspError>
pub fn change_data_bits( &self, data_bits: DataBits, ) -> Result<&UartDriver<'d>, EspError>
Change the number of data bits
sourcepub fn change_parity(&self, parity: Parity) -> Result<&UartDriver<'d>, EspError>
pub fn change_parity(&self, parity: Parity) -> Result<&UartDriver<'d>, EspError>
Change the type of parity checking
sourcepub fn change_baudrate<T>(
&self,
baudrate: T,
) -> Result<&UartDriver<'d>, EspError>where
T: Into<Hertz> + Copy,
pub fn change_baudrate<T>(
&self,
baudrate: T,
) -> Result<&UartDriver<'d>, EspError>where
T: Into<Hertz> + Copy,
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: u32) -> Result<usize, EspError>
pub fn read(&self, buf: &mut [u8], timeout: u32) -> 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: u32) -> Result<(), EspError>
pub fn wait_tx_done(&self, timeout: u32) -> Result<(), EspError>
Waits until the transmission is complete or until the specified timeout expires.
pub fn port(&self) -> u32
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<'d> Drop for UartDriver<'d>
impl<'d> Drop for UartDriver<'d>
source§impl<'d> ErrorType for UartDriver<'d>
impl<'d> ErrorType for UartDriver<'d>
§type Error = SerialError
type Error = SerialError
source§impl<'d> ErrorType for UartDriver<'d>
impl<'d> ErrorType for UartDriver<'d>
§type Error = EspIOError
type Error = EspIOError
source§impl<'d> Read<u8> for UartDriver<'d>
impl<'d> Read<u8> for UartDriver<'d>
§type Error = SerialError
type Error = SerialError
source§impl<'d> Read for UartDriver<'d>
impl<'d> Read for UartDriver<'d>
source§impl<'d> Read for UartDriver<'d>
impl<'d> Read for UartDriver<'d>
source§fn read(
&mut self,
buf: &mut [u8],
) -> Result<usize, <UartDriver<'d> as ErrorType>::Error>
fn read( &mut self, buf: &mut [u8], ) -> Result<usize, <UartDriver<'d> as ErrorType>::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