diff --git a/ports/raspberrypi/common-hal/board/__init__.c b/ports/raspberrypi/common-hal/board/__init__.c index 5fc02d9997..130b4fd692 100644 --- a/ports/raspberrypi/common-hal/board/__init__.c +++ b/ports/raspberrypi/common-hal/board/__init__.c @@ -34,13 +34,3 @@ // Pins aren't actually defined here. They are in the board specific directory // such as boards/arduino_zero/pins.c. - -// routine to reset both pios -void board_reset_pio() { - for ( uint8_t sm = 0; sm < 4; sm++) { - pio_sm_init (pio0, sm, 0, NULL); - pio_sm_init (pio1, sm, 0, NULL); - } - pio_clear_instruction_memory(pio0); - pio_clear_instruction_memory(pio1); -} diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 90c48130e1..485f80b65a 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -34,6 +34,7 @@ #include "src/rp2_common/hardware_dma/include/hardware/dma.h" #include "src/rp2_common/hardware_pio/include/hardware/pio_instructions.h" #include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h" +#include "src/rp2_common/hardware_irq/include/hardware/irq.h" #include "lib/utils/interrupt_char.h" #include "py/obj.h" @@ -101,6 +102,13 @@ void reset_rp2pio_statemachine(void) { _reset_statemachine(pio, j, false); } } + for (uint8_t irq=PIO0_IRQ_0; irq <= PIO1_IRQ_1; irq++) { + irq_handler_t int_handler = irq_get_exclusive_handler(irq); + if (int_handler > 0) { + irq_set_enabled (irq, false); + irq_remove_handler(irq,int_handler); + } + } } STATIC uint32_t _check_pins_free(const mcu_pin_obj_t * first_pin, uint8_t pin_count, bool exclusive_pin_use) { diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index fce618de49..2cbf0b5136 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -45,6 +45,10 @@ #include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h" #endif +#if CIRCUITPY_RP2PIO +#include "bindings/rp2pio/StateMachine.h" +#endif + #if BOARD_I2C // Statically allocate the I2C object so it can live past the end of the heap and into the next VM. // That way it can be used by built-in I2CDisplay displays and be accessible through board.I2C(). @@ -181,6 +185,6 @@ void reset_board_busses(void) { MP_STATE_VM(shared_uart_bus) = NULL; #endif #if CIRCUITPY_RP2PIO - board_reset_pio(); + reset_rp2pio_statemachine(); #endif } diff --git a/shared-module/board/__init__.h b/shared-module/board/__init__.h index 2b970710ae..f7eecd4170 100644 --- a/shared-module/board/__init__.h +++ b/shared-module/board/__init__.h @@ -28,6 +28,5 @@ #define MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H void reset_board_busses(void); -void board_reset_pio(void); #endif // MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H