How to set a pin from a PWM interrupt

Hi, I am very new to Rust and am starting with the rp-pico crate for the RP2040 board.

I have 3 pwm signals working but I want to generate an interrupt on the pwm wrap interrupt, so far I have:

// Interrupt handling
use rp_pico::hal::pac::interrupt;

In main I have:

unsafe {
        pac::NVIC::unmask(hal::pac::Interrupt::PWM_IRQ_WRAP); 
    };

.. and my interrupt handler is:

#[interrupt]
fn PWM_IRQ_WRAP() {
   gpio15.set_high();
}

That obviously gives me an error on the gpio15.set_high();, as I have no mutex on it. Can someone show me how I can "borrow" that gpio so I can use it in the interrupt routine?

my GPIO's were set up like this:

// The single-cycle I/O block controls our GPIO pins
    let sio = hal::Sio::new(pac.SIO);

    // Set the pins up according to their function on this particular board
    let pins = rp_pico::Pins::new(
        pac.IO_BANK0,
        pac.PADS_BANK0,
        sio.gpio_bank0,
        &mut pac.RESETS,
    );

pins represents all the RP2040 pins (How do I "borrow" pins.gpio15 for use in the interrupt routine, I guess is what I am asking.)

Would it help you to take a look at this?

static BUTTON: Mutex<RefCell<Option<gpio::Gpio9<Input>>>> =
Mutex::new(RefCell::new(None));

let mut button = io.pins.gpio9.into_pull_down_input();

critical_section::with(|cs| {
    button.listen(Event::FallingEdge);
    BUTTON.borrow_ref_mut(cs).replace(button)
});

critical_section::with(|cs| {
BUTTON
.borrow_ref_mut(cs)
.as_mut()
.unwrap()
.clear_interrupt()
});

Thanks, but does not help, as that code is specific to ESP32, not RP2040 ...

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.