3636#include "bindings/rp2pio/StateMachine.h"
3737#include "common-hal/pulseio/PulseIn.h"
3838
39- pulseio_pulsein_obj_t * save_self ;
40-
4139#define NO_PIN 0xff
4240#define MAX_PULSE 65535
4341#define MIN_PULSE 10
@@ -62,7 +60,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
6260 self -> idle_state = idle_state ;
6361 self -> start = 0 ;
6462 self -> len = 0 ;
65- save_self = self ;
6663
6764 bool ok = rp2pio_statemachine_construct (& self -> state_machine ,
6865 pulsein_program , sizeof (pulsein_program ) / sizeof (pulsein_program [0 ]),
@@ -88,7 +85,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
8885 buf_index = 0 ;
8986
9087 pio_sm_set_in_pins (self -> state_machine .pio ,self -> state_machine .state_machine ,pin -> number );
91- common_hal_rp2pio_statemachine_set_interrupt_handler (& (self -> state_machine ),& common_hal_pulseio_pulsein_interrupt ,NULL ,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS );
88+ common_hal_rp2pio_statemachine_set_interrupt_handler (& (self -> state_machine ),& common_hal_pulseio_pulsein_interrupt ,self ,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS );
9289
9390 // exec a set pindirs to 0 for input
9491 pio_sm_exec (self -> state_machine .pio ,self -> state_machine .state_machine ,0xe080 );
@@ -124,9 +121,8 @@ void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) {
124121 result = 0 ;
125122 buf_index = 0 ;
126123}
127- void common_hal_pulseio_pulsein_interrupt () {
124+ void common_hal_pulseio_pulsein_interrupt (pulseio_pulsein_obj_t * self ) {
128125
129- pulseio_pulsein_obj_t * self = save_self ;
130126 uint32_t rxfifo = 0 ;
131127
132128 rxfifo = pio_sm_get_blocking (self -> state_machine .pio , self -> state_machine .state_machine );
0 commit comments