pub struct Config<P>where
P: PadSet,{ /* private fields */ }
Expand description
A configurable, disabled I2C peripheral
This struct
represents a configurable I2C peripheral in its disabled
state. It is generic over the set of Pads
.
Upon creation, the Config
takes ownership of the
Sercom
and resets it, returning it configured as an I2C peripheral
with a default configuration in Master mode.
Config
uses a builder-pattern API to configure the peripheral,
culminating in a call to enable
, which consumes the Config
and
returns an enabled I2c
.
Implementations
sourceimpl<P: PadSet> Config<P>
impl<P: PadSet> Config<P>
sourcepub fn new(
apb_clk_ctrl: &APB_CLK_CTRL,
sercom: P::Sercom,
pads: P,
freq: impl Into<Hertz>
) -> Self
pub fn new(
apb_clk_ctrl: &APB_CLK_CTRL,
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. The only available operating mode is currently Master.
Note that Config
takes ownership of both the
PAC Sercom
struct as well as the Pads
.
Users must configure GCLK manually. The freq
parameter represents the
GCLK frequency for this Sercom
instance.
sourceimpl<P: PadSet> Config<P>
impl<P: PadSet> Config<P>
sourcepub unsafe fn sercom(&self) -> &P::Sercom
pub unsafe fn sercom(&self) -> &P::Sercom
Obtain a reference to the PAC SERCOM
struct
Safety
Directly accessing the SERCOM
could break the invariants of the
type-level tracking in this module, so it is unsafe.
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 I2C 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 I2C 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 baud(self, baud: impl Into<Hertz>) -> Self
pub fn baud(self, baud: impl Into<Hertz>) -> 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/10. Values outside this range will saturate at the maximum supported baud rate.
Note that 3x oversampling is not supported.
sourcepub fn set_baud(&mut self, baud: impl Into<Hertz>)
pub fn set_baud(&mut self, baud: impl 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/10. Values outside this range will saturate at the maximum supported baud rate.
sourcepub fn get_baud(&self) -> u32
pub fn get_baud(&self) -> u32
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 low_timeout(self, set: bool) -> Self
pub fn low_timeout(self, set: bool) -> Self
Set SCL Low Time-Out (builder pattern version)
If SCL is held low for 25ms-35ms, the master will release its clock hold, if enabled, and complete the current transaction. A stop condition will automatically be transmitted. INTFLAG.SB or INTFLAG.MB will be set as normal, but the clock hold will be released. The STATUS.LOWTOUT and STATUS.BUSERR status bits will be set.
sourcepub fn set_low_timeout(&mut self, set: bool)
pub fn set_low_timeout(&mut self, set: bool)
Set SCL Low Time-Out (setter version)
If SCL is held low for 25ms-35ms, the master will release its clock hold, if enabled, and complete the current transaction. A stop condition will automatically be transmitted. INTFLAG.SB or INTFLAG.MB will be set as normal, but the clock hold will be released. The STATUS.LOWTOUT and STATUS.BUSERR status bits will be set.
sourcepub fn get_low_timeout(&mut self) -> bool
pub fn get_low_timeout(&mut self) -> bool
Get SCL Low Time-Out setting
If SCL is held low for 25ms-35ms, the master will release its clock hold, if enabled, and complete the current transaction. A stop condition will automatically be transmitted. INTFLAG.SB or INTFLAG.MB will be set as normal, but the clock hold will be released. The STATUS.LOWTOUT and STATUS.BUSERR status bits will be set.
sourcepub fn inactive_timeout(self, timeout: InactiveTimeout) -> Self
pub fn inactive_timeout(self, timeout: InactiveTimeout) -> Self
Set the inactive timeout (builder pattern version).
Timeout after which the bus state will be set to IDLE. Necessary for SMBus compatibility.
sourcepub fn set_inactive_timeout(&mut self, timeout: InactiveTimeout)
pub fn set_inactive_timeout(&mut self, timeout: InactiveTimeout)
Set the inactive timeout (setter version).
Timeout after which the bus state will be set to IDLE. Necessary for SMBus compatibility.
sourcepub fn get_inactive_timeout(&mut self) -> InactiveTimeout
pub fn get_inactive_timeout(&mut self) -> InactiveTimeout
Get the inactive timeout setting.