I2C

Struct I2C 

Source
pub struct I2C<const N: usize> { /* private fields */ }
Expand description

This struct represents a configured I2C peripheral.

Implementations§

Source§

impl<const N: usize> I2C<N>

Source

pub fn new( core: u8, scl_pin: (char, u8), sda_pin: (char, u8), pullup: bool, ) -> Result<Self, ProgError>

Configure a I2C connection with one of the internal I2C peripherals.

This Method expects the used I2C core, two pin identifiers for the scl and sda-pins and if the internal pullup-resistors should be used as parameters and returns the I2C Struct. Specitfy the buffer capapcity with the turbofish operator. Panics if the core or pins are already used or invalid.

Source

pub fn end(self)

Deacitivates the I2C peripheral and destroys the struct, freeing the core and pins.

Source

pub fn begin_transmission(&mut self, addr: u8)

Initiate transmission to a slave with entered address.

Source

pub fn write(&mut self, data: u8) -> Result<(), ProgError>

Add a byte that is send to the slave. Returns an error-enum if transmittion is not initiated or the tx buffer is full.

Source

pub fn end_transmission(&mut self, stop: bool) -> Result<(), I2cError>

Burst tranfers the bytes in the tx buffer to the slave. Specify if a stop bit should be send. Normally this should be true. It can be false if you want to communicate with multiple slaves simultaniously. Returns an error-enum if problems with the connection are detected.

Source

pub fn request_bytes( &mut self, addr: u8, nbytes: u8, stop: bool, ) -> Result<usize, I2cError>

Request a number of bytes from a slave with the specified address. Recieved bytes are stored in the rx buffer. Specify if a stop bit should be send. Normally this should be true. It can be false if you want to communicate with multiple slaves simultaniously. Returns an error-enum if the buffer cannot hold the number of bytes or a problem with the connection is detected.

Source

pub fn available(&self) -> usize

Returns the number of bytes in the rx buffer.

Source

pub fn read(&mut self) -> Option<u8>

Read a byte from the rx buffer. Returns None if buffer is empty.

Source

pub fn set_clock(&self, clk: u32) -> Result<(), I2cError>

Set the clock frequency to a specific value in Hz. Default is 100kHz. Values lower than 10kHz or higher than 400kHz are not recomendet.

Auto Trait Implementations§

§

impl<const N: usize> Freeze for I2C<N>

§

impl<const N: usize> RefUnwindSafe for I2C<N>

§

impl<const N: usize> Send for I2C<N>

§

impl<const N: usize> Sync for I2C<N>

§

impl<const N: usize> Unpin for I2C<N>

§

impl<const N: usize> UnwindSafe for I2C<N>

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, 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.