PCA9535

crates.io documentation license

PCA9535 IO-Expander driver using embedded-hal.

Compatibility

As embedded-hal is still in the alpha phase this driver will have breaking changes on minor versions. Please refer to the table below to select the appropriate driver version for your desired embedded-hal version: | embedded-hal | pca9535 | | ------------- | ------------- | | 1.0.0-alpha.9 | 1.2.* | | 1.0.0-alpha.5 | 1.1.* |

Features

Two expander modes:

Immediate mode issues an i2c bus transaction on each function call, behaving like a normal i2c device library does.

Cached mode takes advantage of the interrupt pin of the device, which indicates a change in the register value. The driver holds an internal representation of the device's registers and thus it only issues a read if any data changed as indicated by the interrupt pin. This mode reduces read access on the bus significantly compared to immediate mode.

Two ways of interacting:

The standard interface offers all needed functions to interact with the GPIO pins of the device.

The HAL Pin Interface offers a way to use the Expander GPIO as embedded-hal GPIO which makes it possible to use them in any other libraries using embedded-hal. The pins are usable across threads using an ExpanderMutex.

Usage Example

This is a basic usage example, for more information visit the docs.

Immediate expander using standard interface: ```rust use pca9535::{GPIOBank, Pca9535Immediate, StandardExpanderInterface};

let i2c = I2c::new().unwrap();

let mut expander = Pca9535Immediate::new(i2c, 32);

expander.pinintoinput(GPIOBank::Bank0, 4).unwrap(); expander.pinintooutput(GPIOBank::Bank1, 6).unwrap();

if expander.pinishigh(GPIOBank::Bank0, 4).unwrap() { expander.pinsethigh(GPIOBank::Bank1, 6).unwrap(); } ```

Cached expander using hal pin interface: ```rust use std::sync::Mutex; use embedded_hal::digital::blocking::{InputPin, OutputPin}; use pca9535::{ExpanderInputPin, ExpanderOutputPin, GPIOBank, IoExpander, Pca9535Cached, PinState};

let i2c = I2c::new().unwrap(); let interruptpin = Gpio::new().unwrap().get(1).unwrap().intoinput();

let expander = Pca9535Cached::new(i2c, 32, interruptpin, true).unwrap(); let ioexpander: IoExpander, _> = IoExpander::new(expander);

let inputpin = ExpanderInputPin::new(&ioexpander, GPIOBank::Bank0, 4).unwrap(); let mut outputpin = ExpanderOutputPin::new(&ioexpander, GPIOBank::Bank1, 6, PinState::Low).unwrap();

if inputpin.ishigh().unwrap() { outputpin.sethigh().unwrap(); } ```

Changelog

See CHANGELOG.md or release page for details.