@@ -56,7 +56,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
5656 self -> idle_state = idle_state ;
5757 self -> start = 0 ;
5858 self -> len = 0 ;
59- self -> len_target = 0 ;
6059
6160 common_hal_rp2pio_statemachine_construct (& self -> state_machine ,
6261 pulsein_program , MP_ARRAY_SIZE (pulsein_program ),
@@ -134,8 +133,6 @@ void common_hal_pulseio_pulsein_interrupt(void *self_in) {
134133 self -> buffer [buf_index ] = (uint16_t )result ;
135134 if (self -> len < self -> maxlen ) {
136135 self -> len ++ ;
137- self -> len_target ++ ; // The interrupt will only cause a problem in either len or len_target, not both.
138- // So we can just check for a match, and choose the higher.
139136 } else {
140137 self -> start = (self -> start + 1 ) % self -> maxlen ;
141138 }
@@ -176,14 +173,10 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
176173 mp_raise_IndexError_varg (translate ("pop from empty %q" ), MP_QSTR_PulseIn );
177174 }
178175 uint16_t value = self -> buffer [self -> start ];
176+ common_hal_mcu_disable_interrupts ();
179177 self -> start = (self -> start + 1 ) % self -> maxlen ;
180- self -> len_target -- ;
181178 self -> len -- ;
182- if (self -> len != self -> len_target ) {
183- uint16_t len_accurate = self -> len > self -> len_target ? self -> len : self -> len_target ;
184- self -> len_target = len_accurate ;
185- self -> len = len_accurate ;
186- }
179+ common_hal_mcu_enable_interrupts ();
187180 return value ;
188181}
189182
0 commit comments