nRF52: properly clean pwm structures on deinit()

pull/14230/head
Martino Facchin 2020-12-01 14:42:02 +01:00 committed by pennam
parent 2e964006b7
commit 56c508b974
3 changed files with 33 additions and 0 deletions

View File

@ -369,6 +369,27 @@ int pin_instance_pwm(PinName pwm)
return instance;
}
/**
* Brief Find hardware instance for the provided PWM pin and free it
*
* Parameter pwm pwm pin.
*
* Return Nothing
*/
void pin_instance_pwm_free(PinName pwm)
{
/* Search dynamic map for entry. */
for (size_t index = 0; index < NORDIC_PWM_COUNT; index++) {
/* Pins match previous dynamic allocation, return instance. */
if (nordic_internal_pwm[index] == pwm) {
nordic_internal_pwm[index] = NC;
break;
}
}
}
/***
* _ _ _____ _______

View File

@ -120,6 +120,15 @@ int pin_instance_spi(PinName mosi, PinName miso, PinName clk);
*/
int pin_instance_pwm(PinName pwm);
/**
* Brief Find hardware instance for the provided PWM pin and free it
*
* Parameter pwm pwm pin.
*
* Return Nothing
*/
void pin_instance_pwm_free(PinName pwm);
/**
* @brief Find hardware instance for the provided UART pins.
*

View File

@ -173,6 +173,9 @@ void pwmout_free(pwmout_t *obj)
MBED_ASSERT(obj);
/* Also deinit the undelying PinMap_PWM entry */
pin_instance_pwm_free(obj->pin);
/* Uninitialize PWM instance. */
nrfx_pwm_uninit(&nordic_nrf5_pwm_instance[obj->instance]);
}