Expand description
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
// 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
Sometimes timing constraints mandate that multiple pin accesses (reading or writing) happen at
the same time. The write_multiple()
and read_multiple()
methods are designed for doing
this.
§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 a custom trait for abstracting different kinds of mutexes:
PortMutex
. 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();
Re-exports§
pub use dev::max7321::Max7321;
pub use dev::mcp23x17::Mcp23x17;
pub use dev::pca9536::Pca9536;
pub use dev::pca9538::Pca9538;
pub use dev::pca9555::Pca9555;
pub use dev::pca9702::Pca9702;
pub use dev::pcal6408a::Pcal6408a;
pub use dev::pcal6416a::Pcal6416a;
pub use dev::pcf8574::Pcf8574;
pub use dev::pcf8574::Pcf8574a;
pub use dev::pcf8575::Pcf8575;
pub use dev::tca6408a::Tca6408a;
Modules§
Structs§
- Pin
- Representation of a port-expander pin.
Traits§
- I2cBus
- Blanket trait for types implementing `i2c::I2c
- Port
Mutex - Common interface for mutex implementations.
Functions§
- read_
multiple - Read multiple pins at the same time.
- write_
multiple - Set multiple pins at the same time.