mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
sbox audio support
This commit is contained in:
parent
4f84d0f5e3
commit
612a0f3fcc
56
tasmota/tasmota_xdrv_driver/xdrv_42_1_i2s_audio.ino
Normal file
56
tasmota/tasmota_xdrv_driver/xdrv_42_1_i2s_audio.ino
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
|
#ifdef ESP32S3_BOX
|
||||||
|
#include <driver/i2s.h>
|
||||||
|
#include <es8156.h>
|
||||||
|
#include <es7243e.h>
|
||||||
|
|
||||||
|
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
|
@ -54,6 +54,10 @@
|
|||||||
#include "AudioFileSourceBuffer.h"
|
#include "AudioFileSourceBuffer.h"
|
||||||
#include "AudioGeneratorAAC.h"
|
#include "AudioGeneratorAAC.h"
|
||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
|
#include <driver/i2s.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef AUDIO_PWR_ON
|
#undef AUDIO_PWR_ON
|
||||||
#undef AUDIO_PWR_OFF
|
#undef AUDIO_PWR_OFF
|
||||||
#define AUDIO_PWR_ON
|
#define AUDIO_PWR_ON
|
||||||
@ -79,6 +83,24 @@
|
|||||||
#define DAC_IIS_DOUT 2
|
#define DAC_IIS_DOUT 2
|
||||||
#endif // USE_M5STACK_CORE2
|
#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;
|
AudioGeneratorMP3 *mp3 = nullptr;
|
||||||
AudioFileSourceFS *file;
|
AudioFileSourceFS *file;
|
||||||
#ifdef USE_I2S_NO_DAC
|
#ifdef USE_I2S_NO_DAC
|
||||||
@ -264,8 +286,14 @@ void I2S_Init(void) {
|
|||||||
out = new AudioOutputI2S();
|
out = new AudioOutputI2S();
|
||||||
#endif // USE_I2S_NO_DAC
|
#endif // USE_I2S_NO_DAC
|
||||||
#ifdef ESP32
|
#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);
|
out->SetPinout(DAC_IIS_BCK, DAC_IIS_WS, DAC_IIS_DOUT);
|
||||||
|
#endif
|
||||||
#endif // ESP32
|
#endif // ESP32
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#ifdef USE_I2S_NO_DAC
|
#ifdef USE_I2S_NO_DAC
|
||||||
out = new AudioOutputI2SNoDAC();
|
out = new AudioOutputI2SNoDAC();
|
||||||
@ -307,8 +335,6 @@ void I2S_Init(void) {
|
|||||||
//#define MICSRATE 44100
|
//#define MICSRATE 44100
|
||||||
#define MICSRATE 16000
|
#define MICSRATE 16000
|
||||||
|
|
||||||
#include <driver/i2s.h>
|
|
||||||
|
|
||||||
uint32_t SpeakerMic(uint8_t spkr) {
|
uint32_t SpeakerMic(uint8_t spkr) {
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
|
|
||||||
@ -469,6 +495,7 @@ void mp3_task(void *arg) {
|
|||||||
if (!mp3->loop()) {
|
if (!mp3->loop()) {
|
||||||
mp3->stop();
|
mp3->stop();
|
||||||
mp3_delete();
|
mp3_delete();
|
||||||
|
out->stop();
|
||||||
if (mp3_task_h) {
|
if (mp3_task_h) {
|
||||||
vTaskDelete(mp3_task_h);
|
vTaskDelete(mp3_task_h);
|
||||||
mp3_task_h = 0;
|
mp3_task_h = 0;
|
||||||
@ -610,6 +637,10 @@ void Play_mp3(const char *path) {
|
|||||||
if (decoder || mp3) return;
|
if (decoder || mp3) return;
|
||||||
if (!out) return;
|
if (!out) return;
|
||||||
|
|
||||||
|
if (!ufsp->exists(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool I2S_Task;
|
bool I2S_Task;
|
||||||
|
|
||||||
AUDIO_PWR_ON
|
AUDIO_PWR_ON
|
||||||
@ -641,6 +672,7 @@ void Play_mp3(const char *path) {
|
|||||||
}
|
}
|
||||||
OsWatchLoop();
|
OsWatchLoop();
|
||||||
}
|
}
|
||||||
|
out->stop();
|
||||||
mp3_delete();
|
mp3_delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user