10000 I2S check for failure of ARB and PIO allocation (#1528) · StarMiner99/arduino-pico@d18f8dc · GitHub
[go: up one dir, main page]

Skip to content

Commit d18f8dc

Browse files
I2S check for failure of ARB and PIO allocation (earlephilhower#1528)
Per earlephilhower#1524 (comment)
1 parent c64cdc1 commit d18f8dc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

libraries/I2S/src/I2S.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ bool I2S::begin() {
146146
} else {
147147
_i2s = new PIOProgram(_isOutput ? (_isLSBJ ? &pio_lsbj_out_swap_program : &pio_i2s_out_swap_program) : &pio_i2s_in_swap_program);
148148
}
149-
_i2s->prepare(&_pio, &_sm, &off);
149+
if (!_i2s->prepare(&_pio, &_sm, &off)) {
150+
_running = false;
151+
delete _i2s;
152+
_i2s = nullptr;
153+
return false;
154+
}
150155
if (_isOutput) {
151156
if (_isLSBJ) {
152157
pio_lsbj_out_program_init(_pio, _sm, off, _pinDOUT, _pinBCLK, _bps, _swapClocks);
@@ -168,7 +173,14 @@ bool I2S::begin() {
168173
_bufferWords = 64 * (_bps == 32 ? 2 : 1);
169174
}
170175
_arb = new AudioBufferManager(_buffers, _bufferWords, _silenceSample, _isOutput ? OUTPUT : INPUT);
171-
_arb->begin(pio_get_dreq(_pio, _sm, _isOutput), _isOutput ? &_pio->txf[_sm] : (volatile void*)&_pio->rxf[_sm]);
176+
if (!_arb->begin(pio_get_dreq(_pio, _sm, _isOutput), _isOutput ? &_pio->txf[_sm] : (volatile void*)&_pio->rxf[_sm])) {
177+
_running = false;
178+
delete _arb;
179+
_arb = nullptr;
180+
delete _i2s;
181+
_i2s = nullptr;
182+
return false;
183+
}
172184
_arb->setCallback(_cb);
173185
pio_sm_set_enabled(_pio, _sm, true);
174186

0 commit comments

Comments
 (0)
0