From 2c1aeba4abc7c1b3aa7d2a0b1f5c78bc75af058a Mon Sep 17 00:00:00 2001 From: FedericoBusero <35894905+FedericoBusero@users.noreply.github.com> Date: Tue, 30 Nov 2021 21:25:30 +0100 Subject: [PATCH] ESP32-C3 Support (#454) * ESP32-C3 has no ULP coprocessor Only the ESP32, ESP32-S2 and ESP32-S3 chips have an ULP coprocessor, ESP32-C3 doesn't have it. So exclude this code from compiling, as it cannot compile in the C3 environment. * uint32_t and size_t is not the same on RISC-V This change is necessary to be able to compile it on ESP32-C3 * uint32_t and size_t is not the same on RISC-V The change is necessary to compile it on ESP32-C3 * ESP32-C3: I2S_MODE_DAC_BUILT_IN / I2S_MODE_PDM not available On some ESP32 chips (e.g. ESP32-C3), builtin DAC is not possible as it lacks the hardware module. In order to be able to compile the library on ESP32-C3 the defines cannot be used. --- src/AudioFileSourceSPIRAMBuffer.cpp | 2 +- src/AudioOutputI2S.cpp | 14 +++++++++++++- src/AudioOutputSPDIF.cpp | 2 +- src/AudioOutputULP.cpp | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/AudioFileSourceSPIRAMBuffer.cpp b/src/AudioFileSourceSPIRAMBuffer.cpp index 2c9eb3b..475afa4 100644 --- a/src/AudioFileSourceSPIRAMBuffer.cpp +++ b/src/AudioFileSourceSPIRAMBuffer.cpp @@ -105,7 +105,7 @@ uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len) } // Read up to the entire buffer from RAM - uint32_t toReadFromBuffer = std::min(len, writePtr - readPtr); + uint32_t toReadFromBuffer = std::min(len, (uint32_t)(writePtr - readPtr)); uint8_t *ptr = reinterpret_cast(data); if (toReadFromBuffer > 0) { #ifdef FAKERAM diff --git a/src/AudioOutputI2S.cpp b/src/AudioOutputI2S.cpp index 1483cb3..760ff1a 100644 --- a/src/AudioOutputI2S.cpp +++ b/src/AudioOutputI2S.cpp @@ -168,11 +168,19 @@ bool AudioOutputI2S::begin(bool txDAC) i2s_mode_t mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); if (output_mode == INTERNAL_DAC) { +#ifdef I2S_MODE_DAC_BUILT_IN mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN); +#else + return false; +#endif } - else if (output_mode == INTERNAL_PDM) + if (output_mode == INTERNAL_PDM) { +#ifdef I2S_MODE_PDM mode = (i2s_mode_t)(mode | I2S_MODE_PDM); +#else + return false; +#endif } i2s_comm_format_t comm_fmt = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB); @@ -199,8 +207,12 @@ bool AudioOutputI2S::begin(bool txDAC) } if (output_mode == INTERNAL_DAC || output_mode == INTERNAL_PDM) { +#ifdef I2S_DAC_CHANNEL_BOTH_EN i2s_set_pin((i2s_port_t)portNo, NULL); i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN); +#else + return false; +#endif } else { diff --git a/src/AudioOutputSPDIF.cpp b/src/AudioOutputSPDIF.cpp index c1370d7..59923f9 100644 --- a/src/AudioOutputSPDIF.cpp +++ b/src/AudioOutputSPDIF.cpp @@ -265,7 +265,7 @@ bool AudioOutputSPDIF::ConsumeSample(int16_t sample[2]) #if defined(ESP32) // Assume DMA buffers are multiples of 16 bytes. Either we write all bytes or none. - uint32_t bytes_written; + size_t bytes_written; esp_err_t ret = i2s_write((i2s_port_t)portNo, (const char*)&buf, 8 * channels, &bytes_written, 0); // If we didn't write all bytes, return false early and do not increment frame_num if ((ret != ESP_OK) || (bytes_written != (8 * channels))) return false; diff --git a/src/AudioOutputULP.cpp b/src/AudioOutputULP.cpp index 63177e3..d8f4e02 100644 --- a/src/AudioOutputULP.cpp +++ b/src/AudioOutputULP.cpp @@ -18,7 +18,7 @@ along with this program. If not, see . */ -#ifdef ESP32 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 #include "AudioOutputULP.h" #include