mcp23017-driver

Crates.iomcp23017-driver
lib.rsmcp23017-driver
version0.1.2
created_at2025-01-20 19:14:43.643402+00
updated_at2025-03-08 06:56:28.885862+00
descriptionA comprehensive Rust driver for the Microchip MCP23017 IO expander.
homepage
repositoryhttps://github.com/finn-eger/mcp23017
max_upload_size
id1524178
size29,636
Finn Eger (finn-eger)

documentation

README

A comprehensive Rust driver for the Microchip MCP23017 IO expander.

  • Split a device into individual embedded-hal pins.
  • Configure modes, pull-ups, and interrupt triggers with a type-level API.
  • Service interrupts efficiently with a centralized controller.

For usage details and explanatory notes, see the documentation.

Overview

let i2c = todo!(/* Setup I2C */);

// Setup a device:
const ADDRESS: u8 = 0x20;
let mut device = Mcp23017::<_, ADDRESS>::new(i2c);
let (pins, mut interrupt_controller) = device.split()?;

// Use a pin as an output:
let mut pin = pins.a0.into_push_pull_output()?;
pin.set_high()?;
pin.is_set_high()?;

// Use another pin as an input:
let mut pin = pins.a1.into_pull_up_input()?;
pin.is_high()?;

// Configure an input pin for interrupts:
let pin = pin.enable_interrupt(Sense::Edge)?;
// When an interrupt occurs,
// immediately notify the controller...
interrupt_controller.interrupt(Bank::A)?;
// ...and later query it about the cause:
interrupt_controller.triggered(&pin);
Commit count: 8

cargo fmt