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

I2S::available/availableForWrite() returns bytes (#1499)

Per the Arduino documentation, I2s::available should return bytes free,
not samples.  Adjust accordingly.
parent f57b5bc7
...@@ -138,6 +138,7 @@ void I2S::onReceive(void(*fn)(void)) { ...@@ -138,6 +138,7 @@ void I2S::onReceive(void(*fn)(void)) {
bool I2S::begin() { bool I2S::begin() {
_running = true; _running = true;
_hasPeeked = false; _hasPeeked = false;
_isHolding = 0;
int off = 0; int off = 0;
if (!_swapClocks) { if (!_swapClocks) {
_i2s = new PIOProgram(_isOutput ? (_isLSBJ ? &pio_lsbj_out_program : &pio_i2s_out_program) : &pio_i2s_in_program); _i2s = new PIOProgram(_isOutput ? (_isLSBJ ? &pio_lsbj_out_program : &pio_i2s_out_program) : &pio_i2s_in_program);
...@@ -189,28 +190,14 @@ int I2S::available() { ...@@ -189,28 +190,14 @@ int I2S::available() {
return 0; return 0;
} else { } else {
auto avail = _arb->available(); auto avail = _arb->available();
switch (_bps) { avail *= 4; // 4 samples per 32-bits
case 8: if (_bps < 24) {
avail *= 4; // 4 samples per 32-bits
if (_isOutput) { if (_isOutput) {
// 16- and 8-bit can have holding bytes available
avail += (32 - _isHolding) / 8; avail += (32 - _isHolding) / 8;
} else { } else {
avail += _isHolding / 8; avail += _isHolding / 8;
} }
break;
case 16:
avail *= 2; // 2 samples per 32-bits
if (_isOutput) {
avail += (32 - _isHolding) / 16;
} else {
avail += _isHolding / 16;
}
break;
case 24:
case 32:
default:
// All stored in 32-bit words and no holding required
break;
} }
return avail; return avail;
} }
......
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