Struct I2c

Source
pub struct I2c<C: AnyConfig, D = NoneT> { /* private fields */ }
Expand description

Abstraction over a I2C peripheral, allowing to perform I2C transactions.

Implementations§

Source§

impl<C, S> I2c<C>
where C: AnyConfig<Sercom = S>, S: Sercom,

Source

pub fn into_future<I>(self, _interrupts: I) -> I2cFuture<C>

Turn an I2c into an I2cFuture

Source§

impl<C: AnyConfig, D> I2c<C, D>

Source

pub fn data_ptr(&self) -> *mut Word

Obtain a pointer to the DATA register. Necessary for DMA transfers.

Source

pub fn read_flags(&self) -> Flags

Read the interrupt flags

Source

pub fn clear_flags(&mut self, flags: Flags)

Clear interrupt status flags

Source

pub fn enable_interrupts(&mut self, flags: Flags)

Enable interrupts for the specified flags.

Source

pub fn disable_interrupts(&mut self, flags: Flags)

Disable interrupts for the specified flags.

Source

pub fn read_status(&self) -> Status

Read the status flags

Source

pub fn clear_status(&mut self, status: Status)

Clear the status flags

Source

pub fn reconfigure<F>(&mut self, update: F)
where F: FnOnce(&mut SpecificConfig<C>),

Reconfigure the I2C peripheral.

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::i2c::I2c;
i2c.reconfigure(|c| c.set_run_in_standby(false));
Source

pub fn disable(self) -> C

Disable the I2C peripheral and return the underlying Config

Source§

impl<C: AnyConfig> I2c<C>

Source

pub fn with_dma_channel<Chan: AnyChannel<Status = Ready>>( self, channel: Chan, ) -> I2c<C, Chan>

Attach a DMA channel to this I2c. Its embedded_hal::i2c::I2c implementation will use DMA to carry out its transactions.

Source§

impl<C, D, S> I2c<C, D>
where C: AnyConfig, D: AnyChannel<Status = S>, S: ReadyChannel,

Source

pub fn take_dma_channel(self) -> (I2c<C, NoneT>, D)

Reclaim the DMA channel. Any subsequent I2C operations will no longer use DMA.

Trait Implementations§

Source§

impl<C: AnyConfig, D> AsMut<I2c<C, D>> for I2cFuture<C, D>

Source§

fn as_mut(&mut self) -> &mut I2c<C, D>

Converts this type into a mutable 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.
Source§

impl<C: AnyConfig, D> AsRef<I2c<C, D>> for I2cFuture<C, D>

Source§

fn as_ref(&self) -> &I2c<C, D>

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

impl<C: AnyConfig, D> ErrorType for I2c<C, D>

Source§

type Error = Error

Error type
Source§

impl<C: AnyConfig> I2c for I2c<C>

Source§

fn transaction( &mut self, address: u8, operations: &mut [Operation<'_>], ) -> Result<(), Self::Error>

Execute the provided operations on the I2C bus. Read more
Source§

fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error>

Writes bytes to slave with address address. Read more
Source§

fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill read. Read more
Source§

fn write_read( &mut self, address: u8, bytes: &[u8], buffer: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill read in a single transaction. Read more
Source§

impl<C, D, S> I2c for I2c<C, D>
where C: AnyConfig<Sercom = S>, S: Sercom, D: AnyChannel<Status = Ready>,

Source§

fn transaction( &mut self, address: u8, operations: &mut [Operation<'_>], ) -> Result<(), Self::Error>

Execute the provided operations on the I2C bus. Read more
Source§

fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error>

Writes bytes to slave with address address. Read more
Source§

fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill read. Read more
Source§

fn write_read( &mut self, address: u8, bytes: &[u8], buffer: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill read in a single transaction. Read more
Source§

impl<C: AnyConfig> Read for I2c<C>

Source§

type Error = Error

Error type
Source§

fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error>

Reads enough bytes from slave with address to fill buffer Read more
Source§

impl<C: AnyConfig> Write for I2c<C>

Source§

type Error = Error

Error type
Source§

fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error>

Writes bytes to slave with address address Read more
Source§

impl<C: AnyConfig> WriteRead for I2c<C>

Source§

type Error = Error

Error type
Source§

fn write_read( &mut self, addr: u8, bytes: &[u8], buffer: &mut [u8], ) -> Result<(), Self::Error>

Writes bytes to slave with address address and then reads enough bytes to fill buffer in a single transaction Read more

Auto Trait Implementations§

§

impl<C, D> Freeze for I2c<C, D>
where C: Freeze, D: Freeze,

§

impl<C, D> RefUnwindSafe for I2c<C, D>

§

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

§

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

§

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

§

impl<C, D> UnwindSafe for I2c<C, D>
where C: UnwindSafe, D: 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> 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.