Unverified Commit 9e659b00 authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Deallocate resources on SerialPIO::end (#596)

Fixes #593

When SerialPIO::end is called, stop the PIO SMs and potentially
disable the IRQ handler if this is the last RX port on that PIO.
parent 7d30e6da
......@@ -257,8 +257,23 @@ void SerialPIO::end() {
if (!_running) {
return;
}
// TODO: Deallocate PIO resources, stop them
_pioSP[pio_get_index(_rxPIO)][_rxSM] = nullptr;
if (_tx != NOPIN) {
pio_sm_set_enabled(_txPIO, _txSM, false);
}
if (_rx != NOPIN) {
pio_sm_set_enabled(_rxPIO, _rxSM, false);
_pioSP[pio_get_index(_rxPIO)][_rxSM] = nullptr;
// If no more active, disable the IRQ
auto pioNum = pio_get_index(_rxPIO);
bool used = false;
for (int i = 0; i < 4; i++) {
used = used || !!_pioSP[pioNum][i];
}
if (!used) {
auto irqno = pioNum == 0 ? PIO0_IRQ_0 : PIO1_IRQ_0;
irq_set_enabled(irqno, false);
}
}
_running = false;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment