[−][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
I2C.take_for(|i2c| { if i2c.initialize(250_000_000, true).is_ok() { println!("scan I2C devices connected to RPi"); let devices = i2c.scan().unwrap(); for d in devices { println!("device detected at 0x{:2X}", d); } } });
To work with a device connected to the I²C bus it's recommended to first check whether this is connected at the specific address. This could be done like so:
let device_addr = 0x68; // check if device is connected I2C.take_for(|i2c| { if i2c.check_device(device_addr).is_ok() { // now that we know the device exists and is connected to something with it } });
Once done simple use the funtions to write to or read from the device registers as required.
Features
ruspiro_pi3
is active by default and ensures the proper MMIO base address is used for Raspberry Pi 3
Structs
I2cImpl | I²C peripheral representation |
Statics
I2C | Static singleton accessor for the I²C bus peripheral
To use the contained i2c API in a safe way use the |
Type Definitions
I2cResult |