diff --git a/rp235x-hal-examples/riscv_examples.txt b/rp235x-hal-examples/riscv_examples.txt index adda18eaa..9e23a6d23 100644 --- a/rp235x-hal-examples/riscv_examples.txt +++ b/rp235x-hal-examples/riscv_examples.txt @@ -9,6 +9,7 @@ block_loop dht11 gpio_dyn_pin_array gpio_in_out +gpio_irq_example i2c lcd_display mem_to_mem_dma @@ -20,6 +21,7 @@ pio_synchronized powman_test pwm_blink pwm_blink_embedded_hal_1 +pwm_irq_input rom_funcs rosc_as_system_clock spi diff --git a/rp235x-hal-examples/src/bin/gpio_irq_example.rs b/rp235x-hal-examples/src/bin/gpio_irq_example.rs index 03baf9886..428c0ee11 100644 --- a/rp235x-hal-examples/src/bin/gpio_irq_example.rs +++ b/rp235x-hal-examples/src/bin/gpio_irq_example.rs @@ -32,9 +32,6 @@ use rp235x_hal as hal; // Some things we need use embedded_hal::digital::StatefulOutputPin; -// Our interrupt macro -use hal::pac::interrupt; - // Some short-cuts to useful types use core::cell::RefCell; use critical_section::Mutex; @@ -133,7 +130,8 @@ fn main() -> ! { // We do this last so that the interrupt can't go off while // it is in the middle of being configured unsafe { - cortex_m::peripheral::NVIC::unmask(hal::pac::Interrupt::IO_IRQ_BANK0); + hal::arch::interrupt_unmask(hal::pac::Interrupt::IO_IRQ_BANK0); + hal::arch::interrupt_enable(); } loop { @@ -142,21 +140,23 @@ fn main() -> ! { } } -#[interrupt] +#[no_mangle] +#[allow(non_snake_case)] fn IO_IRQ_BANK0() { // The `#[interrupt]` attribute covertly converts this to `&'static mut Option` static mut LED_AND_BUTTON: Option = None; + let led_and_button = unsafe { &mut *core::ptr::addr_of_mut!(LED_AND_BUTTON) }; // This is one-time lazy initialisation. We steal the variables given to us // via `GLOBAL_PINS`. - if LED_AND_BUTTON.is_none() { + if led_and_button.is_none() { critical_section::with(|cs| { - *LED_AND_BUTTON = GLOBAL_PINS.borrow(cs).take(); + *led_and_button = GLOBAL_PINS.borrow(cs).take(); }); } // Need to check if our Option contains our pins - if let Some(gpios) = LED_AND_BUTTON { + if let Some(gpios) = led_and_button { // borrow led and button by *destructuring* the tuple // these will be of type `&mut LedPin` and `&mut ButtonPin`, so we don't have // to move them back into the static after we use them diff --git a/rp235x-hal-examples/src/bin/pwm_irq_input.rs b/rp235x-hal-examples/src/bin/pwm_irq_input.rs index 75c428df0..501e58db8 100644 --- a/rp235x-hal-examples/src/bin/pwm_irq_input.rs +++ b/rp235x-hal-examples/src/bin/pwm_irq_input.rs @@ -22,9 +22,6 @@ use rp235x_hal as hal; // Some things we need use embedded_hal::digital::OutputPin; -// Our interrupt macro -use hal::pac::interrupt; - // Shorter alias for gpio and pwm modules use hal::gpio; use hal::pwm; @@ -143,12 +140,12 @@ fn main() -> ! { GLOBAL_PINS.borrow(cs).replace(Some((led, input_pin, pwm))); }); - // Unmask the IO_BANK0 IRQ so that the NVIC interrupt controller - // will jump to the interrupt function when the interrupt occurs. - // We do this last so that the interrupt can't go off while - // it is in the middle of being configured + // Unmask the IO_BANK0 IRQ so that the interrupt controller will jump to the + // interrupt function when the interrupt occurs. We do this last so that the + // interrupt can't go off while it is in the middle of being configured unsafe { - cortex_m::peripheral::NVIC::unmask(hal::pac::Interrupt::IO_IRQ_BANK0); + hal::arch::interrupt_unmask(hal::pac::Interrupt::IO_IRQ_BANK0); + hal::arch::interrupt_enable(); } loop { @@ -157,16 +154,18 @@ fn main() -> ! { } } -#[interrupt] +#[no_mangle] +#[allow(non_snake_case)] fn IO_IRQ_BANK0() { // The `#[interrupt]` attribute covertly converts this to `&'static mut Option` static mut LED_INPUT_AND_PWM: Option = None; + let led_input_and_pwm = unsafe { &mut *core::ptr::addr_of_mut!(LED_INPUT_AND_PWM) }; // This is one-time lazy initialisation. We steal the variables given to us // via `GLOBAL_PINS`. - if LED_INPUT_AND_PWM.is_none() { + if led_input_and_pwm.is_none() { critical_section::with(|cs| { - *LED_INPUT_AND_PWM = GLOBAL_PINS.borrow(cs).take(); + *led_input_and_pwm = GLOBAL_PINS.borrow(cs).take(); }); } @@ -174,7 +173,7 @@ fn IO_IRQ_BANK0() { // borrow led, input and pwm by *destructuring* the tuple // these will be of type `&mut LedPin`, `&mut InputPwmPin` and `&mut PwmSlice`, so we // don't have to move them back into the static after we use them - if let Some((led, input, pwm)) = LED_INPUT_AND_PWM { + if let Some((led, input, pwm)) = led_input_and_pwm { // Check if the interrupt source is from the input pin going from high-to-low. // Note: this will always be true in this example, as that is the only enabled GPIO interrupt source if input.interrupt_status(gpio::Interrupt::EdgeLow) {