File tree Expand file tree Collapse file tree 1 file changed +4
-17
lines changed Expand file tree Collapse file tree 1 file changed +4
-17
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ void I2S::onReceive(void(*fn)(void)) {
138138bool 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 }
You can’t perform that action at this time.
0 commit comments