firmware-latest/platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/src/stm32f10x_tim.c
/**
  * @brief  Configure the TI2 as Input.
  * @param  TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
  * @param  TIM_ICPolarity : The Input Polarity.
  *   This parameter can be one of the following values:
  *     @arg TIM_ICPolarity_Rising
  *     @arg TIM_ICPolarity_Falling
  * @param  TIM_ICSelection: specifies the input to be used.
  *   This parameter can be one of the following values:
  *     @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.
  *     @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.
  *     @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.
  * @param  TIM_ICFilter: Specifies the Input Capture Filter.
  *   This parameter must be a value between 0x00 and 0x0F.
  * @retval None
  */
@brief  Configure the TI2 as Input.
@param  TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 12 or 15 to select the TIM peripheral.
@param  TIM_ICPolarity : The Input Polarity.
This parameter can be one of the following values:
@arg TIM_ICPolarity_Rising
@arg TIM_ICPolarity_Falling
@param  TIM_ICSelection: specifies the input to be used.
This parameter can be one of the following values:
@arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.
@arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.
@arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.
@param  TIM_ICFilter: Specifies the Input Capture Filter.
This parameter must be a value between 0x00 and 0x0F.
@retval None
@brief Configure the TI2 as Input . @param TIMx : where x can be 1 2 3 4 5 8 9 12 or 15 to select the TIM peripheral . @param TIM_ICPolarity : The Input Polarity . This parameter can be one of the following values : @arg TIM_ICPolarity_Rising @arg TIM_ICPolarity_Falling @param TIM_ICSelection : specifies the input to be used . This parameter can be one of the following values : @arg TIM_ICSelection_DirectTI : TIM Input 2 is selected to be connected to IC2 . @arg TIM_ICSelection_IndirectTI : TIM Input 2 is selected to be connected to IC1 . @arg TIM_ICSelection_TRC : TIM Input 2 is selected to be connected to TRC . @param TIM_ICFilter : Specifies the Input Capture Filter . This parameter must be a value between 0x00 and 0x0F . @retval None
static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
                       uint16_t TIM_ICFilter)
{
  uint16_t tmpccmr1 = 0, tmpccer = 0, tmp = 0;
  TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC2E);
  tmpccmr1 = TIMx->CCMR1;
  tmpccer = TIMx->CCER;
  tmp = (uint16_t)(TIM_ICPolarity << 4);
  tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC2S)) & ((uint16_t)~((uint16_t)TIM_CCMR1_IC2F)));
  tmpccmr1 |= (uint16_t)(TIM_ICFilter << 12);
  tmpccmr1 |= (uint16_t)(TIM_ICSelection << 8);
  if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) ||
     (TIMx == TIM4) ||(TIMx == TIM5))
  {
    tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC2P));
    tmpccer |=  (uint16_t)(tmp | (uint16_t)TIM_CCER_CC2E);
  }
  else
  {
    tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC2P | TIM_CCER_CC2NP));
    tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC2E);
  }
  TIMx->CCMR1 = tmpccmr1 ;
  TIMx->CCER = tmpccer;
}
static void TI2_Config ( TIM_TypeDef * TIMx , uint16_t TIM_ICPolarity , uint16_t TIM_ICSelection , uint16_t TIM_ICFilter ) { uint16_t tmpccmr1 = 0 , tmpccer = 0 , tmp = 0 ; TIMx -> CCER &= ( uint16_t ) ~ ( ( uint16_t ) TIM_CCER_CC2E ) ; tmpccmr1 = TIMx -> CCMR1 ; tmpccer = TIMx -> CCER ; tmp = ( uint16_t ) ( TIM_ICPolarity << 4 ) ; tmpccmr1 &= ( uint16_t ) ( ( ( uint16_t ) ~ ( ( uint16_t ) TIM_CCMR1_CC2S ) ) & ( ( uint16_t ) ~ ( ( uint16_t ) TIM_CCMR1_IC2F ) ) ) ; tmpccmr1 |= ( uint16_t ) ( TIM_ICFilter << 12 ) ; tmpccmr1 |= ( uint16_t ) ( TIM_ICSelection << 8 ) ; if ( ( TIMx == TIM1 ) || ( TIMx == TIM8 ) || ( TIMx == TIM2 ) || ( TIMx == TIM3 ) || ( TIMx == TIM4 ) || ( TIMx == TIM5 ) ) { tmpccer &= ( uint16_t ) ~ ( ( uint16_t ) ( TIM_CCER_CC2P ) ) ; tmpccer |= ( uint16_t ) ( tmp | ( uint16_t ) TIM_CCER_CC2E ) ; } else { tmpccer &= ( uint16_t ) ~ ( ( uint16_t ) ( TIM_CCER_CC2P | TIM_CCER_CC2NP ) ) ; tmpccer |= ( uint16_t ) ( TIM_ICPolarity | ( uint16_t ) TIM_CCER_CC2E ) ; } TIMx -> CCMR1 = tmpccmr1 ; TIMx -> CCER = tmpccer ; }
@brief  Configure the TI2 as Input.
@brief Configure the TI2 as Input .
/* Disable the Channel 2: Reset the CC2E Bit */ /* Select the Input and set the filter */ /* Select the Polarity and set the CC2E Bit */ /* Select the Polarity and set the CC2E Bit */ /* Write to TIMx CCMR1 and CCER registers */