STM32F10x Standard Peripherals Library
3.5.0
|
00001 00022 /* Includes ------------------------------------------------------------------*/ 00023 #include "stm32f10x_tim.h" 00024 #include "stm32f10x_rcc.h" 00025 00047 /* ---------------------- TIM registers bit mask ------------------------ */ 00048 #define SMCR_ETR_Mask ((uint16_t)0x00FF) 00049 #define CCMR_Offset ((uint16_t)0x0018) 00050 #define CCER_CCE_Set ((uint16_t)0x0001) 00051 #define CCER_CCNE_Set ((uint16_t)0x0004) 00052 00077 static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, 00078 uint16_t TIM_ICFilter); 00079 static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, 00080 uint16_t TIM_ICFilter); 00081 static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, 00082 uint16_t TIM_ICFilter); 00083 static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, 00084 uint16_t TIM_ICFilter); 00122 void TIM_DeInit(TIM_TypeDef* TIMx) 00123 { 00124 /* Check the parameters */ 00125 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 00126 00127 if (TIMx == TIM1) 00128 { 00129 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, ENABLE); 00130 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, DISABLE); 00131 } 00132 else if (TIMx == TIM2) 00133 { 00134 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, ENABLE); 00135 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE); 00136 } 00137 else if (TIMx == TIM3) 00138 { 00139 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE); 00140 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE); 00141 } 00142 else if (TIMx == TIM4) 00143 { 00144 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, ENABLE); 00145 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4, DISABLE); 00146 } 00147 else if (TIMx == TIM5) 00148 { 00149 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM5, ENABLE); 00150 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM5, DISABLE); 00151 } 00152 else if (TIMx == TIM6) 00153 { 00154 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, ENABLE); 00155 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, DISABLE); 00156 } 00157 else if (TIMx == TIM7) 00158 { 00159 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7, ENABLE); 00160 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7, DISABLE); 00161 } 00162 else if (TIMx == TIM8) 00163 { 00164 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8, ENABLE); 00165 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8, DISABLE); 00166 } 00167 else if (TIMx == TIM9) 00168 { 00169 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM9, ENABLE); 00170 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM9, DISABLE); 00171 } 00172 else if (TIMx == TIM10) 00173 { 00174 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM10, ENABLE); 00175 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM10, DISABLE); 00176 } 00177 else if (TIMx == TIM11) 00178 { 00179 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM11, ENABLE); 00180 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM11, DISABLE); 00181 } 00182 else if (TIMx == TIM12) 00183 { 00184 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM12, ENABLE); 00185 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM12, DISABLE); 00186 } 00187 else if (TIMx == TIM13) 00188 { 00189 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM13, ENABLE); 00190 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM13, DISABLE); 00191 } 00192 else if (TIMx == TIM14) 00193 { 00194 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14, ENABLE); 00195 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14, DISABLE); 00196 } 00197 else if (TIMx == TIM15) 00198 { 00199 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, ENABLE); 00200 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, DISABLE); 00201 } 00202 else if (TIMx == TIM16) 00203 { 00204 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM16, ENABLE); 00205 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM16, DISABLE); 00206 } 00207 else 00208 { 00209 if (TIMx == TIM17) 00210 { 00211 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM17, ENABLE); 00212 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM17, DISABLE); 00213 } 00214 } 00215 } 00216 00226 void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct) 00227 { 00228 uint16_t tmpcr1 = 0; 00229 00230 /* Check the parameters */ 00231 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 00232 assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode)); 00233 assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision)); 00234 00235 tmpcr1 = TIMx->CR1; 00236 00237 if((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM2) || (TIMx == TIM3)|| 00238 (TIMx == TIM4) || (TIMx == TIM5)) 00239 { 00240 /* Select the Counter Mode */ 00241 tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_CR1_DIR | TIM_CR1_CMS))); 00242 tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_CounterMode; 00243 } 00244 00245 if((TIMx != TIM6) && (TIMx != TIM7)) 00246 { 00247 /* Set the clock division */ 00248 tmpcr1 &= (uint16_t)(~((uint16_t)TIM_CR1_CKD)); 00249 tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision; 00250 } 00251 00252 TIMx->CR1 = tmpcr1; 00253 00254 /* Set the Autoreload value */ 00255 TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ; 00256 00257 /* Set the Prescaler value */ 00258 TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler; 00259 00260 if ((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM15)|| (TIMx == TIM16) || (TIMx == TIM17)) 00261 { 00262 /* Set the Repetition Counter value */ 00263 TIMx->RCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter; 00264 } 00265 00266 /* Generate an update event to reload the Prescaler and the Repetition counter 00267 values immediately */ 00268 TIMx->EGR = TIM_PSCReloadMode_Immediate; 00269 } 00270 00279 void TIM_OC1Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct) 00280 { 00281 uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0; 00282 00283 /* Check the parameters */ 00284 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 00285 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode)); 00286 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState)); 00287 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity)); 00288 /* Disable the Channel 1: Reset the CC1E Bit */ 00289 TIMx->CCER &= (uint16_t)(~(uint16_t)TIM_CCER_CC1E); 00290 /* Get the TIMx CCER register value */ 00291 tmpccer = TIMx->CCER; 00292 /* Get the TIMx CR2 register value */ 00293 tmpcr2 = TIMx->CR2; 00294 00295 /* Get the TIMx CCMR1 register value */ 00296 tmpccmrx = TIMx->CCMR1; 00297 00298 /* Reset the Output Compare Mode Bits */ 00299 tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_OC1M)); 00300 tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_CC1S)); 00301 00302 /* Select the Output Compare Mode */ 00303 tmpccmrx |= TIM_OCInitStruct->TIM_OCMode; 00304 00305 /* Reset the Output Polarity level */ 00306 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1P)); 00307 /* Set the Output Compare Polarity */ 00308 tmpccer |= TIM_OCInitStruct->TIM_OCPolarity; 00309 00310 /* Set the Output State */ 00311 tmpccer |= TIM_OCInitStruct->TIM_OutputState; 00312 00313 if((TIMx == TIM1) || (TIMx == TIM8)|| (TIMx == TIM15)|| 00314 (TIMx == TIM16)|| (TIMx == TIM17)) 00315 { 00316 assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState)); 00317 assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity)); 00318 assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState)); 00319 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState)); 00320 00321 /* Reset the Output N Polarity level */ 00322 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1NP)); 00323 /* Set the Output N Polarity */ 00324 tmpccer |= TIM_OCInitStruct->TIM_OCNPolarity; 00325 00326 /* Reset the Output N State */ 00327 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1NE)); 00328 /* Set the Output N State */ 00329 tmpccer |= TIM_OCInitStruct->TIM_OutputNState; 00330 00331 /* Reset the Output Compare and Output Compare N IDLE State */ 00332 tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS1)); 00333 tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS1N)); 00334 00335 /* Set the Output Idle state */ 00336 tmpcr2 |= TIM_OCInitStruct->TIM_OCIdleState; 00337 /* Set the Output N Idle state */ 00338 tmpcr2 |= TIM_OCInitStruct->TIM_OCNIdleState; 00339 } 00340 /* Write to TIMx CR2 */ 00341 TIMx->CR2 = tmpcr2; 00342 00343 /* Write to TIMx CCMR1 */ 00344 TIMx->CCMR1 = tmpccmrx; 00345 00346 /* Set the Capture Compare Register value */ 00347 TIMx->CCR1 = TIM_OCInitStruct->TIM_Pulse; 00348 00349 /* Write to TIMx CCER */ 00350 TIMx->CCER = tmpccer; 00351 } 00352 00362 void TIM_OC2Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct) 00363 { 00364 uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0; 00365 00366 /* Check the parameters */ 00367 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 00368 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode)); 00369 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState)); 00370 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity)); 00371 /* Disable the Channel 2: Reset the CC2E Bit */ 00372 TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC2E)); 00373 00374 /* Get the TIMx CCER register value */ 00375 tmpccer = TIMx->CCER; 00376 /* Get the TIMx CR2 register value */ 00377 tmpcr2 = TIMx->CR2; 00378 00379 /* Get the TIMx CCMR1 register value */ 00380 tmpccmrx = TIMx->CCMR1; 00381 00382 /* Reset the Output Compare mode and Capture/Compare selection Bits */ 00383 tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_OC2M)); 00384 tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_CC2S)); 00385 00386 /* Select the Output Compare Mode */ 00387 tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8); 00388 00389 /* Reset the Output Polarity level */ 00390 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2P)); 00391 /* Set the Output Compare Polarity */ 00392 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 4); 00393 00394 /* Set the Output State */ 00395 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 4); 00396 00397 if((TIMx == TIM1) || (TIMx == TIM8)) 00398 { 00399 assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState)); 00400 assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity)); 00401 assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState)); 00402 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState)); 00403 00404 /* Reset the Output N Polarity level */ 00405 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2NP)); 00406 /* Set the Output N Polarity */ 00407 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 4); 00408 00409 /* Reset the Output N State */ 00410 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2NE)); 00411 /* Set the Output N State */ 00412 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 4); 00413 00414 /* Reset the Output Compare and Output Compare N IDLE State */ 00415 tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS2)); 00416 tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS2N)); 00417 00418 /* Set the Output Idle state */ 00419 tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 2); 00420 /* Set the Output N Idle state */ 00421 tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCNIdleState << 2); 00422 } 00423 /* Write to TIMx CR2 */ 00424 TIMx->CR2 = tmpcr2; 00425 00426 /* Write to TIMx CCMR1 */ 00427 TIMx->CCMR1 = tmpccmrx; 00428 00429 /* Set the Capture Compare Register value */ 00430 TIMx->CCR2 = TIM_OCInitStruct->TIM_Pulse; 00431 00432 /* Write to TIMx CCER */ 00433 TIMx->CCER = tmpccer; 00434 } 00435 00444 void TIM_OC3Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct) 00445 { 00446 uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0; 00447 00448 /* Check the parameters */ 00449 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 00450 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode)); 00451 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState)); 00452 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity)); 00453 /* Disable the Channel 2: Reset the CC2E Bit */ 00454 TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC3E)); 00455 00456 /* Get the TIMx CCER register value */ 00457 tmpccer = TIMx->CCER; 00458 /* Get the TIMx CR2 register value */ 00459 tmpcr2 = TIMx->CR2; 00460 00461 /* Get the TIMx CCMR2 register value */ 00462 tmpccmrx = TIMx->CCMR2; 00463 00464 /* Reset the Output Compare mode and Capture/Compare selection Bits */ 00465 tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_OC3M)); 00466 tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_CC3S)); 00467 /* Select the Output Compare Mode */ 00468 tmpccmrx |= TIM_OCInitStruct->TIM_OCMode; 00469 00470 /* Reset the Output Polarity level */ 00471 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3P)); 00472 /* Set the Output Compare Polarity */ 00473 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 8); 00474 00475 /* Set the Output State */ 00476 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 8); 00477 00478 if((TIMx == TIM1) || (TIMx == TIM8)) 00479 { 00480 assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState)); 00481 assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity)); 00482 assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState)); 00483 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState)); 00484 00485 /* Reset the Output N Polarity level */ 00486 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3NP)); 00487 /* Set the Output N Polarity */ 00488 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 8); 00489 /* Reset the Output N State */ 00490 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3NE)); 00491 00492 /* Set the Output N State */ 00493 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 8); 00494 /* Reset the Output Compare and Output Compare N IDLE State */ 00495 tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS3)); 00496 tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS3N)); 00497 /* Set the Output Idle state */ 00498 tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 4); 00499 /* Set the Output N Idle state */ 00500 tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCNIdleState << 4); 00501 } 00502 /* Write to TIMx CR2 */ 00503 TIMx->CR2 = tmpcr2; 00504 00505 /* Write to TIMx CCMR2 */ 00506 TIMx->CCMR2 = tmpccmrx; 00507 00508 /* Set the Capture Compare Register value */ 00509 TIMx->CCR3 = TIM_OCInitStruct->TIM_Pulse; 00510 00511 /* Write to TIMx CCER */ 00512 TIMx->CCER = tmpccer; 00513 } 00514 00523 void TIM_OC4Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct) 00524 { 00525 uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0; 00526 00527 /* Check the parameters */ 00528 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 00529 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode)); 00530 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState)); 00531 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity)); 00532 /* Disable the Channel 2: Reset the CC4E Bit */ 00533 TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC4E)); 00534 00535 /* Get the TIMx CCER register value */ 00536 tmpccer = TIMx->CCER; 00537 /* Get the TIMx CR2 register value */ 00538 tmpcr2 = TIMx->CR2; 00539 00540 /* Get the TIMx CCMR2 register value */ 00541 tmpccmrx = TIMx->CCMR2; 00542 00543 /* Reset the Output Compare mode and Capture/Compare selection Bits */ 00544 tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_OC4M)); 00545 tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_CC4S)); 00546 00547 /* Select the Output Compare Mode */ 00548 tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8); 00549 00550 /* Reset the Output Polarity level */ 00551 tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC4P)); 00552 /* Set the Output Compare Polarity */ 00553 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 12); 00554 00555 /* Set the Output State */ 00556 tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 12); 00557 00558 if((TIMx == TIM1) || (TIMx == TIM8)) 00559 { 00560 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState)); 00561 /* Reset the Output Compare IDLE State */ 00562 tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS4)); 00563 /* Set the Output Idle state */ 00564 tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 6); 00565 } 00566 /* Write to TIMx CR2 */ 00567 TIMx->CR2 = tmpcr2; 00568 00569 /* Write to TIMx CCMR2 */ 00570 TIMx->CCMR2 = tmpccmrx; 00571 00572 /* Set the Capture Compare Register value */ 00573 TIMx->CCR4 = TIM_OCInitStruct->TIM_Pulse; 00574 00575 /* Write to TIMx CCER */ 00576 TIMx->CCER = tmpccer; 00577 } 00578 00587 void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct) 00588 { 00589 /* Check the parameters */ 00590 assert_param(IS_TIM_CHANNEL(TIM_ICInitStruct->TIM_Channel)); 00591 assert_param(IS_TIM_IC_SELECTION(TIM_ICInitStruct->TIM_ICSelection)); 00592 assert_param(IS_TIM_IC_PRESCALER(TIM_ICInitStruct->TIM_ICPrescaler)); 00593 assert_param(IS_TIM_IC_FILTER(TIM_ICInitStruct->TIM_ICFilter)); 00594 00595 if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) || 00596 (TIMx == TIM4) ||(TIMx == TIM5)) 00597 { 00598 assert_param(IS_TIM_IC_POLARITY(TIM_ICInitStruct->TIM_ICPolarity)); 00599 } 00600 else 00601 { 00602 assert_param(IS_TIM_IC_POLARITY_LITE(TIM_ICInitStruct->TIM_ICPolarity)); 00603 } 00604 if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1) 00605 { 00606 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 00607 /* TI1 Configuration */ 00608 TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, 00609 TIM_ICInitStruct->TIM_ICSelection, 00610 TIM_ICInitStruct->TIM_ICFilter); 00611 /* Set the Input Capture Prescaler value */ 00612 TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); 00613 } 00614 else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_2) 00615 { 00616 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 00617 /* TI2 Configuration */ 00618 TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, 00619 TIM_ICInitStruct->TIM_ICSelection, 00620 TIM_ICInitStruct->TIM_ICFilter); 00621 /* Set the Input Capture Prescaler value */ 00622 TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); 00623 } 00624 else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_3) 00625 { 00626 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 00627 /* TI3 Configuration */ 00628 TI3_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, 00629 TIM_ICInitStruct->TIM_ICSelection, 00630 TIM_ICInitStruct->TIM_ICFilter); 00631 /* Set the Input Capture Prescaler value */ 00632 TIM_SetIC3Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); 00633 } 00634 else 00635 { 00636 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 00637 /* TI4 Configuration */ 00638 TI4_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, 00639 TIM_ICInitStruct->TIM_ICSelection, 00640 TIM_ICInitStruct->TIM_ICFilter); 00641 /* Set the Input Capture Prescaler value */ 00642 TIM_SetIC4Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); 00643 } 00644 } 00645 00654 void TIM_PWMIConfig(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct) 00655 { 00656 uint16_t icoppositepolarity = TIM_ICPolarity_Rising; 00657 uint16_t icoppositeselection = TIM_ICSelection_DirectTI; 00658 /* Check the parameters */ 00659 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 00660 /* Select the Opposite Input Polarity */ 00661 if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising) 00662 { 00663 icoppositepolarity = TIM_ICPolarity_Falling; 00664 } 00665 else 00666 { 00667 icoppositepolarity = TIM_ICPolarity_Rising; 00668 } 00669 /* Select the Opposite Input */ 00670 if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI) 00671 { 00672 icoppositeselection = TIM_ICSelection_IndirectTI; 00673 } 00674 else 00675 { 00676 icoppositeselection = TIM_ICSelection_DirectTI; 00677 } 00678 if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1) 00679 { 00680 /* TI1 Configuration */ 00681 TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection, 00682 TIM_ICInitStruct->TIM_ICFilter); 00683 /* Set the Input Capture Prescaler value */ 00684 TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); 00685 /* TI2 Configuration */ 00686 TI2_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter); 00687 /* Set the Input Capture Prescaler value */ 00688 TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); 00689 } 00690 else 00691 { 00692 /* TI2 Configuration */ 00693 TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection, 00694 TIM_ICInitStruct->TIM_ICFilter); 00695 /* Set the Input Capture Prescaler value */ 00696 TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); 00697 /* TI1 Configuration */ 00698 TI1_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter); 00699 /* Set the Input Capture Prescaler value */ 00700 TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler); 00701 } 00702 } 00703 00712 void TIM_BDTRConfig(TIM_TypeDef* TIMx, TIM_BDTRInitTypeDef *TIM_BDTRInitStruct) 00713 { 00714 /* Check the parameters */ 00715 assert_param(IS_TIM_LIST2_PERIPH(TIMx)); 00716 assert_param(IS_TIM_OSSR_STATE(TIM_BDTRInitStruct->TIM_OSSRState)); 00717 assert_param(IS_TIM_OSSI_STATE(TIM_BDTRInitStruct->TIM_OSSIState)); 00718 assert_param(IS_TIM_LOCK_LEVEL(TIM_BDTRInitStruct->TIM_LOCKLevel)); 00719 assert_param(IS_TIM_BREAK_STATE(TIM_BDTRInitStruct->TIM_Break)); 00720 assert_param(IS_TIM_BREAK_POLARITY(TIM_BDTRInitStruct->TIM_BreakPolarity)); 00721 assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(TIM_BDTRInitStruct->TIM_AutomaticOutput)); 00722 /* Set the Lock level, the Break enable Bit and the Ploarity, the OSSR State, 00723 the OSSI State, the dead time value and the Automatic Output Enable Bit */ 00724 TIMx->BDTR = (uint32_t)TIM_BDTRInitStruct->TIM_OSSRState | TIM_BDTRInitStruct->TIM_OSSIState | 00725 TIM_BDTRInitStruct->TIM_LOCKLevel | TIM_BDTRInitStruct->TIM_DeadTime | 00726 TIM_BDTRInitStruct->TIM_Break | TIM_BDTRInitStruct->TIM_BreakPolarity | 00727 TIM_BDTRInitStruct->TIM_AutomaticOutput; 00728 } 00729 00736 void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct) 00737 { 00738 /* Set the default configuration */ 00739 TIM_TimeBaseInitStruct->TIM_Period = 0xFFFF; 00740 TIM_TimeBaseInitStruct->TIM_Prescaler = 0x0000; 00741 TIM_TimeBaseInitStruct->TIM_ClockDivision = TIM_CKD_DIV1; 00742 TIM_TimeBaseInitStruct->TIM_CounterMode = TIM_CounterMode_Up; 00743 TIM_TimeBaseInitStruct->TIM_RepetitionCounter = 0x0000; 00744 } 00745 00752 void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct) 00753 { 00754 /* Set the default configuration */ 00755 TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing; 00756 TIM_OCInitStruct->TIM_OutputState = TIM_OutputState_Disable; 00757 TIM_OCInitStruct->TIM_OutputNState = TIM_OutputNState_Disable; 00758 TIM_OCInitStruct->TIM_Pulse = 0x0000; 00759 TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High; 00760 TIM_OCInitStruct->TIM_OCNPolarity = TIM_OCPolarity_High; 00761 TIM_OCInitStruct->TIM_OCIdleState = TIM_OCIdleState_Reset; 00762 TIM_OCInitStruct->TIM_OCNIdleState = TIM_OCNIdleState_Reset; 00763 } 00764 00771 void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct) 00772 { 00773 /* Set the default configuration */ 00774 TIM_ICInitStruct->TIM_Channel = TIM_Channel_1; 00775 TIM_ICInitStruct->TIM_ICPolarity = TIM_ICPolarity_Rising; 00776 TIM_ICInitStruct->TIM_ICSelection = TIM_ICSelection_DirectTI; 00777 TIM_ICInitStruct->TIM_ICPrescaler = TIM_ICPSC_DIV1; 00778 TIM_ICInitStruct->TIM_ICFilter = 0x00; 00779 } 00780 00787 void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* TIM_BDTRInitStruct) 00788 { 00789 /* Set the default configuration */ 00790 TIM_BDTRInitStruct->TIM_OSSRState = TIM_OSSRState_Disable; 00791 TIM_BDTRInitStruct->TIM_OSSIState = TIM_OSSIState_Disable; 00792 TIM_BDTRInitStruct->TIM_LOCKLevel = TIM_LOCKLevel_OFF; 00793 TIM_BDTRInitStruct->TIM_DeadTime = 0x00; 00794 TIM_BDTRInitStruct->TIM_Break = TIM_Break_Disable; 00795 TIM_BDTRInitStruct->TIM_BreakPolarity = TIM_BreakPolarity_Low; 00796 TIM_BDTRInitStruct->TIM_AutomaticOutput = TIM_AutomaticOutput_Disable; 00797 } 00798 00806 void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState) 00807 { 00808 /* Check the parameters */ 00809 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 00810 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00811 00812 if (NewState != DISABLE) 00813 { 00814 /* Enable the TIM Counter */ 00815 TIMx->CR1 |= TIM_CR1_CEN; 00816 } 00817 else 00818 { 00819 /* Disable the TIM Counter */ 00820 TIMx->CR1 &= (uint16_t)(~((uint16_t)TIM_CR1_CEN)); 00821 } 00822 } 00823 00831 void TIM_CtrlPWMOutputs(TIM_TypeDef* TIMx, FunctionalState NewState) 00832 { 00833 /* Check the parameters */ 00834 assert_param(IS_TIM_LIST2_PERIPH(TIMx)); 00835 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00836 if (NewState != DISABLE) 00837 { 00838 /* Enable the TIM Main Output */ 00839 TIMx->BDTR |= TIM_BDTR_MOE; 00840 } 00841 else 00842 { 00843 /* Disable the TIM Main Output */ 00844 TIMx->BDTR &= (uint16_t)(~((uint16_t)TIM_BDTR_MOE)); 00845 } 00846 } 00847 00872 void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState) 00873 { 00874 /* Check the parameters */ 00875 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 00876 assert_param(IS_TIM_IT(TIM_IT)); 00877 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00878 00879 if (NewState != DISABLE) 00880 { 00881 /* Enable the Interrupt sources */ 00882 TIMx->DIER |= TIM_IT; 00883 } 00884 else 00885 { 00886 /* Disable the Interrupt sources */ 00887 TIMx->DIER &= (uint16_t)~TIM_IT; 00888 } 00889 } 00890 00909 void TIM_GenerateEvent(TIM_TypeDef* TIMx, uint16_t TIM_EventSource) 00910 { 00911 /* Check the parameters */ 00912 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 00913 assert_param(IS_TIM_EVENT_SOURCE(TIM_EventSource)); 00914 00915 /* Set the event sources */ 00916 TIMx->EGR = TIM_EventSource; 00917 } 00918 00937 void TIM_DMAConfig(TIM_TypeDef* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength) 00938 { 00939 /* Check the parameters */ 00940 assert_param(IS_TIM_LIST4_PERIPH(TIMx)); 00941 assert_param(IS_TIM_DMA_BASE(TIM_DMABase)); 00942 assert_param(IS_TIM_DMA_LENGTH(TIM_DMABurstLength)); 00943 /* Set the DMA Base and the DMA Burst Length */ 00944 TIMx->DCR = TIM_DMABase | TIM_DMABurstLength; 00945 } 00946 00964 void TIM_DMACmd(TIM_TypeDef* TIMx, uint16_t TIM_DMASource, FunctionalState NewState) 00965 { 00966 /* Check the parameters */ 00967 assert_param(IS_TIM_LIST9_PERIPH(TIMx)); 00968 assert_param(IS_TIM_DMA_SOURCE(TIM_DMASource)); 00969 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00970 00971 if (NewState != DISABLE) 00972 { 00973 /* Enable the DMA sources */ 00974 TIMx->DIER |= TIM_DMASource; 00975 } 00976 else 00977 { 00978 /* Disable the DMA sources */ 00979 TIMx->DIER &= (uint16_t)~TIM_DMASource; 00980 } 00981 } 00982 00989 void TIM_InternalClockConfig(TIM_TypeDef* TIMx) 00990 { 00991 /* Check the parameters */ 00992 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 00993 /* Disable slave mode to clock the prescaler directly with the internal clock */ 00994 TIMx->SMCR &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS)); 00995 } 00996 01008 void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource) 01009 { 01010 /* Check the parameters */ 01011 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 01012 assert_param(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource)); 01013 /* Select the Internal Trigger */ 01014 TIM_SelectInputTrigger(TIMx, TIM_InputTriggerSource); 01015 /* Select the External clock mode1 */ 01016 TIMx->SMCR |= TIM_SlaveMode_External1; 01017 } 01018 01035 void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_TIxExternalCLKSource, 01036 uint16_t TIM_ICPolarity, uint16_t ICFilter) 01037 { 01038 /* Check the parameters */ 01039 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 01040 assert_param(IS_TIM_TIXCLK_SOURCE(TIM_TIxExternalCLKSource)); 01041 assert_param(IS_TIM_IC_POLARITY(TIM_ICPolarity)); 01042 assert_param(IS_TIM_IC_FILTER(ICFilter)); 01043 /* Configure the Timer Input Clock Source */ 01044 if (TIM_TIxExternalCLKSource == TIM_TIxExternalCLK1Source_TI2) 01045 { 01046 TI2_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter); 01047 } 01048 else 01049 { 01050 TI1_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter); 01051 } 01052 /* Select the Trigger source */ 01053 TIM_SelectInputTrigger(TIMx, TIM_TIxExternalCLKSource); 01054 /* Select the External clock mode1 */ 01055 TIMx->SMCR |= TIM_SlaveMode_External1; 01056 } 01057 01075 void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity, 01076 uint16_t ExtTRGFilter) 01077 { 01078 uint16_t tmpsmcr = 0; 01079 /* Check the parameters */ 01080 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01081 assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler)); 01082 assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity)); 01083 assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter)); 01084 /* Configure the ETR Clock source */ 01085 TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter); 01086 01087 /* Get the TIMx SMCR register value */ 01088 tmpsmcr = TIMx->SMCR; 01089 /* Reset the SMS Bits */ 01090 tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS)); 01091 /* Select the External clock mode1 */ 01092 tmpsmcr |= TIM_SlaveMode_External1; 01093 /* Select the Trigger selection : ETRF */ 01094 tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_TS)); 01095 tmpsmcr |= TIM_TS_ETRF; 01096 /* Write to TIMx SMCR */ 01097 TIMx->SMCR = tmpsmcr; 01098 } 01099 01117 void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, 01118 uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter) 01119 { 01120 /* Check the parameters */ 01121 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01122 assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler)); 01123 assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity)); 01124 assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter)); 01125 /* Configure the ETR Clock source */ 01126 TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter); 01127 /* Enable the External clock mode2 */ 01128 TIMx->SMCR |= TIM_SMCR_ECE; 01129 } 01130 01148 void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity, 01149 uint16_t ExtTRGFilter) 01150 { 01151 uint16_t tmpsmcr = 0; 01152 /* Check the parameters */ 01153 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01154 assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler)); 01155 assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity)); 01156 assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter)); 01157 tmpsmcr = TIMx->SMCR; 01158 /* Reset the ETR Bits */ 01159 tmpsmcr &= SMCR_ETR_Mask; 01160 /* Set the Prescaler, the Filter value and the Polarity */ 01161 tmpsmcr |= (uint16_t)(TIM_ExtTRGPrescaler | (uint16_t)(TIM_ExtTRGPolarity | (uint16_t)(ExtTRGFilter << (uint16_t)8))); 01162 /* Write to TIMx SMCR */ 01163 TIMx->SMCR = tmpsmcr; 01164 } 01165 01176 void TIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode) 01177 { 01178 /* Check the parameters */ 01179 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 01180 assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode)); 01181 /* Set the Prescaler value */ 01182 TIMx->PSC = Prescaler; 01183 /* Set or reset the UG Bit */ 01184 TIMx->EGR = TIM_PSCReloadMode; 01185 } 01186 01199 void TIM_CounterModeConfig(TIM_TypeDef* TIMx, uint16_t TIM_CounterMode) 01200 { 01201 uint16_t tmpcr1 = 0; 01202 /* Check the parameters */ 01203 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01204 assert_param(IS_TIM_COUNTER_MODE(TIM_CounterMode)); 01205 tmpcr1 = TIMx->CR1; 01206 /* Reset the CMS and DIR Bits */ 01207 tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_CR1_DIR | TIM_CR1_CMS))); 01208 /* Set the Counter Mode */ 01209 tmpcr1 |= TIM_CounterMode; 01210 /* Write to TIMx CR1 register */ 01211 TIMx->CR1 = tmpcr1; 01212 } 01213 01229 void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource) 01230 { 01231 uint16_t tmpsmcr = 0; 01232 /* Check the parameters */ 01233 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 01234 assert_param(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource)); 01235 /* Get the TIMx SMCR register value */ 01236 tmpsmcr = TIMx->SMCR; 01237 /* Reset the TS Bits */ 01238 tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_TS)); 01239 /* Set the Input Trigger source */ 01240 tmpsmcr |= TIM_InputTriggerSource; 01241 /* Write to TIMx SMCR */ 01242 TIMx->SMCR = tmpsmcr; 01243 } 01244 01264 void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode, 01265 uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity) 01266 { 01267 uint16_t tmpsmcr = 0; 01268 uint16_t tmpccmr1 = 0; 01269 uint16_t tmpccer = 0; 01270 01271 /* Check the parameters */ 01272 assert_param(IS_TIM_LIST5_PERIPH(TIMx)); 01273 assert_param(IS_TIM_ENCODER_MODE(TIM_EncoderMode)); 01274 assert_param(IS_TIM_IC_POLARITY(TIM_IC1Polarity)); 01275 assert_param(IS_TIM_IC_POLARITY(TIM_IC2Polarity)); 01276 01277 /* Get the TIMx SMCR register value */ 01278 tmpsmcr = TIMx->SMCR; 01279 01280 /* Get the TIMx CCMR1 register value */ 01281 tmpccmr1 = TIMx->CCMR1; 01282 01283 /* Get the TIMx CCER register value */ 01284 tmpccer = TIMx->CCER; 01285 01286 /* Set the encoder Mode */ 01287 tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS)); 01288 tmpsmcr |= TIM_EncoderMode; 01289 01290 /* Select the Capture Compare 1 and the Capture Compare 2 as input */ 01291 tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC1S)) & (uint16_t)(~((uint16_t)TIM_CCMR1_CC2S))); 01292 tmpccmr1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0; 01293 01294 /* Set the TI1 and the TI2 Polarities */ 01295 tmpccer &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCER_CC1P)) & ((uint16_t)~((uint16_t)TIM_CCER_CC2P))); 01296 tmpccer |= (uint16_t)(TIM_IC1Polarity | (uint16_t)(TIM_IC2Polarity << (uint16_t)4)); 01297 01298 /* Write to TIMx SMCR */ 01299 TIMx->SMCR = tmpsmcr; 01300 /* Write to TIMx CCMR1 */ 01301 TIMx->CCMR1 = tmpccmr1; 01302 /* Write to TIMx CCER */ 01303 TIMx->CCER = tmpccer; 01304 } 01305 01315 void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction) 01316 { 01317 uint16_t tmpccmr1 = 0; 01318 /* Check the parameters */ 01319 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 01320 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction)); 01321 tmpccmr1 = TIMx->CCMR1; 01322 /* Reset the OC1M Bits */ 01323 tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1M); 01324 /* Configure The Forced output Mode */ 01325 tmpccmr1 |= TIM_ForcedAction; 01326 /* Write to TIMx CCMR1 register */ 01327 TIMx->CCMR1 = tmpccmr1; 01328 } 01329 01339 void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction) 01340 { 01341 uint16_t tmpccmr1 = 0; 01342 /* Check the parameters */ 01343 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 01344 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction)); 01345 tmpccmr1 = TIMx->CCMR1; 01346 /* Reset the OC2M Bits */ 01347 tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2M); 01348 /* Configure The Forced output Mode */ 01349 tmpccmr1 |= (uint16_t)(TIM_ForcedAction << 8); 01350 /* Write to TIMx CCMR1 register */ 01351 TIMx->CCMR1 = tmpccmr1; 01352 } 01353 01363 void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction) 01364 { 01365 uint16_t tmpccmr2 = 0; 01366 /* Check the parameters */ 01367 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01368 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction)); 01369 tmpccmr2 = TIMx->CCMR2; 01370 /* Reset the OC1M Bits */ 01371 tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3M); 01372 /* Configure The Forced output Mode */ 01373 tmpccmr2 |= TIM_ForcedAction; 01374 /* Write to TIMx CCMR2 register */ 01375 TIMx->CCMR2 = tmpccmr2; 01376 } 01377 01387 void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction) 01388 { 01389 uint16_t tmpccmr2 = 0; 01390 /* Check the parameters */ 01391 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01392 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction)); 01393 tmpccmr2 = TIMx->CCMR2; 01394 /* Reset the OC2M Bits */ 01395 tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4M); 01396 /* Configure The Forced output Mode */ 01397 tmpccmr2 |= (uint16_t)(TIM_ForcedAction << 8); 01398 /* Write to TIMx CCMR2 register */ 01399 TIMx->CCMR2 = tmpccmr2; 01400 } 01401 01409 void TIM_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState NewState) 01410 { 01411 /* Check the parameters */ 01412 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 01413 assert_param(IS_FUNCTIONAL_STATE(NewState)); 01414 if (NewState != DISABLE) 01415 { 01416 /* Set the ARR Preload Bit */ 01417 TIMx->CR1 |= TIM_CR1_ARPE; 01418 } 01419 else 01420 { 01421 /* Reset the ARR Preload Bit */ 01422 TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_ARPE); 01423 } 01424 } 01425 01433 void TIM_SelectCOM(TIM_TypeDef* TIMx, FunctionalState NewState) 01434 { 01435 /* Check the parameters */ 01436 assert_param(IS_TIM_LIST2_PERIPH(TIMx)); 01437 assert_param(IS_FUNCTIONAL_STATE(NewState)); 01438 if (NewState != DISABLE) 01439 { 01440 /* Set the COM Bit */ 01441 TIMx->CR2 |= TIM_CR2_CCUS; 01442 } 01443 else 01444 { 01445 /* Reset the COM Bit */ 01446 TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCUS); 01447 } 01448 } 01449 01458 void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState NewState) 01459 { 01460 /* Check the parameters */ 01461 assert_param(IS_TIM_LIST4_PERIPH(TIMx)); 01462 assert_param(IS_FUNCTIONAL_STATE(NewState)); 01463 if (NewState != DISABLE) 01464 { 01465 /* Set the CCDS Bit */ 01466 TIMx->CR2 |= TIM_CR2_CCDS; 01467 } 01468 else 01469 { 01470 /* Reset the CCDS Bit */ 01471 TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCDS); 01472 } 01473 } 01474 01483 void TIM_CCPreloadControl(TIM_TypeDef* TIMx, FunctionalState NewState) 01484 { 01485 /* Check the parameters */ 01486 assert_param(IS_TIM_LIST5_PERIPH(TIMx)); 01487 assert_param(IS_FUNCTIONAL_STATE(NewState)); 01488 if (NewState != DISABLE) 01489 { 01490 /* Set the CCPC Bit */ 01491 TIMx->CR2 |= TIM_CR2_CCPC; 01492 } 01493 else 01494 { 01495 /* Reset the CCPC Bit */ 01496 TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCPC); 01497 } 01498 } 01499 01509 void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload) 01510 { 01511 uint16_t tmpccmr1 = 0; 01512 /* Check the parameters */ 01513 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 01514 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload)); 01515 tmpccmr1 = TIMx->CCMR1; 01516 /* Reset the OC1PE Bit */ 01517 tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1PE); 01518 /* Enable or Disable the Output Compare Preload feature */ 01519 tmpccmr1 |= TIM_OCPreload; 01520 /* Write to TIMx CCMR1 register */ 01521 TIMx->CCMR1 = tmpccmr1; 01522 } 01523 01534 void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload) 01535 { 01536 uint16_t tmpccmr1 = 0; 01537 /* Check the parameters */ 01538 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 01539 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload)); 01540 tmpccmr1 = TIMx->CCMR1; 01541 /* Reset the OC2PE Bit */ 01542 tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2PE); 01543 /* Enable or Disable the Output Compare Preload feature */ 01544 tmpccmr1 |= (uint16_t)(TIM_OCPreload << 8); 01545 /* Write to TIMx CCMR1 register */ 01546 TIMx->CCMR1 = tmpccmr1; 01547 } 01548 01558 void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload) 01559 { 01560 uint16_t tmpccmr2 = 0; 01561 /* Check the parameters */ 01562 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01563 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload)); 01564 tmpccmr2 = TIMx->CCMR2; 01565 /* Reset the OC3PE Bit */ 01566 tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3PE); 01567 /* Enable or Disable the Output Compare Preload feature */ 01568 tmpccmr2 |= TIM_OCPreload; 01569 /* Write to TIMx CCMR2 register */ 01570 TIMx->CCMR2 = tmpccmr2; 01571 } 01572 01582 void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload) 01583 { 01584 uint16_t tmpccmr2 = 0; 01585 /* Check the parameters */ 01586 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01587 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload)); 01588 tmpccmr2 = TIMx->CCMR2; 01589 /* Reset the OC4PE Bit */ 01590 tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4PE); 01591 /* Enable or Disable the Output Compare Preload feature */ 01592 tmpccmr2 |= (uint16_t)(TIM_OCPreload << 8); 01593 /* Write to TIMx CCMR2 register */ 01594 TIMx->CCMR2 = tmpccmr2; 01595 } 01596 01606 void TIM_OC1FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast) 01607 { 01608 uint16_t tmpccmr1 = 0; 01609 /* Check the parameters */ 01610 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 01611 assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast)); 01612 /* Get the TIMx CCMR1 register value */ 01613 tmpccmr1 = TIMx->CCMR1; 01614 /* Reset the OC1FE Bit */ 01615 tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1FE); 01616 /* Enable or Disable the Output Compare Fast Bit */ 01617 tmpccmr1 |= TIM_OCFast; 01618 /* Write to TIMx CCMR1 */ 01619 TIMx->CCMR1 = tmpccmr1; 01620 } 01621 01632 void TIM_OC2FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast) 01633 { 01634 uint16_t tmpccmr1 = 0; 01635 /* Check the parameters */ 01636 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 01637 assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast)); 01638 /* Get the TIMx CCMR1 register value */ 01639 tmpccmr1 = TIMx->CCMR1; 01640 /* Reset the OC2FE Bit */ 01641 tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2FE); 01642 /* Enable or Disable the Output Compare Fast Bit */ 01643 tmpccmr1 |= (uint16_t)(TIM_OCFast << 8); 01644 /* Write to TIMx CCMR1 */ 01645 TIMx->CCMR1 = tmpccmr1; 01646 } 01647 01657 void TIM_OC3FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast) 01658 { 01659 uint16_t tmpccmr2 = 0; 01660 /* Check the parameters */ 01661 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01662 assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast)); 01663 /* Get the TIMx CCMR2 register value */ 01664 tmpccmr2 = TIMx->CCMR2; 01665 /* Reset the OC3FE Bit */ 01666 tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3FE); 01667 /* Enable or Disable the Output Compare Fast Bit */ 01668 tmpccmr2 |= TIM_OCFast; 01669 /* Write to TIMx CCMR2 */ 01670 TIMx->CCMR2 = tmpccmr2; 01671 } 01672 01682 void TIM_OC4FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast) 01683 { 01684 uint16_t tmpccmr2 = 0; 01685 /* Check the parameters */ 01686 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01687 assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast)); 01688 /* Get the TIMx CCMR2 register value */ 01689 tmpccmr2 = TIMx->CCMR2; 01690 /* Reset the OC4FE Bit */ 01691 tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4FE); 01692 /* Enable or Disable the Output Compare Fast Bit */ 01693 tmpccmr2 |= (uint16_t)(TIM_OCFast << 8); 01694 /* Write to TIMx CCMR2 */ 01695 TIMx->CCMR2 = tmpccmr2; 01696 } 01697 01707 void TIM_ClearOC1Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear) 01708 { 01709 uint16_t tmpccmr1 = 0; 01710 /* Check the parameters */ 01711 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01712 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear)); 01713 01714 tmpccmr1 = TIMx->CCMR1; 01715 01716 /* Reset the OC1CE Bit */ 01717 tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1CE); 01718 /* Enable or Disable the Output Compare Clear Bit */ 01719 tmpccmr1 |= TIM_OCClear; 01720 /* Write to TIMx CCMR1 register */ 01721 TIMx->CCMR1 = tmpccmr1; 01722 } 01723 01733 void TIM_ClearOC2Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear) 01734 { 01735 uint16_t tmpccmr1 = 0; 01736 /* Check the parameters */ 01737 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01738 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear)); 01739 tmpccmr1 = TIMx->CCMR1; 01740 /* Reset the OC2CE Bit */ 01741 tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2CE); 01742 /* Enable or Disable the Output Compare Clear Bit */ 01743 tmpccmr1 |= (uint16_t)(TIM_OCClear << 8); 01744 /* Write to TIMx CCMR1 register */ 01745 TIMx->CCMR1 = tmpccmr1; 01746 } 01747 01757 void TIM_ClearOC3Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear) 01758 { 01759 uint16_t tmpccmr2 = 0; 01760 /* Check the parameters */ 01761 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01762 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear)); 01763 tmpccmr2 = TIMx->CCMR2; 01764 /* Reset the OC3CE Bit */ 01765 tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3CE); 01766 /* Enable or Disable the Output Compare Clear Bit */ 01767 tmpccmr2 |= TIM_OCClear; 01768 /* Write to TIMx CCMR2 register */ 01769 TIMx->CCMR2 = tmpccmr2; 01770 } 01771 01781 void TIM_ClearOC4Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear) 01782 { 01783 uint16_t tmpccmr2 = 0; 01784 /* Check the parameters */ 01785 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01786 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear)); 01787 tmpccmr2 = TIMx->CCMR2; 01788 /* Reset the OC4CE Bit */ 01789 tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4CE); 01790 /* Enable or Disable the Output Compare Clear Bit */ 01791 tmpccmr2 |= (uint16_t)(TIM_OCClear << 8); 01792 /* Write to TIMx CCMR2 register */ 01793 TIMx->CCMR2 = tmpccmr2; 01794 } 01795 01805 void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity) 01806 { 01807 uint16_t tmpccer = 0; 01808 /* Check the parameters */ 01809 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 01810 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity)); 01811 tmpccer = TIMx->CCER; 01812 /* Set or Reset the CC1P Bit */ 01813 tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC1P); 01814 tmpccer |= TIM_OCPolarity; 01815 /* Write to TIMx CCER register */ 01816 TIMx->CCER = tmpccer; 01817 } 01818 01828 void TIM_OC1NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity) 01829 { 01830 uint16_t tmpccer = 0; 01831 /* Check the parameters */ 01832 assert_param(IS_TIM_LIST2_PERIPH(TIMx)); 01833 assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity)); 01834 01835 tmpccer = TIMx->CCER; 01836 /* Set or Reset the CC1NP Bit */ 01837 tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC1NP); 01838 tmpccer |= TIM_OCNPolarity; 01839 /* Write to TIMx CCER register */ 01840 TIMx->CCER = tmpccer; 01841 } 01842 01852 void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity) 01853 { 01854 uint16_t tmpccer = 0; 01855 /* Check the parameters */ 01856 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 01857 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity)); 01858 tmpccer = TIMx->CCER; 01859 /* Set or Reset the CC2P Bit */ 01860 tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC2P); 01861 tmpccer |= (uint16_t)(TIM_OCPolarity << 4); 01862 /* Write to TIMx CCER register */ 01863 TIMx->CCER = tmpccer; 01864 } 01865 01875 void TIM_OC2NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity) 01876 { 01877 uint16_t tmpccer = 0; 01878 /* Check the parameters */ 01879 assert_param(IS_TIM_LIST1_PERIPH(TIMx)); 01880 assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity)); 01881 01882 tmpccer = TIMx->CCER; 01883 /* Set or Reset the CC2NP Bit */ 01884 tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC2NP); 01885 tmpccer |= (uint16_t)(TIM_OCNPolarity << 4); 01886 /* Write to TIMx CCER register */ 01887 TIMx->CCER = tmpccer; 01888 } 01889 01899 void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity) 01900 { 01901 uint16_t tmpccer = 0; 01902 /* Check the parameters */ 01903 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01904 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity)); 01905 tmpccer = TIMx->CCER; 01906 /* Set or Reset the CC3P Bit */ 01907 tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC3P); 01908 tmpccer |= (uint16_t)(TIM_OCPolarity << 8); 01909 /* Write to TIMx CCER register */ 01910 TIMx->CCER = tmpccer; 01911 } 01912 01922 void TIM_OC3NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity) 01923 { 01924 uint16_t tmpccer = 0; 01925 01926 /* Check the parameters */ 01927 assert_param(IS_TIM_LIST1_PERIPH(TIMx)); 01928 assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity)); 01929 01930 tmpccer = TIMx->CCER; 01931 /* Set or Reset the CC3NP Bit */ 01932 tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC3NP); 01933 tmpccer |= (uint16_t)(TIM_OCNPolarity << 8); 01934 /* Write to TIMx CCER register */ 01935 TIMx->CCER = tmpccer; 01936 } 01937 01947 void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity) 01948 { 01949 uint16_t tmpccer = 0; 01950 /* Check the parameters */ 01951 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 01952 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity)); 01953 tmpccer = TIMx->CCER; 01954 /* Set or Reset the CC4P Bit */ 01955 tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC4P); 01956 tmpccer |= (uint16_t)(TIM_OCPolarity << 12); 01957 /* Write to TIMx CCER register */ 01958 TIMx->CCER = tmpccer; 01959 } 01960 01974 void TIM_CCxCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCx) 01975 { 01976 uint16_t tmp = 0; 01977 01978 /* Check the parameters */ 01979 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 01980 assert_param(IS_TIM_CHANNEL(TIM_Channel)); 01981 assert_param(IS_TIM_CCX(TIM_CCx)); 01982 01983 tmp = CCER_CCE_Set << TIM_Channel; 01984 01985 /* Reset the CCxE Bit */ 01986 TIMx->CCER &= (uint16_t)~ tmp; 01987 01988 /* Set or reset the CCxE Bit */ 01989 TIMx->CCER |= (uint16_t)(TIM_CCx << TIM_Channel); 01990 } 01991 02004 void TIM_CCxNCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCxN) 02005 { 02006 uint16_t tmp = 0; 02007 02008 /* Check the parameters */ 02009 assert_param(IS_TIM_LIST2_PERIPH(TIMx)); 02010 assert_param(IS_TIM_COMPLEMENTARY_CHANNEL(TIM_Channel)); 02011 assert_param(IS_TIM_CCXN(TIM_CCxN)); 02012 02013 tmp = CCER_CCNE_Set << TIM_Channel; 02014 02015 /* Reset the CCxNE Bit */ 02016 TIMx->CCER &= (uint16_t) ~tmp; 02017 02018 /* Set or reset the CCxNE Bit */ 02019 TIMx->CCER |= (uint16_t)(TIM_CCxN << TIM_Channel); 02020 } 02021 02045 void TIM_SelectOCxM(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode) 02046 { 02047 uint32_t tmp = 0; 02048 uint16_t tmp1 = 0; 02049 02050 /* Check the parameters */ 02051 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 02052 assert_param(IS_TIM_CHANNEL(TIM_Channel)); 02053 assert_param(IS_TIM_OCM(TIM_OCMode)); 02054 02055 tmp = (uint32_t) TIMx; 02056 tmp += CCMR_Offset; 02057 02058 tmp1 = CCER_CCE_Set << (uint16_t)TIM_Channel; 02059 02060 /* Disable the Channel: Reset the CCxE Bit */ 02061 TIMx->CCER &= (uint16_t) ~tmp1; 02062 02063 if((TIM_Channel == TIM_Channel_1) ||(TIM_Channel == TIM_Channel_3)) 02064 { 02065 tmp += (TIM_Channel>>1); 02066 02067 /* Reset the OCxM bits in the CCMRx register */ 02068 *(__IO uint32_t *) tmp &= (uint32_t)~((uint32_t)TIM_CCMR1_OC1M); 02069 02070 /* Configure the OCxM bits in the CCMRx register */ 02071 *(__IO uint32_t *) tmp |= TIM_OCMode; 02072 } 02073 else 02074 { 02075 tmp += (uint16_t)(TIM_Channel - (uint16_t)4)>> (uint16_t)1; 02076 02077 /* Reset the OCxM bits in the CCMRx register */ 02078 *(__IO uint32_t *) tmp &= (uint32_t)~((uint32_t)TIM_CCMR1_OC2M); 02079 02080 /* Configure the OCxM bits in the CCMRx register */ 02081 *(__IO uint32_t *) tmp |= (uint16_t)(TIM_OCMode << 8); 02082 } 02083 } 02084 02092 void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState NewState) 02093 { 02094 /* Check the parameters */ 02095 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02096 assert_param(IS_FUNCTIONAL_STATE(NewState)); 02097 if (NewState != DISABLE) 02098 { 02099 /* Set the Update Disable Bit */ 02100 TIMx->CR1 |= TIM_CR1_UDIS; 02101 } 02102 else 02103 { 02104 /* Reset the Update Disable Bit */ 02105 TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_UDIS); 02106 } 02107 } 02108 02120 void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, uint16_t TIM_UpdateSource) 02121 { 02122 /* Check the parameters */ 02123 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02124 assert_param(IS_TIM_UPDATE_SOURCE(TIM_UpdateSource)); 02125 if (TIM_UpdateSource != TIM_UpdateSource_Global) 02126 { 02127 /* Set the URS Bit */ 02128 TIMx->CR1 |= TIM_CR1_URS; 02129 } 02130 else 02131 { 02132 /* Reset the URS Bit */ 02133 TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_URS); 02134 } 02135 } 02136 02144 void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState NewState) 02145 { 02146 /* Check the parameters */ 02147 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 02148 assert_param(IS_FUNCTIONAL_STATE(NewState)); 02149 if (NewState != DISABLE) 02150 { 02151 /* Set the TI1S Bit */ 02152 TIMx->CR2 |= TIM_CR2_TI1S; 02153 } 02154 else 02155 { 02156 /* Reset the TI1S Bit */ 02157 TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_TI1S); 02158 } 02159 } 02160 02170 void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, uint16_t TIM_OPMode) 02171 { 02172 /* Check the parameters */ 02173 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02174 assert_param(IS_TIM_OPM_MODE(TIM_OPMode)); 02175 /* Reset the OPM Bit */ 02176 TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_OPM); 02177 /* Configure the OPM Mode */ 02178 TIMx->CR1 |= TIM_OPMode; 02179 } 02180 02202 void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource) 02203 { 02204 /* Check the parameters */ 02205 assert_param(IS_TIM_LIST7_PERIPH(TIMx)); 02206 assert_param(IS_TIM_TRGO_SOURCE(TIM_TRGOSource)); 02207 /* Reset the MMS Bits */ 02208 TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_MMS); 02209 /* Select the TRGO source */ 02210 TIMx->CR2 |= TIM_TRGOSource; 02211 } 02212 02225 void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode) 02226 { 02227 /* Check the parameters */ 02228 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 02229 assert_param(IS_TIM_SLAVE_MODE(TIM_SlaveMode)); 02230 /* Reset the SMS Bits */ 02231 TIMx->SMCR &= (uint16_t)~((uint16_t)TIM_SMCR_SMS); 02232 /* Select the Slave Mode */ 02233 TIMx->SMCR |= TIM_SlaveMode; 02234 } 02235 02246 void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_MasterSlaveMode) 02247 { 02248 /* Check the parameters */ 02249 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 02250 assert_param(IS_TIM_MSM_STATE(TIM_MasterSlaveMode)); 02251 /* Reset the MSM Bit */ 02252 TIMx->SMCR &= (uint16_t)~((uint16_t)TIM_SMCR_MSM); 02253 02254 /* Set or Reset the MSM Bit */ 02255 TIMx->SMCR |= TIM_MasterSlaveMode; 02256 } 02257 02264 void TIM_SetCounter(TIM_TypeDef* TIMx, uint16_t Counter) 02265 { 02266 /* Check the parameters */ 02267 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02268 /* Set the Counter Register value */ 02269 TIMx->CNT = Counter; 02270 } 02271 02278 void TIM_SetAutoreload(TIM_TypeDef* TIMx, uint16_t Autoreload) 02279 { 02280 /* Check the parameters */ 02281 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02282 /* Set the Autoreload Register value */ 02283 TIMx->ARR = Autoreload; 02284 } 02285 02292 void TIM_SetCompare1(TIM_TypeDef* TIMx, uint16_t Compare1) 02293 { 02294 /* Check the parameters */ 02295 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 02296 /* Set the Capture Compare1 Register value */ 02297 TIMx->CCR1 = Compare1; 02298 } 02299 02306 void TIM_SetCompare2(TIM_TypeDef* TIMx, uint16_t Compare2) 02307 { 02308 /* Check the parameters */ 02309 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 02310 /* Set the Capture Compare2 Register value */ 02311 TIMx->CCR2 = Compare2; 02312 } 02313 02320 void TIM_SetCompare3(TIM_TypeDef* TIMx, uint16_t Compare3) 02321 { 02322 /* Check the parameters */ 02323 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 02324 /* Set the Capture Compare3 Register value */ 02325 TIMx->CCR3 = Compare3; 02326 } 02327 02334 void TIM_SetCompare4(TIM_TypeDef* TIMx, uint16_t Compare4) 02335 { 02336 /* Check the parameters */ 02337 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 02338 /* Set the Capture Compare4 Register value */ 02339 TIMx->CCR4 = Compare4; 02340 } 02341 02353 void TIM_SetIC1Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC) 02354 { 02355 /* Check the parameters */ 02356 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 02357 assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC)); 02358 /* Reset the IC1PSC Bits */ 02359 TIMx->CCMR1 &= (uint16_t)~((uint16_t)TIM_CCMR1_IC1PSC); 02360 /* Set the IC1PSC value */ 02361 TIMx->CCMR1 |= TIM_ICPSC; 02362 } 02363 02375 void TIM_SetIC2Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC) 02376 { 02377 /* Check the parameters */ 02378 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 02379 assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC)); 02380 /* Reset the IC2PSC Bits */ 02381 TIMx->CCMR1 &= (uint16_t)~((uint16_t)TIM_CCMR1_IC2PSC); 02382 /* Set the IC2PSC value */ 02383 TIMx->CCMR1 |= (uint16_t)(TIM_ICPSC << 8); 02384 } 02385 02397 void TIM_SetIC3Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC) 02398 { 02399 /* Check the parameters */ 02400 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 02401 assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC)); 02402 /* Reset the IC3PSC Bits */ 02403 TIMx->CCMR2 &= (uint16_t)~((uint16_t)TIM_CCMR2_IC3PSC); 02404 /* Set the IC3PSC value */ 02405 TIMx->CCMR2 |= TIM_ICPSC; 02406 } 02407 02419 void TIM_SetIC4Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC) 02420 { 02421 /* Check the parameters */ 02422 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 02423 assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC)); 02424 /* Reset the IC4PSC Bits */ 02425 TIMx->CCMR2 &= (uint16_t)~((uint16_t)TIM_CCMR2_IC4PSC); 02426 /* Set the IC4PSC value */ 02427 TIMx->CCMR2 |= (uint16_t)(TIM_ICPSC << 8); 02428 } 02429 02441 void TIM_SetClockDivision(TIM_TypeDef* TIMx, uint16_t TIM_CKD) 02442 { 02443 /* Check the parameters */ 02444 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 02445 assert_param(IS_TIM_CKD_DIV(TIM_CKD)); 02446 /* Reset the CKD Bits */ 02447 TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_CKD); 02448 /* Set the CKD value */ 02449 TIMx->CR1 |= TIM_CKD; 02450 } 02451 02457 uint16_t TIM_GetCapture1(TIM_TypeDef* TIMx) 02458 { 02459 /* Check the parameters */ 02460 assert_param(IS_TIM_LIST8_PERIPH(TIMx)); 02461 /* Get the Capture 1 Register value */ 02462 return TIMx->CCR1; 02463 } 02464 02470 uint16_t TIM_GetCapture2(TIM_TypeDef* TIMx) 02471 { 02472 /* Check the parameters */ 02473 assert_param(IS_TIM_LIST6_PERIPH(TIMx)); 02474 /* Get the Capture 2 Register value */ 02475 return TIMx->CCR2; 02476 } 02477 02483 uint16_t TIM_GetCapture3(TIM_TypeDef* TIMx) 02484 { 02485 /* Check the parameters */ 02486 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 02487 /* Get the Capture 3 Register value */ 02488 return TIMx->CCR3; 02489 } 02490 02496 uint16_t TIM_GetCapture4(TIM_TypeDef* TIMx) 02497 { 02498 /* Check the parameters */ 02499 assert_param(IS_TIM_LIST3_PERIPH(TIMx)); 02500 /* Get the Capture 4 Register value */ 02501 return TIMx->CCR4; 02502 } 02503 02509 uint16_t TIM_GetCounter(TIM_TypeDef* TIMx) 02510 { 02511 /* Check the parameters */ 02512 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02513 /* Get the Counter Register value */ 02514 return TIMx->CNT; 02515 } 02516 02522 uint16_t TIM_GetPrescaler(TIM_TypeDef* TIMx) 02523 { 02524 /* Check the parameters */ 02525 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02526 /* Get the Prescaler Register value */ 02527 return TIMx->PSC; 02528 } 02529 02556 FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, uint16_t TIM_FLAG) 02557 { 02558 ITStatus bitstatus = RESET; 02559 /* Check the parameters */ 02560 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02561 assert_param(IS_TIM_GET_FLAG(TIM_FLAG)); 02562 02563 if ((TIMx->SR & TIM_FLAG) != (uint16_t)RESET) 02564 { 02565 bitstatus = SET; 02566 } 02567 else 02568 { 02569 bitstatus = RESET; 02570 } 02571 return bitstatus; 02572 } 02573 02600 void TIM_ClearFlag(TIM_TypeDef* TIMx, uint16_t TIM_FLAG) 02601 { 02602 /* Check the parameters */ 02603 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02604 assert_param(IS_TIM_CLEAR_FLAG(TIM_FLAG)); 02605 02606 /* Clear the flags */ 02607 TIMx->SR = (uint16_t)~TIM_FLAG; 02608 } 02609 02632 ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t TIM_IT) 02633 { 02634 ITStatus bitstatus = RESET; 02635 uint16_t itstatus = 0x0, itenable = 0x0; 02636 /* Check the parameters */ 02637 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02638 assert_param(IS_TIM_GET_IT(TIM_IT)); 02639 02640 itstatus = TIMx->SR & TIM_IT; 02641 02642 itenable = TIMx->DIER & TIM_IT; 02643 if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET)) 02644 { 02645 bitstatus = SET; 02646 } 02647 else 02648 { 02649 bitstatus = RESET; 02650 } 02651 return bitstatus; 02652 } 02653 02676 void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, uint16_t TIM_IT) 02677 { 02678 /* Check the parameters */ 02679 assert_param(IS_TIM_ALL_PERIPH(TIMx)); 02680 assert_param(IS_TIM_IT(TIM_IT)); 02681 /* Clear the IT pending Bit */ 02682 TIMx->SR = (uint16_t)~TIM_IT; 02683 } 02684 02701 static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, 02702 uint16_t TIM_ICFilter) 02703 { 02704 uint16_t tmpccmr1 = 0, tmpccer = 0; 02705 /* Disable the Channel 1: Reset the CC1E Bit */ 02706 TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC1E); 02707 tmpccmr1 = TIMx->CCMR1; 02708 tmpccer = TIMx->CCER; 02709 /* Select the Input and set the filter */ 02710 tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC1S)) & ((uint16_t)~((uint16_t)TIM_CCMR1_IC1F))); 02711 tmpccmr1 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4)); 02712 02713 if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) || 02714 (TIMx == TIM4) ||(TIMx == TIM5)) 02715 { 02716 /* Select the Polarity and set the CC1E Bit */ 02717 tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC1P)); 02718 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC1E); 02719 } 02720 else 02721 { 02722 /* Select the Polarity and set the CC1E Bit */ 02723 tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC1P | TIM_CCER_CC1NP)); 02724 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC1E); 02725 } 02726 02727 /* Write to TIMx CCMR1 and CCER registers */ 02728 TIMx->CCMR1 = tmpccmr1; 02729 TIMx->CCER = tmpccer; 02730 } 02731 02748 static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, 02749 uint16_t TIM_ICFilter) 02750 { 02751 uint16_t tmpccmr1 = 0, tmpccer = 0, tmp = 0; 02752 /* Disable the Channel 2: Reset the CC2E Bit */ 02753 TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC2E); 02754 tmpccmr1 = TIMx->CCMR1; 02755 tmpccer = TIMx->CCER; 02756 tmp = (uint16_t)(TIM_ICPolarity << 4); 02757 /* Select the Input and set the filter */ 02758 tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC2S)) & ((uint16_t)~((uint16_t)TIM_CCMR1_IC2F))); 02759 tmpccmr1 |= (uint16_t)(TIM_ICFilter << 12); 02760 tmpccmr1 |= (uint16_t)(TIM_ICSelection << 8); 02761 02762 if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) || 02763 (TIMx == TIM4) ||(TIMx == TIM5)) 02764 { 02765 /* Select the Polarity and set the CC2E Bit */ 02766 tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC2P)); 02767 tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC2E); 02768 } 02769 else 02770 { 02771 /* Select the Polarity and set the CC2E Bit */ 02772 tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC2P | TIM_CCER_CC2NP)); 02773 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC2E); 02774 } 02775 02776 /* Write to TIMx CCMR1 and CCER registers */ 02777 TIMx->CCMR1 = tmpccmr1 ; 02778 TIMx->CCER = tmpccer; 02779 } 02780 02797 static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, 02798 uint16_t TIM_ICFilter) 02799 { 02800 uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0; 02801 /* Disable the Channel 3: Reset the CC3E Bit */ 02802 TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC3E); 02803 tmpccmr2 = TIMx->CCMR2; 02804 tmpccer = TIMx->CCER; 02805 tmp = (uint16_t)(TIM_ICPolarity << 8); 02806 /* Select the Input and set the filter */ 02807 tmpccmr2 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR2_CC3S)) & ((uint16_t)~((uint16_t)TIM_CCMR2_IC3F))); 02808 tmpccmr2 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4)); 02809 02810 if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) || 02811 (TIMx == TIM4) ||(TIMx == TIM5)) 02812 { 02813 /* Select the Polarity and set the CC3E Bit */ 02814 tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC3P)); 02815 tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC3E); 02816 } 02817 else 02818 { 02819 /* Select the Polarity and set the CC3E Bit */ 02820 tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC3P | TIM_CCER_CC3NP)); 02821 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC3E); 02822 } 02823 02824 /* Write to TIMx CCMR2 and CCER registers */ 02825 TIMx->CCMR2 = tmpccmr2; 02826 TIMx->CCER = tmpccer; 02827 } 02828 02845 static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection, 02846 uint16_t TIM_ICFilter) 02847 { 02848 uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0; 02849 02850 /* Disable the Channel 4: Reset the CC4E Bit */ 02851 TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC4E); 02852 tmpccmr2 = TIMx->CCMR2; 02853 tmpccer = TIMx->CCER; 02854 tmp = (uint16_t)(TIM_ICPolarity << 12); 02855 /* Select the Input and set the filter */ 02856 tmpccmr2 &= (uint16_t)((uint16_t)(~(uint16_t)TIM_CCMR2_CC4S) & ((uint16_t)~((uint16_t)TIM_CCMR2_IC4F))); 02857 tmpccmr2 |= (uint16_t)(TIM_ICSelection << 8); 02858 tmpccmr2 |= (uint16_t)(TIM_ICFilter << 12); 02859 02860 if((TIMx == TIM1) || (TIMx == TIM8) || (TIMx == TIM2) || (TIMx == TIM3) || 02861 (TIMx == TIM4) ||(TIMx == TIM5)) 02862 { 02863 /* Select the Polarity and set the CC4E Bit */ 02864 tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC4P)); 02865 tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC4E); 02866 } 02867 else 02868 { 02869 /* Select the Polarity and set the CC4E Bit */ 02870 tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC3P | TIM_CCER_CC4NP)); 02871 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC4E); 02872 } 02873 /* Write to TIMx CCMR2 and CCER registers */ 02874 TIMx->CCMR2 = tmpccmr2; 02875 TIMx->CCER = tmpccer; 02876 } 02877 02890 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/