From f95f15fcb34e5fad061f0b657b8eac9bdd65a1a2 Mon Sep 17 00:00:00 2001 From: FedericoBusero <35894905+FedericoBusero@users.noreply.github.com> Date: Thu, 1 Sep 2022 21:16:14 +0200 Subject: [PATCH] I2S: register I2S object to platform failed (#568) ESP32: When calling destructor after stop, and then create a new object, then an error is shown "I2S: register I2S object to platform failed" because i2s_driver_uninstall had not been called. ESP8266 : i2s_end is not called when stopping, but i2sOn is false, resulting in new call i2s_rxtx_begin --- src/AudioOutputI2S.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/AudioOutputI2S.cpp b/src/AudioOutputI2S.cpp index 621db59..919679d 100644 --- a/src/AudioOutputI2S.cpp +++ b/src/AudioOutputI2S.cpp @@ -67,18 +67,7 @@ AudioOutputI2S::AudioOutputI2S(long sampleRate, pin_size_t sck, pin_size_t data) AudioOutputI2S::~AudioOutputI2S() { - #ifdef ESP32 - if (i2sOn) { - audioLogger->printf("UNINSTALL I2S\n"); - i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver - } - #elif defined(ESP8266) - if (i2sOn) - i2s_end(); - #elif defined(ARDUINO_ARCH_RP2040) - stop(); - #endif - i2sOn = false; + stop(); } bool AudioOutputI2S::SetPinout() @@ -359,6 +348,10 @@ bool AudioOutputI2S::stop() #ifdef ESP32 i2s_zero_dma_buffer((i2s_port_t)portNo); + audioLogger->printf("UNINSTALL I2S\n"); + i2s_driver_uninstall((i2s_port_t)portNo); //stop & destroy i2s driver + #elif defined(ESP8266) + i2s_end(); #elif defined(ARDUINO_ARCH_RP2040) i2s.end(); #endif