Skip to content

[WIP] Sketch out alternative interrupts API#29

Open
Rahix wants to merge 1 commit intomainfrom
interrupts-2
Open

[WIP] Sketch out alternative interrupts API#29
Rahix wants to merge 1 commit intomainfrom
interrupts-2

Conversation

@Rahix
Copy link
Owner

@Rahix Rahix commented Apr 1, 2024

An alternative to #28. This variant decouples the pins better.

Example usage:

let pca_irq = todo!("GPIO pin of the MCU");
let mut pca9555 = port_expander::Pca9555::new(i2c, true, false, false);
let pca_pins = pca9555.split();

let p1 = pca_pins.io0_0;
let p2 = pca_pins.io0_3;

// Enable interrupts for these two pins
p1.listen().unwrap();
p2.listen().unwrap();

loop {
    // Wait for an interrupt
    while !pca_irq.is_low() {}

    // Fetch interrupt status (can be called on any pin of the expander)
    p1.fetch_all_interrupt_state().unwrap();

    let p1_changed: bool = p1.query_pin_change();
    let p2_changed: bool = p2.query_pin_change();

    // Calling the function again always yields false.  Only after a new
    // interrupt and fetch_all_interrupt_state() will you receive results again.
    assert_eq!(p1.query_pin_change(), false);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant