1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! 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
//! ```no_run
//! // Initialize I2C peripheral from HAL
//! let i2c = todo!();
//! # let i2c = embedded_hal_mock::eh1::i2c::Mock::new(&[]);
//!
//! // 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!
//!
//! - [`MAX7321`](Max7321)
//! - [`PCA9536`](Pca9536)
//! - [`PCA9538`](Pca9538)
//! - [`PCA9555`](Pca9555)
//! - [`PCA9702`](Pca9702)
//! - [`PCF8574A`](Pcf8574a)
//! - [`PCF8574`](Pcf8574)
//! - [`PCF8575`](Pcf8575)
//! - [`TCA6408A`](Tca6408a)
//! - [`MCP23x17`](Mcp23x17)
//!
//! ## 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:
//!
//! ```ignore
//! // Initialize I2C peripheral from HAL
//! let i2c = todo!();
//! # let i2c = embedded_hal_mock::i2c::Mock::new(&[]);
//!
//! // 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();
//! ```
pub use I2cBus;
pub use mode;
pub use read_multiple;
pub use write_multiple;
pub use PortMutex;
pub use Pin;
pub use PinError;
pub use I2cExt;
pub use SpiBus;
pub use Direction;
pub use PortDriver;
pub use PortDriverPolarity;
pub use PortDriverPullDown;
pub use PortDriverPullUp;
pub use PortDriverTotemPole;
pub use Max7321;
pub use Mcp23x17;
pub use Pca9536;
pub use Pca9538;
pub use Pca9555;
pub use Pca9702;
pub use Pcal6408a;
pub use Pcal6416a;
pub use Pcf8574;
pub use Pcf8574a;
pub use Pcf8575;
pub use Tca6408a;