@@ -151,26 +151,30 @@ int periph_i2s_deinit(void *periph_handle)
151151 i2s_chan_handle_t handle = (i2s_chan_handle_t )periph_handle ;
152152 for (size_t i = 0 ; i < SOC_I2S_NUM ; i ++ ) {
153153 if (i2s_chan_handles [i ].chan_out == handle ) {
154+ i2s_channel_disable (i2s_chan_handles [i ].chan_out );
154155 i2s_del_channel (i2s_chan_handles [i ].chan_out );
155156 i2s_chan_handles [i ].chan_out = NULL ;
156157 i2s_chan_handles [i ].out_en = false;
157- ESP_LOGW (TAG , "Caution: Releasing TX (%p), RX (%p) forced to stop." ,
158- i2s_chan_handles [i ].chan_out , i2s_chan_handles [i ].chan_in );
159- i2s_channel_disable (i2s_chan_handles [i ].chan_in );
160- i2s_del_channel (i2s_chan_handles [i ].chan_in );
161- i2s_chan_handles [i ].chan_in = NULL ;
162- i2s_chan_handles [i ].in_en = false;
158+ ESP_LOGW (TAG , "Caution: Releasing TX (%p)." , i2s_chan_handles [i ].chan_out );
159+ if (i2s_chan_handles [i ].chan_in != NULL && i2s_chan_handles [i ].in_en == false) {
160+ ESP_LOGW (TAG , "Caution: RX (%p) forced to stop." , i2s_chan_handles [i ].chan_in );
161+ i2s_channel_disable (i2s_chan_handles [i ].chan_in );
162+ i2s_del_channel (i2s_chan_handles [i ].chan_in );
163+ i2s_chan_handles [i ].chan_in = NULL ;
164+ }
163165 }
164166 if (i2s_chan_handles [i ].chan_in == handle ) {
167+ i2s_channel_disable (i2s_chan_handles [i ].chan_in );
165168 i2s_del_channel (i2s_chan_handles [i ].chan_in );
166169 i2s_chan_handles [i ].chan_in = NULL ;
167170 i2s_chan_handles [i ].in_en = false;
168- ESP_LOGW (TAG , "Caution: Releasing RX (%p), TX (%p) forced to stop." ,
169- i2s_chan_handles [i ].chan_in , i2s_chan_handles [i ].chan_out );
170- i2s_channel_disable (i2s_chan_handles [i ].chan_out );
171- i2s_del_channel (i2s_chan_handles [i ].chan_out );
172- i2s_chan_handles [i ].chan_out = NULL ;
173- i2s_chan_handles [i ].out_en = false;
171+ ESP_LOGW (TAG , "Caution: Releasing RX (%p)." , i2s_chan_handles [i ].chan_in );
172+ if (i2s_chan_handles [i ].chan_out != NULL && i2s_chan_handles [i ].out_en == false) {
173+ ESP_LOGW (TAG , "Caution: TX (%p) forced to stop." , i2s_chan_handles [i ].chan_out );
174+ i2s_channel_disable (i2s_chan_handles [i ].chan_out );
175+ i2s_del_channel (i2s_chan_handles [i ].chan_out );
176+ i2s_chan_handles [i ].chan_out = NULL ;
177+ }
174178 }
175179 }
176180 return 0 ;
0 commit comments