Struct avr_hal_generic::i2c::I2c

source ·
pub struct I2c<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> { /* private fields */ }
Expand description

I2C driver

§Example

(for Arduino Uno)

let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);

let mut i2c = arduino_hal::I2c::new(
    dp.TWI,
    pins.a4.into_pull_up_input(),
    pins.a5.into_pull_up_input(),
    50000,
);

// i2c implements the embedded-hal traits so it can be used with generic drivers.

Implementations§

source§

impl<H, I2C, SDAPIN, SCLPIN, CLOCK> I2c<H, I2C, Pin<Input, SDAPIN>, Pin<Input, SCLPIN>, CLOCK>
where I2C: I2cOps<H, Pin<Input, SDAPIN>, Pin<Input, SCLPIN>>, SDAPIN: PinOps, SCLPIN: PinOps, CLOCK: Clock,

source

pub fn new( p: I2C, sda: Pin<Input<PullUp>, SDAPIN>, scl: Pin<Input<PullUp>, SCLPIN>, speed: u32 ) -> Self

Initialize an I2C peripheral on the given pins.

Note that the SDA and SCL pins are hardwired for each I2C peripheral and you must pass the correct ones. This is enforced at compile time.

This method expects the internal pull-ups to be configured for both pins to comply with the I2C specification. If you have external pull-ups connected, use I2c::with_external_pullup instead.

source

pub fn with_external_pullup( p: I2C, sda: Pin<Input<Floating>, SDAPIN>, scl: Pin<Input<Floating>, SCLPIN>, speed: u32 ) -> Self

Initialize an I2C peripheral on the given pins.

Note that the SDA and SCL pins are hardwired for each I2C peripheral and you must pass the correct ones. This is enforced at compile time.

This method expects that external resistors pull up SDA and SCL.

source§

impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> I2c<H, I2C, SDA, SCL, CLOCK>
where CLOCK: Clock, Delay<CLOCK>: DelayMs<u16>,

source

pub fn ping_device( &mut self, address: u8, direction: Direction ) -> Result<bool, Error>

Test whether a device answers on a certain address.

source

pub fn i2cdetect<W: uWrite>( &mut self, w: &mut W, direction: Direction ) -> Result<(), W::Error>

Scan the bus for connected devices. This method will output an summary in the format known from i2cdetect(8) on the selected serial connection. For example:

-    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:       -- -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- 38 39 -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Trait Implementations§

source§

impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> ErrorType for I2c<H, I2C, SDA, SCL, CLOCK>

§

type Error = Error

Error type
source§

impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> I2c for I2c<H, I2C, SDA, SCL, CLOCK>

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 read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error>

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

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

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

fn write_read( &mut self, address: A, write: &[u8], read: &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<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> Read for I2c<H, I2C, SDA, SCL, CLOCK>

§

type Error = Error

Error type
source§

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

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

impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> Write for I2c<H, I2C, SDA, SCL, CLOCK>

§

type Error = Error

Error type
source§

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

Writes bytes to slave with address address Read more
source§

impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> WriteRead for I2c<H, I2C, SDA, SCL, CLOCK>

§

type Error = Error

Error type
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 buffer in a single transaction Read more

Auto Trait Implementations§

§

impl<H, I2C, SDA, SCL, CLOCK> Freeze for I2c<H, I2C, SDA, SCL, CLOCK>
where I2C: Freeze, SCL: Freeze, SDA: Freeze,

§

impl<H, I2C, SDA, SCL, CLOCK> RefUnwindSafe for I2c<H, I2C, SDA, SCL, CLOCK>

§

impl<H, I2C, SDA, SCL, CLOCK> Send for I2c<H, I2C, SDA, SCL, CLOCK>
where CLOCK: Send, H: Send, I2C: Send, SCL: Send, SDA: Send,

§

impl<H, I2C, SDA, SCL, CLOCK> Sync for I2c<H, I2C, SDA, SCL, CLOCK>
where CLOCK: Sync, H: Sync, I2C: Sync, SCL: Sync, SDA: Sync,

§

impl<H, I2C, SDA, SCL, CLOCK> Unpin for I2c<H, I2C, SDA, SCL, CLOCK>
where CLOCK: Unpin, H: Unpin, I2C: Unpin, SCL: Unpin, SDA: Unpin,

§

impl<H, I2C, SDA, SCL, CLOCK> UnwindSafe for I2c<H, I2C, SDA, SCL, CLOCK>
where CLOCK: UnwindSafe, H: UnwindSafe, I2C: UnwindSafe, SCL: UnwindSafe, SDA: 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, 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.