Struct serpente::sercom::v2::uart::Uart

source ·
pub struct Uart<C, D>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.

  • Rx or RxDuplex: Can perform receive transactions
  • Tx or TxDuplex: Can perform transmit transactions
  • Duplex: Can perform receive and transmit transactions. Additionally, you can call split to return a (Uart<C, RxDuplex>, Uart<C, TxDuplex>) tuple.

Implementations§

source§

impl<C, D> Uart<C, D>where C: ValidConfig, D: Capability,

source

pub fn read_flags(&self) -> Flags

Read the interrupt flags

source

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 Receive capability: RXC, RXS, RXBRK and ERROR
  • Available flags for Transmit capability: DRE and TXC. Note: The CTSIC flag can only be cleared if a CTS Pad was specified in the Config via the clear_ctsic method.
  • Since Duplex Uarts are Receive + Transmit they have all flags available.

Warning: The implementation of of Write::flush waits on and clears the TXC flag. Manually clearing this flag could cause it to hang indefinitely.

source

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 Receive capability: RXC, RXS, RXBRK and ERROR
  • Available flags for Transmit capability: DRE and TXC. Note: The CTSIC interrupt can only be enabled if a CTS Pad was specified in the Config via the enable_ctsic method.
  • Since Duplex Uarts are Receive + Transmit they have all flags available.
source

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 Receive capability: RXC, RXS, RXBRK and ERROR
  • Available flags for Transmit capability: DRE and TXC. Note: The CTSIC interrupt can only be disabled if a CTS Pad was specified in the Config via the disable_ctsic method.
  • Since Duplex Uarts are Receive + Transmit they have all flags available.
source

pub fn read_status(&self) -> Status

Read the status flags

source

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> Uart<C, D>where C: ValidConfig, <<C as AnyConfig>::Pads as PadSet>::Cts: SomePad, D: Transmit,

source

pub fn clear_ctsic(&mut self)

Clear the CTSIC interrupt flag

source

pub fn enable_ctsic(&mut self)

Enable the CTSIC interrupt

source

pub fn disable_ctsic(&mut self)

Disable the CTSIC interrupt

source§

impl<C, D> Uart<C, D>where C: ValidConfig, D: Simplex,

source

pub fn disable(self) -> C

Disable the UART peripheral and return the underlying Config

source

pub fn reconfigure<U>(&mut self, update: U)where U: FnOnce(&mut Config<<C as AnyConfig>::Pads, <C as AnyConfig>::CharSize>),

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::v2::uart::{BaudMode, Oversampling, Uart};
uart.reconfigure(|c| c.set_run_in_standby(false));
source§

impl<C> Uart<C, Duplex>where C: ValidConfig,

source

pub fn split(self) -> (Uart<C, RxDuplex>, Uart<C, TxDuplex>)

Split the Uart into RxDuplex and TxDuplex halves

source

pub fn disable(self) -> C

Disable the UART peripheral and return the underlying Config

source

pub fn reconfigure<F>(&mut self, update: F)where F: FnOnce(&mut Config<<C as AnyConfig>::Pads, <C as AnyConfig>::CharSize>),

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::v2::uart::{BaudMode, Oversampling, Uart};
uart.reconfigure(|c| c.set_run_in_standby(false));
source

pub fn join(rx: Uart<C, RxDuplex>, _tx: Uart<C, TxDuplex>) -> Uart<C, Duplex>

Join RxDuplex and TxDuplex halves back into a full Uart<C, Duplex>

source§

impl<C, D> Uart<C, D>where C: ValidConfig, D: Receive, u16: AsPrimitive<<C as AnyConfig>::Word>,

source

pub unsafe fn read_data(&mut self) -> u16

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.

source

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> Uart<C, D>where C: ValidConfig, D: Transmit,

source

pub unsafe fn write_data(&mut self, data: u16)

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.

Trait Implementations§

source§

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) -> &Config<<C as AnyConfig>::Pads, <C as AnyConfig>::CharSize>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<C, D> Read<<C as AnyConfig>::Word> for Uart<C, D>where C: ValidConfig, D: Receive, u16: AsPrimitive<<C as AnyConfig>::Word>,

source§

fn read(&mut self) -> Result<<C as AnyConfig>::Word, Error<Error>>

Wait for an RXC flag, then read the word

§

type Error = Error

Read error
source§

impl<C, D> Write<<C as AnyConfig>::Word> for Uart<C, D>where C: ValidConfig, D: Transmit,

source§

fn write( &mut self, word: <C as AnyConfig>::Word ) -> Result<(), Error<<Uart<C, D> as Write<<C as AnyConfig>::Word>>::Error>>

Wait for a DRE flag, then write a word

source§

fn flush( &mut self ) -> Result<(), Error<<Uart<C, D> as Write<<C as AnyConfig>::Word>>::Error>>

Wait for a TXC flag

§

type Error = Infallible

Write error
source§

impl<C, D> Default<<C as AnyConfig>::Word> for Uart<C, D>where C: ValidConfig, D: Transmit, Uart<C, D>: Write<<C as AnyConfig>::Word>,

Auto Trait Implementations§

§

impl<C, D> RefUnwindSafe for Uart<C, D>where C: RefUnwindSafe, D: RefUnwindSafe,

§

impl<C, D> Send for Uart<C, D>where C: Send, D: Send,

§

impl<C, D> Sync for Uart<C, D>where C: Sync, D: Sync,

§

impl<C, D> Unpin for Uart<C, D>where C: Unpin, D: Unpin,

§

impl<C, D> UnwindSafe for Uart<C, D>where C: UnwindSafe, D: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.
source§

impl<S, Word> Write<Word> for Swhere S: Default<Word>, Word: Clone,

§

type Error = <S as Write<Word>>::Error

The type of error that can occur when writing
source§

fn bwrite_all( &mut self, buffer: &[Word] ) -> Result<(), <S as Write<Word>>::Error>

Writes a slice, blocking until everything has been written Read more
source§

fn bflush(&mut self) -> Result<(), <S as Write<Word>>::Error>

Block until the serial interface has sent all buffered words