Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Sketch out alternative interrupts API #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

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