mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
Diff: targets/TARGET_STM/pwmout_api.c
- Revision:
- 187:0387e8f68319
- Parent:
- 160:d5399cc887bb
- Child:
- 189:f392fc9709a3
--- a/targets/TARGET_STM/pwmout_api.c Fri Jun 22 16:45:37 2018 +0100 +++ b/targets/TARGET_STM/pwmout_api.c Thu Sep 06 13:40:20 2018 +0100 @@ -39,7 +39,7 @@ static TIM_HandleTypeDef TimHandle; -void pwmout_init(pwmout_t* obj, PinName pin) +void pwmout_init(pwmout_t *obj, PinName pin) { // Get the peripheral name from the pin and assign it to the object obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM); @@ -53,7 +53,7 @@ // Enable TIM clock #if defined(TIM1_BASE) - if (obj->pwm == PWM_1){ + if (obj->pwm == PWM_1) { __HAL_RCC_TIM1_CLK_ENABLE(); } #endif @@ -163,13 +163,13 @@ pwmout_period_us(obj, 20000); // 20 ms per default } -void pwmout_free(pwmout_t* obj) +void pwmout_free(pwmout_t *obj) { // Configure GPIO pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0)); } -void pwmout_write(pwmout_t* obj, float value) +void pwmout_write(pwmout_t *obj, float value) { TIM_OC_InitTypeDef sConfig; int channel = 0; @@ -228,7 +228,7 @@ } } -float pwmout_read(pwmout_t* obj) +float pwmout_read(pwmout_t *obj) { float value = 0; if (obj->period > 0) { @@ -237,17 +237,17 @@ return ((value > (float)1.0) ? (float)(1.0) : (value)); } -void pwmout_period(pwmout_t* obj, float seconds) +void pwmout_period(pwmout_t *obj, float seconds) { pwmout_period_us(obj, seconds * 1000000.0f); } -void pwmout_period_ms(pwmout_t* obj, int ms) +void pwmout_period_ms(pwmout_t *obj, int ms) { pwmout_period_us(obj, ms * 1000); } -void pwmout_period_us(pwmout_t* obj, int us) +void pwmout_period_us(pwmout_t *obj, int us) { TimHandle.Instance = (TIM_TypeDef *)(obj->pwm); RCC_ClkInitTypeDef RCC_ClkInitStruct; @@ -263,14 +263,15 @@ HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); /* Parse the pwm / apb mapping table to find the right entry */ - while(pwm_apb_map_table[i].pwm != obj->pwm) { + while (pwm_apb_map_table[i].pwm != obj->pwm) { i++; } - if(pwm_apb_map_table[i].pwm == 0) + if (pwm_apb_map_table[i].pwm == 0) { error("Unknown PWM instance"); + } - if(pwm_apb_map_table[i].pwmoutApb == PWMOUT_ON_APB1) { + if (pwm_apb_map_table[i].pwmoutApb == PWMOUT_ON_APB1) { PclkFreq = HAL_RCC_GetPCLK1Freq(); APBxCLKDivider = RCC_ClkInitStruct.APB1CLKDivider; } else { @@ -295,9 +296,9 @@ while ((TimHandle.Init.Period > 0xFFFF) || (TimHandle.Init.Prescaler > 0xFFFF)) { obj->prescaler = obj->prescaler * 2; if (APBxCLKDivider == RCC_HCLK_DIV1) { - TimHandle.Init.Prescaler = (((PclkFreq) / 1000000) * obj->prescaler) - 1; + TimHandle.Init.Prescaler = (((PclkFreq) / 1000000) * obj->prescaler) - 1; } else { - TimHandle.Init.Prescaler = (((PclkFreq * 2) / 1000000) * obj->prescaler) - 1; + TimHandle.Init.Prescaler = (((PclkFreq * 2) / 1000000) * obj->prescaler) - 1; } TimHandle.Init.Period = (us - 1) / obj->prescaler; /* Period decreases and prescaler increases over loops, so check for @@ -324,17 +325,17 @@ __HAL_TIM_ENABLE(&TimHandle); } -void pwmout_pulsewidth(pwmout_t* obj, float seconds) +void pwmout_pulsewidth(pwmout_t *obj, float seconds) { pwmout_pulsewidth_us(obj, seconds * 1000000.0f); } -void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) +void pwmout_pulsewidth_ms(pwmout_t *obj, int ms) { pwmout_pulsewidth_us(obj, ms * 1000); } -void pwmout_pulsewidth_us(pwmout_t* obj, int us) +void pwmout_pulsewidth_us(pwmout_t *obj, int us) { float value = (float)us / (float)obj->period; pwmout_write(obj, value);