port-expander crates.io page docs.rs page

This is a crate providing a common abstraction for I²C port-expanders. This abstraction is not necessarily the most performant, but it allows using the pins just like direct GPIOs. Because the pin types also implement the embedded-hal digital IO traits, they can also be passed to further drivers downstream (e.g. as a reset or chip-select pin).

Example

```rust // Initialize I2C peripheral from HAL let i2c = todo!();

// A0: HIGH, A1: LOW, A2: LOW let mut pca9555 = portexpander::Pca9555::new(i2c, true, false, false); let pcapins = pca9555.split();

let io00 = pcapins.io00.intooutput().unwrap(); let io15 = pcapins.io0_1; // default is input

io00.sethigh().unwrap(); assert!(io15.ishigh().unwrap()); ```

Supported Devices

The following list is what port-expander currently supports. If you needs support for an additional device, it should be easy to add. It's best to take a similar existing implementation as inspiration. Contributions welcome!

Non-local sharing

port-expander uses the BusMutex from shared-bus under the hood. This means you can also make the pins shareable across task/thread boundaries, given that you provide an appropriate mutex type:

```rust // Initialize I2C peripheral from HAL let i2c = todo!();

// A0: HIGH, A1: LOW, A2: LOW let mut pca9555: portexpander::Pca9555> = portexpander::Pca9555::withmutex(i2c, true, false, false); let pcapins = pca9555.split(); ```

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.