pub struct USART<I, State> {
pub rx: Rx<I, State>,
pub tx: Tx<I, State, NoThrottle>,
/* private fields */
}Expand description
Interface to a USART peripheral
Controls the USART. Use Peripherals to gain access to an instance of
this struct.
You can either use this struct as-is, if you need to send and receive in the
same place, or you can move the rx and tx fields out of this struct, to
use the sender and receiver from different contexts.
Please refer to the module documentation for more information.
§embedded-hal traits
embedded_hal::serial::Readfor non-blocking readsembedded_hal::serial::Writefor non-blocking writesembedded_hal::blocking::serial::Writefor blocking writes
Fields§
§rx: Rx<I, State>The USART Receiver
tx: Tx<I, State, NoThrottle>The USART Transmitter
Implementations§
Source§impl<I> USART<I, Disabled>where
I: Instance,
impl<I> USART<I, Disabled>where
I: Instance,
Sourcepub fn enable_async<RxPin, TxPin, CLOCK, W>(
self,
clock: &Clock<CLOCK, AsyncMode>,
syscon: &mut Handle,
_: Function<I::Rx, Assigned<RxPin>>,
_: Function<I::Tx, Assigned<TxPin>>,
settings: Settings<W>,
) -> USART<I, Enabled<W, AsyncMode>>where
CLOCK: ClockSource,
W: Word,
pub fn enable_async<RxPin, TxPin, CLOCK, W>(
self,
clock: &Clock<CLOCK, AsyncMode>,
syscon: &mut Handle,
_: Function<I::Rx, Assigned<RxPin>>,
_: Function<I::Tx, Assigned<TxPin>>,
settings: Settings<W>,
) -> USART<I, Enabled<W, AsyncMode>>where
CLOCK: ClockSource,
W: Word,
Enable the USART in asynchronous mode
Asynchronous mode works without an external clock signal. The word “asynchronous” has no relation to blocking or non-blocking APIs, in this context.
This method is only available, if USART is in the Disabled state.
Code that attempts to call this method when the peripheral is already
enabled will not compile.
Consumes this instance of USART and returns another instance that has
its State type parameter set to Enabled.
§Limitations
For USART to function correctly, the UARTFRG reset must be cleared. This is the default, so unless you have messed with those settings, you should be good.
§Examples
Please refer to the module documentation for a full example.
Sourcepub fn enable_sync_as_master<RxPin, TxPin, SclkPin, C, W>(
self,
clock: &Clock<C, SyncMode>,
syscon: &mut Handle,
_: Function<I::Rx, Assigned<RxPin>>,
_: Function<I::Tx, Assigned<TxPin>>,
_: Function<I::Sclk, Assigned<SclkPin>>,
settings: Settings<W>,
) -> USART<I, Enabled<W, SyncMode>>where
C: ClockSource,
W: Word,
pub fn enable_sync_as_master<RxPin, TxPin, SclkPin, C, W>(
self,
clock: &Clock<C, SyncMode>,
syscon: &mut Handle,
_: Function<I::Rx, Assigned<RxPin>>,
_: Function<I::Tx, Assigned<TxPin>>,
_: Function<I::Sclk, Assigned<SclkPin>>,
settings: Settings<W>,
) -> USART<I, Enabled<W, SyncMode>>where
C: ClockSource,
W: Word,
Enable the USART in synchronous mode as master
Synchronous mode works with an external clock signal. The word “synchronous” has no relation to blocking or non-blocking APIs, in this context.
This method is only available, if USART is in the Disabled state.
Code that attempts to call this method when the peripheral is already
enabled will not compile.
Consumes this instance of USART and returns another instance that has
its State type parameter set to Enabled.
§Limitations
For USART to function correctly, the UARTFRG reset must be cleared. This is the default, so unless you have messed with those settings, you should be good.
Sourcepub fn enable_sync_as_slave<RxPin, TxPin, SclkPin, C, W>(
self,
_clock: &C,
syscon: &mut Handle,
_: Function<I::Rx, Assigned<RxPin>>,
_: Function<I::Tx, Assigned<TxPin>>,
_: Function<I::Sclk, Assigned<SclkPin>>,
settings: Settings<W>,
) -> USART<I, Enabled<W, SyncMode>>where
C: ClockSource,
W: Word,
pub fn enable_sync_as_slave<RxPin, TxPin, SclkPin, C, W>(
self,
_clock: &C,
syscon: &mut Handle,
_: Function<I::Rx, Assigned<RxPin>>,
_: Function<I::Tx, Assigned<TxPin>>,
_: Function<I::Sclk, Assigned<SclkPin>>,
settings: Settings<W>,
) -> USART<I, Enabled<W, SyncMode>>where
C: ClockSource,
W: Word,
Enable the USART in synchronous mode as slave
Synchronous mode works with an external clock signal. The word “synchronous” has no relation to blocking or non-blocking APIs, in this context.
This method is only available, if USART is in the Disabled state.
Code that attempts to call this method when the peripheral is already
enabled will not compile.
Consumes this instance of USART and returns another instance that has
its State type parameter set to Enabled.
§Limitations
For USART to function correctly, the UARTFRG reset must be cleared. This is the default, so unless you have messed with those settings, you should be good.
Source§impl<I, W, Mode> USART<I, Enabled<W, Mode>>
impl<I, W, Mode> USART<I, Enabled<W, Mode>>
Sourcepub fn is_flag_set(&self, flag: Flag) -> bool
pub fn is_flag_set(&self, flag: Flag) -> bool
Query whether the provided flag is set
Flags that need to be reset by software will be reset by this operation.
Sourcepub fn enable_in_nvic(&mut self)
pub fn enable_in_nvic(&mut self)
Enable interrupts for this instance in the NVIC
This only enables the interrupts in the NVIC. It doesn’t enable any specific interrupt in this USART instance.
Sourcepub fn disable_in_nvic(&mut self)
pub fn disable_in_nvic(&mut self)
Disable interrupts for this instance in the NVIC
This only disables the interrupts in the NVIC. It doesn’t change anything about the interrupt configuration within this USART instance.
Sourcepub fn clear_nvic_pending(&mut self)
pub fn clear_nvic_pending(&mut self)
Clear’s this instance’s interrupt pending flag in the NVIC
This only clears the interrupt’s pending flag in the NVIC. It does not affect any of the interrupt-related flags in the peripheral.
Sourcepub fn enable_interrupts(&mut self, interrupts: Interrupts)
pub fn enable_interrupts(&mut self, interrupts: Interrupts)
Enable interrupts
Enables all interrupts set to true in interrupts. Interrupts set to
false are not affected.
§Example
use lpc8xx_hal::usart;
// Enable only RXRDY and TXRDY, leave other interrupts untouched.
usart.enable_interrupts(usart::Interrupts {
RXRDY: true,
TXRDY: true,
.. usart::Interrupts::default()
});Sourcepub fn disable_interrupts(&mut self, interrupts: Interrupts)
pub fn disable_interrupts(&mut self, interrupts: Interrupts)
Disable interrupts
Disables all interrupts set to true in interrupts. Interrupts set to
false are not affected.
§Example
use lpc8xx_hal::usart;
// Disable only RXRDY and TXRDY, leave other interrupts untouched.
usart.disable_interrupts(usart::Interrupts {
RXRDY: true,
TXRDY: true,
.. usart::Interrupts::default()
});Source§impl<I, State> USART<I, State>where
I: Instance,
impl<I, State> USART<I, State>where
I: Instance,
Sourcepub fn free(self) -> I
pub fn free(self) -> I
Return the raw peripheral
This method serves as an escape hatch from the HAL API. It returns the raw peripheral, allowing you to do whatever you want with it, without limitations imposed by the API.
If you are using this method because a feature you need is missing from the HAL API, please open an issue or, if an issue for your feature request already exists, comment on the existing issue, so we can prioritize it accordingly.