File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -257,8 +257,23 @@ void SerialPIO::end() {
257257 if (!_running) {
258258 return ;
259259 }
260- // TODO: Deallocate PIO resources, stop them
261- _pioSP[pio_get_index (_rxPIO)][_rxSM] = nullptr ;
260+ if (_tx != NOPIN) {
261+ pio_sm_set_enabled (_txPIO, _txSM, false );
262+ }
263+ if (_rx != NOPIN) {
264+ pio_sm_set_enabled (_rxPIO, _rxSM, false );
265+ _pioSP[pio_get_index (_rxPIO)][_rxSM] = nullptr ;
266+ // If no more active, disable the IRQ
267+ auto pioNum = pio_get_index (_rxPIO);
268+ bool used = false ;
269+ for (int i = 0 ; i < 4 ; i++) {
270+ used = used || !!_pioSP[pioNum][i];
271+ }
272+ if (!used) {
273+ auto irqno = pioNum == 0 ? PIO0_IRQ_0 : PIO1_IRQ_0;
274+ irq_set_enabled (irqno, false );
275+ }
276+ }
262277 _running = false ;
263278}
264279
You can’t perform that action at this time.
0 commit comments