diff --git a/tasmota/tasmota_xdrv_driver/xdrv_42_1_i2s_audio.ino b/tasmota/tasmota_xdrv_driver/xdrv_42_1_i2s_audio.ino new file mode 100644 index 000000000..c48c342c6 --- /dev/null +++ b/tasmota/tasmota_xdrv_driver/xdrv_42_1_i2s_audio.ino @@ -0,0 +1,56 @@ + +#ifdef ESP32 +#ifdef ESP32S3_BOX +#include +#include +#include + +void S3boxAudioPower(uint8_t pwr) { + pinMode(46 , OUTPUT); + digitalWrite(46, pwr); +} + +uint32_t ES8156_init() { + uint32_t ret_val = ESP_OK; + + if (I2cSetDevice(ES8156_ADDR, 1)) { + I2cSetActiveFound(ES8156_ADDR, "ES8156-I2C", 1); + audio_hal_codec_config_t cfg = { + .i2s_iface = { + .mode = AUDIO_HAL_MODE_SLAVE, + .bits = AUDIO_HAL_BIT_LENGTH_16BITS, + } + }; + ret_val |= es8156_codec_init(&Wire1, &cfg); + ret_val |= es8156_codec_set_voice_volume(75); + } + return ret_val; +} + +uint32_t es7243e_init() { + uint32_t ret_val = ESP_OK; + + if (I2cSetDevice(ES7243_ADDR, 1)) { + I2cSetActiveFound(ES7243_ADDR, "ES7243e-I2C", 1); + } + + audio_hal_codec_config_t cfg = { + .i2s_iface = { + .mode = AUDIO_HAL_MODE_SLAVE, + .bits = AUDIO_HAL_BIT_LENGTH_16BITS, + } + }; + + ret_val |= es8156_codec_init(&Wire1, &cfg); + + return ret_val; +} + +void S3boxInit() { + if (TasmotaGlobal.i2c_enabled_2) { + ES8156_init(); + es7243e_init(); + } +} +#endif +#endif diff --git a/tasmota/tasmota_xdrv_driver/xdrv_42_i2s_audio.ino b/tasmota/tasmota_xdrv_driver/xdrv_42_i2s_audio.ino index 6849859de..31cfb64ca 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_42_i2s_audio.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_42_i2s_audio.ino @@ -54,6 +54,10 @@ #include "AudioFileSourceBuffer.h" #include "AudioGeneratorAAC.h" +#ifdef ESP32 +#include +#endif + #undef AUDIO_PWR_ON #undef AUDIO_PWR_OFF #define AUDIO_PWR_ON @@ -79,6 +83,24 @@ #define DAC_IIS_DOUT 2 #endif // USE_M5STACK_CORE2 + +#ifdef ESP32S3_BOX +#undef AUDIO_PWR_ON +#undef AUDIO_PWR_OFF +#define AUDIO_PWR_ON S3boxAudioPower(true); +#define AUDIO_PWR_OFF S3boxAudioPower(false); + +#undef DAC_IIS_BCK +#undef DAC_IIS_WS +#undef DAC_IIS_DOUT +#define DAC_IIS_BCK 17 +#define DAC_IIS_WS 47 +#define DAC_IIS_DOUT 15 +#define DAC_IIS_DIN 16 +#define DAC_IIS_MCLK 2 + +#endif // ESP32S3_BOX + AudioGeneratorMP3 *mp3 = nullptr; AudioFileSourceFS *file; #ifdef USE_I2S_NO_DAC @@ -264,8 +286,14 @@ void I2S_Init(void) { out = new AudioOutputI2S(); #endif // USE_I2S_NO_DAC #ifdef ESP32 +#ifdef ESP32S3_BOX + S3boxInit(); + out->SetPinout(DAC_IIS_BCK, DAC_IIS_WS, DAC_IIS_DOUT, DAC_IIS_MCLK, DAC_IIS_DIN); +#else out->SetPinout(DAC_IIS_BCK, DAC_IIS_WS, DAC_IIS_DOUT); +#endif #endif // ESP32 + #else #ifdef USE_I2S_NO_DAC out = new AudioOutputI2SNoDAC(); @@ -307,8 +335,6 @@ void I2S_Init(void) { //#define MICSRATE 44100 #define MICSRATE 16000 -#include - uint32_t SpeakerMic(uint8_t spkr) { esp_err_t err = ESP_OK; @@ -469,6 +495,7 @@ void mp3_task(void *arg) { if (!mp3->loop()) { mp3->stop(); mp3_delete(); + out->stop(); if (mp3_task_h) { vTaskDelete(mp3_task_h); mp3_task_h = 0; @@ -610,6 +637,10 @@ void Play_mp3(const char *path) { if (decoder || mp3) return; if (!out) return; + if (!ufsp->exists(path)) { + return; + } + bool I2S_Task; AUDIO_PWR_ON @@ -641,6 +672,7 @@ void Play_mp3(const char *path) { } OsWatchLoop(); } + out->stop(); mp3_delete(); }