Struct stm32f1xx_hal::serial::Serial
source · pub struct Serial<USART, PINS> {
pub tx: Tx<USART>,
pub rx: Rx<USART>,
pub token: ReleaseToken<USART, PINS>,
}
Expand description
Serial abstraction
Fields§
§tx: Tx<USART>
§rx: Rx<USART>
§token: ReleaseToken<USART, PINS>
Implementations§
source§impl<USART: Instance, PINS> Serial<USART, PINS>
impl<USART: Instance, PINS> Serial<USART, PINS>
sourcepub fn new(
usart: USART,
pins: PINS,
mapr: &mut MAPR,
config: impl Into<Config>,
clocks: &Clocks
) -> Selfwhere
PINS: Pins<USART>,
pub fn new(
usart: USART,
pins: PINS,
mapr: &mut MAPR,
config: impl Into<Config>,
clocks: &Clocks
) -> Selfwhere
PINS: Pins<USART>,
Configures the serial interface and creates the interface struct.
Bps
is the baud rate of the interface.
Clocks
passes information about the current frequencies of
the clocks. The existence of the struct ensures that the
clock settings are fixed.
The serial
struct takes ownership over the USARTX
device
registers and the specified PINS
MAPR
and APBX
are register handles which are passed for
configuration. (MAPR
is used to map the USART to the
corresponding pins. APBX
is used to reset the USART.)
sourcepub fn reconfigure(
&mut self,
config: impl Into<Config>,
clocks: &Clocks
) -> Result<(), Infallible>
pub fn reconfigure(
&mut self,
config: impl Into<Config>,
clocks: &Clocks
) -> Result<(), Infallible>
Reconfigure the USART instance.
If a transmission is currently in progress, this returns
nb::Error::WouldBlock
.
sourcepub fn release(self) -> (USART, PINS)
pub fn release(self) -> (USART, PINS)
Returns ownership of the borrowed register handles
Examples
Basic usage:
let mut serial = Serial::new(usart, (tx_pin, rx_pin), &mut afio.mapr, 9600.bps(), &clocks);
// You can split the `Serial`
let Serial { tx, rx, token } = serial;
// You can reunite the `Serial` back
let serial = Serial { tx, rx, token };
// Release `Serial`
let (usart, (tx_pin, rx_pin)) = serial.release();
source§impl<USART: Instance, PINS> Serial<USART, PINS>
impl<USART: Instance, PINS> Serial<USART, PINS>
sourcepub fn listen(&mut self, event: Event)
pub fn listen(&mut self, event: Event)
Starts listening to the USART by enabling the Received data ready to be read (RXNE) interrupt and Transmit data register empty (TXE) interrupt
sourcepub fn unlisten(&mut self, event: Event)
pub fn unlisten(&mut self, event: Event)
Stops listening to the USART by disabling the Received data ready to be read (RXNE) interrupt and Transmit data register empty (TXE) interrupt
sourcepub fn is_tx_empty(&self) -> bool
pub fn is_tx_empty(&self) -> bool
Returns true if the tx register is empty (and can accept data)
sourcepub fn is_rx_not_empty(&self) -> bool
pub fn is_rx_not_empty(&self) -> bool
Returns true if the rx register is not empty (and can be read)
sourcepub fn clear_idle_interrupt(&self)
pub fn clear_idle_interrupt(&self)
Clear idle line interrupt flag