atsamd_hal::sercom::i2c

Struct Config

Source
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§

Source§

impl<P: PadSet> Config<P>

Source

pub fn new( apb_clk_ctrl: &ApbClkCtrl, 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.

Source§

impl<P: PadSet> Config<P>

Source

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.

Source

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

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

Source

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

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

Source

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.

Source

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.

Source

pub fn get_run_in_standby(&self) -> bool

Get the current run in standby mode

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_inactive_timeout(&mut self) -> InactiveTimeout

Get the inactive timeout setting.

Source

pub fn enable(self) -> I2c<Self>
where Self: AnyConfig,

Enable the I2C peripheral

I2C transactions are not possible until the peripheral is enabled.

Trait Implementations§

Source§

impl<P: PadSet> AnyConfig for Config<P>

Source§

type Sercom = <P as PadSet>::Sercom

Source§

type Pads = P

Source§

impl<P: PadSet> AsMut<Config<P>> for Config<P>

Source§

fn as_mut(&mut self) -> &mut Self

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<P: PadSet> AsRef<Config<P>> for Config<P>

Source§

fn as_ref(&self) -> &Self

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

impl<P: PadSet> AsRef<Config<P>> for I2c<Config<P>>

Source§

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

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

Auto Trait Implementations§

§

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

§

impl<P> RefUnwindSafe for Config<P>

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where T: Sealed + AsRef<T> + AsMut<T>,

Source§

type Type = T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.