Crate mcp23s17_async

Source
Expand description

§Async MCP23S17 driver

Crates.io Crates.io Crates.io

An asynchronous driver for the MCP23S17 I/O expander which is accessed over an SPI bus.

§Example usage

// spi_device implements the SpiDevice trait from embedded_hal_async >= 1.0.0
// The hardware address corresponds to the way the pins
// A0, A1, A2 are physically connected
let mut mcp23s17 = mcp23s17_async::Mcp23s17::new(spi_device, 0b000).await.ok().unwrap();

// Configure pin GPA0 as an output
mcp23s17.pin_mode(0, mcp23s17_async::PinMode::Output).await.ok().unwrap();
// Set pin GPA0 high
mcp23s17.set_high(0).await.ok().unwrap();

// Configure pin GPA1 as an pullup input
mcp23s17.pin_mode(1, mcp23s17_async::PinMode::InputPullup).await.ok().unwrap();
// Read GPA1's level
let is_high = mcp23s17.read(1).await.ok().unwrap();

§Acknowledgements

Many of the documentation comments in this library are taken direct from the MCP23S17 datasheet and are © 2005-2022 Microchip Technology Inc. and its subsidiaries.

Inspired by this Arduino MCP23S17 Library and the RPPAL MCP23S17 Library

Structs§

IOCON
I/O Expander Configuration Register (IOCON) bit definitions.
Mcp23s17
A structure that represents an instance of the MCP23S17 I/O expander chip.
Mcp23s17SpiError
The only error that operation of the MCP23S17 can raise, because of an internal SPI error.

Enums§

InterruptMode
Interrupt input trigger modes that every pin configured as Input supports.
PinMode
The possible configurations of a pin. PinMode::InputPullup uses a 100k internal pullup resistor.
RegisterAddress
The register addresses within the device.