USART

Struct USART 

Source
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

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,

Source

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.

Source

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.

Source

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>>
where I: Instance, W: Word,

Source

pub fn disable(self, syscon: &mut Handle) -> USART<I, Disabled>

Disable the USART

This method is only available, if USART is in the Enabled state. Code that attempts to call this method when the peripheral is already disabled will not compile.

Consumes this instance of USART and returns another instance that has its State type parameter set to Disabled.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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()
});
Source

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,

Source

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.

Trait Implementations§

Source§

impl<I, Mode> Write for USART<I, Enabled<u8, Mode>>
where Self: BlockingWriteDefault<u8>, I: Instance,

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded.

1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more
Source§

impl<I, W, Mode> Read<W> for USART<I, Enabled<W, Mode>>
where I: Instance, W: Word,

Source§

fn read(&mut self) -> Result<W, Self::Error>

Reads a single word from the serial interface

Source§

type Error = Error<W>

Read error
Source§

impl<I, W, Mode> Write<W> for USART<I, Enabled<W, Mode>>
where I: Instance, W: Word,

Source§

fn write(&mut self, word: W) -> Result<(), Self::Error>

Writes a single word to the serial interface

Source§

fn flush(&mut self) -> Result<(), Self::Error>

Ensures that none of the previously written words are still buffered

Source§

type Error = Void

Write error
Source§

impl<I, W, Mode> Default<W> for USART<I, Enabled<W, Mode>>
where I: Instance, W: Word,

Auto Trait Implementations§

§

impl<I, State> Freeze for USART<I, State>
where I: Freeze,

§

impl<I, State> RefUnwindSafe for USART<I, State>
where I: RefUnwindSafe, State: RefUnwindSafe,

§

impl<I, State> Send for USART<I, State>
where I: Send, State: Send,

§

impl<I, State> Sync for USART<I, State>
where I: Sync, State: Sync,

§

impl<I, State> Unpin for USART<I, State>
where I: Unpin, State: Unpin,

§

impl<I, State> UnwindSafe for USART<I, State>
where I: UnwindSafe, State: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, Word> Write<Word> for S
where S: Default<Word>, Word: Clone,

Source§

type Error = <S as Write<Word>>::Error

The type of error that can occur when writing
Source§

fn bwrite_all( &mut self, buffer: &[Word], ) -> Result<(), <S as Write<Word>>::Error>

Writes a slice, blocking until everything has been written Read more
Source§

fn bflush(&mut self) -> Result<(), <S as Write<Word>>::Error>

Block until the serial interface has sent all buffered words