Skip to content

Commit 1bc770c

Browse files
committed
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.
1 parent e2b5ae2 commit 1bc770c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ports/esp32s2/common-hal/pulseio/PulseIn.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ void pulsein_reset(void) {
7777
for (size_t i = 0; i < RMT_CHANNEL_MAX; i++) {
7878
handles[i] = NULL;
7979
}
80-
supervisor_disable_tick();
80+
if (refcount != 0) {
81+
supervisor_disable_tick();
82+
}
8183
refcount = 0;
8284
}
8385

@@ -122,8 +124,10 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu
122124

123125
// start RMT RX, and enable ticks so the core doesn't turn off.
124126
rmt_rx_start(channel, true);
125-
supervisor_enable_tick();
126127
refcount++;
128+
if (refcount == 1) {
129+
supervisor_enable_tick();
130+
}
127131
}
128132

129133
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) {

0 commit comments

Comments
 (0)