4 #include "AudioTools/CoreAudio/AudioPWM/PWMAudioBase.h"
14 using PWMDriver = PWMDriverESP32;
46 is_timer_started =
false;
47 for (
int j = 0; j < audio_config.
channels; j++) {
48 #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 0, 0)
49 ledcDetach(pins[j].gpio);
51 ledcDetachPin(pins[j].gpio);
62 audio_config = audioInfo();
64 is_timer_started =
true;
71 audio_config.pwm_frequency =
frequency(audio_config.resolution) * 1000;
74 for (
int j = 0; j < audio_config.
channels; j++) {
75 pins[j].gpio = audio_config.pins()[j];
76 #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 0, 0)
77 if (!ledcAttach(pins[j].gpio, audio_config.pwm_frequency,
78 audio_config.resolution)) {
79 LOGE(
"ledcAttach: %d", pins[j].gpio);
83 pins[j].pwm_channel = pwmChannel;
84 ledcSetup(pins[j].pwm_channel, audio_config.pwm_frequency,
85 audio_config.resolution);
86 ledcAttachPin(pins[j].gpio, pins[j].pwm_channel);
88 LOGI(
"setupPWM: pin=%d, channel=%d, frequency=%u, resolution=%d",
89 pins[j].gpio, pins[j].pwm_channel, (
unsigned)audio_config.pwm_frequency,
90 audio_config.resolution);
96 for (
int j = 0; j < pins.size(); j++) {
97 LOGI(
"pin%d: %d", j, pins[j].gpio);
103 timer.setCallbackParameter(
this);
104 timer.setIsSave(
false);
110 #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(5, 0, 0)
111 ledcWrite(pins[channel].gpio, value);
113 ledcWrite(pins[channel].pwm_channel, value);
124 virtual int maxChannels() {
return 16; };
134 #if defined(ESP32S2) || defined(ESP32S3)
135 switch (resolution) {
149 switch (resolution) {
166 if (accessAudioPWM !=
nullptr) {