pub struct Uart<'d, M: Mode> { /* private fields */ }
Expand description
Bidirectional UART Driver, which acts as a combination of UartTx
and UartRx
.
§Notes on embedded_io::Read
embedded_io::Read
requires guarantees that the base UartRx
cannot provide.
See UartRx
for more details, and see BufferedUart
and RingBufferedUartRx
as alternatives that do provide the necessary guarantees for embedded_io::Read
.
Implementations§
source§impl<'d> Uart<'d, Async>
impl<'d> Uart<'d, Async>
sourcepub fn new<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd,
rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd,
config: Config,
) -> Result<Self, ConfigError>
pub fn new<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>
Create a new bidirectional UART
sourcepub fn new_with_rtscts<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd,
rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd,
config: Config,
) -> Result<Self, ConfigError>
pub fn new_with_rtscts<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, rts: impl Peripheral<P = impl RtsPin<T>> + 'd, cts: impl Peripheral<P = impl CtsPin<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>
Create a new bidirectional UART with request-to-send and clear-to-send pins
sourcepub fn new_with_de<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
de: impl Peripheral<P = impl DePin<T>> + 'd,
tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd,
rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd,
config: Config,
) -> Result<Self, ConfigError>
pub fn new_with_de<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, de: impl Peripheral<P = impl DePin<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>
Create a new bidirectional UART with a driver-enable pin
sourcepub fn new_half_duplex<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd,
rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd,
config: Config,
half_duplex: HalfDuplexConfig,
) -> Result<Self, ConfigError>
pub fn new_half_duplex<T: Instance>( peri: impl Peripheral<P = T> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, half_duplex: HalfDuplexConfig, ) -> Result<Self, ConfigError>
Create a single-wire half-duplex Uart transceiver on a single Tx pin.
See new_half_duplex_on_rx
if you would prefer to use an Rx pin
(when it is available for your chip). There is no functional difference between these methods, as both
allow bidirectional communication.
The TX pin is always released when no data is transmitted. Thus, it acts as a standard I/O in idle or in reception. It means that the I/O must be configured so that TX is configured as alternate function open-drain with an external pull-up Apart from this, the communication protocol is similar to normal USART mode. Any conflict on the line must be managed by software (for instance by using a centralized arbiter).
sourcepub fn new_half_duplex_on_rx<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
_irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd,
tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd,
rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd,
config: Config,
half_duplex: HalfDuplexConfig,
) -> Result<Self, ConfigError>
pub fn new_half_duplex_on_rx<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, half_duplex: HalfDuplexConfig, ) -> Result<Self, ConfigError>
Create a single-wire half-duplex Uart transceiver on a single Rx pin.
See new_half_duplex
if you would prefer to use an Tx pin.
There is no functional difference between these methods, as both allow bidirectional communication.
The pin is always released when no data is transmitted. Thus, it acts as a standard I/O in idle or in reception. Apart from this, the communication protocol is similar to normal USART mode. Any conflict on the line must be managed by software (for instance by using a centralized arbiter).
sourcepub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>
pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>
Perform an asynchronous write
source§impl<'d> Uart<'d, Blocking>
impl<'d> Uart<'d, Blocking>
sourcepub fn new_blocking<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
config: Config,
) -> Result<Self, ConfigError>
pub fn new_blocking<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>
Create a new blocking bidirectional UART.
sourcepub fn new_blocking_with_rtscts<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
rts: impl Peripheral<P = impl RtsPin<T>> + 'd,
cts: impl Peripheral<P = impl CtsPin<T>> + 'd,
config: Config,
) -> Result<Self, ConfigError>
pub fn new_blocking_with_rtscts<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, rts: impl Peripheral<P = impl RtsPin<T>> + 'd, cts: impl Peripheral<P = impl CtsPin<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>
Create a new bidirectional UART with request-to-send and clear-to-send pins
sourcepub fn new_blocking_with_de<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
de: impl Peripheral<P = impl DePin<T>> + 'd,
config: Config,
) -> Result<Self, ConfigError>
pub fn new_blocking_with_de<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, de: impl Peripheral<P = impl DePin<T>> + 'd, config: Config, ) -> Result<Self, ConfigError>
Create a new bidirectional UART with a driver-enable pin
sourcepub fn new_blocking_half_duplex<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
tx: impl Peripheral<P = impl TxPin<T>> + 'd,
config: Config,
half_duplex: HalfDuplexConfig,
) -> Result<Self, ConfigError>
pub fn new_blocking_half_duplex<T: Instance>( peri: impl Peripheral<P = T> + 'd, tx: impl Peripheral<P = impl TxPin<T>> + 'd, config: Config, half_duplex: HalfDuplexConfig, ) -> Result<Self, ConfigError>
Create a single-wire half-duplex Uart transceiver on a single Tx pin.
See new_half_duplex_on_rx
if you would prefer to use an Rx pin
(when it is available for your chip). There is no functional difference between these methods, as both
allow bidirectional communication.
The pin is always released when no data is transmitted. Thus, it acts as a standard I/O in idle or in reception. Apart from this, the communication protocol is similar to normal USART mode. Any conflict on the line must be managed by software (for instance by using a centralized arbiter).
sourcepub fn new_blocking_half_duplex_on_rx<T: Instance>(
peri: impl Peripheral<P = T> + 'd,
rx: impl Peripheral<P = impl RxPin<T>> + 'd,
config: Config,
half_duplex: HalfDuplexConfig,
) -> Result<Self, ConfigError>
pub fn new_blocking_half_duplex_on_rx<T: Instance>( peri: impl Peripheral<P = T> + 'd, rx: impl Peripheral<P = impl RxPin<T>> + 'd, config: Config, half_duplex: HalfDuplexConfig, ) -> Result<Self, ConfigError>
Create a single-wire half-duplex Uart transceiver on a single Rx pin.
See new_half_duplex
if you would prefer to use an Tx pin.
There is no functional difference between these methods, as both allow bidirectional communication.
The pin is always released when no data is transmitted. Thus, it acts as a standard I/O in idle or in reception. Apart from this, the communication protocol is similar to normal USART mode. Any conflict on the line must be managed by software (for instance by using a centralized arbiter).
source§impl<'d, M: Mode> Uart<'d, M>
impl<'d, M: Mode> Uart<'d, M>
sourcepub fn blocking_flush(&mut self) -> Result<(), Error>
pub fn blocking_flush(&mut self) -> Result<(), Error>
Block until transmission complete
sourcepub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
Perform a blocking read into buffer
sourcepub fn split(self) -> (UartTx<'d, M>, UartRx<'d, M>)
pub fn split(self) -> (UartTx<'d, M>, UartRx<'d, M>)
Split the Uart into a transmitter and receiver, which is particularly useful when having two tasks correlating to transmitting and receiving.
sourcepub fn send_break(&self)
pub fn send_break(&self)
Send break character
Trait Implementations§
source§impl<'d, M: Mode> SetConfig for Uart<'d, M>
impl<'d, M: Mode> SetConfig for Uart<'d, M>
source§type ConfigError = ConfigError
type ConfigError = ConfigError
set_config
fails.