Fix for deallocation of PWM pins (missing destructor).

This commit is contained in:
Blaz Kristan 2021-03-01 10:27:55 +01:00
parent bd7671c07e
commit d433b25627

View File

@ -229,21 +229,10 @@ class BusPwm : public Bus {
for (uint8_t i = 0; i < numPins; i++) { for (uint8_t i = 0; i < numPins; i++) {
_pins[i] = bc.pins[i]; _pins[i] = bc.pins[i];
#ifdef WLED_DEBUG
Serial.print(F("Init: Allocating pin #"));
Serial.println(i);
#endif
if (!pinManager.allocatePin(_pins[i])) { if (!pinManager.allocatePin(_pins[i])) {
#ifdef WLED_DEBUG //deallocatePins(); return;
Serial.print(F("Init: Wooooow!!!! Allocation failed for pin=")); _pins[i] = 255; break;
Serial.println(_pins[i]);
#endif
deallocatePins(); return;
} }
#ifdef WLED_DEBUG
Serial.print(F("Init: Allocation successful for pin="));
Serial.println(bc.pins[i]);
#endif
#ifdef ESP8266 #ifdef ESP8266
pinMode(_pins[i], OUTPUT); pinMode(_pins[i], OUTPUT);
#else #else
@ -254,6 +243,10 @@ class BusPwm : public Bus {
_valid = true; _valid = true;
}; };
~BusPwm() {
cleanup();
}
void setPixelColor(uint16_t pix, uint32_t c) { void setPixelColor(uint16_t pix, uint32_t c) {
if (pix != 0 || !_valid) return; //only react to first pixel if (pix != 0 || !_valid) return; //only react to first pixel
uint8_t r = c >> 16; uint8_t r = c >> 16;
@ -325,26 +318,14 @@ class BusPwm : public Bus {
void deallocatePins() { void deallocatePins() {
uint8_t numPins = NUM_PWM_PINS(_type); uint8_t numPins = NUM_PWM_PINS(_type);
#ifdef WLED_DEBUG
Serial.print(F("DeAllocating pin "));
Serial.println(numPins);
#endif
for (uint8_t i = 0; i < numPins; i++) { for (uint8_t i = 0; i < numPins; i++) {
pinManager.deallocatePin(_pins[i]);
if (!pinManager.isPinOk(_pins[i])) continue; if (!pinManager.isPinOk(_pins[i])) continue;
#ifdef WLED_DEBUG
Serial.print(F("DeAllocating pin #"));
Serial.println(i);
#endif
#ifdef ESP8266 #ifdef ESP8266
digitalWrite(_pins[i], LOW); //turn off PWM interrupt digitalWrite(_pins[i], LOW); //turn off PWM interrupt
#else #else
if (_ledcStart < 16) ledcDetachPin(_pins[i]); if (_ledcStart < 16) ledcDetachPin(_pins[i]);
#endif #endif
pinManager.deallocatePin(_pins[i]);
#ifdef WLED_DEBUG
Serial.print(F("DeAllocatied pin="));
Serial.println(_pins[i]);
#endif
} }
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
pinManager.deallocateLedc(_ledcStart, numPins); pinManager.deallocateLedc(_ledcStart, numPins);