10000 I2S::available/availableForWrite() returns bytes (#1499) · StarMiner99/arduino-pico@2888f4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2888f4d

Browse files
I2S::available/availableForWrite() returns bytes (earlephilhower#1499)
Per the Arduino documentation, I2s::available should return bytes free, not samples. Adjust accordingly.
1 parent f57b5bc commit 2888f4d

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

libraries/I2S/src/I2S.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void I2S::onReceive(void(*fn)(void)) {
138138
bool I2S::begin() {
139139
_running = true;
140140
_hasPeeked = false;
141+
_isHolding = 0;
141142
int off = 0;
142143
if (!_swapClocks) {
143144
_i2s = new PIOProgram(_isOutput ? (_isLSBJ ? &pio_lsbj_out_program : &pio_i2s_out_program) : &pio_i2s_in_program);
@@ -189,28 +190,14 @@ int I2S::available() {
189190
return 0;
190191
} else {
191192
auto avail = _arb->available();
192-
switch (_bps) {
193-
case 8:
194-
avail *= 4; // 4 samples per 32-bits
193+
avail *= 4; // 4 samples per 32-bits
194+
if (_bps < 24) {
195195
if (_isOutput) {
196+
// 16- and 8-bit can have holding bytes available
196197
avail += (32 - _isHolding) / 8;
197198
} else {
198199
avail += _isHolding / 8;
199200
}
200-
break;
201-
case 16:
202-
avail *= 2; // 2 samples per 32-bits
203-
if (_isOutput) {
204-
avail += (32 - _isHolding) / 16;
205-
} else {
206-
avail += _isHolding / 16;
207-
}
208-
break;
209-
case 24:
210-
case 32:
211-
default:
212-
// All stored in 32-bit words and no holding required
213-
break;
214201
}
215202
return avail;
216203
}

0 commit comments

Comments
 (0)
0