Skip to main content

Uart

Struct Uart 

Source
pub struct Uart<'d, I: Instance, M: TransferMode> { /* private fields */ }
Expand description

UART driver, backed by a RingBuffer and 16-byte on-device FIFO buffer.

Implementations§

Source§

impl<'d, I: Instance> Uart<'d, I, Async>

Source

pub fn new_async<RxInt: InterruptType, TeInt: InterruptType, TxInt: InterruptType>( _peri: Peri<'d, I>, tx_pin: Peri<'d, impl TxPin<I>>, tx_buffer: &'d mut [u8], rx_pin: Peri<'d, impl RxPin<I>>, rx_buffer: &'d mut [u8], irqs: impl Binding<RxInt, RxInterruptHandler<I>> + Binding<TeInt, TeInterruptHandler<I>> + Binding<TxInt, TxInterruptHandler<I>> + 'd, config: Config, ) -> Self

Configures a new UART and returns the driver.

Source

pub async fn read(&self, buf: &mut [u8]) -> Result<usize, UartError>

Reads data from the UART.

§Returns

Returns when there is data in the RX RingBuffer. buf is not guaranteed to be full and the length of its contents is returned.

Source§

impl<'d, I: Instance> Uart<'d, I, Blocking>

Source

pub fn new_blocking( _peri: Peri<'d, I>, tx_pin: Peri<'d, impl TxPin<I>>, rx_pin: Peri<'d, impl RxPin<I>>, config: Config, ) -> Self

Configures a new UART and returns the driver.

Source

pub fn blocking_read(&self, data: &mut [u8])

Reads data from the UART, blocks until data is full.

Source

pub fn blocking_write(&mut self, data: &[u8])

Writes data to the UART, blocking until the last byte has been sent out on the wire.

Source§

impl<'d, I: Instance, M: TransferMode> Uart<'d, I, M>

Source

pub fn set_data_bits(&mut self, n: DataBits)

Sets the number of bits in a byte.

Note:

  • 9 bit data is supported by the underlying hardware but not yet by this driver.
  • This will disable the transmitter and temporarily disable the receiver (RA4M1 §28.2.9 note 4).
Source

pub fn set_parity(&mut self, parity: Parity)

Sets baud rate for the SCI instance.

Note: This will disable the transmitter and temporarily disable the receiver (§28.2.9 note 4).

Source

pub fn set_stop_bits(&mut self, stop_bits: StopBits)

Set stop bit length.

Note: This will disable the transmitter and temporarily disable the receiver (§28.2.9 note 4).

Source

pub fn set_baud_rate(&mut self, baud_rate: u32)

Sets baud rate for the SCI instance.

Note:

§Arguments
  • baud_rate - Desired baud rate.

Trait Implementations§

Source§

impl<'d, I: Instance, M: TransferMode> Drop for Uart<'d, I, M>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'d, I: Instance> ErrorType for Uart<'d, I, Async>

Source§

type Error = UartError

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

impl<'d, I: Instance> MutBlockingRx for Uart<'d, I, Blocking>

Source§

type Error = ()

The error type returned if a function fails.
Source§

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

Read a single octet from the port’s receiver, blocking until the octet can be read from the buffer. Read more
Source§

fn gets<I>(&mut self, buffer: &mut I) -> Result<(), (usize, Self::Error)>
where I: AsMut<[u8]> + ?Sized,

Read a specified number of octets into the given buffer, blocking until that many have been read. Read more
Source§

impl<'d, I: Instance> MutBlockingTx for Uart<'d, I, Blocking>

Source§

type Error = ()

The error type returned if a function fails.
Source§

fn putc(&mut self, ch: u8) -> Result<(), Self::Error>

Write a single octet to the port’s transmitter, blocking until the octet can be stored in the buffer (not necessarily that the octet has been transmitted). Read more
Source§

fn puts<I>(&mut self, data: &I) -> Result<(), (usize, Self::Error)>
where I: AsRef<[u8]> + ?Sized,

Write a complete string to the UART. If this returns Ok(()), all the data was sent. Otherwise you get number of octets sent and the error.
Source§

impl<'d, I: Instance> Read for Uart<'d, I, Async>

Source§

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

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

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

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

impl<'d, I: Instance> ReadReady for Uart<'d, I, Async>

Source§

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

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

impl<'d, I: Instance> Write for Uart<'d, I, Async>

Source§

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

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

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

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
Source§

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

Write an entire buffer into this writer. Read more

Auto Trait Implementations§

§

impl<'d, I, M> Forget for Uart<'d, I, M>

§

impl<'d, I, M> Freeze for Uart<'d, I, M>

§

impl<'d, I, M> Move for Uart<'d, I, M>

§

impl<'d, I, M> RefUnwindSafe for Uart<'d, I, M>

§

impl<'d, I, M> Send for Uart<'d, I, M>
where PhantomData<&'d I>: Send, M: Send,

§

impl<'d, I, M> Sync for Uart<'d, I, M>
where PhantomData<&'d I>: Sync, M: Sync,

§

impl<'d, I, M> Unpin for Uart<'d, I, M>

§

impl<'d, I, M> UnsafeUnpin for Uart<'d, I, M>

§

impl<'d, I, M> UnwindSafe for Uart<'d, I, M>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.