44
44
#include "shared-bindings/pulseio/PulseIn.h"
45
45
#include "supervisor/shared/tick.h"
46
46
#include "supervisor/shared/translate.h"
47
+ #include "supervisor/port.h"
47
48
48
49
// This timer is shared amongst all PulseIn objects as a higher resolution clock.
49
50
static uint8_t refcount = 0 ;
@@ -77,7 +78,7 @@ static void pulsein_set_config(pulseio_pulsein_obj_t* self, bool first_edge) {
77
78
}
78
79
79
80
void pulsein_interrupt_handler (uint8_t channel ) {
80
- // turn off interrupts while in the handler
81
+ // Turn off interrupts while in handler
81
82
common_hal_mcu_disable_interrupts ();
82
83
// Grab the current time first.
83
84
uint32_t current_overflow = overflow_count ;
@@ -90,10 +91,8 @@ void pulsein_interrupt_handler(uint8_t channel) {
90
91
uint32_t current_count = tc -> COUNT16 .COUNT .reg ;
91
92
92
93
pulseio_pulsein_obj_t * self = get_eic_channel_data (channel );
93
- if (!supervisor_background_tasks_ok () ) {
94
- common_hal_mcu_enable_interrupts ();
95
- mp_raise_RuntimeError (translate ("Input taking too long" ));
96
- return ;
94
+ if (self -> len == 0 ) {
95
+ update_background_ticks ();
97
96
}
98
97
if (self -> first_edge ) {
99
98
self -> first_edge = false;
@@ -123,6 +122,11 @@ void pulsein_interrupt_handler(uint8_t channel) {
123
122
self -> start ++ ;
124
123
}
125
124
}
125
+ if (!supervisor_background_tasks_ok () ) {
126
+ common_hal_mcu_enable_interrupts ();
127
+ mp_raise_RuntimeError (translate ("Input taking too long" ));
128
+ return ;
129
+ }
126
130
self -> last_overflow = current_overflow ;
127
131
self -> last_count = current_count ;
128
132
common_hal_mcu_enable_interrupts ();
@@ -304,7 +308,6 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) {
304
308
self -> start = (self -> start + 1 ) % self -> maxlen ;
305
309
self -> len -- ;
306
310
common_hal_mcu_enable_interrupts ();
307
-
308
311
return value ;
309
312
}
310
313
0 commit comments