pub struct Usart<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> { /* private fields */ }
Expand description

USART/Serial driver

Example

(This example is taken from Arduino Uno)

let dp = arduino_uno::Peripherals::take().unwrap();
let mut pins = arduino_uno::Pins::new(dp.PORTB, dp.PORTC, dp.PORTD);
let mut serial = arduino_uno::Serial::new(
    dp.USART0,
    pins.d0,
    pins.d1.into_output(&mut pins.ddr),
    57600.into_baudrate(),
);

ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap();

loop {
    let b = nb::block!(serial.read()).void_unwrap();
    ufmt::uwriteln!(&mut serial, "Got {}!\r", b).void_unwrap();
}

Implementations

Initialize a USART peripheral on the given pins.

Note that the RX and TX pins are hardwired for each USART peripheral and you must pass the correct ones. This is enforced at compile time.

Deinitialize/disable this peripheral and release the pins.

Block until all remaining data has been transmitted.

Transmit a byte.

This method will block until the byte has been enqueued for transmission but not until it was entirely sent.

Receive a byte.

This method will block until a byte could be received.

Enable the interrupt for Event.

Disable the interrupt for Event.

Split this USART into a UsartReader and a UsartWriter.

This allows concurrently receiving and transmitting data from different contexts.

Trait Implementations

Read error

Reads a single word from the serial interface

Write error

Writes a single word to the serial interface

Ensures that none of the previously written words are still buffered

The error associated to this writer

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

Writes a char into this writer, returning whether the write succeeded. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.