I have two buttons : button_up and button_down, and I want to listen to the buttons and then based on which button is clicked launch a specific handler. In the documentation all examples are for one specific gpio ...
The set_handler is connection to the io, so it's only one interrupt handler for all gpio's? Is there a way to set an interrupt handler to a specific gpio instead of the io?
// code ...
let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// set the interrupt handler
io.set_interrupt_handler(handler);
// set gpio9 as input
let mut button_up = Input::new(io.pins.gpio9, Pull::Up);
let mut button_down = Input::new(io.pins.gpio10, Pull::Up);
// ANCHOR: critical_section
critical_section::with(|cs| {
button_up.listen(Event::FallingEdge);
BUTTON_UP.borrow_ref_mut(cs).replace(button_up)
});
critical_section::with(|cs| {
button_down.listen(Event::FallingEdge);
BUTTON_DOWN.borrow_ref_mut(cs).replace(button_down)
});
// ANCHOR end
//..
// and then we call the interrupt handler
#[handler]
fn handler() {
critical_section::with(|cs| {
println!("GPIO9 Interrupt + 0.5");
BUTTON_UP
.borrow_ref_mut(cs)
.as_mut()
.unwrap()
.clear_interrupt()
});
critical_section::with(|cs| {
println!("GPIO10 Interrupt - 0.5");
BUTTON_DOWN
.borrow_ref_mut(cs)
.as_mut()
.unwrap()
.clear_interrupt()
})
}
Help would be greatly appreciated.
Thank you in advance, Alex