Skip to main content

Lpuart

Struct Lpuart 

pub struct Lpuart { /* private fields */ }
Expand description

LPUART peripheral.

Lpuart lets you configure the LPUART peripheral, and perform I/O. See the module-level documentation for an example.

Lpuart implements serial traits from embedded-hal. It models DMA transfers as futures. The type exposes a lower-level API for coordinating DMA transfers. However, you may find it easier to use the dma interface.

Implementations§

§

impl Lpuart

pub fn dma_write<'a>( &'a mut self, channel: &'a mut Channel, buffer: &'a [u8], ) -> Write<'a, Lpuart, u8>

Use a DMA channel to write data to the UART peripheral

Completes when all data in buffer has been written to the UART peripheral.

pub fn dma_read<'a>( &'a mut self, channel: &'a mut Channel, buffer: &'a mut [u8], ) -> Read<'a, Lpuart, u8>

Use a DMA channel to read data from the UART peripheral

Completes when buffer is filled.

§

impl Lpuart

pub fn with_pins<TX, RX, const N: u8>( lpuart: Instance<RegisterBlock, N>, pins: Pins<TX, RX>, ) -> Lpuart
where TX: Pin<Module = Const<N>, Direction = Tx>, RX: Pin<Module = Const<N>, Direction = Rx>,

Create a new LPUART peripheral from its peripheral registers and TX / RX pins.

When this call returns, the peripheral is reset, the pins are configured for their LPUART functions, and the TX and RX halves are enabled.

The pins are consumed to ensure they’re properly configured, but they are not stored in the driver.

pub fn without_pins<const N: u8>(lpuart: Instance<RegisterBlock, N>) -> Lpuart

Create a new LPUART peripheral from its peripheral registers without any pins.

This is similar to with_pins(), but it does not configure pins to function as inputs and outputs. You’re responsible for configuring TX and RX pins and for making sure the pin state doesn’t change.

pub fn is_enabled(&self, direction: Direction) -> bool

Indicates if the transmit / receive functions are (true) or are not (false) enabled.

pub fn set_enable(&mut self, direction: Direction, enable: bool)

Enable (true) or disable (false) the transmit / receive functions.

pub fn reset(&mut self)

Resets all internal logic and registers.

Note that this may not reset all peripheral state, like the state in the peripheral’s global register.

pub fn disable<R>(&mut self, func: impl FnOnce(&mut Disabled<'_>) -> R) -> R

Temporarily disable the LPUART peripheral.

The handle to a Disabled driver lets you modify LPUART settings that require a fully disabled peripheral. This will flush TX and RX buffers.

pub fn baud(&self) -> Baud

Return the baud-specific timing values for this UART peripheral.

pub fn parity(&self) -> Option<Parity>

Return the parity seting for the UART peripheral.

Result is None if there is no parity setting.

pub fn is_inverted(&self, direction: Direction) -> bool

Indicates if the bits are inverted.

pub fn is_fifo_enabled(&self, direction: Direction) -> bool

Indicates if the FIFO is enabled.

pub fn fifo_watermark(&self, direction: Direction) -> u32

Returns the FIFO watermark value.

pub fn read_data(&self) -> ReadData

Read the data register.

pub fn write_byte(&self, byte: u8)

Write a byte.

This does not perform any checks for space in the transmit buffer. To check transmit buffer space, use status, and check for the transmit data register empty.

pub fn status(&self) -> Status

Check the peripheral status register.

pub fn clear_status(&mut self, status: Status)

Clear the status flags.

Bits that are read-only will be cleared by the implementation, so it’s safe to call with Status::all().

pub fn flush_fifo(&mut self, direction: Direction)

Flush data from the FIFO.

This does not flush anything that’s already in the transmit or receive register.

pub fn interrupts(&self) -> Interrupts

Return the interrupt flags.

The interrupt flags indicate the reasons that this peripheral may generate an interrupt.

pub fn enable_dma_transmit(&mut self)

Let the peripheral act as a DMA destination.

After this call, the peripheral will signal to the DMA engine whenever it has free space in its transfer buffer.

pub fn disable_dma_transmit(&mut self)

Stop the peripheral from acting as a DMA destination.

See the DMA chapter in the reference manual to understand when this should be called in the DMA transfer lifecycle.

pub fn data(&self) -> *const RWRegister<u32>

Produces a pointer to the data register.

You should use this pointer when coordinating a DMA transfer. You’re not expected to read from this pointer in software.

pub fn enable_dma_receive(&mut self)

Let the peripheral act as a DMA source.

After this call, the peripheral will signal to the DMA engine whenever it has data available to read.

pub fn disable_dma_receive(&mut self)

Stop the peripheral from acting as a DMA source.

See the DMA chapter in the reference manual to understand when this should be called in the DMA transfer lifecycle.

pub fn try_write(&mut self, byte: u8) -> bool

Attempts to write a single byte to the bus.

Returns false if the fifo was already full.

pub fn try_read(&mut self) -> Result<Option<u8>, ReadFlags>

Attempts to read a single byte from the bus.

Returns:

  • Ok(Some(u8)) if data was read
  • Ok(None) if the fifo was empty
  • Err(..) if a read error happened

Trait Implementations§

§

impl Destination<u8> for Lpuart

§

fn destination_signal(&self) -> u32

Peripheral destination request signal Read more
§

fn destination_address(&self) -> *const u8

Returns a pointer to the register into which the DMA channel writes data Read more
§

fn enable_destination(&mut self)

Perform any actions necessary to enable DMA transfers Read more
§

fn disable_destination(&mut self)

Perform any actions necessary to disable or cancel DMA transfers Read more
§

impl ErrorType for Lpuart

§

type Error = ReadFlags

Error type of all the IO operations on this type.
§

impl Read for Lpuart

§

fn read( &mut self, buf: &mut [u8], ) -> Result<usize, <Lpuart as ErrorType>::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
§

fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
§

impl Read<u8> for Lpuart

§

type Error = ReadFlags

Read error
§

fn read(&mut self) -> Result<u8, Error<<Lpuart as Read<u8>>::Error>>

Reads a single word from the serial interface
§

impl ReadReady for Lpuart

§

fn read_ready(&mut self) -> Result<bool, <Lpuart as ErrorType>::Error>

Get whether the reader is ready for immediately reading. Read more
§

impl Source<u8> for Lpuart

§

fn source_signal(&self) -> u32

Peripheral source request signal Read more
§

fn source_address(&self) -> *const u8

Returns a pointer to the register from which the DMA channel reads data Read more
§

fn enable_source(&mut self)

Perform any actions necessary to enable DMA transfers Read more
§

fn disable_source(&mut self)

Perform any actions necessary to disable or cancel DMA transfers Read more
§

impl Write for Lpuart

§

fn write(&mut self, buf: &[u8]) -> Result<usize, <Lpuart as ErrorType>::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
§

fn flush(&mut self) -> Result<(), <Lpuart as ErrorType>::Error>

Flush this output stream, blocking until all intermediately buffered contents reach their destination.
§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more
§

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

Write a formatted string into this writer, returning any error encountered. Read more
§

impl Write<u8> for Lpuart

§

type Error = Infallible

Write error
§

fn write(&mut self, word: u8) -> Result<(), Error<<Lpuart as Write<u8>>::Error>>

Writes a single word to the serial interface
§

fn flush(&mut self) -> Result<(), Error<<Lpuart as Write<u8>>::Error>>

Ensures that none of the previously written words are still buffered
§

impl Write<u8> for Lpuart

§

type Error = Infallible

The type of error that can occur when writing
§

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

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

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

Block until the serial interface has sent all buffered words
§

impl WriteReady for Lpuart

§

fn write_ready(&mut self) -> Result<bool, <Lpuart as ErrorType>::Error>

Get whether the writer is ready for immediately writing. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Lpuart

§

impl !Sync for Lpuart

§

impl !UnwindSafe for Lpuart

§

impl Freeze for Lpuart

§

impl Send for Lpuart

§

impl Unpin for Lpuart

§

impl UnsafeUnpin for Lpuart

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.