esp32s2: PulseIn: Fix supervisor tick enabling
Before, there were two problems: * Even if a pulsein was never constructed, supervisor_disable_tick would occur during restart. This could cancel out a supervisor_enable_tick from someplace else, with unexpected results. * If two or more pulseins were constructed, each one would enable ticks, but only the last one deinited (or the reset routine) would disable, leaving ticks running indefinitely. In my testing, it seemed that this led to the board sometimes stopping when it should have auto-reloaded.
This commit is contained in:
parent
e2b5ae2d77
commit
1bc770c3dc
|
@ -77,7 +77,9 @@ void pulsein_reset(void) {
|
|||
for (size_t i = 0; i < RMT_CHANNEL_MAX; i++) {
|
||||
handles[i] = NULL;
|
||||
}
|
||||
supervisor_disable_tick();
|
||||
if (refcount != 0) {
|
||||
supervisor_disable_tick();
|
||||
}
|
||||
refcount = 0;
|
||||
}
|
||||
|
||||
|
@ -122,8 +124,10 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu
|
|||
|
||||
// start RMT RX, and enable ticks so the core doesn't turn off.
|
||||
rmt_rx_start(channel, true);
|
||||
supervisor_enable_tick();
|
||||
refcount++;
|
||||
if (refcount == 1) {
|
||||
supervisor_enable_tick();
|
||||
}
|
||||
}
|
||||
|
||||
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {
|
||||
|
|
Loading…
Reference in New Issue