3 #include "AudioConfig.h"
4 #if defined(USE_PWM) && defined(__AVR__)
5 #include "AudioTools/CoreAudio/AudioPWM/PWMAudioBase.h"
6 #include "AudioTools/CoreAudio/AudioTimer/AudioTimerAVR.h"
11 using PWMDriver = PWMDriverAVR;
12 static PWMDriverAVR *accessAudioPWM =
nullptr;
28 accessAudioPWM =
this;
31 virtual int maxChannels() {
return 2; };
43 is_timer_started =
false;
54 LOGE(
"requested sample rate not supported: %d - we use %d",
58 LOGD(
"compare match register set to %d", steps);
66 TCCR1B |= (1 << WGM12);
68 TCCR1B |= (1 << CS11);
69 TIMSK1 |= (1 << OCIE1A);
77 LOGW(
"Max 2 channels supported - you requested %d",
82 for (
int j = 0; j < audio_config.
channels; j++) {
83 LOGD(
"Processing channel %d", j);
93 void setupPin(
int pin) {
98 TCCR2B = TCCR2B & B11111000 | B00000001;
99 LOGI(
"PWM Frequency changed for D3 and D11");
103 LOGE(
"PWM Unsupported pin: %d", pin);
106 pinMode(pin, OUTPUT);
109 virtual void pwmWrite(
int channel,
int value) {
110 analogWrite(pins[channel], value);
114 audio_config.logConfig();
115 LOGI(
"pwm freq: %f khz", 62.5);
117 LOGI(
"output pin: %d", pins[0]);
119 LOGI(
"output pins: %d / %d", pins[0], pins[1]);
124 int pins[2] = {3, 11};
126 virtual int maxOutputValue() {
return 255; }
132 if (accessAudioPWM !=
nullptr && accessAudioPWM->is_timer_started) {
140 TimerAlarmRepeatingDriverAVR::tickerCallback();