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 ValidConfig
s.
Implementations
sourceimpl<P: ValidPads> Config<P>
impl<P: ValidPads> Config<P>
sourcepub fn new(clk: &Clock, sercom: P::Sercom, pads: P, freq: impl Into<Hertz>) -> Self
pub fn new(clk: &Clock, sercom: P::Sercom, pads: P, freq: impl Into<Hertz>) -> Self
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.
sourceimpl<P, C> Config<P, C>where
P: ValidPads,
C: CharSize,
impl<P, C> Config<P, C>where
P: ValidPads,
C: CharSize,
sourcepub fn char_size<C2: FixedCharSize>(self) -> Config<P, C2>
pub fn char_size<C2: FixedCharSize>(self) -> Config<P, C2>
Change the CharSize
.
sourcepub fn dyn_char_size(self) -> Config<P, DynCharSize>
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
method.
sourcepub fn bit_order(self, bit_order: BitOrder) -> Self
pub fn bit_order(self, bit_order: BitOrder) -> Self
Change the bit order of transmission (builder pattern version)
sourcepub fn set_bit_order(&mut self, bit_order: BitOrder)
pub fn set_bit_order(&mut self, bit_order: BitOrder)
Change the bit order of transmission (setter version)
sourcepub fn get_bit_order(&self) -> BitOrder
pub fn get_bit_order(&self) -> BitOrder
Get the current bit order
sourcepub fn parity(self, parity: Parity) -> Self
pub fn parity(self, parity: Parity) -> Self
Change the parity setting (builder pattern version)
sourcepub fn set_parity(&mut self, parity: Parity)
pub fn set_parity(&mut self, parity: Parity)
Change the parity setting (setter version)
sourcepub fn get_parity(&self) -> Parity
pub fn get_parity(&self) -> Parity
Get the current parity setting
sourcepub fn stop_bits(self, stop_bits: StopBits) -> Self
pub fn stop_bits(self, stop_bits: StopBits) -> Self
Change the stop bit setting (builder pattern version)
sourcepub fn set_stop_bits(&mut self, stop_bits: StopBits)
pub fn set_stop_bits(&mut self, stop_bits: StopBits)
Change the stop bit setting (setter version)
sourcepub fn get_stop_bits(&self) -> StopBits
pub fn get_stop_bits(&self) -> StopBits
Get the current stop bit setting
sourcepub fn start_of_frame_detection(self, enabled: bool) -> Self
pub fn start_of_frame_detection(self, enabled: bool) -> Self
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.
sourcepub fn set_start_of_frame_detection(&mut self, enabled: bool)
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.
sourcepub fn get_start_of_frame_detection(&self) -> bool
pub fn get_start_of_frame_detection(&self) -> bool
Get the current SOF detector setting
sourcepub fn collision_detection(self, enabled: bool) -> Self
pub fn collision_detection(self, enabled: bool) -> Self
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.
sourcepub fn set_collision_detection(&mut self, enabled: bool)
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.
sourcepub fn get_collision_detection(&self) -> bool
pub fn get_collision_detection(&self) -> bool
Get the current collision detector setting
sourcepub fn baud<B: Into<Hertz>>(self, baud: B, mode: BaudMode) -> Self
pub fn baud<B: Into<Hertz>>(self, baud: B, mode: BaudMode) -> Self
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.
sourcepub fn set_baud<B: Into<Hertz>>(&mut self, baud: B, mode: BaudMode)
pub fn set_baud<B: Into<Hertz>>(&mut self, baud: B, mode: BaudMode)
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.
sourcepub fn get_baud(&self) -> (u16, BaudMode)
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.
sourcepub fn immediate_overflow_notification(self, set: bool) -> Self
pub fn immediate_overflow_notification(self, set: bool) -> Self
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.
sourcepub fn set_immediate_overflow_notification(&mut self, set: bool)
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.
sourcepub fn get_immediate_overflow_notification(&self) -> bool
pub fn get_immediate_overflow_notification(&self) -> bool
Get the current immediate overflow notification setting
sourcepub fn run_in_standby(self, set: bool) -> Self
pub fn run_in_standby(self, set: bool) -> Self
Run in standby mode (builder pattern version)
When set, the UART peripheral will run in standby mode. See the datasheet for more details.
sourcepub fn set_run_in_standby(&mut self, set: bool)
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.
sourcepub fn get_run_in_standby(&self) -> bool
pub fn get_run_in_standby(&self) -> bool
Get the current run in standby mode
sourcepub fn irda_encoding(self, pulse_length: Option<u8>) -> Self
pub fn irda_encoding(self, pulse_length: Option<u8>) -> Self
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.
sourcepub fn set_irda_encoding(&mut self, pulse_length: Option<u8>)
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.
sourcepub fn get_irda_encoding(&self) -> Option<u8>
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
.
sourceimpl<P: ValidPads> Config<P, DynCharSize>
impl<P: ValidPads> Config<P, DynCharSize>
sourcepub fn set_dyn_char_size(&mut self, char_size: CharSizeEnum)
pub fn set_dyn_char_size(&mut self, char_size: CharSizeEnum)
Dynamically change the character size
sourcepub fn get_dyn_char_size(&self) -> CharSizeEnum
pub fn get_dyn_char_size(&self) -> CharSizeEnum
Get the current character size setting
sourceimpl<P, C> Config<P, C>where
P: ValidPads,
C: CharSize,
Self: ValidConfig,
impl<P, C> Config<P, C>where
P: ValidPads,
C: CharSize,
Self: ValidConfig,
sourcepub fn enable(self) -> Uart<Self, P::Capability>
pub fn enable(self) -> Uart<Self, P::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 ValidConfig
s