Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cores/arduino/wiring_analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions cores/arduino/wiring_digital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down