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 split_ref(&mut self) -> (&mut UartTx<'d, M>, &mut UartRx<'d, M>)
pub fn split_ref(&mut self) -> (&mut UartTx<'d, M>, &mut UartRx<'d, M>)
Split the Uart into a transmitter and receiver by mutable reference, 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.