Crate mcp23x17

Source
Expand description

§Rust Library for the Microchip MCP23X17

In its current incarnation, this only supports I2C but the register map is the same for SPI as well.

Internally, the chip supports a segreggated layout of registers to make two 8 bit GPIO ports or can interleave the registers to emulate one 16 bit GPIO port. This library works on the former layout and so disables setting BANK when calling set_config().

use linux_hal::I2cdev;
use mcp23x17::{
    Mcp23x17 as Expander,  
    Port
};
 
fn main() -> Result<(), Box<Error>> {
    let i2c = I2cdev::new("/dev/i2c-1")?;
    let mut exp = Expander::new(i2c)?;
 
    exp.select_port(Port::B);
    exp.set_direction(0x00)?;
    exp.set_data(0xff)?;
}

Implementation details taken from http://ww1.microchip.com/downloads/en/DeviceDoc/20001952C.pdf

Structs§

Config
Configuration register definition. This register is mirrored in the register map and pertains to all ports
Mcp23x17
16bit GPIO Expander

Enums§

Port
Which port we’re actively using. Currently you must select which is active by using select_port on mcp23x17. Port A is the default.

Constants§

ADDRESS
Device address