2 unstable releases
Uses old Rust 2015
0.2.0 | Nov 17, 2018 |
---|---|
0.1.0 | Nov 11, 2018 |
#17 in #expander
11KB
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!
lib.rs
:
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
Dependencies
~175KB