From f68c5baea63ca1730fb32575119c5adccdaab642 Mon Sep 17 00:00:00 2001 From: Wangjialin Date: Tue, 23 May 2017 19:32:10 +0800 Subject: [PATCH] bugfix(i2s): fix error when changing changel number in i2s_set_clk function --- components/driver/i2s.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/components/driver/i2s.c b/components/driver/i2s.c index 3f6279f25..ac0c3fb07 100644 --- a/components/driver/i2s.c +++ b/components/driver/i2s.c @@ -204,7 +204,16 @@ esp_err_t i2s_set_clk(i2s_port_t i2s_num, uint32_t rate, i2s_bits_per_sample_t b i2s_stop(i2s_num); - p_i2s_obj[i2s_num]->channel_num = (ch == 2) ? 2 : 1; + uint32_t cur_mode = 0; + if (p_i2s_obj[i2s_num]->channel_num != ch) { + p_i2s_obj[i2s_num]->channel_num = (ch == 2) ? 2 : 1; + cur_mode = I2S[i2s_num]->fifo_conf.tx_fifo_mod; + I2S[i2s_num]->fifo_conf.tx_fifo_mod = (ch == 2) ? cur_mode - 1 : cur_mode + 1; + cur_mode = I2S[i2s_num]->fifo_conf.rx_fifo_mod; + I2S[i2s_num]->fifo_conf.rx_fifo_mod = (ch == 2) ? cur_mode -1 : cur_mode + 1; + I2S[i2s_num]->conf_chan.tx_chan_mod = (ch == 2) ? 0 : 1; + I2S[i2s_num]->conf_chan.rx_chan_mod = (ch == 2) ? 0 : 1; + } if (bits != p_i2s_obj[i2s_num]->bits_per_sample) {