Fixed issue with PWM not being freed when the object is destroyed

pull/10074/head
Ryan Morse 2019-03-12 17:26:30 -07:00
parent 401a3c8551
commit 51a47139f3
2 changed files with 8 additions and 3 deletions

View File

@ -68,6 +68,7 @@ public:
~PwmOut()
{
core_util_critical_section_enter();
pwmout_free(&_pwm);
unlock_deep_sleep();
core_util_critical_section_exit();
}

View File

@ -235,9 +235,13 @@ void pwmout_init(pwmout_t *obj, PinName pin)
void pwmout_free(pwmout_t *obj)
{
/* Does nothing because it is not called in the MBED PWMOUT driver
* destructor. The pwmout_init handles multiple calls of constructor.
*/
#if DEVICE_SLEEP && DEVICE_LPTICKER
if (!Cy_SysPm_UnregisterCallback(&obj->pm_callback_handler)) {
error("PM callback unregistration failed!");
}
#endif
Cy_TCPWM_PWM_Disable(obj->base, obj->counter_id);
Cy_TCPWM_PWM_DeInit(obj->base, obj->counter_id, &pwm_config);
}
void pwmout_write(pwmout_t *obj, float percent)