feat: TransparentPins now talks to regular pins too

This commit is contained in:
dogeystamp 2024-04-14 18:01:43 -04:00
parent 2bbabaff5c
commit ca6c3f85f4
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 15 additions and 4 deletions

View File

@ -79,10 +79,14 @@ async fn main(_spawner: Spawner) {
let i2c = i2c::I2c::new_blocking(p.I2C0, scl, sda, i2c_config);
log::info!("main: starting transparent pin driver");
let mut pin_driver = pins::TransparentPins::new(i2c, [0x20, 0x27], []);
let mut pin_driver = pins::TransparentPins::new(
i2c,
[0x20, 0x27],
pins::pin_array!(p.PIN_15, p.PIN_14, p.PIN_13, p.PIN_12, p.PIN_11, p.PIN_10, p.PIN_18, p.PIN_19),
);
log::info!("main: setting pins as input");
for i in 0..pins::N_EXTENDED_PINS {
for i in 0..(pins::N_EXTENDED_PINS + pins::N_REGULAR_PINS) {
log::debug!("main: setting pin {} as input, pull up", i);
unwrap(pin_driver.set_input(i as u8)).await;
unwrap(pin_driver.set_pull(i as u8, gpio::Pull::Up)).await;

View File

@ -32,7 +32,7 @@ pub const PINS_PER_EXTENDER: usize = 16;
/// Number of MCP23017 chips used.
pub const N_PIN_EXTENDERS: usize = 2;
/// Number of pins driven directly by the board.
pub const N_REGULAR_PINS: usize = 0;
pub const N_REGULAR_PINS: usize = 8;
/// Number of total extended pins
pub const N_EXTENDED_PINS: usize = PINS_PER_EXTENDER * N_PIN_EXTENDERS;
@ -83,6 +83,14 @@ pub struct TransparentPins {
i2c_bus: I2cBus,
}
/// Helper to define the onboard pins in TransparentPins
macro_rules! pin_array {
($($pin: expr),*) => {
[$($pin.into(),)*]
}
}
pub(crate) use pin_array;
/// Create a new short-lived MCP23017 struct.
///
/// This is needed because our bus proxy uses references to the bus,
@ -130,7 +138,6 @@ impl TransparentPins {
ret |= (ext.read_gpioab()? as u64) << (i * PINS_PER_EXTENDER);
}
for pin in 0..N_REGULAR_PINS {
log::trace!("pin read: {}", pin);
ret |= (self.pins[pin].is_high() as u64) << (N_EXTENDED_PINS + pin);
}