#io #expander #i2c #driver #embedded-hal-driver

no-std mcp23x17

A Rust embedded-hal driver for a Microchip GPIO Expander of the same name

2 unstable releases

Uses old Rust 2015

0.2.0 Nov 17, 2018
0.1.0 Nov 11, 2018

#46 in #i2c

MIT license

138 lines

The Microchip mcp23x17 GPIO expander -- Now with more Rust

This is a Rust Embedded HAL crate to work with a GPIO expander. I bought this chip just to play with, so don't expect battle hardened code here. Ideally one day it will expose embedded-hal style GPIO pins but that's not a priority.

In fact, nothing here is a priority. Do you feel like making it better? Let me know!


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,  

fn main() -> Result<(), Box<Error>> {
    let i2c = I2cdev::new("/dev/i2c-1")?;
    let mut exp = Expander::new(i2c)?;


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