@@ -286,6 +286,9 @@ bool I2SClass::initSTD(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
286286 if (_dout >= 0 ) if (!perimanSetPinBus (_dout, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
287287 if (_din >= 0 ) if (!perimanSetPinBus (_din, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
288288
289+ // Set peripheral manager detach function for I2S
290+ perimanSetBusDeinit (ESP32_BUS_TYPE_I2S_STD, I2SClass::i2sDetachBus);
291+
289292 // I2S configuration
290293 i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG ();
291294 if (_dout >= 0 && _din >= 0 ) {
@@ -335,6 +338,9 @@ bool I2SClass::initTDM(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mo
335338 if (_dout >= 0 ) if (!perimanSetPinBus (_dout, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
336339 if (_din >= 0 ) if (!perimanSetPinBus (_din, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
337340
341+ // Set peripheral manager detach function for I2S
342+ perimanSetBusDeinit (ESP32_BUS_TYPE_I2S_TDM, I2SClass::i2sDetachBus);
343+
338344 // I2S configuration
339345 i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG ();
340346 if (_dout >= 0 && _din >= 0 ) {
@@ -383,6 +389,9 @@ bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
383389 if (_tx_dout0 >= 0 ) if (!perimanSetPinBus (_tx_dout0, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
384390 if (_tx_dout1 >= 0 ) if (!perimanSetPinBus (_tx_dout1, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
385391
392+ // Set peripheral manager detach function for I2S
393+ perimanSetBusDeinit (ESP32_BUS_TYPE_I2S_PDM_TX, I2SClass::i2sDetachBus);
394+
386395 // I2S configuration
387396 i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG ();
388397 I2S_ERROR_CHECK_RETURN_FALSE (i2s_new_channel (&chan_cfg, &tx_chan, NULL ));
@@ -397,9 +406,9 @@ bool I2SClass::initPDMtx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
397406 }
398407
399408 // Peripheral manager set bus type to I2S
400- if (_tx_clk >= 0 ) if (!perimanSetPinBus (_tx_clk, ESP32_BUS_TYPE_I2S_PDM , (void *)(this ))){ goto err; }
401- if (_tx_dout0 >= 0 ) if (!perimanSetPinBus (_tx_dout0, ESP32_BUS_TYPE_I2S_PDM , (void *)(this ))){ goto err; }
402- if (_tx_dout1 >= 0 ) if (!perimanSetPinBus (_tx_dout1, ESP32_BUS_TYPE_I2S_PDM , (void *)(this ))){ goto err; }
409+ if (_tx_clk >= 0 ) if (!perimanSetPinBus (_tx_clk, ESP32_BUS_TYPE_I2S_PDM_TX , (void *)(this ))){ goto err; }
410+ if (_tx_dout0 >= 0 ) if (!perimanSetPinBus (_tx_dout0, ESP32_BUS_TYPE_I2S_PDM_TX , (void *)(this ))){ goto err; }
411+ if (_tx_dout1 >= 0 ) if (!perimanSetPinBus (_tx_dout1, ESP32_BUS_TYPE_I2S_PDM_TX , (void *)(this ))){ goto err; }
403412
404413 return true ;
405414err:
@@ -418,6 +427,9 @@ bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
418427 if (_rx_din2 >= 0 ) if (!perimanSetPinBus (_rx_din2, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
419428 if (_rx_din3 >= 0 ) if (!perimanSetPinBus (_rx_din3, ESP32_BUS_TYPE_INIT, NULL )){ return false ; }
420429
430+ // Set peripheral manager detach function for I2S
431+ perimanSetBusDeinit (ESP32_BUS_TYPE_I2S_PDM_RX, I2SClass::i2sDetachBus);
432+
421433 // I2S configuration
422434 i2s_chan_config_t chan_cfg = I2S_DEFAULT_CFG ();
423435 I2S_ERROR_CHECK_RETURN_FALSE (i2s_new_channel (&chan_cfg, NULL , &rx_chan));
@@ -432,11 +444,11 @@ bool I2SClass::initPDMrx(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_
432444 }
433445
434446 // Peripheral manager set bus type to I2S
435- if (_rx_clk >= 0 ) if (!perimanSetPinBus (_rx_clk, ESP32_BUS_TYPE_I2S_PDM , (void *)(this ))){ goto err; }
436- if (_rx_din0 >= 0 ) if (!perimanSetPinBus (_rx_din0, ESP32_BUS_TYPE_I2S_PDM , (void *)(this ))){ goto err; }
437- if (_rx_din1 >= 0 ) if (!perimanSetPinBus (_rx_din1, ESP32_BUS_TYPE_I2S_PDM , (void *)(this ))){ goto err; }
438- if (_rx_din2 >= 0 ) if (!perimanSetPinBus (_rx_din2, ESP32_BUS_TYPE_I2S_PDM , (void *)(this ))){ goto err; }
439- if (_rx_din3 >= 0 ) if (!perimanSetPinBus (_rx_din3, ESP32_BUS_TYPE_I2S_PDM , (void *)(this ))){ goto err; }
447+ if (_rx_clk >= 0 ) if (!perimanSetPinBus (_rx_clk, ESP32_BUS_TYPE_I2S_PDM_RX , (void *)(this ))){ goto err; }
448+ if (_rx_din0 >= 0 ) if (!perimanSetPinBus (_rx_din0, ESP32_BUS_TYPE_I2S_PDM_RX , (void *)(this ))){ goto err; }
449+ if (_rx_din1 >= 0 ) if (!perimanSetPinBus (_rx_din1, ESP32_BUS_TYPE_I2S_PDM_RX , (void *)(this ))){ goto err; }
450+ if (_rx_din2 >= 0 ) if (!perimanSetPinBus (_rx_din2, ESP32_BUS_TYPE_I2S_PDM_RX , (void *)(this ))){ goto err; }
451+ if (_rx_din3 >= 0 ) if (!perimanSetPinBus (_rx_din3, ESP32_BUS_TYPE_I2S_PDM_RX , (void *)(this ))){ goto err; }
440452
441453 return true ;
442454err:
0 commit comments