pub struct Uart<C, D, RxDma = NoneT, TxDma = NoneT>where
C: ValidConfig,
D: Capability,{ /* private fields */ }Expand description
Abstraction over a UART peripheral, allowing to perform UART transactions.
The second type parameter, D, denotes what the struct’s Capability is.
Implementations§
Source§impl<C, D, S> Uart<C, D, NoneT, NoneT>
impl<C, D, S> Uart<C, D, NoneT, NoneT>
Sourcepub fn into_future<I>(self, _interrupts: I) -> UartFuture<C, D>
pub fn into_future<I>(self, _interrupts: I) -> UartFuture<C, D>
Turn a Uart into a UartFuture. This method is only available for
Uarts which have a Tx,
Rx or Duplex Capability.
Source§impl<C, D, R, T> Uart<C, D, R, T>where
C: ValidConfig,
D: Capability,
impl<C, D, R, T> Uart<C, D, R, T>where
C: ValidConfig,
D: Capability,
Sourcepub fn read_flags(&self) -> Flags
pub fn read_flags(&self) -> Flags
Read the interrupt flags
Sourcepub fn clear_flags(&mut self, flags: Flags)
pub fn clear_flags(&mut self, flags: Flags)
Clear interrupt status flags
Setting the ERROR, RXBRK, CTSIC, RXS, or TXC flag will clear
the interrupts. This function has no effect on the DRE or
RXC flags.
Note that only the flags pertinent to Self’s Capability
will be cleared. The other flags will be SILENTLY IGNORED.
- Available flags for
Receivecapability:RXC,RXS,RXBRKandERROR - Available flags for
Transmitcapability:DREandTXC. Note: TheCTSICflag can only be cleared if aCTSPad was specified in theConfigvia theclear_ctsicmethod. - Since
DuplexUarts areReceive+Transmitthey have all flags available.
Warning: The implementations of of
Write::flush waits on and
clears the TXC flag. Manually clearing this flag could cause it to
hang indefinitely.
Sourcepub fn enable_interrupts(&mut self, flags: Flags)
pub fn enable_interrupts(&mut self, flags: Flags)
Enable interrupts for the specified flags.
Note that only the flags pertinent to Self’s Capability
will be cleared. The other flags will be SILENTLY IGNORED.
- Available flags for
Receivecapability:RXC,RXS,RXBRKandERROR - Available flags for
Transmitcapability:DREandTXC. Note: TheCTSICinterrupt can only be enabled if aCTSPad was specified in theConfigvia theenable_ctsicmethod. - Since
DuplexUarts areReceive+Transmitthey have all flags available.
Sourcepub fn disable_interrupts(&mut self, flags: Flags)
pub fn disable_interrupts(&mut self, flags: Flags)
Disable interrupts for the specified flags.
Note that only the flags pertinent to Self’s Capability
will be cleared. The other flags will be SILENTLY IGNORED
- Available flags for
Receivecapability:RXC,RXS,RXBRKandERROR - Available flags for
Transmitcapability:DREandTXC. Note: TheCTSICinterrupt can only be disabled if aCTSPad was specified in theConfigvia thedisable_ctsicmethod. - Since
DuplexUarts areReceive+Transmitthey have all flags available.
Sourcepub fn read_status(&self) -> Status
pub fn read_status(&self) -> Status
Read the status flags
Sourcepub fn clear_status(&mut self, status: Status)
pub fn clear_status(&mut self, status: Status)
Clear the status flags
Note that only the status flags pertinent to Self’s Capability
will be cleared. The other stattus flags will be SILENTLY IGNORED.
Source§impl<C, D, R, T> Uart<C, D, R, T>
impl<C, D, R, T> Uart<C, D, R, T>
Sourcepub fn clear_ctsic(&mut self)
pub fn clear_ctsic(&mut self)
Clear the CTSIC interrupt flag
Sourcepub fn enable_ctsic(&mut self)
pub fn enable_ctsic(&mut self)
Enable the CTSIC interrupt
Sourcepub fn disable_ctsic(&mut self)
pub fn disable_ctsic(&mut self)
Disable the CTSIC interrupt
Source§impl<C, D, R, T> Uart<C, D, R, T>where
C: ValidConfig,
D: Simplex,
impl<C, D, R, T> Uart<C, D, R, T>where
C: ValidConfig,
D: Simplex,
Sourcepub fn reconfigure<U>(&mut self, update: U)where
U: FnOnce(&mut SpecificConfig<C>),
pub fn reconfigure<U>(&mut self, update: U)where
U: FnOnce(&mut SpecificConfig<C>),
Reconfigure the UART.
Calling this method will temporarily disable the SERCOM peripheral, as some registers are enable-protected. This may interrupt any ongoing transactions.
use atsamd_hal::sercom::uart::{BaudMode, Oversampling, Uart};
uart.reconfigure(|c| c.set_run_in_standby(false));Source§impl<C, D, T> Uart<C, D, NoneT, T>where
C: ValidConfig,
D: Capability,
impl<C, D, T> Uart<C, D, NoneT, T>where
C: ValidConfig,
D: Capability,
Sourcepub fn with_rx_channel<R: AnyChannel<Status = Ready>>(
self,
rx_channel: R,
) -> Uart<C, D, R, T>
pub fn with_rx_channel<R: AnyChannel<Status = Ready>>( self, rx_channel: R, ) -> Uart<C, D, R, T>
Source§impl<C, D, R> Uart<C, D, R, NoneT>where
C: ValidConfig,
D: Capability,
impl<C, D, R> Uart<C, D, R, NoneT>where
C: ValidConfig,
D: Capability,
Sourcepub fn with_tx_channel<T: AnyChannel<Status = Ready>>(
self,
tx_channel: T,
) -> Uart<C, D, R, T>
pub fn with_tx_channel<T: AnyChannel<Status = Ready>>( self, tx_channel: T, ) -> Uart<C, D, R, T>
Source§impl<C, D, R, T, S> Uart<C, D, R, T>
impl<C, D, R, T, S> Uart<C, D, R, T>
Sourcepub fn take_rx_channel(self) -> (Uart<C, D, NoneT, T>, R)
pub fn take_rx_channel(self) -> (Uart<C, D, NoneT, T>, R)
Reclaim the RX DMA channel. Subsequent RX operations will no longer use DMA.
Source§impl<C, D, R, T, S> Uart<C, D, R, T>
impl<C, D, R, T, S> Uart<C, D, R, T>
Sourcepub fn take_tx_channel(self) -> (Uart<C, D, R, NoneT>, T)
pub fn take_tx_channel(self) -> (Uart<C, D, R, NoneT>, T)
Reclaim the TX DMA channel. Subsequent TX operations will no longer use DMA.
Source§impl<C, R, T> Uart<C, Duplex, R, T>where
C: ValidConfig,
impl<C, R, T> Uart<C, Duplex, R, T>where
C: ValidConfig,
Sourcepub fn reconfigure<F>(&mut self, update: F)where
F: FnOnce(&mut SpecificConfig<C>),
pub fn reconfigure<F>(&mut self, update: F)where
F: FnOnce(&mut SpecificConfig<C>),
Update the UART Configuration.
Calling this method will temporarily disable the SERCOM peripheral, as some registers are enable-protected. This may interrupt any ongoing transactions.
use atsamd_hal::sercom::uart::{BaudMode, Oversampling, Uart};
uart.reconfigure(|c| c.set_run_in_standby(false));Source§impl<C, D, R, T> Uart<C, D, R, T>
impl<C, D, R, T> Uart<C, D, R, T>
Sourcepub unsafe fn read_data(&mut self) -> DataReg
pub unsafe fn read_data(&mut self) -> DataReg
Read from the DATA register
§Safety
Reading from the data register directly is unsafe, because it will
clear the RXC flag, which could break assumptions made elsewhere in
this module.
Sourcepub fn flush_rx_buffer(&mut self)
pub fn flush_rx_buffer(&mut self)
Flush the RX buffer and clear RX errors.
Note: The datasheet states that disabling the receiver (RXEN) clears the RX buffer, and clears the BUFOVF, PERR and FERR bits. However, in practice, it seems like BUFOVF errors still pop up after a disable/enable cycle of the receiver, then immediately begin reading bytes from the DATA register. Instead, this method uses a workaround, which reads a few bytes to clear the RX buffer (3 bytes seems to be the trick), then manually clear the error bits.
Source§impl<C, D, R, T> Uart<C, D, R, T>where
C: ValidConfig,
D: Transmit,
impl<C, D, R, T> Uart<C, D, R, T>where
C: ValidConfig,
D: Transmit,
Sourcepub unsafe fn write_data(&mut self, data: DataReg)
pub unsafe fn write_data(&mut self, data: DataReg)
Write to the DATA register
§Safety
Writing to the data register directly is unsafe, because it will clear
the DRE flag, which could break assumptions made elsewhere in this
module.
Source§impl<C, D> Uart<C, D>
impl<C, D> Uart<C, D>
Sourcepub fn receive_with_dma<Ch, B>(
self,
buf: B,
channel: Ch,
) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<Self, B>>
pub fn receive_with_dma<Ch, B>( self, buf: B, channel: Ch, ) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<Self, B>>
Transform an Uart into a DMA Transfer) and start reveiving into
the provided buffer.
In order to be (safely) non-blocking, his method has to take a 'static
buffer. If you’d rather use DMA with the blocking
embedded_io::Read trait, and avoid having
to use static buffers,
use Uart::with_rx_channel instead.
Source§impl<C, D> Uart<C, D>
impl<C, D> Uart<C, D>
Sourcepub fn send_with_dma<Ch, B>(
self,
buf: B,
channel: Ch,
) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<B, Self>>
pub fn send_with_dma<Ch, B>( self, buf: B, channel: Ch, ) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<B, Self>>
Transform an Uart into a DMA Transfer) and start sending the
provided buffer.
In order to be (safely) non-blocking, his method takes a 'static
buffer. If you’d rather use DMA with the blocking
embedded_io::Write trait, and avoid
having to use static buffers,
useUart::with_tx_channel instead.
Trait Implementations§
Source§impl<C, D, R, T, S> AsMut<Uart<C, D, R, T>> for UartFuture<C, D, R, T>
impl<C, D, R, T, S> AsMut<Uart<C, D, R, T>> for UartFuture<C, D, R, T>
Source§impl<C: ValidConfig, R, T> AsMut<Uart<C, Duplex, R, T>> for (&mut Uart<C, RxDuplex, R, NoneT>, &mut Uart<C, TxDuplex, NoneT, T>)
impl<C: ValidConfig, R, T> AsMut<Uart<C, Duplex, R, T>> for (&mut Uart<C, RxDuplex, R, NoneT>, &mut Uart<C, TxDuplex, NoneT, T>)
Source§impl<C, D> AsRef<Config<<C as AnyConfig>::Pads, <C as AnyConfig>::CharSize>> for Uart<C, D>where
C: ValidConfig,
D: Capability,
impl<C, D> AsRef<Config<<C as AnyConfig>::Pads, <C as AnyConfig>::CharSize>> for Uart<C, D>where
C: ValidConfig,
D: Capability,
Source§fn as_ref(&self) -> &SpecificConfig<C>
fn as_ref(&self) -> &SpecificConfig<C>
Source§impl<C, D, R, T, S> AsRef<Uart<C, D, R, T>> for UartFuture<C, D, R, T>
impl<C, D, R, T, S> AsRef<Uart<C, D, R, T>> for UartFuture<C, D, R, T>
Source§impl<C, D> Buffer for Uart<C, D>
impl<C, D> Buffer for Uart<C, D>
Source§fn dma_ptr(&mut self) -> *mut Self::Beat
fn dma_ptr(&mut self) -> *mut Self::Beat
Source§fn incrementing(&self) -> bool
fn incrementing(&self) -> bool
Source§fn buffer_len(&self) -> usize
fn buffer_len(&self) -> usize
Source§impl<C, D, R, T> ErrorType for Uart<C, D, R, T>where
C: ValidConfig,
D: Capability,
impl<C, D, R, T> ErrorType for Uart<C, D, R, T>where
C: ValidConfig,
D: Capability,
Source§impl<P, D, T> Read for Uart<Config<P, EightBit>, D, NoneT, T>
impl<P, D, T> Read for Uart<Config<P, EightBit>, D, NoneT, T>
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<P, D, R, T, S> Read for Uart<Config<P, EightBit>, D, R, T>
impl<P, D, R, T, S> Read for Uart<Config<P, EightBit>, D, R, T>
Source§fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, buffer: &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 more