Change Berry gpio.pin_mode frees PWM on pin

This commit is contained in:
Theo Arends 2025-01-24 16:33:12 +01:00
parent 5cbe5fe9e4
commit a91771e0cf
5 changed files with 20 additions and 7 deletions

View File

@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
- Allow negative values for AdcParam/AdcGpio INPUT, TEMP and RANGE parameters (#22809)
- GPIOViewer from v1.5.9 to v1.6.0 (No functional change)
- ESP32 Platform from 2025.01.30 to 2025.01.31 (#22832)
- Berry `gpio.pin_mode` frees PWM on pin
### Fixed
- Sonoff SPM `PowerOnState` overrules `SSPMPowerOnState` in mixed 4Relay setup with 4Relay version 1.0.0

View File

@ -148,6 +148,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
- Allow negative values for AdcParam/AdcGpio INPUT, TEMP and RANGE parameters [#22809](https://github.com/arendst/Tasmota/issues/22809)
- Command `Pixels` has backwards compatible arguments fixing #22755 [#22791](https://github.com/arendst/Tasmota/issues/22791)
- ESP32 disable PSRAM check (and on restart some relay toggles) with `#define DISABLE_PSRAMCHECK true` [#21266](https://github.com/arendst/Tasmota/issues/21266)
- Berry `gpio.pin_mode` frees PWM on pin
- Berry bit-shift operators to `int64` [#22709](https://github.com/arendst/Tasmota/issues/22709)
- HASPmota use 'roboto.ttf' for automatic sizing of default font [#22697](https://github.com/arendst/Tasmota/issues/22697)
- HASPmota add 'tag' attribute for free-form JSON [#22698](https://github.com/arendst/Tasmota/issues/22698)

View File

@ -326,15 +326,20 @@ int32_t analogAttach(uint32_t pin, bool output_invert) { // returns ledc chan
return chan;
}
void analogDetach(uint32_t pin) {
if (pin_to_channel[pin] > 0) {
#if ESP_IDF_VERSION_MAJOR < 5
ledcDetachPin(pin);
#else
ledcDetach(pin);
#endif
pin_to_channel[pin] = 0;
}
}
void analogDetachAll(void) {
for (uint32_t pin = 0; pin < SOC_GPIO_PIN_COUNT; pin++) {
if (pin_to_channel[pin] > 0) {
#if ESP_IDF_VERSION_MAJOR < 5
ledcDetachPin(pin);
#else
ledcDetach(pin);
#endif
}
analogDetach(pin);
}
}

View File

@ -56,6 +56,11 @@ uint8_t ledcReadResolution(uint8_t chan);
// Returns: hardware channel number, or -1 if it failed
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
//
// analogDetach - detach attached GPIO from a hardware PWM
//
void analogDetach(uint32_t pin);
//
// analogDetachAll - detach all attached GPIOs from a hardware PWM
//

View File

@ -54,6 +54,7 @@ extern "C" {
if (pin >= 0) {
if (mode > 0) {
// standard ESP mode
analogDetach(pin);
pinMode(pin, mode);
} else {
// synthetic mode