6 releases (3 breaking)
|0.4.0||Aug 13, 2023|
|0.3.1||Aug 13, 2023|
|0.3.0||May 6, 2022|
|0.2.1||Apr 26, 2021|
|0.1.0||Apr 24, 2021|
#189 in Embedded development
88 downloads per month
Used in 2 crates
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
digital IO traits, they can also be passed to further drivers downstream (e.g.
as a reset or chip-select pin).
// Initialize I2C peripheral from HAL let i2c = todo!(); // A0: HIGH, A1: LOW, A2: LOW let mut pca9555 = port_expander::Pca9555::new(i2c, true, false, false); let pca_pins = pca9555.split(); let io0_0 = pca_pins.io0_0.into_output().unwrap(); let io1_5 = pca_pins.io0_1; // default is input io0_0.set_high().unwrap(); assert!(io1_5.is_high().unwrap());
Accessing multiple pins at the same time
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!
port-expander uses the
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:
// Initialize I2C peripheral from HAL let i2c = todo!(); // A0: HIGH, A1: LOW, A2: LOW let mut pca9555: port_expander::Pca9555<std::sync::Mutex<_>> = port_expander::Pca9555::with_mutex(i2c, true, false, false); let pca_pins = pca9555.split();
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.