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

no-std mcp23017

A rust driver for the MCP23017 (16-Bit I2C I/O Expander with Serial Interface)

4 releases (2 stable)

1.1.0 Sep 14, 2024
1.0.0 May 20, 2021
0.1.1 Nov 10, 2019
0.1.0 Oct 15, 2019

#690 in Embedded development

Download history 19/week @ 2024-07-27 1/week @ 2024-08-03 195/week @ 2024-09-14 25/week @ 2024-09-21 11/week @ 2024-09-28 1/week @ 2024-10-05

207 downloads per month

MIT license

17KB
294 lines

mcp23017

no_std driver for MCP23017 (16-Bit I2C I/O Expander with Serial Interface module)

Build Status crates.io Docs

Basic usage

Include this library as a dependency in your Cargo.toml:

[dependencies.mcp23017]
version = "<version>"

Use embedded-hal implementation to get I2C handle and then create mcp23017 handle:

extern crate mcp23017;

match mcp23017::MCP23017::default(i2c) {
    Ok(mut u) => {
        u.init_hardware();
        u.pin_mode(1, mcp23017::PinMode::OUTPUT);   // for the first pin
        u.all_pin_mode(mcp23017::PinMode::OUTPUT);  // or for all pins

        let status = u.read_gpioab().unwrap();
        println!("all {:#?}", status).unwrap();

        let read_a = u.read_gpio(mcp23017::Port::GPIOA).unwrap();
        println!("port a {:#?}", read_a).unwrap();

        match u.write_gpioab(65503){
            Ok(_) => {
                println!("ok").unwrap();
            }
            _ => {
                println!("something wrong").unwrap();
            }
        }
    }
    Err(mcp23017::MCP23017::Error::BusError(error)) => {
        println!("{:#?}", error).unwrap();;
        panic!();
    }
    _ => {
        panic!();
    }
};

Hardware address pins

Documentation

API Docs available on docs.rs

License

MIT license

Dependencies

~71KB