Struct avr_hal_generic::usart::Usart
source · 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").unwrap_infallible();
loop {
let b = nb::block!(serial.read()).unwrap_infallible();
ufmt::uwriteln!(&mut serial, "Got {}!\r", b).unwrap_infallible();
}
Implementations§
source§impl<H, USART, RXPIN, TXPIN, CLOCK> Usart<H, USART, Pin<Input, RXPIN>, Pin<Output, TXPIN>, CLOCK>
impl<H, USART, RXPIN, TXPIN, CLOCK> Usart<H, USART, Pin<Input, RXPIN>, Pin<Output, TXPIN>, CLOCK>
sourcepub fn new<IMODE: InputMode>(
p: USART,
rx: Pin<Input<IMODE>, RXPIN>,
tx: Pin<Output, TXPIN>,
baudrate: Baudrate<CLOCK>
) -> Self
pub fn new<IMODE: InputMode>( p: USART, rx: Pin<Input<IMODE>, RXPIN>, tx: Pin<Output, TXPIN>, baudrate: Baudrate<CLOCK> ) -> Self
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.
source§impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> Usart<H, USART, RX, TX, CLOCK>
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> Usart<H, USART, RX, TX, CLOCK>
sourcepub fn release(self) -> (USART, RX, TX)
pub fn release(self) -> (USART, RX, TX)
Deinitialize/disable this peripheral and release the pins.
sourcepub fn write_byte(&mut self, byte: u8)
pub fn write_byte(&mut self, byte: u8)
Transmit a byte.
This method will block until the byte has been enqueued for transmission but not until it was entirely sent.
sourcepub fn read_byte(&mut self) -> u8
pub fn read_byte(&mut self) -> u8
Receive a byte.
This method will block until a byte could be received.
sourcepub fn split(
self
) -> (UsartReader<H, USART, RX, TX, CLOCK>, UsartWriter<H, USART, RX, TX, CLOCK>)
pub fn split( self ) -> (UsartReader<H, USART, RX, TX, CLOCK>, UsartWriter<H, USART, RX, TX, CLOCK>)
Split this USART into a UsartReader
and a UsartWriter
.
This allows concurrently receiving and transmitting data from different contexts.
Trait Implementations§
source§impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> Read<u8> for Usart<H, USART, RX, TX, CLOCK>
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> Read<u8> for Usart<H, USART, RX, TX, CLOCK>
source§impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> Write<u8> for Usart<H, USART, RX, TX, CLOCK>
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> Write<u8> for Usart<H, USART, RX, TX, CLOCK>
source§impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> uWrite for Usart<H, USART, RX, TX, CLOCK>
impl<H, USART: UsartOps<H, RX, TX>, RX, TX, CLOCK> uWrite for Usart<H, USART, RX, TX, CLOCK>
Auto Trait Implementations§
impl<H, USART, RX, TX, CLOCK> Freeze for Usart<H, USART, RX, TX, CLOCK>
impl<H, USART, RX, TX, CLOCK> RefUnwindSafe for Usart<H, USART, RX, TX, CLOCK>where
CLOCK: RefUnwindSafe,
H: RefUnwindSafe,
RX: RefUnwindSafe,
TX: RefUnwindSafe,
USART: RefUnwindSafe,
impl<H, USART, RX, TX, CLOCK> Send for Usart<H, USART, RX, TX, CLOCK>
impl<H, USART, RX, TX, CLOCK> Sync for Usart<H, USART, RX, TX, CLOCK>
impl<H, USART, RX, TX, CLOCK> Unpin for Usart<H, USART, RX, TX, CLOCK>
impl<H, USART, RX, TX, CLOCK> UnwindSafe for Usart<H, USART, RX, TX, CLOCK>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more