[][src]Struct avr_hal_generic::i2c::I2c

pub struct I2c<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> { /* fields omitted */ }

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

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
[src]

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

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.

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

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.

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

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

Test whether a device answers on a certain address.

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

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

impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> Read<u8> for I2c<H, I2C, SDA, SCL, CLOCK>[src]

type Error = Error

Error type

impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> Write<u8> for I2c<H, I2C, SDA, SCL, CLOCK>[src]

type Error = Error

Error type

impl<H, I2C: I2cOps<H, SDA, SCL>, SDA, SCL, CLOCK> WriteRead<u8> for I2c<H, I2C, SDA, SCL, CLOCK>[src]

type Error = Error

Error type

Auto Trait Implementations

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
[src]

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
[src]

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
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.