From ca6c3f85f4e9100eda5fb807c2ddf36f2dd4be07 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 14 Apr 2024 18:01:43 -0400 Subject: [PATCH] feat: TransparentPins now talks to regular pins too --- src/main.rs | 8 ++++++-- src/pins.rs | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index f694081..d5f8681 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; diff --git a/src/pins.rs b/src/pins.rs index 03def41..a756577 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -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); }