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

I2S check for failure of ARB and PIO allocation (#1528)

Per https://github.com/earlephilhower/arduino-pico/pull/1524#issuecomment-1587885054
parent c64cdc14
......@@ -146,7 +146,12 @@ bool I2S::begin() {
} else {
_i2s = new PIOProgram(_isOutput ? (_isLSBJ ? &pio_lsbj_out_swap_program : &pio_i2s_out_swap_program) : &pio_i2s_in_swap_program);
}
_i2s->prepare(&_pio, &_sm, &off);
if (!_i2s->prepare(&_pio, &_sm, &off)) {
_running = false;
delete _i2s;
_i2s = nullptr;
return false;
}
if (_isOutput) {
if (_isLSBJ) {
pio_lsbj_out_program_init(_pio, _sm, off, _pinDOUT, _pinBCLK, _bps, _swapClocks);
......@@ -168,7 +173,14 @@ bool I2S::begin() {
_bufferWords = 64 * (_bps == 32 ? 2 : 1);
}
_arb = new AudioBufferManager(_buffers, _bufferWords, _silenceSample, _isOutput ? OUTPUT : INPUT);
_arb->begin(pio_get_dreq(_pio, _sm, _isOutput), _isOutput ? &_pio->txf[_sm] : (volatile void*)&_pio->rxf[_sm]);
if (!_arb->begin(pio_get_dreq(_pio, _sm, _isOutput), _isOutput ? &_pio->txf[_sm] : (volatile void*)&_pio->rxf[_sm])) {
_running = false;
delete _arb;
_arb = nullptr;
delete _i2s;
_i2s = nullptr;
return false;
}
_arb->setCallback(_cb);
pio_sm_set_enabled(_pio, _sm, true);
......
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