Struct rp2040_hal::uart::UartPeripheral
source · pub struct UartPeripheral<S: State, D: UartDevice, P: ValidUartPinout<D>> { /* private fields */ }
Expand description
An UART Peripheral based on an underlying UART device.
Implementations§
source§impl<S: State, D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<S, D, P>
impl<S: State, D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<S, D, P>
source§impl<D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<Disabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<Disabled, D, P>
sourcepub fn new(
device: D,
pins: P,
resets: &mut RESETS
) -> UartPeripheral<Disabled, D, P>
pub fn new( device: D, pins: P, resets: &mut RESETS ) -> UartPeripheral<Disabled, D, P>
Creates an UartPeripheral in Disabled state.
sourcepub fn enable(
self,
config: UartConfig,
frequency: HertzU32
) -> Result<UartPeripheral<Enabled, D, P>, Error>
pub fn enable( self, config: UartConfig, frequency: HertzU32 ) -> Result<UartPeripheral<Enabled, D, P>, Error>
Enables the provided UART device with the given configuration.
source§impl<D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<Enabled, D, P>
sourcepub fn disable(self) -> UartPeripheral<Disabled, D, P>
pub fn disable(self) -> UartPeripheral<Disabled, D, P>
Disable this UART Peripheral, falling back to the Disabled state.
sourcepub fn set_fifos(&mut self, enable: bool)
pub fn set_fifos(&mut self, enable: bool)
Enable/disable the rx/tx FIFO
Unfortunately, it’s not possible to enable/disable rx/tx independently on this chip Default is false
sourcepub fn set_rx_watermark(&mut self, watermark: FifoWatermark)
pub fn set_rx_watermark(&mut self, watermark: FifoWatermark)
Set rx FIFO watermark
See DS: Table 423
sourcepub fn set_tx_watermark(&mut self, watermark: FifoWatermark)
pub fn set_tx_watermark(&mut self, watermark: FifoWatermark)
Set tx FIFO watermark
See DS: Table 423
sourcepub fn enable_rx_interrupt(&mut self)
pub fn enable_rx_interrupt(&mut self)
Enables the Receive Interrupt.
The relevant UARTx IRQ will fire when there is data in the receive register.
sourcepub fn enable_tx_interrupt(&mut self)
pub fn enable_tx_interrupt(&mut self)
Enables the Transmit Interrupt.
The relevant UARTx IRQ will fire when there is space in the transmit FIFO.
sourcepub fn disable_rx_interrupt(&mut self)
pub fn disable_rx_interrupt(&mut self)
Disables the Receive Interrupt.
sourcepub fn disable_tx_interrupt(&mut self)
pub fn disable_tx_interrupt(&mut self)
Disables the Transmit Interrupt.
sourcepub fn uart_is_writable(&self) -> bool
pub fn uart_is_writable(&self) -> bool
Is there space in the UART TX FIFO for new data to be written?
sourcepub fn uart_is_busy(&self) -> bool
pub fn uart_is_busy(&self) -> bool
Is the UART still busy transmitting data?
sourcepub fn uart_is_readable(&self) -> bool
pub fn uart_is_readable(&self) -> bool
Is there data in the UART RX FIFO ready to be read?
sourcepub fn write_raw<'d>(&self, data: &'d [u8]) -> Result<&'d [u8], Infallible>
pub fn write_raw<'d>(&self, data: &'d [u8]) -> Result<&'d [u8], Infallible>
Writes bytes to the UART. This function writes as long as it can. As soon that the FIFO is full, if :
- 0 bytes were written, a WouldBlock Error is returned
- some bytes were written, it is deemed to be a success Upon success, the remaining slice is returned.
sourcepub fn read_raw<'b>(&self, buffer: &'b mut [u8]) -> Result<usize, ReadError<'b>>
pub fn read_raw<'b>(&self, buffer: &'b mut [u8]) -> Result<usize, ReadError<'b>>
Reads bytes from the UART. This function reads as long as it can. As soon that the FIFO is empty, if :
- 0 bytes were read, a WouldBlock Error is returned
- some bytes were read, it is deemed to be a success Upon success, it will return how many bytes were read.
sourcepub fn write_full_blocking(&self, data: &[u8])
pub fn write_full_blocking(&self, data: &[u8])
Writes bytes to the UART. This function blocks until the full buffer has been sent.
sourcepub fn read_full_blocking(&self, buffer: &mut [u8]) -> Result<(), ReadErrorType>
pub fn read_full_blocking(&self, buffer: &mut [u8]) -> Result<(), ReadErrorType>
Reads bytes from the UART. This function blocks until the full buffer has been received.
sourcepub fn lowlevel_break_start(&mut self)
pub fn lowlevel_break_start(&mut self)
Initiates a break
If transmitting, this takes effect immediately after the current byte has completed.
For proper execution of the break command, this must be held for at least 2 complete frames
worth of time.
§Example
serial.lowlevel_break_start();
// at 115_200Bps on 8N1 configuration, 20bits takes (20*10⁶)/115200 = 173.611…μs.
timer.delay_us(175);
serial.lowlevel_break_stop();
sourcepub fn lowlevel_break_stop(&mut self)
pub fn lowlevel_break_stop(&mut self)
Terminates a break condition.
See lowlevel_break_start
for more details.
source§impl<P: ValidUartPinout<UART0>> UartPeripheral<Enabled, UART0, P>
impl<P: ValidUartPinout<UART0>> UartPeripheral<Enabled, UART0, P>
Trait Implementations§
source§impl<D: UartDevice, P: ValidUartPinout<D>> ErrorType for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> ErrorType for UartPeripheral<Enabled, D, P>
§type Error = ReadErrorType
type Error = ReadErrorType
source§impl<D: UartDevice, P: ValidUartPinout<D>> ErrorType for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> ErrorType for UartPeripheral<Enabled, D, P>
§type Error = ReadErrorType
type Error = ReadErrorType
source§impl<D: UartDevice, P: ValidUartPinout<D>> Read for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> Read for UartPeripheral<Enabled, D, P>
source§impl<D: UartDevice, P: ValidUartPinout<D>> Read for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> Read for UartPeripheral<Enabled, D, P>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
source§fn read_exact(
&mut self,
buf: &mut [u8]
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8] ) -> Result<(), ReadExactError<Self::Error>>
buf
. Read moresource§impl<D: UartDevice, P: ValidUartPinout<D>> Write for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> Write for UartPeripheral<Enabled, D, P>
source§impl<D: UartDevice, P: ValidUartPinout<D>> Write for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> Write for UartPeripheral<Enabled, D, P>
source§fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>
source§fn flush(&mut self) -> Result<(), Self::Error>
fn flush(&mut self) -> Result<(), Self::Error>
source§impl<D: UartDevice, P: ValidUartPinout<D>> Write for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> Write for UartPeripheral<Enabled, D, P>
source§impl<D: UartDevice, P: ValidUartPinout<D>> Read<u8> for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> Read<u8> for UartPeripheral<Enabled, D, P>
source§impl<D: UartDevice, P: ValidUartPinout<D>> Write<u8> for UartPeripheral<Enabled, D, P>
impl<D: UartDevice, P: ValidUartPinout<D>> Write<u8> for UartPeripheral<Enabled, D, P>
Auto Trait Implementations§
impl<S, D, P> Freeze for UartPeripheral<S, D, P>
impl<S, D, P> RefUnwindSafe for UartPeripheral<S, D, P>
impl<S, D, P> Send for UartPeripheral<S, D, P>
impl<S, D, P> Sync for UartPeripheral<S, D, P>
impl<S, D, P> Unpin for UartPeripheral<S, D, P>
impl<S, D, P> UnwindSafe for UartPeripheral<S, D, P>
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
source§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more