From 0ea762b4a83cfafa663da1591208450650eb677b Mon Sep 17 00:00:00 2001 From: Gregg Date: Sat, 25 Sep 2021 14:33:32 -0500 Subject: [PATCH] Added backwards compatibility to PWM to operate in 2.0.0 and 1.0.6 Accounts for new *required* elements of the LEDC channel and timer structures to be set in later versions of the IDF. These elements are not available in earlier versions of the IDF and the program can't be compiled unless ignored. --- src/extras/PwmPin.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/extras/PwmPin.cpp b/src/extras/PwmPin.cpp index 018437c..e45e873 100644 --- a/src/extras/PwmPin.cpp +++ b/src/extras/PwmPin.cpp @@ -18,7 +18,10 @@ LedC::LedC(uint8_t pin, uint16_t freq){ timerList[nTimer][nMode]->speed_mode=(ledc_mode_t)nMode; timerList[nTimer][nMode]->timer_num=(ledc_timer_t)nTimer; timerList[nTimer][nMode]->freq_hz=freq; + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) timerList[nTimer][nMode]->clk_cfg=LEDC_USE_APB_CLK; +#endif int res=LEDC_TIMER_BIT_MAX-1; // find the maximum possible resolution while(getApbFrequency()/(freq*pow(2,res))<1) @@ -37,7 +40,9 @@ LedC::LedC(uint8_t pin, uint16_t freq){ channelList[nChannel][nMode]->channel=(ledc_channel_t)nChannel; channelList[nChannel][nMode]->timer_sel=(ledc_timer_t)nTimer; channelList[nChannel][nMode]->intr_type=LEDC_INTR_DISABLE; +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0) channelList[nChannel][nMode]->flags.output_invert=0; +#endif channelList[nChannel][nMode]->hpoint=0; channelList[nChannel][nMode]->gpio_num=pin; timer=timerList[nTimer][nMode];