TransparentPins: total pin number only accessible through getter now
This commit is contained in:
parent
be6240ba3c
commit
70526c44eb
@ -45,7 +45,7 @@ struct Connection {
|
||||
#[embassy_executor::task]
|
||||
async fn scanner_task(mut pin_driver: pins::TransparentPins) {
|
||||
log::info!("scanner_task: setting pins as input");
|
||||
for i in 0..pin_driver.n_total_pins {
|
||||
for i in 0..pin_driver.n_usable_pins() {
|
||||
unwrap(pin_driver.set_input(i as u8)).await;
|
||||
unwrap(pin_driver.set_pull(i as u8, gpio::Pull::Up)).await;
|
||||
}
|
||||
@ -61,15 +61,15 @@ async fn scanner_task(mut pin_driver: pins::TransparentPins) {
|
||||
log::info!("");
|
||||
log::info!("---");
|
||||
log::info!("STARTING SCAN...");
|
||||
for gnd_pin in 0..pin_driver.n_total_pins {
|
||||
for gnd_pin in 0..pin_driver.n_usable_pins() {
|
||||
let gnd_pin = gnd_pin as u8;
|
||||
unwrap(pin_driver.set_output(gnd_pin)).await;
|
||||
let input = unwrap(pin_driver.read_all()).await;
|
||||
unwrap(pin_driver.set_input(gnd_pin)).await;
|
||||
|
||||
// this represents the pins that are different from expected
|
||||
let mask = input ^ (((1 << pin_driver.n_total_pins) - 1) ^ (1 << gnd_pin));
|
||||
for input_pin in 0..pin_driver.n_total_pins {
|
||||
let mask = input ^ (((1 << pin_driver.n_usable_pins()) - 1) ^ (1 << gnd_pin));
|
||||
for input_pin in 0..pin_driver.n_usable_pins() {
|
||||
let input_pin = input_pin as u8;
|
||||
if ((1 << input_pin) & mask) != 0 && n_connections < MAX_CONNECTIONS {
|
||||
connections[n_connections] = Some(Connection { gnd_pin, input_pin });
|
||||
|
@ -60,7 +60,7 @@ async fn main(_spawner: Spawner) {
|
||||
.await;
|
||||
|
||||
log::info!("main: setting pins as input");
|
||||
for i in 0..pin_driver.n_total_pins {
|
||||
for i in 0..pin_driver.n_usable_pins() {
|
||||
unwrap(pin_driver.set_input(i as u8)).await;
|
||||
unwrap(pin_driver.set_pull(i as u8, gpio::Pull::Up)).await;
|
||||
}
|
||||
|
@ -95,8 +95,8 @@ pub struct TransparentPins {
|
||||
pins: [Flex<'static, AnyPin>; N_REGULAR_PINS],
|
||||
i2c_bus: I2cBus,
|
||||
disable_unsafe_pins: bool,
|
||||
/// Number of total usable pins. Transparent pins all have an address from `0..n_total_pins`.
|
||||
pub n_total_pins: usize,
|
||||
/// Number of total usable pins.
|
||||
n_total_pins: usize,
|
||||
/// Usable pins per extender. Depends on `disable_unsafe_pins`.
|
||||
usable_pins_per_extender: usize,
|
||||
/// Usable pin count on all extenders. Depends on `disable_unsafe_pins`.
|
||||
@ -122,6 +122,11 @@ macro_rules! extender {
|
||||
}
|
||||
|
||||
impl TransparentPins {
|
||||
/// Get amount of usable pins. Transparent pins all have an address from `0..n_usable_pins()`.
|
||||
pub fn n_usable_pins(&self) -> usize {
|
||||
self.n_total_pins
|
||||
}
|
||||
|
||||
/// Transform addresses into a transparent pin number, taking into account pins that aren't being used.
|
||||
fn addr_to_pin(&self, addr: u8) -> u8 {
|
||||
if self.disable_unsafe_pins {
|
||||
|
Loading…
Reference in New Issue
Block a user