libraries/mbed/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F103RB/stm32f10x_tim.c
/**
  * @brief  Configures the TIMx Encoder Interface.
  * @param  TIMx: where x can be  1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
  * @param  TIM_EncoderMode: specifies the TIMx Encoder Mode.
  *   This parameter can be one of the following values:
  *     @arg TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge depending on TI2FP2 level.
  *     @arg TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge depending on TI1FP1 level.
  *     @arg TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and TI2FP2 edges depending
  *                                on the level of the other input.
  * @param  TIM_IC1Polarity: specifies the IC1 Polarity
  *   This parameter can be one of the following values:
  *     @arg TIM_ICPolarity_Falling: IC Falling edge.
  *     @arg TIM_ICPolarity_Rising: IC Rising edge.
  * @param  TIM_IC2Polarity: specifies the IC2 Polarity
  *   This parameter can be one of the following values:
  *     @arg TIM_ICPolarity_Falling: IC Falling edge.
  *     @arg TIM_ICPolarity_Rising: IC Rising edge.
  * @retval None
  */
@brief  Configures the TIMx Encoder Interface.
@param  TIMx: where x can be  1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
@param  TIM_EncoderMode: specifies the TIMx Encoder Mode.
This parameter can be one of the following values:
@arg TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge depending on TI2FP2 level.
@arg TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge depending on TI1FP1 level.
@arg TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and TI2FP2 edges depending
on the level of the other input.
@param  TIM_IC1Polarity: specifies the IC1 Polarity
This parameter can be one of the following values:
@arg TIM_ICPolarity_Falling: IC Falling edge.
@arg TIM_ICPolarity_Rising: IC Rising edge.
@param  TIM_IC2Polarity: specifies the IC2 Polarity
This parameter can be one of the following values:
@arg TIM_ICPolarity_Falling: IC Falling edge.
@arg TIM_ICPolarity_Rising: IC Rising edge.
@retval None
@brief Configures the TIMx Encoder Interface . @param TIMx : where x can be 1 2 3 4 5 or 8 to select the TIM peripheral . @param TIM_EncoderMode : specifies the TIMx Encoder Mode . This parameter can be one of the following values : @arg TIM_EncoderMode_TI1 : Counter counts on TI1FP1 edge depending on TI2FP2 level . @arg TIM_EncoderMode_TI2 : Counter counts on TI2FP2 edge depending on TI1FP1 level . @arg TIM_EncoderMode_TI12 : Counter counts on both TI1FP1 and TI2FP2 edges depending on the level of the other input . @param TIM_IC1Polarity : specifies the IC1 Polarity This parameter can be one of the following values : @arg TIM_ICPolarity_Falling : IC Falling edge . @arg TIM_ICPolarity_Rising : IC Rising edge . @param TIM_IC2Polarity : specifies the IC2 Polarity This parameter can be one of the following values : @arg TIM_ICPolarity_Falling : IC Falling edge . @arg TIM_ICPolarity_Rising : IC Rising edge . @retval None
void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode,
                                uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity)
{
  uint16_t tmpsmcr = 0;
  uint16_t tmpccmr1 = 0;
  uint16_t tmpccer = 0;
  assert_param(IS_TIM_LIST5_PERIPH(TIMx));
  assert_param(IS_TIM_ENCODER_MODE(TIM_EncoderMode));
  assert_param(IS_TIM_IC_POLARITY(TIM_IC1Polarity));
  assert_param(IS_TIM_IC_POLARITY(TIM_IC2Polarity));
  tmpsmcr = TIMx->SMCR;
  tmpccmr1 = TIMx->CCMR1;
  tmpccer = TIMx->CCER;
  tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS));
  tmpsmcr |= TIM_EncoderMode;
  tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC1S)) & (uint16_t)(~((uint16_t)TIM_CCMR1_CC2S)));
  tmpccmr1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
  tmpccer &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCER_CC1P)) & ((uint16_t)~((uint16_t)TIM_CCER_CC2P)));
  tmpccer |= (uint16_t)(TIM_IC1Polarity | (uint16_t)(TIM_IC2Polarity << (uint16_t)4));
  TIMx->SMCR = tmpsmcr;
  TIMx->CCMR1 = tmpccmr1;
  TIMx->CCER = tmpccer;
}
void TIM_EncoderInterfaceConfig ( TIM_TypeDef * TIMx , uint16_t TIM_EncoderMode , uint16_t TIM_IC1Polarity , uint16_t TIM_IC2Polarity ) { uint16_t tmpsmcr = 0 ; uint16_t tmpccmr1 = 0 ; uint16_t tmpccer = 0 ; assert_param ( IS_TIM_LIST5_PERIPH ( TIMx ) ) ; assert_param ( IS_TIM_ENCODER_MODE ( TIM_EncoderMode ) ) ; assert_param ( IS_TIM_IC_POLARITY ( TIM_IC1Polarity ) ) ; assert_param ( IS_TIM_IC_POLARITY ( TIM_IC2Polarity ) ) ; tmpsmcr = TIMx -> SMCR ; tmpccmr1 = TIMx -> CCMR1 ; tmpccer = TIMx -> CCER ; tmpsmcr &= ( uint16_t ) ( ~ ( ( uint16_t ) TIM_SMCR_SMS ) ) ; tmpsmcr |= TIM_EncoderMode ; tmpccmr1 &= ( uint16_t ) ( ( ( uint16_t ) ~ ( ( uint16_t ) TIM_CCMR1_CC1S ) ) & ( uint16_t ) ( ~ ( ( uint16_t ) TIM_CCMR1_CC2S ) ) ) ; tmpccmr1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0 ; tmpccer &= ( uint16_t ) ( ( ( uint16_t ) ~ ( ( uint16_t ) TIM_CCER_CC1P ) ) & ( ( uint16_t ) ~ ( ( uint16_t ) TIM_CCER_CC2P ) ) ) ; tmpccer |= ( uint16_t ) ( TIM_IC1Polarity | ( uint16_t ) ( TIM_IC2Polarity << ( uint16_t ) 4 ) ) ; TIMx -> SMCR = tmpsmcr ; TIMx -> CCMR1 = tmpccmr1 ; TIMx -> CCER = tmpccer ; }
@brief  Configures the TIMx Encoder Interface.
@brief Configures the TIMx Encoder Interface .
/* Check the parameters */ /* Get the TIMx SMCR register value */ /* Get the TIMx CCMR1 register value */ /* Get the TIMx CCER register value */ /* Set the encoder Mode */ /* Select the Capture Compare 1 and the Capture Compare 2 as input */ /* Set the TI1 and the TI2 Polarities */ /* Write to TIMx SMCR */ /* Write to TIMx CCMR1 */ /* Write to TIMx CCER */