/** * @brief Configure the LPTIMx peripheral according to the specified parameters. * @note LL_LPTIM_Init can only be called when the LPTIM instance is disabled. * @note LPTIMx can be disabled using unitary function @ref LL_LPTIM_Disable(). * @param LPTIMx LP Timer Instance * @param LPTIM_InitStruct pointer to a @ref LL_LPTIM_InitTypeDef structure * @retval An ErrorStatus enumeration value: * - SUCCESS: LPTIMx instance has been initialized * - ERROR: LPTIMx instance hasn't been initialized */ ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef * LPTIMx, LL_LPTIM_InitTypeDef* LPTIM_InitStruct) { ErrorStatus result = SUCCESS; /* The LPTIMx_CFGR register must only be modified when the LPTIM is disabled (ENABLE bit is reset to 0). */ if (LL_LPTIM_IsEnabled(LPTIMx)) { result = ERROR; } else { /* Check the parameters */ assert_param(IS_LPTIM_INSTANCE(LPTIMx)); assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->ClockSource)); assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->Prescaler)); assert_param(IS_LPTIM_WAVEFORM(LPTIM_InitStruct->Waveform)); assert_param(IS_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->Polarity)); /* Set CKSEL bitfield according to ClockSource value */ /* Set PRESC bitfield according to Prescaler value */ /* Set WAVE bitfield according to Waveform value */ /* Set WAVEPOL bitfield according to Polarity value */ MODIFY_REG(LPTIMx->CFGR, (LPTIM_CFGR_CKSEL | LPTIM_CFGR_PRESC | LPTIM_CFGR_WAVE| LPTIM_CFGR_WAVPOL), LPTIM_InitStruct->ClockSource | \ LPTIM_InitStruct->Prescaler | \ LPTIM_InitStruct->Waveform | \ LPTIM_InitStruct->Polarity); } return result; }
/** * @brief Initializes the LPTIMx peripheral according to the specified parameters * in the LPTIM_InitStruct. * @param LPTIMx: where x can be 1. * @param LPTIM_InitStruct: pointer to an LPTIM_InitTypeDef structure that contains * the configuration information for the specified LPTIM peripheral. * @retval None * * @note It is mandatory to disable the peripheral to use this function. */ void LPTIM_Init(LPTIM_TypeDef* LPTIMx, LPTIM_InitTypeDef* LPTIM_InitStruct) { uint32_t tmpreg1 = 0; /* Check the parameters */ assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx)); assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->LPTIM_ClockSource)); assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->LPTIM_Prescaler)); assert_param(IS_LPTIM_WAVEFORM(LPTIM_InitStruct->LPTIM_Waveform)); assert_param(IS_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->LPTIM_OutputPolarity)); /* Get the LPTIMx CFGR value */ tmpreg1 = LPTIMx->CFGR; /* Clear CKSEL, PRESC, WAVE and WAVEPOL bits */ tmpreg1 &= CFGR_INIT_CLEAR_MASK; /* Set or Reset CKSEL bit according to LPTIM_ClockSource value */ /* Set or Reset PRESC bits according to LPTIM_Prescaler value */ /* Set or Reset WAVE bit according to LPTIM_Waveform value */ /* Set or Reset WAVEPOL bit according to LPTIM_OutputPolarity value */ tmpreg1 |= (LPTIM_InitStruct->LPTIM_ClockSource | LPTIM_InitStruct->LPTIM_Prescaler |LPTIM_InitStruct->LPTIM_Waveform | LPTIM_InitStruct->LPTIM_OutputPolarity); /* Write to LPTIMx CFGR */ LPTIMx->CFGR = tmpreg1; }
/** * @brief Configures the Waveform shape. * @param LPTIMx: where x can be 1. * @param LPTIM_Waveform: the selected waveform shape. * This parameter can be: * @arg LPTIM_Waveform_PWM_OnePulse : PWM/One Pulse is selected * @arg LPTIM_Waveform_SetOnce : Set once is selected * @retval None * * @note It is mandatory to disable the peripheral to use this function. */ void LPTIM_ConfigWaveform(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Waveform) { /* Check the parameters */ assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx)); assert_param(IS_LPTIM_WAVEFORM(LPTIM_Waveform)); /* Clear the WAVE bit */ LPTIMx->CFGR &= ~(LPTIM_CFGR_CKFLT); /* Set or Reset the WAVE bit according to LPTIM_Waveform */ LPTIMx->CFGR |= (LPTIM_Waveform); }