Skip to content

Commit 4c1ef09

Browse files
committed
enable/disable TX RDY on write/empty
1 parent 34c9a7f commit 4c1ef09

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

libraries/I2S/src/I2S.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ int I2SClass::begin(int mode, long sampleRate, int bitsPerSample, int driveClock
166166
NVIC_EnableIRQ(I2S_IRQn);
167167
NVIC_SetPriority(I2S_IRQn, (1 << __NVIC_PRIO_BITS) - 1); /* set Priority */
168168

169-
if (_uc_index == 0) {
170-
_i2s->INTENSET.bit.TXRDY0 = 1;
171-
} else {
172-
_i2s->INTENSET.bit.TXRDY1 = 1;
173-
}
174-
175169
return 0;
176170
}
177171

@@ -261,22 +255,29 @@ int I2SClass::write(int32_t data)
261255
_aui_buffer[i] = data;
262256
_i_head = i;
263257

258+
259+
if (_uc_index == 0) {
260+
_i2s->INTENSET.bit.TXRDY0 = 1;
261+
} else {
262+
_i2s->INTENSET.bit.TXRDY1 = 1;
263+
}
264+
264265
return 1;
265266
}
266267

267268
void I2SClass::onService() {
268269

269270
if (_uc_index == 0) {
270271
if (_i2s->INTFLAG.bit.TXRDY0) {
271-
int32_t data = 0;
272-
273272
if (_i_head != _i_tail) {
274-
data = _aui_buffer[_i_tail];
273+
int32_t data = _aui_buffer[_i_tail];
275274
_i_tail = ((uint32_t)(_i_tail + 1) % I2S_BUFFER_SIZE);
276-
}
277275

278-
while (_i2s->SYNCBUSY.bit.DATA0);
279-
_i2s->DATA[_uc_index].bit.DATA = data;
276+
while (_i2s->SYNCBUSY.bit.DATA0);
277+
_i2s->DATA[_uc_index].bit.DATA = data;
278+
} else {
279+
_i2s->INTENSET.bit.TXRDY0 = 0;
280+
}
280281

281282
_i2s->INTFLAG.bit.TXRDY0 = 1;
282283
}

0 commit comments

Comments
 (0)