/** * @brief Initializes the TIM3 peripheral according to the specified parameters. * @param TIM3_Channel specifies the Input Capture Channel from @ref TIM3_Channel_TypeDef. * @param TIM3_ICPolarity specifies the Input Capture Polarity from @ref TIM3_ICPolarity_TypeDef. * @param TIM3_ICSelection specifies the Input Capture Selection from @ref TIM3_ICSelection_TypeDef. * @param TIM3_ICPrescaler specifies the Input Capture Prescaler from @ref TIM3_ICPSC_TypeDef. * @param TIM3_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F). * @retval None */ void TIM3_ICInit(TIM3_Channel_TypeDef TIM3_Channel, TIM3_ICPolarity_TypeDef TIM3_ICPolarity, TIM3_ICSelection_TypeDef TIM3_ICSelection, TIM3_ICPSC_TypeDef TIM3_ICPrescaler, uint8_t TIM3_ICFilter) { /* Check the parameters */ assert_param(IS_TIM3_CHANNEL_OK(TIM3_Channel)); assert_param(IS_TIM3_IC_POLARITY_OK(TIM3_ICPolarity)); assert_param(IS_TIM3_IC_SELECTION_OK(TIM3_ICSelection)); assert_param(IS_TIM3_IC_PRESCALER_OK(TIM3_ICPrescaler)); assert_param(IS_TIM3_IC_FILTER_OK(TIM3_ICFilter)); if (TIM3_Channel != TIM3_CHANNEL_2) { /* TI1 Configuration */ TI1_Config((uint8_t)TIM3_ICPolarity, (uint8_t)TIM3_ICSelection, (uint8_t)TIM3_ICFilter); /* Set the Input Capture Prescaler value */ TIM3_SetIC1Prescaler(TIM3_ICPrescaler); } else { /* TI2 Configuration */ TI2_Config((uint8_t)TIM3_ICPolarity, (uint8_t)TIM3_ICSelection, (uint8_t)TIM3_ICFilter); /* Set the Input Capture Prescaler value */ TIM3_SetIC2Prescaler(TIM3_ICPrescaler); } }
/** * @brief Configures the TIM2 Trigger as External Clock. * @param TIM2_TIxExternalCLKSource : Specifies Trigger source. * This parameter can be one of the @ref TIM2_TIxExternalCLK1Source_TypeDef enumeration. * @param TIM2_ICPolarity : Specifies the TIx Polarity. * This parameter can be @ref TIM2_ICPolarity_TypeDef enumeration. * @param ICFilter : Specifies the filter value. * This parameter must be a value between 0x00 and 0x0F * @retval None */ void TIM2_TIxExternalClockConfig(TIM2_TIxExternalCLK1Source_TypeDef TIM2_TIxExternalCLKSource, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, uint8_t ICFilter) { /* Check the parameters */ assert_param(IS_TIM2_TIXCLK_SOURCE(TIM2_TIxExternalCLKSource)); assert_param(IS_TIM2_IC_POLARITY(TIM2_ICPolarity)); assert_param(IS_TIM2_IC_FILTER(ICFilter)); /* Configure the TIM2 Input Clock Source */ if (TIM2_TIxExternalCLKSource == TIM2_TIxExternalCLK1Source_TI2) { TI2_Config(TIM2_ICPolarity, TIM2_ICSelection_DirectTI, ICFilter); } else { TI1_Config(TIM2_ICPolarity, TIM2_ICSelection_DirectTI, ICFilter); } /* Select the Trigger source */ TIM2_SelectInputTrigger((TIM2_TRGSelection_TypeDef)TIM2_TIxExternalCLKSource); /* Select the External clock mode1 */ TIM2->SMCR |= (uint8_t)(TIM2_SlaveMode_External1); }
/** * @brief Initializes the TIM2 peripheral according to the specified parameters. * @param TIM2_Channel : This parameter can be any member of the @Ref TIM2_Channel_TypeDef enumeration. * @param TIM2_ICPolarity : This parameter can be any member of the @Ref TIM2_ICPolarity_TypeDef enumeration. * @param TIM2_ICSelection : This parameter can be any member of the @Ref TIM2_ICSelection_TypeDef enumeration. * @param TIM2_ICPrescaler : This parameter can be any member of the @Ref TIM2_ICPSC_TypeDef enumeration. * @param TIM2_ICFilter : This parameter must be a value between 0x00 and 0x0F. * @retval None */ void TIM2_ICInit(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter) { /* Check the parameters */ assert_param(IS_TIM2_CHANNEL(TIM2_Channel)); if (TIM2_Channel == TIM2_Channel_1) { /* TI1 Configuration */ TI1_Config(TIM2_ICPolarity, TIM2_ICSelection, TIM2_ICFilter); /* Set the Input Capture Prescaler value */ TIM2_SetIC1Prescaler(TIM2_ICPrescaler); } else /* if (TIM2_Channel == TIM2_Channel_2) */ { /* TI2 Configuration */ TI2_Config(TIM2_ICPolarity, TIM2_ICSelection, TIM2_ICFilter); /* Set the Input Capture Prescaler value */ TIM2_SetIC2Prescaler(TIM2_ICPrescaler); } }
/** * @brief Configures the TIM3 peripheral in PWM Input Mode according to the specified parameters. * @param TIM3_Channel specifies the Input Capture Channel from @ref TIM3_Channel_TypeDef. * @param TIM3_ICPolarity specifies the Input Capture Polarity from @ref TIM3_ICPolarity_TypeDef. * @param TIM3_ICSelection specifies the Input Capture Selection from @ref TIM3_ICSelection_TypeDef. * @param TIM3_ICPrescaler specifies the Input Capture Prescaler from @ref TIM3_ICPSC_TypeDef. * @param TIM3_ICFilter specifies the Input Capture Filter value (value can be an integer from 0x00 to 0x0F). * @retval None */ void TIM3_PWMIConfig(TIM3_Channel_TypeDef TIM3_Channel, TIM3_ICPolarity_TypeDef TIM3_ICPolarity, TIM3_ICSelection_TypeDef TIM3_ICSelection, TIM3_ICPSC_TypeDef TIM3_ICPrescaler, uint8_t TIM3_ICFilter) { uint8_t icpolarity = (uint8_t)TIM3_ICPOLARITY_RISING; uint8_t icselection = (uint8_t)TIM3_ICSELECTION_DIRECTTI; /* Check the parameters */ assert_param(IS_TIM3_PWMI_CHANNEL_OK(TIM3_Channel)); assert_param(IS_TIM3_IC_POLARITY_OK(TIM3_ICPolarity)); assert_param(IS_TIM3_IC_SELECTION_OK(TIM3_ICSelection)); assert_param(IS_TIM3_IC_PRESCALER_OK(TIM3_ICPrescaler)); /* Select the Opposite Input Polarity */ if (TIM3_ICPolarity != TIM3_ICPOLARITY_FALLING) { icpolarity = (uint8_t)TIM3_ICPOLARITY_FALLING; } else { icpolarity = (uint8_t)TIM3_ICPOLARITY_RISING; } /* Select the Opposite Input */ if (TIM3_ICSelection == TIM3_ICSELECTION_DIRECTTI) { icselection = (uint8_t)TIM3_ICSELECTION_INDIRECTTI; } else { icselection = (uint8_t)TIM3_ICSELECTION_DIRECTTI; } if (TIM3_Channel != TIM3_CHANNEL_2) { /* TI1 Configuration */ TI1_Config((uint8_t)TIM3_ICPolarity, (uint8_t)TIM3_ICSelection, (uint8_t)TIM3_ICFilter); /* Set the Input Capture Prescaler value */ TIM3_SetIC1Prescaler(TIM3_ICPrescaler); /* TI2 Configuration */ TI2_Config(icpolarity, icselection, TIM3_ICFilter); /* Set the Input Capture Prescaler value */ TIM3_SetIC2Prescaler(TIM3_ICPrescaler); } else { /* TI2 Configuration */ TI2_Config((uint8_t)TIM3_ICPolarity, (uint8_t)TIM3_ICSelection, (uint8_t)TIM3_ICFilter); /* Set the Input Capture Prescaler value */ TIM3_SetIC2Prescaler(TIM3_ICPrescaler); /* TI1 Configuration */ TI1_Config(icpolarity, icselection, TIM3_ICFilter); /* Set the Input Capture Prescaler value */ TIM3_SetIC1Prescaler(TIM3_ICPrescaler); } }
/** * @brief Configures the TIM2 peripheral in PWM Input Mode according to the * specified parameters. * @param TIM2_Channel : This parameter can be any member of the @Ref TIM2_Channel_TypeDef enumeration. * @param TIM2_ICPolarity : This parameter can be any member of the @Ref TIM2_ICPolarity_TypeDef enumeration. * @param TIM2_ICSelection : This parameter can be any member of the @Ref TIM2_ICSelection_TypeDef enumeration. * @param TIM2_ICPrescaler : This parameter can be any member of the @Ref TIM2_ICPSC_TypeDef enumeration. * @param TIM2_ICFilter : This parameter must be a value between 0x00 and 0x0F. * @retval None */ void TIM2_PWMIConfig(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter) { uint8_t icpolarity = TIM2_ICPolarity_Rising; uint8_t icselection = TIM2_ICSelection_DirectTI; /* Check the parameters */ assert_param(IS_TIM2_CHANNEL(TIM2_Channel)); /* Select the Opposite Input Polarity */ if (TIM2_ICPolarity == TIM2_ICPolarity_Rising) { icpolarity = TIM2_ICPolarity_Falling; } else { icpolarity = TIM2_ICPolarity_Rising; } /* Select the Opposite Input */ if (TIM2_ICSelection == TIM2_ICSelection_DirectTI) { icselection = TIM2_ICSelection_IndirectTI; } else { icselection = TIM2_ICSelection_DirectTI; } if (TIM2_Channel == TIM2_Channel_1) { /* TI1 Configuration */ TI1_Config(TIM2_ICPolarity, TIM2_ICSelection, TIM2_ICFilter); /* Set the Input Capture Prescaler value */ TIM2_SetIC1Prescaler(TIM2_ICPrescaler); /* TI2 Configuration */ TI2_Config((TIM2_ICPolarity_TypeDef)icpolarity, (TIM2_ICSelection_TypeDef)icselection, TIM2_ICFilter); /* Set the Input Capture Prescaler value */ TIM2_SetIC2Prescaler(TIM2_ICPrescaler); } else { /* TI2 Configuration */ TI2_Config(TIM2_ICPolarity, TIM2_ICSelection, TIM2_ICFilter); /* Set the Input Capture Prescaler value */ TIM2_SetIC2Prescaler(TIM2_ICPrescaler); /* TI1 Configuration */ TI1_Config((TIM2_ICPolarity_TypeDef)icpolarity, (TIM2_ICSelection_TypeDef)icselection, TIM2_ICFilter); /* Set the Input Capture Prescaler value */ TIM2_SetIC1Prescaler(TIM2_ICPrescaler); } }