Struct serpente::sercom::v2::uart::Config

source ·
pub struct Config<P, C = EightBit>where
    P: ValidPads,
    C: CharSize,{ /* private fields */ }
Expand description

A configurable, disabled UART peripheral

This struct represents a configurable UART peripheral in its disabled state. It is generic over the set of Pads and CharSize. Upon creation, the Config takes ownership of the Sercom and resets it, returning it configured as an UART peripheral with a default configuration:

  • EightBit
  • No parity
  • One stop bit
  • LSB-first

Config uses a builder-pattern API to configure the peripheral, culminating in a call to enable, which consumes the Config and returns enabled Uart. The enable method is restricted to ValidConfigs.

Implementations§

source§

impl<P> Config<P, EightBit>where P: ValidPads,

source

pub fn new( clk: &PM, sercom: <P as PadSet>::Sercom, pads: P, freq: impl Into<Hertz> ) -> Config<P, EightBit>

Create a new Config in the default configuration

This function will enable the corresponding APB clock, reset the Sercom peripheral, and return a Config in the default configuration:

Config takes ownership of the Sercom and Pads.

Users must configure GCLK manually. The freq parameter represents the GCLK frequency for this Sercom instance.

source§

impl<P, C> Config<P, C>where P: ValidPads, C: CharSize,

source

pub fn reset(self) -> Config<P, EightBit>

Trigger the Sercom’s SWRST and return a Config in the default configuration.

source

pub fn free(self) -> (<P as PadSet>::Sercom, P)

Consume the Config, reset the peripheral, and return the Sercom and Pads

source

pub fn char_size<C2>(self) -> Config<P, C2>where C2: FixedCharSize,

Change the CharSize.

source

pub fn dyn_char_size(self) -> Config<P, DynCharSize>

Change the CharSize to DynCharSize. The UART’s character size will be changed to the default CharSizeEnum::EightBit, and can then be changed dynamically on an enabled Uart without changing the underlying Config’s type through the [reconfigure](Uart:: reconfigure) method.

source

pub fn bit_order(self, bit_order: BitOrder) -> Config<P, C>

Change the bit order of transmission (builder pattern version)

source

pub fn set_bit_order(&mut self, bit_order: BitOrder)

Change the bit order of transmission (setter version)

source

pub fn get_bit_order(&self) -> BitOrder

Get the current bit order

source

pub fn parity(self, parity: Parity) -> Config<P, C>

Change the parity setting (builder pattern version)

source

pub fn set_parity(&mut self, parity: Parity)

Change the parity setting (setter version)

source

pub fn get_parity(&self) -> Parity

Get the current parity setting

source

pub fn stop_bits(self, stop_bits: StopBits) -> Config<P, C>

Change the stop bit setting (builder pattern version)

source

pub fn set_stop_bits(&mut self, stop_bits: StopBits)

Change the stop bit setting (setter version)

source

pub fn get_stop_bits(&self) -> StopBits

Get the current stop bit setting

source

pub fn start_of_frame_detection(self, enabled: bool) -> Config<P, C>

Enable or disable the start of frame detector (builder pattern version)

When set, the UART will generate interrupts for RXC and/or RXS if these interrupt flags have been enabled.

source

pub fn set_start_of_frame_detection(&mut self, enabled: bool)

Enable or disable the start of frame detector (setter version)

When set, the UART will generate interrupts for RXC and/or RXS if these interrupt flags have been enabled.

source

pub fn get_start_of_frame_detection(&self) -> bool

Get the current SOF detector setting

source

pub fn collision_detection(self, enabled: bool) -> Config<P, C>

Enable or disable the collision detector (builder pattern version)

When set, the UART will detect collisions and update the corresponding flag in the STATUS register.

source

pub fn set_collision_detection(&mut self, enabled: bool)

Enable or disable the collision detector (setter version)

When set, the UART will detect collisions and update the corresponding flag in the STATUS register.

source

pub fn get_collision_detection(&self) -> bool

Get the current collision detector setting

source

pub fn baud<B>(self, baud: B, mode: BaudMode) -> Config<P, C>where B: Into<Hertz>,

Set the baud rate (builder pattern version)

This function will calculate the best BAUD register setting based on the stored GCLK frequency and desired baud rate. The maximum baud rate is GCLK frequency/oversampling. Values outside this range will saturate at the maximum supported baud rate.

Note that 3x oversampling is not supported.

source

pub fn set_baud<B>(&mut self, baud: B, mode: BaudMode)where B: Into<Hertz>,

Set the baud rate (setter version)

This function will calculate the best BAUD register setting based on the stored GCLK frequency and desired baud rate. The maximum baud rate is GCLK frequency/oversampling. Values outside this range will saturate at the maximum supported baud rate.

Note that 3x oversampling is not supported.

source

pub fn get_baud(&self) -> (u16, BaudMode)

Get the contents of the BAUD register and the current baud mode. Note that only the CONTENTS of BAUD are returned, and not the actual baud rate. Refer to the datasheet to convert the BAUD register contents into a baud rate.

source

pub fn immediate_overflow_notification(self, set: bool) -> Config<P, C>

Control the buffer overflow notification (builder pattern version)

If set to true, an Error::Overflow will be issued as soon as an overflow occurs. Otherwise, it will not be issued until its place within the data stream.

source

pub fn set_immediate_overflow_notification(&mut self, set: bool)

Control the buffer overflow notification (setter version)

If set to true, an Error::Overflow will be issued as soon as an overflow occurs. Otherwise, it will not be issued until its place within the data stream.

source

pub fn get_immediate_overflow_notification(&self) -> bool

Get the current immediate overflow notification setting

source

pub fn run_in_standby(self, set: bool) -> Config<P, C>

Run in standby mode (builder pattern version)

When set, the UART peripheral will run in standby mode. See the datasheet for more details.

source

pub fn set_run_in_standby(&mut self, set: bool)

Run in standby mode (setter version)

When set, the UART peripheral will run in standby mode. See the datasheet for more details.

source

pub fn get_run_in_standby(&self) -> bool

Get the current run in standby mode

source

pub fn irda_encoding(self, pulse_length: Option<u8>) -> Config<P, C>

Enable or disable IrDA encoding (builder pattern version)

The pulse length controls the minimum pulse length that is required for a pulse to be accepted by the IrDA receiver with regards to the serial engine clock period. See datasheet for more information.

source

pub fn set_irda_encoding(&mut self, pulse_length: Option<u8>)

Enable or disable IrDA encoding (setter version)

The pulse length controls the minimum pulse length that is required for a pulse to be accepted by the IrDA receiver with regards to the serial engine clock period. See datasheet for more information.

source

pub fn get_irda_encoding(&self) -> Option<u8>

Get the current IrDA encoding setting. The return type is the pulse length wrapped in an Option.

source§

impl<P> Config<P, DynCharSize>where P: ValidPads,

source

pub fn set_dyn_char_size(&mut self, char_size: CharSizeEnum)

Dynamically change the character size

source

pub fn get_dyn_char_size(&self) -> CharSizeEnum

Get the current character size setting

source§

impl<P, C> Config<P, C>where P: ValidPads, C: CharSize, Config<P, C>: ValidConfig,

source

pub fn enable(self) -> Uart<Config<P, C>, <P as ValidPads>::Capability>

Enable the UART peripheral and return a Uart struct.

UART transactions are not possible until the peripheral is enabled. This method is limited to ValidConfigs

Trait Implementations§

source§

impl<P, C> AnyConfig for Config<P, C>where P: ValidPads, C: CharSize,

§

type Sercom = <P as PadSet>::Sercom

§

type Word = <C as CharSize>::Word

§

type Pads = P

§

type CharSize = C

source§

impl<P, C> AsMut<Config<P, C>> for Config<P, C>where P: ValidPads, C: CharSize,

source§

fn as_mut(&mut self) -> &mut Config<P, C>

Converts this type into a mutable reference of the (usually inferred) input type.
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<P, C> AsRef<Config<P, C>> for Config<P, C>where P: ValidPads, C: CharSize,

source§

fn as_ref(&self) -> &Config<P, C>

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

impl<P, C> ValidConfig for Config<P, C>where P: ValidPads, C: CharSize,

Auto Trait Implementations§

§

impl<P, C> RefUnwindSafe for Config<P, C>where C: RefUnwindSafe, P: RefUnwindSafe, <P as PadSet>::Sercom: RefUnwindSafe,

§

impl<P, C> Send for Config<P, C>where C: Send, P: Send, <P as PadSet>::Sercom: Send,

§

impl<P, C> Sync for Config<P, C>where C: Sync, P: Sync,

§

impl<P, C> Unpin for Config<P, C>where C: Unpin, P: Unpin, <P as PadSet>::Sercom: Unpin,

§

impl<P, C> UnwindSafe for Config<P, C>where C: UnwindSafe, P: UnwindSafe, <P as PadSet>::Sercom: 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> Is for Twhere T: Sealed + AsRef<T> + AsMut<T>,

§

type Type = T

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.