Struct atsamd_hal::sercom::i2c::I2c

source ·
pub struct I2c<C: AnyConfig> { /* private fields */ }
Expand description

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

Implementations§

source§

impl<C: AnyConfig> I2c<C>

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 init_dma_transfer(&mut self) -> Result<I2cBusReady, Error>

Initialize the bus to start receiving with DMA.

In reality, this function only checks whether or not the I2C bus is ready to accept a new transaction. A call to init_dma_transfer should immediately be followed by a call to send_with_dma or receive_with_dma.

// Assume `i2c` is a fully configured `I2c`, and `chan0` a fully configured `dmac::Channel`.
let token = i2c.init_dma_transfer()?;
i2c.send_with_dma(ADDRESS, token, buf_src, chan0, |_| {});
source

pub fn receive_with_dma<Ch, B, W>( self, address: u8, _ready_token: I2cBusReady, buf: B, channel: Ch, waker: W ) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<Self, B>, W>
where Ch: AnyChannel<Status = Ready>, B: Buffer<Beat = Word> + 'static, W: FnOnce(CallbackStatus) + 'static,

Transform an I2c into a DMA Transfer) and start receiving into the provided buffer. The buffer length must be 255 bytes or shorter.

It is recommended that you check for errors after the transfer is complete by calling read_status.

source

pub fn send_with_dma<Ch, B, W>( self, address: u8, _ready_token: I2cBusReady, buf: B, channel: Ch, waker: W ) -> Transfer<Channel<Ch::Id, Busy>, BufferPair<B, Self>, W>
where Ch: AnyChannel<Status = Ready>, B: Buffer<Beat = Word> + 'static, W: FnOnce(CallbackStatus) + 'static,

Transform an I2c into a DMA Transfer) and start sending the provided buffer. The buffer length must be 255 bytes or shorter.

It is recommended that you check for errors after the transfer is complete by calling read_status.

Trait Implementations§

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> Buffer for I2c<C>

§

type Beat = u8

DMAC beat size
source§

fn dma_ptr(&mut self) -> *mut Self::Beat

Pointer to the buffer. If the buffer is incrementing, the address should point to one past the last beat transfer in the block.
source§

fn incrementing(&self) -> bool

Return whether the buffer pointer should be incrementing or not
source§

fn buffer_len(&self) -> usize

Buffer length in beats
source§

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

§

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: AnyConfig> Read for I2c<C>

§

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>

§

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>

§

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> Freeze for I2c<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for I2c<C>
where C: RefUnwindSafe,

§

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

§

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

§

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

§

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

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.