Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2S Fix Builtin DAC&PDM on ESP32 & compiling warning ESP32-C3 #461

Merged

Conversation

FedericoBusero
Copy link
Contributor

The PR to make the library compatible with ESP32C3 was not fully correct: Builtin DAC&PDM functionality was lost on ESP32. This should fix it again.

Also some compiling warnings are removed about I2S_COMM_FORMAT_STAND_MSB being deprecated, when compiling in the ESP32 Arduino core v2 (IDF>=4.2)

#442

The code for enabling compatibility with ESP32C3 had broken DAC builtin and PDM mode on ESP32. This should fix it again
@FedericoBusero FedericoBusero mentioned this pull request Dec 13, 2021
@FedericoBusero
Copy link
Contributor Author

To test the library in Arduino ESP32 core version 2:

  • on ESP32-C3, use Arduino ESP32 core version 2.0.1 and don't use pin 4.
  • on ESP32 you need to use Arduino ESP32 core version 2.0.0rc2.

A test program for ESP32-C3 that should work:

#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorRTTTL.h"
#include "AudioOutputI2S.h"

#define I2S_SPEAKER_SERIAL_CLOCK GPIO_NUM_6 // BCLK
#define I2S_SPEAKER_LEFT_RIGHT_CLOCK GPIO_NUM_7 // WSEL,LRC 
#define I2S_SPEAKER_SERIAL_DATA GPIO_NUM_10 // DIN

const char rudolph[] PROGMEM = 
"Rudolph the Red Nosed Raindeer:d=8,o=5,b=250:g,4a,g,4e,4c6,4a,2g.,g,a,g,a,4g,4c6,2b.,4p,f,4g,f,4d,4b,4a,2g.,g,a,g,a,4g,4a,2e.,4p,g,4a,a,4e,4c6,4a,2g.,g,a,g,a,4g,4c6,2b.,4p,f,4g,f,4d,4b,4a,2g.,g,a,g,a,4g,4d6,2c.6,4p,4a,4a,4c6,4a,4g,4e,2g,4d,4e,4g,4a,4b,4b,2b,4c6,4c6,4b,4a,4g,4f,2d,g,4a,g,4e,4c6,4a,2g.,g,a,g,a,4g,4c6,2b.,4p,f,4g,f,4d,4b,4a,2g.,4g,4a,4g,4a,2g,2d6,1c.6.";

AudioGeneratorRTTTL *rtttl;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;

void setup()
{
  Serial.begin(115200);
  delay(1000);

  Serial.printf("RTTTL start\n");

  audioLogger = &Serial;
  file = new AudioFileSourcePROGMEM( rudolph, strlen_P(rudolph) );
  out = new AudioOutputI2S();
  out -> SetPinout(I2S_SPEAKER_SERIAL_CLOCK,I2S_SPEAKER_LEFT_RIGHT_CLOCK,I2S_SPEAKER_SERIAL_DATA);
  rtttl = new AudioGeneratorRTTTL();
  rtttl->begin(file, out);
}

void loop()
{
  if (rtttl->isRunning()) {
    if (!rtttl->loop()) rtttl->stop();
  } else {
    Serial.printf("RTTTL done\n");
    delay(1000);
  }
}

@FedericoBusero
Copy link
Contributor Author

The cool thing is that also the NoDac output works out-of-the-box on ESP-C3! So you can get audio out of the ESP32C3 without internal/external DAC using this lib.

@goberhammer
Copy link

Thanks a lot for this patch! I was pulling my hairs out with a new M5StickC Plus to get internal DAC to work!
Now at least I have some output, albeit with a lot of noise, but that is another problem.
Thanks again!

@earlephilhower earlephilhower merged commit 7ac86f0 into earlephilhower:master Dec 18, 2021
@sh-user
Copy link

sh-user commented Dec 19, 2021

At the first compilation in Arduino IDE 1.8.13 on Windows, warning messages I2S_COMM_FORMAT_STAND_MSB appear, but at the second compilation everything is fine, there are no messages.

@FedericoBusero FedericoBusero deleted the FedericoBusero-i2s_IDF_4_2 branch December 27, 2021 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants