pub fn read_multiple<PD, MUTEX, MODE: HasInput, const N: usize>(
    pins: [&Pin<'_, MODE, MUTEX>; N]
) -> Result<[bool; N], PD::Error>
where PD: PortDriver, MUTEX: PortMutex<Port = PD>,
Expand description

Read multiple pins at the same time.

When a port-expander sends an interrupt that one of its inputs changed state, it might be important to find out which input was responsible as quickly as possible and by checking all inputs at once. The naive approach of checking the pins in order

if io0.is_high().unwrap() {
    // ...
} else if io1.is_high().unwrap() {
    // ...
}

is suboptimal because each read will happen as its own bus transaction and there is thus quite some delay. Also the pins are checked one after the other, not all at once, which could lead to glitches. The read_multiple() function provides an interface to circumvent these problems.

§Example

let values = port_expander::read_multiple([&io0, &io1]).unwrap();
if values[0] {
    // ...
} else if values[1] {
    // ...
}