Skip to content

Commit 0faef8e

Browse files
committed
Fix PWM channels after restart (arendst#20732)
1 parent d3093a1 commit 0faef8e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,14 @@ int32_t analogAttach(uint32_t pin, bool output_invert) { // returns ledc chan
323323
return chan;
324324
}
325325

326+
void analogDetach(void) {
327+
for (uint32_t pin = 0; pin < SOC_GPIO_PIN_COUNT; pin++) {
328+
if (pin_to_channel[pin] > 0) {
329+
ledcDetachPin(pin);
330+
}
331+
}
332+
}
333+
326334
extern "C" uint32_t ledcReadFreq2(uint8_t chan) {
327335
// extern "C" uint32_t __wrap_ledcReadFreq(uint8_t chan) {
328336
if (chan > MAX_PWMS) {

lib/libesp32/ESP32-to-ESP8266-compat/src/esp8266toEsp32.h

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ uint8_t ledcReadResolution(uint8_t chan);
5555
// Returns: hardware channel number, or -1 if it failed
5656
int32_t analogAttach(uint32_t pin, bool output_invert = false); // returns the ledc channel, or -1 if failed. This is implicitly called by analogWrite if the channel was not already allocated
5757

58+
void analogDetach(void);
59+
5860
// change both freq and range
5961
// `0`: set to global value
6062
// `-1`: keep unchanged

tasmota/tasmota_xdrv_driver/xdrv_01_9_webserver.ino

+5
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,11 @@ void HandleModuleConfiguration(void) {
18161816

18171817
if (Webserver->hasArg(F("save"))) {
18181818
ModuleSaveSettings();
1819+
1820+
#ifdef CONFIG_IDF_TARGET_ESP32
1821+
analogDetach();
1822+
#endif
1823+
18191824
WebRestart(1);
18201825
return;
18211826
}

0 commit comments

Comments
 (0)