[−][src]Crate ruspiro_i2c
Raspberry Pi I²C bus interface
Simple access to the I²C bus available on the Raspberry Pi. When the I²C bus is used this reserves the GPIO pins 2 and 3 for exclusive use by the bus.
Usage
use ruspiro_i2c::I2C; use ruspiro_console::*; fn demo() { I2C.take_for(|i2c| { if i2c.initialize(250_000_000, true).is_ok() { println!("scan I2C devices connected to RPi"); i2c.scan(); } }); }
To work with a device connected to the I²C bus it first must be retrieved from the I2C interface (it will internally check whether this device is really connected). Then this device could be used to pass request to it using the I2C API.
use ruspiro_i2c::{I2C, I2cDevice}; fn demo() { let device = I2C.take_for(|i2c| i2c.get_device(0x68)) .expect("no I2C device connected to 0x68"); I2C.take_for(|i2c| { // configure the device... // as arbitary example pass value 0x1 to the 8bit register 0x10 i2c.write_register_u8(device, 0x10, 0x1); }) }
Structs
I2cImpl | I²C peripheral representation |
I2cDevice | I²C device representation |
Statics
I2C | Static singleton accessor for the I²C bus peripheral
To use the contained i2c API in a safe way use the |