diff --git a/cores/arduino/wiring_analog.cpp b/cores/arduino/wiring_analog.cpp index aec8a47d0..d11783d68 100644 --- a/cores/arduino/wiring_analog.cpp +++ b/cores/arduino/wiring_analog.cpp @@ -68,6 +68,17 @@ void analogWrite(pin_size_t pin, int val) #endif float percent = (float)val/(float)((1 << write_resolution)-1); mbed::PwmOut* pwm = digitalPinToPwm(pin); + + /* Check if this pin has been previously configured as a GPIO pin. + * If it has, delete the GPIO allocation as well as the PWM allocation + * to enforce a full re-initialisation of the PWM module. + */ + mbed::DigitalInOut * gpio = digitalPinToGpio(pin); + if ((gpio != NULL) && (pwm != NULL)) { + delete gpio; gpio = NULL; digitalPinToGpio(pin) = NULL; + delete pwm; pwm = NULL; digitalPinToPwm(pin) = NULL; + } + if (pwm == NULL) { pwm = new mbed::PwmOut(digitalPinToPinName(pin)); digitalPinToPwm(pin) = pwm; diff --git a/cores/arduino/wiring_digital.cpp b/cores/arduino/wiring_digital.cpp index c4fa74b0c..f20c0da0c 100644 --- a/cores/arduino/wiring_digital.cpp +++ b/cores/arduino/wiring_digital.cpp @@ -94,6 +94,17 @@ void digitalWrite(pin_size_t pin, PinStatus val) return; } mbed::DigitalInOut* gpio = digitalPinToGpio(pin); + + /* Check if this pin has been previously configured as a PWM pin. + * If it has, delete the GPIO allocation as well as the PWM allocation + * to enforce a full re-initialisation of the GPIO module. + */ + mbed::PwmOut * pwm = digitalPinToPwm(pin); + if ((gpio != NULL) && (pwm != NULL)) { + delete gpio; gpio = NULL; digitalPinToGpio(pin) = NULL; + delete pwm; pwm = NULL; digitalPinToPwm(pin) = NULL; + } + if (gpio == NULL) { gpio = new mbed::DigitalInOut(digitalPinToPinName(pin), PIN_OUTPUT, PullNone, val); digitalPinToGpio(pin) = gpio; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy