Skip to content

Commit 19d09ea

Browse files
Preserve prior bitrate for I2S begin (#6349)
Fixes #6066 Preserve any existing sample rate for the I2S unit when performing an `i2s_begin`. If nothing has ever been set, default to 44.1KHz as before.
1 parent c6bfec9 commit 19d09ea

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cores/esp8266/core_esp8266_i2s.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ bool i2s_rxtx_begin(bool enableRx, bool enableTx) {
507507
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, FUNC_I2SI_WS);
508508
}
509509

510-
_i2s_sample_rate = 0;
511510
if (!i2s_slc_begin()) {
512511
// OOM in SLC memory allocations, tear it all down and abort!
513512
i2s_end();
@@ -530,7 +529,13 @@ bool i2s_rxtx_begin(bool enableRx, bool enableTx) {
530529
// I2STXCMM, I2SRXCMM=0 => Dual channel mode
531530
I2SCC &= ~((I2STXCMM << I2STXCM) | (I2SRXCMM << I2SRXCM)); // Set RX/TX CHAN_MOD=0
532531

533-
i2s_set_rate(44100);
532+
// Ensure a sane clock is set, but don't change any pre-existing ones.
533+
// But we also need to make sure the other bits weren't reset by a previous
534+
// reset. So, store the present one, clear the flag, then set the same
535+
// value (writing all needed config bits in the process
536+
uint32_t save_rate = _i2s_sample_rate;
537+
_i2s_sample_rate = 0;
538+
i2s_set_rate(save_rate ? save_rate : 44100);
534539

535540
if (rx) {
536541
// Need to prime the # of samples to receive in the engine

0 commit comments

Comments
 (0)