]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_M0_STM32F0518_IAR/Libraries/STM32F0xx_StdPeriph_Driver/src/stm32f0xx_tim.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / CORTEX_M0_STM32F0518_IAR / Libraries / STM32F0xx_StdPeriph_Driver / src / stm32f0xx_tim.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32f0xx_tim.c\r
4   * @author  MCD Application Team\r
5   * @version V1.0.0RC1\r
6   * @date    27-January-2012\r
7   * @brief   This file provides firmware functions to manage the following \r
8   *          functionalities of the TIM peripheral:\r
9   *            + TimeBase management\r
10   *            + Output Compare management\r
11   *            + Input Capture management\r
12   *            + Interrupts, DMA and flags management\r
13   *            + Clocks management\r
14   *            + Synchronization management\r
15   *            + Specific interface management\r
16   *            + Specific remapping management      \r
17   *              \r
18   *  @verbatim\r
19   \r
20  ===============================================================================\r
21                     ##### How to use this driver #####\r
22  ===============================================================================\r
23     [..] This driver provides functions to configure and program the TIM \r
24          of all STM32F0xx devices These functions are split in 8 groups: \r
25          (#) TIM TimeBase management: this group includes all needed functions \r
26              to configure the TM Timebase unit:\r
27              (++) Set/Get Prescaler.\r
28              (++) Set/Get Autoreload.\r
29              (++) Counter modes configuration.\r
30              (++) Set Clock division.\r
31              (++) Select the One Pulse mode.\r
32              (++) Update Request Configuration.\r
33              (++) Update Disable Configuration.\r
34              (++) Auto-Preload Configuration.\r
35              (++) Enable/Disable the counter.\r
36   \r
37          (#) TIM Output Compare management: this group includes all needed \r
38              functions to configure the Capture/Compare unit used in Output \r
39              compare mode: \r
40              (++) Configure each channel, independently, in Output Compare mode.\r
41              (++) Select the output compare modes.\r
42              (++) Select the Polarities of each channel.\r
43              (++) Set/Get the Capture/Compare register values.\r
44              (++) Select the Output Compare Fast mode. \r
45              (++) Select the Output Compare Forced mode.  \r
46              (++) Output Compare-Preload Configuration. \r
47              (++) Clear Output Compare Reference.\r
48              (++) Select the OCREF Clear signal.\r
49              (++) Enable/Disable the Capture/Compare Channels.    \r
50   \r
51          (#) TIM Input Capture management: this group includes all needed \r
52              functions to configure the Capture/Compare unit used in \r
53              Input Capture mode:\r
54              (++) Configure each channel in input capture mode.\r
55              (++) Configure Channel1/2 in PWM Input mode.\r
56              (++) Set the Input Capture Prescaler.\r
57              (++) Get the Capture/Compare values.  \r
58              \r
59         (#) Advanced-control timers (TIM1) specific features\r
60             (++) Configures the Break input, dead time, Lock level, the OSSI,\r
61                  the OSSR State and the AOE(automatic output enable)\r
62             (++) Enable/Disable the TIM peripheral Main Outputs\r
63             (++) Select the Commutation event\r
64             (++) Set/Reset the Capture Compare Preload Control bit     \r
65   \r
66          (#) TIM interrupts, DMA and flags management.\r
67              (++) Enable/Disable interrupt sources.\r
68              (++) Get flags status.\r
69              (++) Clear flags/ Pending bits.\r
70              (++) Enable/Disable DMA requests. \r
71              (++) Configure DMA burst mode.\r
72              (++) Select CaptureCompare DMA request.  \r
73   \r
74          (#) TIM clocks management: this group includes all needed functions \r
75              to configure the clock controller unit:\r
76              (++) Select internal/External clock.\r
77              (++) Select the external clock mode: ETR(Mode1/Mode2), TIx or ITRx.\r
78   \r
79          (#) TIM synchronization management: this group includes all needed. \r
80              functions to configure the Synchronization unit:\r
81              (++) Select Input Trigger.  \r
82              (++) Select Output Trigger.  \r
83              (++) Select Master Slave Mode. \r
84              (++) ETR Configuration when used as external trigger.   \r
85   \r
86          (#) TIM specific interface management, this group includes all \r
87              needed functions to use the specific TIM interface:\r
88              (++) Encoder Interface Configuration.\r
89              (++) Select Hall Sensor.   \r
90   \r
91          (#) TIM specific remapping management includes the Remapping \r
92              configuration of specific timers\r
93   \r
94 @endverbatim\r
95   *    \r
96   ******************************************************************************\r
97   * @attention\r
98   *\r
99   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS\r
100   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE\r
101   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY\r
102   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING\r
103   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE\r
104   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.\r
105   *\r
106   * FOR MORE INFORMATION PLEASE READ CAREFULLY THE LICENSE AGREEMENT FILE\r
107   * LOCATED IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.\r
108   *\r
109   * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>\r
110   ******************************************************************************\r
111   */\r
112 \r
113 /* Includes ------------------------------------------------------------------*/\r
114 #include "stm32f0xx_tim.h"\r
115 #include "stm32f0xx_rcc.h"\r
116 \r
117 /** @addtogroup STM32F0xx_StdPeriph_Driver\r
118   * @{\r
119   */\r
120 \r
121 /** @defgroup TIM \r
122   * @brief TIM driver modules\r
123   * @{\r
124   */\r
125 \r
126 /* Private typedef -----------------------------------------------------------*/\r
127 /* Private define ------------------------------------------------------------*/\r
128 \r
129 /* ---------------------- TIM registers bit mask ------------------------ */\r
130 #define SMCR_ETR_MASK               ((uint16_t)0x00FF) \r
131 #define CCMR_OFFSET                 ((uint16_t)0x0018)\r
132 #define CCER_CCE_SET                ((uint16_t)0x0001)\r
133 #define CCER_CCNE_SET               ((uint16_t)0x0004) \r
134   \r
135 /* Private macro -------------------------------------------------------------*/\r
136 /* Private variables ---------------------------------------------------------*/\r
137 /* Private function prototypes -----------------------------------------------*/\r
138 \r
139 static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,\r
140                        uint16_t TIM_ICFilter);\r
141 static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,\r
142                        uint16_t TIM_ICFilter);\r
143 static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,\r
144                        uint16_t TIM_ICFilter);\r
145 static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,\r
146                        uint16_t TIM_ICFilter);\r
147 /* Private functions ---------------------------------------------------------*/\r
148 \r
149 /** @defgroup TIM_Private_Functions\r
150   * @{\r
151   */\r
152 \r
153 /** @defgroup TIM_Group1 TimeBase management functions\r
154  *  @brief   TimeBase management functions \r
155  *\r
156 @verbatim\r
157  ===============================================================================\r
158                  ##### TimeBase management functions #####\r
159  ===============================================================================\r
160   \r
161         *** TIM Driver: how to use it in Timing(Time base) Mode ***\r
162  ===============================================================================\r
163     [..] To use the Timer in Timing(Time base) mode, the following steps are \r
164          mandatory:\r
165          (#) Enable TIM clock using \r
166              RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) function.\r
167          (#) Fill the TIM_TimeBaseInitStruct with the desired parameters.\r
168          (#) Call TIM_TimeBaseInit(TIMx, &TIM_TimeBaseInitStruct) to configure \r
169              the Time Base unit with the corresponding configuration.\r
170          (#) Enable the NVIC if you need to generate the update interrupt. \r
171          (#) Enable the corresponding interrupt using the function \r
172              TIM_ITConfig(TIMx, TIM_IT_Update). \r
173          (#) Call the TIM_Cmd(ENABLE) function to enable the TIM counter.\r
174     [..]\r
175         (@) All other functions can be used seperatly to modify, if needed,\r
176             a specific feature of the Timer. \r
177 \r
178 @endverbatim\r
179   * @{\r
180   */\r
181 \r
182 /**\r
183   * @brief  Deinitializes the TIMx peripheral registers to their default reset values.\r
184   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM peripheral.\r
185   * @retval None\r
186   *   \r
187   */\r
188 void TIM_DeInit(TIM_TypeDef* TIMx)\r
189 {\r
190   /* Check the parameters */\r
191   assert_param(IS_TIM_ALL_PERIPH(TIMx)); \r
192 \r
193   if (TIMx == TIM1)\r
194   {\r
195     RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, ENABLE);\r
196     RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, DISABLE);  \r
197   }     \r
198   else if (TIMx == TIM2)\r
199   {\r
200     RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, ENABLE);\r
201     RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);\r
202   }\r
203   else if (TIMx == TIM3)\r
204   {\r
205     RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE);\r
206     RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE);\r
207   }\r
208   else if (TIMx == TIM6)\r
209   {\r
210     RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, ENABLE);\r
211     RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6, DISABLE);\r
212   } \r
213   else if (TIMx == TIM14) \r
214   {       \r
215     RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14, ENABLE);\r
216     RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM14, DISABLE);  \r
217   }        \r
218   else if (TIMx == TIM15)\r
219   {\r
220     RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, ENABLE);\r
221     RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15, DISABLE);\r
222   } \r
223   else if (TIMx == TIM16)\r
224   {\r
225     RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM16, ENABLE);\r
226     RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM16, DISABLE);\r
227   } \r
228   else\r
229   {\r
230     if (TIMx == TIM17)\r
231     {\r
232       RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM17, ENABLE);\r
233       RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM17, DISABLE);\r
234     }  \r
235   }\r
236      \r
237 }\r
238 \r
239 /**\r
240   * @brief  Initializes the TIMx Time Base Unit peripheral according to \r
241   *         the specified parameters in the TIM_TimeBaseInitStruct.\r
242   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM \r
243   *         peripheral.\r
244   * @param  TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef\r
245   *         structure that contains the configuration information for\r
246   *         the specified TIM peripheral.\r
247   * @retval None\r
248   */\r
249 void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)\r
250 {\r
251   uint16_t tmpcr1 = 0;\r
252 \r
253   /* Check the parameters */\r
254   assert_param(IS_TIM_ALL_PERIPH(TIMx)); \r
255   assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode));\r
256   assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision));\r
257 \r
258   tmpcr1 = TIMx->CR1;  \r
259 \r
260   if((TIMx == TIM1) || (TIMx == TIM2) || (TIMx == TIM3))\r
261   {\r
262     /* Select the Counter Mode */\r
263     tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_CR1_DIR | TIM_CR1_CMS)));\r
264     tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_CounterMode;\r
265   }\r
266  \r
267   if(TIMx != TIM6)\r
268   {\r
269     /* Set the clock division */\r
270     tmpcr1 &= (uint16_t)(~((uint16_t)TIM_CR1_CKD));\r
271     tmpcr1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision;\r
272   }\r
273 \r
274   TIMx->CR1 = tmpcr1;\r
275 \r
276   /* Set the Autoreload value */\r
277   TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ;\r
278  \r
279   /* Set the Prescaler value */\r
280   TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler;\r
281     \r
282   if ((TIMx == TIM1) || (TIMx == TIM15)|| (TIMx == TIM16) || (TIMx == TIM17))  \r
283   {\r
284     /* Set the Repetition Counter value */\r
285     TIMx->RCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter;\r
286   }\r
287 \r
288   /* Generate an update event to reload the Prescaler and the Repetition counter\r
289      values immediately */\r
290   TIMx->EGR = TIM_PSCReloadMode_Immediate;           \r
291 }\r
292 \r
293 /**\r
294   * @brief  Fills each TIM_TimeBaseInitStruct member with its default value.\r
295   * @param  TIM_TimeBaseInitStruct : pointer to a TIM_TimeBaseInitTypeDef\r
296   *         structure which will be initialized.\r
297   * @retval None\r
298   */\r
299 void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct)\r
300 {\r
301   /* Set the default configuration */\r
302   TIM_TimeBaseInitStruct->TIM_Period = 0xFFFFFFFF;\r
303   TIM_TimeBaseInitStruct->TIM_Prescaler = 0x0000;\r
304   TIM_TimeBaseInitStruct->TIM_ClockDivision = TIM_CKD_DIV1;\r
305   TIM_TimeBaseInitStruct->TIM_CounterMode = TIM_CounterMode_Up;\r
306   TIM_TimeBaseInitStruct->TIM_RepetitionCounter = 0x0000;\r
307 }\r
308 \r
309 /**\r
310   * @brief  Configures the TIMx Prescaler.\r
311   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM peripheral.\r
312   * @param  Prescaler: specifies the Prescaler Register value\r
313   * @param  TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode\r
314   *   This parameter can be one of the following values:\r
315   *     @arg TIM_PSCReloadMode_Update: The Prescaler is loaded at the update event.\r
316   *     @arg TIM_PSCReloadMode_Immediate: The Prescaler is loaded immediatly.\r
317   * @retval None\r
318   */\r
319 void TIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode)\r
320 {\r
321   /* Check the parameters */\r
322   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
323   assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode));\r
324   \r
325   /* Set the Prescaler value */\r
326   TIMx->PSC = Prescaler;\r
327   /* Set or reset the UG Bit */\r
328   TIMx->EGR = TIM_PSCReloadMode;\r
329 }\r
330 \r
331 /**\r
332   * @brief  Specifies the TIMx Counter Mode to be used.\r
333   * @param  TIMx: where x can be 1, 2, or 3 to select the TIM peripheral.\r
334   * @param  TIM_CounterMode: specifies the Counter Mode to be used\r
335   *   This parameter can be one of the following values:\r
336   *     @arg TIM_CounterMode_Up: TIM Up Counting Mode\r
337   *     @arg TIM_CounterMode_Down: TIM Down Counting Mode\r
338   *     @arg TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1\r
339   *     @arg TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2\r
340   *     @arg TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3\r
341   * @retval None\r
342   */\r
343 void TIM_CounterModeConfig(TIM_TypeDef* TIMx, uint16_t TIM_CounterMode)\r
344 {\r
345   uint16_t tmpcr1 = 0;\r
346   \r
347   /* Check the parameters */\r
348   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
349   assert_param(IS_TIM_COUNTER_MODE(TIM_CounterMode));\r
350   \r
351   tmpcr1 = TIMx->CR1;\r
352   /* Reset the CMS and DIR Bits */\r
353   tmpcr1 &= (uint16_t)(~((uint16_t)(TIM_CR1_DIR | TIM_CR1_CMS)));\r
354   /* Set the Counter Mode */\r
355   tmpcr1 |= TIM_CounterMode;\r
356   /* Write to TIMx CR1 register */\r
357   TIMx->CR1 = tmpcr1;\r
358 }\r
359 \r
360 /**\r
361   * @brief  Sets the TIMx Counter Register value\r
362   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM \r
363   *          peripheral.\r
364   * @param  Counter: specifies the Counter register new value.\r
365   * @retval None\r
366   */\r
367 void TIM_SetCounter(TIM_TypeDef* TIMx, uint32_t Counter)\r
368 {\r
369   /* Check the parameters */\r
370    assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
371    \r
372   /* Set the Counter Register value */\r
373   TIMx->CNT = Counter;\r
374 }\r
375 \r
376 /**\r
377   * @brief  Sets the TIMx Autoreload Register value\r
378   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM peripheral.\r
379   * @param  Autoreload: specifies the Autoreload register new value.\r
380   * @retval None\r
381   */\r
382 void TIM_SetAutoreload(TIM_TypeDef* TIMx, uint32_t Autoreload)\r
383 {\r
384   /* Check the parameters */\r
385   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
386   \r
387   /* Set the Autoreload Register value */\r
388   TIMx->ARR = Autoreload;\r
389 }\r
390 \r
391 /**\r
392   * @brief  Gets the TIMx Counter value.\r
393   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM \r
394   *         peripheral.\r
395   * @retval Counter Register value.\r
396   */\r
397 uint32_t TIM_GetCounter(TIM_TypeDef* TIMx)\r
398 {\r
399   /* Check the parameters */\r
400   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
401   \r
402   /* Get the Counter Register value */\r
403   return TIMx->CNT;\r
404 }\r
405 \r
406 /**\r
407   * @brief  Gets the TIMx Prescaler value.\r
408   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM \r
409   *         peripheral.\r
410   * @retval Prescaler Register value.\r
411   */\r
412 uint16_t TIM_GetPrescaler(TIM_TypeDef* TIMx)\r
413 {\r
414   /* Check the parameters */\r
415   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
416   \r
417   /* Get the Prescaler Register value */\r
418   return TIMx->PSC;\r
419 }\r
420 \r
421 /**\r
422   * @brief  Enables or Disables the TIMx Update event.\r
423   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM \r
424   *         peripheral.\r
425   * @param  NewState: new state of the TIMx UDIS bit\r
426   *   This parameter can be: ENABLE or DISABLE.\r
427   * @retval None\r
428   */\r
429 void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState NewState)\r
430 {\r
431   /* Check the parameters */\r
432   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
433   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
434   \r
435   if (NewState != DISABLE)\r
436   {\r
437     /* Set the Update Disable Bit */\r
438     TIMx->CR1 |= TIM_CR1_UDIS;\r
439   }\r
440   else\r
441   {\r
442     /* Reset the Update Disable Bit */\r
443     TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_UDIS);\r
444   }\r
445 }\r
446 \r
447 /**\r
448   * @brief  Configures the TIMx Update Request Interrupt source.\r
449   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM \r
450   *         peripheral.\r
451   * @param  TIM_UpdateSource: specifies the Update source.\r
452   *   This parameter can be one of the following values:\r
453   *     @arg TIM_UpdateSource_Regular: Source of update is the counter overflow/underflow\r
454                                        or the setting of UG bit, or an update generation\r
455                                        through the slave mode controller.\r
456   *     @arg TIM_UpdateSource_Global: Source of update is counter overflow/underflow.\r
457   * @retval None\r
458   */\r
459 void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, uint16_t TIM_UpdateSource)\r
460 {\r
461   /* Check the parameters */\r
462   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
463   assert_param(IS_TIM_UPDATE_SOURCE(TIM_UpdateSource));\r
464   \r
465   if (TIM_UpdateSource != TIM_UpdateSource_Global)\r
466   {\r
467     /* Set the URS Bit */\r
468     TIMx->CR1 |= TIM_CR1_URS;\r
469   }\r
470   else\r
471   {\r
472     /* Reset the URS Bit */\r
473     TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_URS);\r
474   }\r
475 }\r
476 \r
477 /**\r
478   * @brief  Enables or disables TIMx peripheral Preload register on ARR.\r
479   * @param  TIMx: where x can be  1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM \r
480   *         peripheral.\r
481   * @param  NewState: new state of the TIMx peripheral Preload register\r
482   *   This parameter can be: ENABLE or DISABLE.\r
483   * @retval None\r
484   */\r
485 void TIM_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState NewState)\r
486 {\r
487   /* Check the parameters */\r
488   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
489   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
490   \r
491   if (NewState != DISABLE)\r
492   {\r
493     /* Set the ARR Preload Bit */\r
494     TIMx->CR1 |= TIM_CR1_ARPE;\r
495   }\r
496   else\r
497   {\r
498     /* Reset the ARR Preload Bit */\r
499     TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_ARPE);\r
500   }\r
501 }\r
502 \r
503 /**\r
504   * @brief  Selects the TIMx's One Pulse Mode.\r
505   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17 to select the TIM \r
506   *         peripheral.\r
507   * @param  TIM_OPMode: specifies the OPM Mode to be used.\r
508   *   This parameter can be one of the following values:\r
509   *     @arg TIM_OPMode_Single\r
510   *     @arg TIM_OPMode_Repetitive\r
511   * @retval None\r
512   */\r
513 void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, uint16_t TIM_OPMode)\r
514 {\r
515   /* Check the parameters */\r
516   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
517   assert_param(IS_TIM_OPM_MODE(TIM_OPMode));\r
518   \r
519   /* Reset the OPM Bit */\r
520   TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_OPM);\r
521   /* Configure the OPM Mode */\r
522   TIMx->CR1 |= TIM_OPMode;\r
523 }\r
524 \r
525 /**\r
526   * @brief  Sets the TIMx Clock Division value.\r
527   * @param  TIMx: where x can be  1, 2, 3, 14, 15, 16 and 17 to select the TIM peripheral.\r
528   * @param  TIM_CKD: specifies the clock division value.\r
529   *   This parameter can be one of the following value:\r
530   *     @arg TIM_CKD_DIV1: TDTS = Tck_tim\r
531   *     @arg TIM_CKD_DIV2: TDTS = 2*Tck_tim\r
532   *     @arg TIM_CKD_DIV4: TDTS = 4*Tck_tim\r
533   * @retval None\r
534   */\r
535 void TIM_SetClockDivision(TIM_TypeDef* TIMx, uint16_t TIM_CKD)\r
536 {\r
537   /* Check the parameters */\r
538   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
539   assert_param(IS_TIM_CKD_DIV(TIM_CKD));\r
540   \r
541   /* Reset the CKD Bits */\r
542   TIMx->CR1 &= (uint16_t)~((uint16_t)TIM_CR1_CKD);\r
543   /* Set the CKD value */\r
544   TIMx->CR1 |= TIM_CKD;\r
545 }\r
546 \r
547 /**\r
548   * @brief  Enables or disables the specified TIM peripheral.\r
549   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 and 17to select the TIMx\r
550   *         peripheral.\r
551   * @param  NewState: new state of the TIMx peripheral.\r
552   *         This parameter can be: ENABLE or DISABLE.\r
553   * @retval None\r
554   */\r
555 void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)\r
556 {\r
557   /* Check the parameters */\r
558   assert_param(IS_TIM_ALL_PERIPH(TIMx)); \r
559   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
560   \r
561   if (NewState != DISABLE)\r
562   {\r
563     /* Enable the TIM Counter */\r
564     TIMx->CR1 |= TIM_CR1_CEN;\r
565   }\r
566   else\r
567   {\r
568     /* Disable the TIM Counter */\r
569     TIMx->CR1 &= (uint16_t)(~((uint16_t)TIM_CR1_CEN));\r
570   }\r
571 }\r
572 \r
573 /**\r
574   * @}\r
575   */\r
576 \r
577 /** @defgroup TIM_Group2 Advanced-control timers (TIM1) specific features\r
578  *  @brief   Advanced-control timers (TIM1) specific features\r
579  *\r
580 @verbatim   \r
581  ===============================================================================\r
582       ##### Advanced-control timers (TIM1) specific features #####\r
583  ===============================================================================  \r
584   \r
585        ===================================================================      \r
586               *** TIM Driver: how to use the Break feature ***\r
587        =================================================================== \r
588        [..] After configuring the Timer channel(s) in the appropriate Output Compare mode: \r
589                          \r
590            (#) Fill the TIM_BDTRInitStruct with the desired parameters for the Timer\r
591                Break Polarity, dead time, Lock level, the OSSI/OSSR State and the \r
592                AOE(automatic output enable).\r
593                \r
594            (#) Call TIM_BDTRConfig(TIMx, &TIM_BDTRInitStruct) to configure the Timer\r
595           \r
596            (#) Enable the Main Output using TIM_CtrlPWMOutputs(TIM1, ENABLE) \r
597           \r
598            (#) Once the break even occurs, the Timer's output signals are put in reset\r
599                state or in a known state (according to the configuration made in\r
600                TIM_BDTRConfig() function).\r
601 \r
602 @endverbatim\r
603   * @{\r
604   */\r
605 /**\r
606   * @brief  Configures the: Break feature, dead time, Lock level, the OSSI,\r
607   *   the OSSR State and the AOE(automatic output enable).\r
608   * @param  TIMx: where x can be  1, 15, 16 or 17 to select the TIM \r
609   * @param  TIM_BDTRInitStruct: pointer to a TIM_BDTRInitTypeDef structure that\r
610   *   contains the BDTR Register configuration  information for the TIM peripheral.\r
611   * @retval None\r
612   */\r
613 void TIM_BDTRConfig(TIM_TypeDef* TIMx, TIM_BDTRInitTypeDef *TIM_BDTRInitStruct)\r
614 {\r
615   /* Check the parameters */\r
616   assert_param(IS_TIM_LIST2_PERIPH(TIMx));\r
617   assert_param(IS_TIM_OSSR_STATE(TIM_BDTRInitStruct->TIM_OSSRState));\r
618   assert_param(IS_TIM_OSSI_STATE(TIM_BDTRInitStruct->TIM_OSSIState));\r
619   assert_param(IS_TIM_LOCK_LEVEL(TIM_BDTRInitStruct->TIM_LOCKLevel));\r
620   assert_param(IS_TIM_BREAK_STATE(TIM_BDTRInitStruct->TIM_Break));\r
621   assert_param(IS_TIM_BREAK_POLARITY(TIM_BDTRInitStruct->TIM_BreakPolarity));\r
622   assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(TIM_BDTRInitStruct->TIM_AutomaticOutput));\r
623   /* Set the Lock level, the Break enable Bit and the Ploarity, the OSSR State,\r
624      the OSSI State, the dead time value and the Automatic Output Enable Bit */\r
625   TIMx->BDTR |= (uint32_t)TIM_BDTRInitStruct->TIM_OSSRState | TIM_BDTRInitStruct->TIM_OSSIState |\r
626              TIM_BDTRInitStruct->TIM_LOCKLevel | TIM_BDTRInitStruct->TIM_DeadTime |\r
627              TIM_BDTRInitStruct->TIM_Break | TIM_BDTRInitStruct->TIM_BreakPolarity |\r
628              TIM_BDTRInitStruct->TIM_AutomaticOutput;\r
629 }\r
630 \r
631 /**\r
632   * @brief  Fills each TIM_BDTRInitStruct member with its default value.\r
633   * @param  TIM_BDTRInitStruct: pointer to a TIM_BDTRInitTypeDef structure which\r
634   *   will be initialized.\r
635   * @retval None\r
636   */\r
637 void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* TIM_BDTRInitStruct)\r
638 {\r
639   /* Set the default configuration */\r
640   TIM_BDTRInitStruct->TIM_OSSRState = TIM_OSSRState_Disable;\r
641   TIM_BDTRInitStruct->TIM_OSSIState = TIM_OSSIState_Disable;\r
642   TIM_BDTRInitStruct->TIM_LOCKLevel = TIM_LOCKLevel_OFF;\r
643   TIM_BDTRInitStruct->TIM_DeadTime = 0x00;\r
644   TIM_BDTRInitStruct->TIM_Break = TIM_Break_Disable;\r
645   TIM_BDTRInitStruct->TIM_BreakPolarity = TIM_BreakPolarity_Low;\r
646   TIM_BDTRInitStruct->TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;\r
647 }\r
648 \r
649 /**\r
650   * @brief  Enables or disables the TIM peripheral Main Outputs.\r
651   * @param  TIMx: where x can be 1, 15, 16 or 17 to select the TIMx peripheral.\r
652   * @param  NewState: new state of the TIM peripheral Main Outputs.\r
653   *   This parameter can be: ENABLE or DISABLE.\r
654   * @retval None\r
655   */\r
656 void TIM_CtrlPWMOutputs(TIM_TypeDef* TIMx, FunctionalState NewState)\r
657 {\r
658   /* Check the parameters */\r
659   assert_param(IS_TIM_LIST2_PERIPH(TIMx));\r
660   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
661   if (NewState != DISABLE)\r
662   {\r
663     /* Enable the TIM Main Output */\r
664     TIMx->BDTR |= TIM_BDTR_MOE;\r
665   }\r
666   else\r
667   {\r
668     /* Disable the TIM Main Output */\r
669     TIMx->BDTR &= (uint16_t)(~((uint16_t)TIM_BDTR_MOE));\r
670   }  \r
671 }\r
672 \r
673 /**\r
674   * @}\r
675   */\r
676 \r
677 /** @defgroup TIM_Group3 Output Compare management functions\r
678  *  @brief    Output Compare management functions \r
679  *\r
680 @verbatim\r
681  ===============================================================================\r
682                 ##### Output Compare management functions #####\r
683  ===============================================================================\r
684         *** TIM Driver: how to use it in Output Compare Mode ***\r
685  ===============================================================================\r
686     [..] To use the Timer in Output Compare mode, the following steps are mandatory:\r
687          (#) Enable TIM clock using \r
688              RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) function.\r
689          (#) Configure the TIM pins by configuring the corresponding GPIO pins\r
690          (#) Configure the Time base unit as described in the first part of this \r
691              driver, if needed, else the Timer will run with the default \r
692              configuration:\r
693              (++) Autoreload value = 0xFFFF.\r
694              (++) Prescaler value = 0x0000.\r
695              (++) Counter mode = Up counting.\r
696              (++) Clock Division = TIM_CKD_DIV1.\r
697          (#) Fill the TIM_OCInitStruct with the desired parameters including:\r
698              (++) The TIM Output Compare mode: TIM_OCMode.\r
699              (++) TIM Output State: TIM_OutputState.\r
700              (++) TIM Pulse value: TIM_Pulse.\r
701              (++) TIM Output Compare Polarity : TIM_OCPolarity.\r
702          (#) Call TIM_OCxInit(TIMx, &TIM_OCInitStruct) to configure the desired \r
703              channel with the corresponding configuration.\r
704          (#) Call the TIM_Cmd(ENABLE) function to enable the TIM counter.\r
705     [..]\r
706         (@) All other functions can be used separately to modify, if needed,\r
707           a specific feature of the Timer.\r
708         (@) In case of PWM mode, this function is mandatory:\r
709             TIM_OCxPreloadConfig(TIMx, TIM_OCPreload_ENABLE).\r
710         (@) If the corresponding interrupt or DMA request are needed, the user should:\r
711             (#@) Enable the NVIC (or the DMA) to use the TIM interrupts (or DMA requests).\r
712             (#@) Enable the corresponding interrupt (or DMA request) using the function\r
713                  TIM_ITConfig(TIMx, TIM_IT_CCx) (or TIM_DMA_Cmd(TIMx, TIM_DMA_CCx)).\r
714 \r
715 @endverbatim\r
716   * @{\r
717   */\r
718 \r
719 /**\r
720   * @brief  Initializes the TIMx Channel1 according to the specified\r
721   *         parameters in the TIM_OCInitStruct.\r
722   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 and 17 to select the TIM peripheral.\r
723   * @param  TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure\r
724   *         that contains the configuration information for the specified TIM \r
725   *         peripheral.\r
726   * @retval None\r
727   */\r
728 void TIM_OC1Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)\r
729 {\r
730   uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;\r
731    \r
732   /* Check the parameters */\r
733   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
734   assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));\r
735   assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));\r
736   assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));   \r
737  /* Disable the Channel 1: Reset the CC1E Bit */\r
738   TIMx->CCER &= (uint16_t)(~(uint16_t)TIM_CCER_CC1E);\r
739   /* Get the TIMx CCER register value */\r
740   tmpccer = TIMx->CCER;\r
741   /* Get the TIMx CR2 register value */\r
742   tmpcr2 =  TIMx->CR2;\r
743   \r
744   /* Get the TIMx CCMR1 register value */\r
745   tmpccmrx = TIMx->CCMR1;\r
746     \r
747   /* Reset the Output Compare Mode Bits */\r
748   tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_OC1M));\r
749   tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_CC1S));\r
750 \r
751   /* Select the Output Compare Mode */\r
752   tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;\r
753   \r
754   /* Reset the Output Polarity level */\r
755   tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1P));\r
756   /* Set the Output Compare Polarity */\r
757   tmpccer |= TIM_OCInitStruct->TIM_OCPolarity;\r
758   \r
759   /* Set the Output State */\r
760   tmpccer |= TIM_OCInitStruct->TIM_OutputState;\r
761     \r
762   if((TIMx == TIM1) || (TIMx == TIM15) || (TIMx == TIM16) || (TIMx == TIM17))\r
763   {\r
764     assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));\r
765     assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));\r
766     assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));\r
767     assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));\r
768     \r
769     /* Reset the Output N Polarity level */\r
770     tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1NP));\r
771     /* Set the Output N Polarity */\r
772     tmpccer |= TIM_OCInitStruct->TIM_OCNPolarity;\r
773     \r
774     /* Reset the Output N State */\r
775     tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC1NE));    \r
776     /* Set the Output N State */\r
777     tmpccer |= TIM_OCInitStruct->TIM_OutputNState;\r
778     \r
779     /* Reset the Ouput Compare and Output Compare N IDLE State */\r
780     tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS1));\r
781     tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS1N));\r
782     \r
783     /* Set the Output Idle state */\r
784     tmpcr2 |= TIM_OCInitStruct->TIM_OCIdleState;\r
785     /* Set the Output N Idle state */\r
786     tmpcr2 |= TIM_OCInitStruct->TIM_OCNIdleState;\r
787   }\r
788   /* Write to TIMx CR2 */\r
789   TIMx->CR2 = tmpcr2;\r
790   \r
791   /* Write to TIMx CCMR1 */\r
792   TIMx->CCMR1 = tmpccmrx;\r
793 \r
794   /* Set the Capture Compare Register value */\r
795   TIMx->CCR1 = TIM_OCInitStruct->TIM_Pulse; \r
796  \r
797   /* Write to TIMx CCER */\r
798   TIMx->CCER = tmpccer;\r
799 }\r
800 \r
801 /**\r
802   * @brief  Initializes the TIMx Channel2 according to the specified\r
803   *         parameters in the TIM_OCInitStruct.\r
804   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
805   * @param  TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure\r
806   *         that contains the configuration information for the specified TIM \r
807   *         peripheral.\r
808   * @retval None\r
809   */\r
810 void TIM_OC2Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)\r
811 {\r
812   uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;\r
813    \r
814   /* Check the parameters */\r
815   assert_param(IS_TIM_LIST6_PERIPH(TIMx)); \r
816   assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));\r
817   assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));\r
818   assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));   \r
819    /* Disable the Channel 2: Reset the CC2E Bit */\r
820   TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC2E));\r
821   \r
822   /* Get the TIMx CCER register value */  \r
823   tmpccer = TIMx->CCER;\r
824   /* Get the TIMx CR2 register value */\r
825   tmpcr2 =  TIMx->CR2;\r
826   \r
827   /* Get the TIMx CCMR1 register value */\r
828   tmpccmrx = TIMx->CCMR1;\r
829     \r
830   /* Reset the Output Compare mode and Capture/Compare selection Bits */\r
831   tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_OC2M));\r
832   tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR1_CC2S));\r
833   \r
834   /* Select the Output Compare Mode */\r
835   tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8);\r
836   \r
837   /* Reset the Output Polarity level */\r
838   tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2P));\r
839   /* Set the Output Compare Polarity */\r
840   tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 4);\r
841   \r
842   /* Set the Output State */\r
843   tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 4);\r
844     \r
845   if(TIMx == TIM1)\r
846   {\r
847     assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));\r
848     assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));\r
849     assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));\r
850     assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));\r
851     \r
852     /* Reset the Output N Polarity level */\r
853     tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2NP));\r
854     /* Set the Output N Polarity */\r
855     tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 4);\r
856     \r
857     /* Reset the Output N State */\r
858     tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC2NE));    \r
859     /* Set the Output N State */\r
860     tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 4);\r
861     \r
862     /* Reset the Ouput Compare and Output Compare N IDLE State */\r
863     tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS2));\r
864     tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS2N));\r
865     \r
866     /* Set the Output Idle state */\r
867     tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 2);\r
868     /* Set the Output N Idle state */\r
869     tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCNIdleState << 2);\r
870   }\r
871   /* Write to TIMx CR2 */\r
872   TIMx->CR2 = tmpcr2;\r
873   \r
874   /* Write to TIMx CCMR1 */\r
875   TIMx->CCMR1 = tmpccmrx;\r
876 \r
877   /* Set the Capture Compare Register value */\r
878   TIMx->CCR2 = TIM_OCInitStruct->TIM_Pulse;\r
879   \r
880   /* Write to TIMx CCER */\r
881   TIMx->CCER = tmpccer;\r
882 }\r
883 \r
884 /**\r
885   * @brief  Initializes the TIMx Channel3 according to the specified\r
886   *         parameters in the TIM_OCInitStruct.\r
887   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
888   * @param  TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure\r
889   *         that contains the configuration information for the specified TIM \r
890   *         peripheral.\r
891   * @retval None\r
892   */\r
893 void TIM_OC3Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)\r
894 {\r
895   uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;\r
896    \r
897   /* Check the parameters */\r
898   assert_param(IS_TIM_LIST3_PERIPH(TIMx)); \r
899   assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));\r
900   assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));\r
901   assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));   \r
902   /* Disable the Channel 2: Reset the CC2E Bit */\r
903   TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC3E));\r
904   \r
905   /* Get the TIMx CCER register value */\r
906   tmpccer = TIMx->CCER;\r
907   /* Get the TIMx CR2 register value */\r
908   tmpcr2 =  TIMx->CR2;\r
909   \r
910   /* Get the TIMx CCMR2 register value */\r
911   tmpccmrx = TIMx->CCMR2;\r
912     \r
913   /* Reset the Output Compare mode and Capture/Compare selection Bits */\r
914   tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_OC3M));\r
915   tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_CC3S));  \r
916   /* Select the Output Compare Mode */\r
917   tmpccmrx |= TIM_OCInitStruct->TIM_OCMode;\r
918   \r
919   /* Reset the Output Polarity level */\r
920   tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3P));\r
921   /* Set the Output Compare Polarity */\r
922   tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 8);\r
923   \r
924   /* Set the Output State */\r
925   tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 8);\r
926     \r
927   if(TIMx == TIM1)\r
928   {\r
929     assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct->TIM_OutputNState));\r
930     assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct->TIM_OCNPolarity));\r
931     assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct->TIM_OCNIdleState));\r
932     assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));\r
933     \r
934     /* Reset the Output N Polarity level */\r
935     tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3NP));\r
936     /* Set the Output N Polarity */\r
937     tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCNPolarity << 8);\r
938     /* Reset the Output N State */\r
939     tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC3NE));\r
940     \r
941     /* Set the Output N State */\r
942     tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputNState << 8);\r
943     /* Reset the Ouput Compare and Output Compare N IDLE State */\r
944     tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS3));\r
945     tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS3N));\r
946     /* Set the Output Idle state */\r
947     tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 4);\r
948     /* Set the Output N Idle state */\r
949     tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCNIdleState << 4);\r
950   }\r
951   /* Write to TIMx CR2 */\r
952   TIMx->CR2 = tmpcr2;\r
953   \r
954   /* Write to TIMx CCMR2 */\r
955   TIMx->CCMR2 = tmpccmrx;\r
956 \r
957   /* Set the Capture Compare Register value */\r
958   TIMx->CCR3 = TIM_OCInitStruct->TIM_Pulse;\r
959   \r
960   /* Write to TIMx CCER */\r
961   TIMx->CCER = tmpccer;\r
962 }\r
963 \r
964 /**\r
965   * @brief  Initializes the TIMx Channel4 according to the specified\r
966   *         parameters in the TIM_OCInitStruct.\r
967   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
968   * @param  TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure\r
969   *         that contains the configuration information for the specified TIM \r
970   *         peripheral.\r
971   * @retval None\r
972   */\r
973 void TIM_OC4Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)\r
974 {\r
975   uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;\r
976    \r
977   /* Check the parameters */\r
978   assert_param(IS_TIM_LIST3_PERIPH(TIMx)); \r
979   assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct->TIM_OCMode));\r
980   assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct->TIM_OutputState));\r
981   assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct->TIM_OCPolarity));   \r
982   /* Disable the Channel 2: Reset the CC4E Bit */\r
983   TIMx->CCER &= (uint16_t)(~((uint16_t)TIM_CCER_CC4E));\r
984   \r
985   /* Get the TIMx CCER register value */\r
986   tmpccer = TIMx->CCER;\r
987   /* Get the TIMx CR2 register value */\r
988   tmpcr2 =  TIMx->CR2;\r
989   \r
990   /* Get the TIMx CCMR2 register value */\r
991   tmpccmrx = TIMx->CCMR2;\r
992     \r
993   /* Reset the Output Compare mode and Capture/Compare selection Bits */\r
994   tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_OC4M));\r
995   tmpccmrx &= (uint16_t)(~((uint16_t)TIM_CCMR2_CC4S));\r
996   \r
997   /* Select the Output Compare Mode */\r
998   tmpccmrx |= (uint16_t)(TIM_OCInitStruct->TIM_OCMode << 8);\r
999   \r
1000   /* Reset the Output Polarity level */\r
1001   tmpccer &= (uint16_t)(~((uint16_t)TIM_CCER_CC4P));\r
1002   /* Set the Output Compare Polarity */\r
1003   tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OCPolarity << 12);\r
1004   \r
1005   /* Set the Output State */\r
1006   tmpccer |= (uint16_t)(TIM_OCInitStruct->TIM_OutputState << 12);\r
1007     \r
1008   if(TIMx == TIM1)\r
1009   {\r
1010     assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct->TIM_OCIdleState));\r
1011     /* Reset the Ouput Compare IDLE State */\r
1012     tmpcr2 &= (uint16_t)(~((uint16_t)TIM_CR2_OIS4));\r
1013     /* Set the Output Idle state */\r
1014     tmpcr2 |= (uint16_t)(TIM_OCInitStruct->TIM_OCIdleState << 6);\r
1015   }\r
1016   /* Write to TIMx CR2 */\r
1017   TIMx->CR2 = tmpcr2;\r
1018   \r
1019   /* Write to TIMx CCMR2 */  \r
1020   TIMx->CCMR2 = tmpccmrx;\r
1021 \r
1022   /* Set the Capture Compare Register value */\r
1023   TIMx->CCR4 = TIM_OCInitStruct->TIM_Pulse;\r
1024   \r
1025   /* Write to TIMx CCER */\r
1026   TIMx->CCER = tmpccer;\r
1027 }\r
1028 \r
1029 /**\r
1030   * @brief  Fills each TIM_OCInitStruct member with its default value.\r
1031   * @param  TIM_OCInitStruct : pointer to a TIM_OCInitTypeDef structure which will\r
1032   *         be initialized.\r
1033   * @retval None\r
1034   */\r
1035 void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct)\r
1036 {\r
1037   /* Set the default configuration */\r
1038   TIM_OCInitStruct->TIM_OCMode = TIM_OCMode_Timing;\r
1039   TIM_OCInitStruct->TIM_OutputState = TIM_OutputState_Disable;\r
1040   TIM_OCInitStruct->TIM_OutputNState = TIM_OutputNState_Disable;\r
1041   TIM_OCInitStruct->TIM_Pulse = 0x0000000;\r
1042   TIM_OCInitStruct->TIM_OCPolarity = TIM_OCPolarity_High;\r
1043   TIM_OCInitStruct->TIM_OCNPolarity = TIM_OCPolarity_High;\r
1044   TIM_OCInitStruct->TIM_OCIdleState = TIM_OCIdleState_Reset;\r
1045   TIM_OCInitStruct->TIM_OCNIdleState = TIM_OCNIdleState_Reset;\r
1046 }\r
1047 \r
1048 /**\r
1049   * @brief  Selects the TIM Output Compare Mode.\r
1050   * @note   This function disables the selected channel before changing the Output\r
1051   *         Compare Mode.\r
1052   *         User has to enable this channel using TIM_CCxCmd and TIM_CCxNCmd functions.\r
1053   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
1054   * @param  TIM_Channel: specifies the TIM Channel\r
1055   *   This parameter can be one of the following values:\r
1056   *     @arg TIM_Channel_1: TIM Channel 1\r
1057   *     @arg TIM_Channel_2: TIM Channel 2\r
1058   *     @arg TIM_Channel_3: TIM Channel 3\r
1059   *     @arg TIM_Channel_4: TIM Channel 4\r
1060   * @param  TIM_OCMode: specifies the TIM Output Compare Mode.\r
1061   *   This parameter can be one of the following values:\r
1062   *     @arg TIM_OCMode_Timing\r
1063   *     @arg TIM_OCMode_Active\r
1064   *     @arg TIM_OCMode_Toggle\r
1065   *     @arg TIM_OCMode_PWM1\r
1066   *     @arg TIM_OCMode_PWM2\r
1067   *     @arg TIM_ForcedAction_Active\r
1068   *     @arg TIM_ForcedAction_InActive\r
1069   * @retval None\r
1070   */\r
1071 void TIM_SelectOCxM(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode)\r
1072 {\r
1073   uint32_t tmp = 0;\r
1074   uint16_t tmp1 = 0;\r
1075 \r
1076   /* Check the parameters */\r
1077   assert_param(IS_TIM_LIST4_PERIPH(TIMx));  \r
1078   assert_param(IS_TIM_OCM(TIM_OCMode));\r
1079   \r
1080   tmp = (uint32_t) TIMx;\r
1081   tmp += CCMR_OFFSET;\r
1082 \r
1083   tmp1 = CCER_CCE_SET << (uint16_t)TIM_Channel;\r
1084 \r
1085   /* Disable the Channel: Reset the CCxE Bit */\r
1086   TIMx->CCER &= (uint16_t) ~tmp1;\r
1087 \r
1088   if((TIM_Channel == TIM_Channel_1) ||(TIM_Channel == TIM_Channel_3))\r
1089   {\r
1090     tmp += (TIM_Channel>>1);\r
1091 \r
1092     /* Reset the OCxM bits in the CCMRx register */\r
1093     *(__IO uint32_t *) tmp &= (uint32_t)~((uint32_t)TIM_CCMR1_OC1M);\r
1094    \r
1095     /* Configure the OCxM bits in the CCMRx register */\r
1096     *(__IO uint32_t *) tmp |= TIM_OCMode;\r
1097   }\r
1098   else\r
1099   {\r
1100     tmp += (uint16_t)(TIM_Channel - (uint16_t)4)>> (uint16_t)1;\r
1101 \r
1102     /* Reset the OCxM bits in the CCMRx register */\r
1103     *(__IO uint32_t *) tmp &= (uint32_t)~((uint32_t)TIM_CCMR1_OC2M);\r
1104     \r
1105     /* Configure the OCxM bits in the CCMRx register */\r
1106     *(__IO uint32_t *) tmp |= (uint16_t)(TIM_OCMode << 8);\r
1107   }\r
1108 }\r
1109 \r
1110 /**\r
1111   * @brief  Sets the TIMx Capture Compare1 Register value\r
1112   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
1113   * @param  Compare1: specifies the Capture Compare1 register new value.\r
1114   * @retval None\r
1115   */\r
1116 void TIM_SetCompare1(TIM_TypeDef* TIMx, uint32_t Compare1)\r
1117 {\r
1118   /* Check the parameters */\r
1119   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
1120   \r
1121   /* Set the Capture Compare1 Register value */\r
1122   TIMx->CCR1 = Compare1;\r
1123 }\r
1124 \r
1125 /**\r
1126   * @brief  Sets the TIMx Capture Compare2 Register value\r
1127   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
1128   * @param  Compare2: specifies the Capture Compare2 register new value.\r
1129   * @retval None\r
1130   */\r
1131 void TIM_SetCompare2(TIM_TypeDef* TIMx, uint32_t Compare2)\r
1132 {\r
1133   /* Check the parameters */\r
1134   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
1135   \r
1136   /* Set the Capture Compare2 Register value */\r
1137   TIMx->CCR2 = Compare2;\r
1138 }\r
1139 \r
1140 /**\r
1141   * @brief  Sets the TIMx Capture Compare3 Register value\r
1142   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1143   * @param  Compare3: specifies the Capture Compare3 register new value.\r
1144   * @retval None\r
1145   */\r
1146 void TIM_SetCompare3(TIM_TypeDef* TIMx, uint32_t Compare3)\r
1147 {\r
1148   /* Check the parameters */\r
1149   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1150   \r
1151   /* Set the Capture Compare3 Register value */\r
1152   TIMx->CCR3 = Compare3;\r
1153 }\r
1154 \r
1155 /**\r
1156   * @brief  Sets the TIMx Capture Compare4 Register value\r
1157   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1158   * @param  Compare4: specifies the Capture Compare4 register new value.\r
1159   * @retval None\r
1160   */\r
1161 void TIM_SetCompare4(TIM_TypeDef* TIMx, uint32_t Compare4)\r
1162 {\r
1163   /* Check the parameters */\r
1164   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1165   \r
1166   /* Set the Capture Compare4 Register value */\r
1167   TIMx->CCR4 = Compare4;\r
1168 }\r
1169 \r
1170 /**\r
1171   * @brief  Forces the TIMx output 1 waveform to active or inactive level.\r
1172   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
1173   * @param  TIM_ForcedAction: specifies the forced Action to be set to the output waveform.\r
1174   *   This parameter can be one of the following values:\r
1175   *     @arg TIM_ForcedAction_Active: Force active level on OC1REF\r
1176   *     @arg TIM_ForcedAction_InActive: Force inactive level on OC1REF.\r
1177   * @retval None\r
1178   */\r
1179 void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)\r
1180 {\r
1181   uint16_t tmpccmr1 = 0;\r
1182   /* Check the parameters */\r
1183   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
1184   assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));\r
1185   tmpccmr1 = TIMx->CCMR1;\r
1186   /* Reset the OC1M Bits */\r
1187   tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1M);\r
1188   /* Configure The Forced output Mode */\r
1189   tmpccmr1 |= TIM_ForcedAction;\r
1190   /* Write to TIMx CCMR1 register */\r
1191   TIMx->CCMR1 = tmpccmr1;\r
1192 }\r
1193  \r
1194 /**\r
1195   * @brief  Forces the TIMx output 2 waveform to active or inactive level.\r
1196   * @param  TIMx: where x can be 1, 2, 3, or 15 to select the TIM \r
1197   *   peripheral.\r
1198   * @param  TIM_ForcedAction: specifies the forced Action to be set to the output waveform.\r
1199   *   This parameter can be one of the following values:\r
1200   *     @arg TIM_ForcedAction_Active: Force active level on OC2REF\r
1201   *     @arg TIM_ForcedAction_InActive: Force inactive level on OC2REF.\r
1202   * @retval None\r
1203   */\r
1204 void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)\r
1205 {\r
1206   uint16_t tmpccmr1 = 0;\r
1207   \r
1208   /* Check the parameters */\r
1209   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
1210   assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));\r
1211   \r
1212   tmpccmr1 = TIMx->CCMR1;\r
1213   /* Reset the OC2M Bits */\r
1214   tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2M);\r
1215   /* Configure The Forced output Mode */\r
1216   tmpccmr1 |= (uint16_t)(TIM_ForcedAction << 8);\r
1217   /* Write to TIMx CCMR1 register */\r
1218   TIMx->CCMR1 = tmpccmr1;\r
1219 }\r
1220 \r
1221 /**\r
1222   * @brief  Forces the TIMx output 3 waveform to active or inactive level.\r
1223   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1224   * @param  TIM_ForcedAction: specifies the forced Action to be set to the output waveform.\r
1225   *   This parameter can be one of the following values:\r
1226   *     @arg TIM_ForcedAction_Active: Force active level on OC3REF\r
1227   *     @arg TIM_ForcedAction_InActive: Force inactive level on OC3REF.\r
1228   * @retval None\r
1229   */\r
1230 void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)\r
1231 {\r
1232   uint16_t tmpccmr2 = 0;\r
1233   \r
1234   /* Check the parameters */\r
1235   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1236   assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));\r
1237   \r
1238   tmpccmr2 = TIMx->CCMR2;\r
1239   /* Reset the OC1M Bits */\r
1240   tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3M);\r
1241   /* Configure The Forced output Mode */\r
1242   tmpccmr2 |= TIM_ForcedAction;\r
1243   /* Write to TIMx CCMR2 register */\r
1244   TIMx->CCMR2 = tmpccmr2;\r
1245 }\r
1246 \r
1247 /**\r
1248   * @brief  Forces the TIMx output 4 waveform to active or inactive level.\r
1249   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1250   * @param  TIM_ForcedAction: specifies the forced Action to be set to the output waveform.\r
1251   *   This parameter can be one of the following values:\r
1252   *     @arg TIM_ForcedAction_Active: Force active level on OC4REF\r
1253   *     @arg TIM_ForcedAction_InActive: Force inactive level on OC4REF.\r
1254   * @retval None\r
1255   */\r
1256 void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction)\r
1257 {\r
1258   uint16_t tmpccmr2 = 0;\r
1259   /* Check the parameters */\r
1260   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1261   assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));\r
1262   \r
1263   tmpccmr2 = TIMx->CCMR2;\r
1264   /* Reset the OC2M Bits */\r
1265   tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4M);\r
1266   /* Configure The Forced output Mode */\r
1267   tmpccmr2 |= (uint16_t)(TIM_ForcedAction << 8);\r
1268   /* Write to TIMx CCMR2 register */\r
1269   TIMx->CCMR2 = tmpccmr2;\r
1270 }\r
1271 \r
1272 /**\r
1273   * @brief  Sets or Resets the TIM peripheral Capture Compare Preload Control bit.\r
1274   * @param  TIMx: where x can be   1, 2, 3 or 15 \r
1275   *         to select the TIMx peripheral\r
1276   * @param  NewState: new state of the Capture Compare Preload Control bit\r
1277   *   This parameter can be: ENABLE or DISABLE.\r
1278   * @retval None\r
1279   */\r
1280 void TIM_CCPreloadControl(TIM_TypeDef* TIMx, FunctionalState NewState)\r
1281\r
1282   /* Check the parameters */\r
1283   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
1284   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1285   if (NewState != DISABLE)\r
1286   {\r
1287     /* Set the CCPC Bit */\r
1288     TIMx->CR2 |= TIM_CR2_CCPC;\r
1289   }\r
1290   else\r
1291   {\r
1292     /* Reset the CCPC Bit */\r
1293     TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCPC);\r
1294   }\r
1295 }\r
1296 \r
1297 \r
1298 /**\r
1299   * @brief  Enables or disables the TIMx peripheral Preload register on CCR1.\r
1300   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 and 17 to select the TIM peripheral.\r
1301   * @param  TIM_OCPreload: new state of the TIMx peripheral Preload register\r
1302   *   This parameter can be one of the following values:\r
1303   *     @arg TIM_OCPreload_Enable\r
1304   *     @arg TIM_OCPreload_Disable\r
1305   * @retval None\r
1306   */\r
1307 void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)\r
1308 {\r
1309   uint16_t tmpccmr1 = 0;\r
1310   /* Check the parameters */\r
1311   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
1312   assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));\r
1313   \r
1314   tmpccmr1 = TIMx->CCMR1;\r
1315   /* Reset the OC1PE Bit */\r
1316   tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1PE);\r
1317   /* Enable or Disable the Output Compare Preload feature */\r
1318   tmpccmr1 |= TIM_OCPreload;\r
1319   /* Write to TIMx CCMR1 register */\r
1320   TIMx->CCMR1 = tmpccmr1;\r
1321 }\r
1322 \r
1323 /**\r
1324   * @brief  Enables or disables the TIMx peripheral Preload register on CCR2.\r
1325   * @param  TIMx: where x can be 1, 2, 3 and 15 to select the TIM peripheral.\r
1326   * @param  TIM_OCPreload: new state of the TIMx peripheral Preload register\r
1327   *   This parameter can be one of the following values:\r
1328   *     @arg TIM_OCPreload_Enable\r
1329   *     @arg TIM_OCPreload_Disable\r
1330   * @retval None\r
1331   */\r
1332 void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)\r
1333 {\r
1334   uint16_t tmpccmr1 = 0;\r
1335   /* Check the parameters */\r
1336   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
1337   assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));\r
1338   \r
1339   tmpccmr1 = TIMx->CCMR1;\r
1340   /* Reset the OC2PE Bit */\r
1341   tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2PE);\r
1342   /* Enable or Disable the Output Compare Preload feature */\r
1343   tmpccmr1 |= (uint16_t)(TIM_OCPreload << 8);\r
1344   /* Write to TIMx CCMR1 register */\r
1345   TIMx->CCMR1 = tmpccmr1;\r
1346 }\r
1347 \r
1348 /**\r
1349   * @brief  Enables or disables the TIMx peripheral Preload register on CCR3.\r
1350   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1351   * @param  TIM_OCPreload: new state of the TIMx peripheral Preload register\r
1352   *   This parameter can be one of the following values:\r
1353   *     @arg TIM_OCPreload_Enable\r
1354   *     @arg TIM_OCPreload_Disable\r
1355   * @retval None\r
1356   */\r
1357 void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)\r
1358 {\r
1359   uint16_t tmpccmr2 = 0;\r
1360   \r
1361   /* Check the parameters */\r
1362   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1363   assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));\r
1364   \r
1365   tmpccmr2 = TIMx->CCMR2;\r
1366   /* Reset the OC3PE Bit */\r
1367   tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3PE);\r
1368   /* Enable or Disable the Output Compare Preload feature */\r
1369   tmpccmr2 |= TIM_OCPreload;\r
1370   /* Write to TIMx CCMR2 register */\r
1371   TIMx->CCMR2 = tmpccmr2;\r
1372 }\r
1373 \r
1374 /**\r
1375   * @brief  Enables or disables the TIMx peripheral Preload register on CCR4.\r
1376   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1377   * @param  TIM_OCPreload: new state of the TIMx peripheral Preload register\r
1378   *   This parameter can be one of the following values:\r
1379   *     @arg TIM_OCPreload_Enable\r
1380   *     @arg TIM_OCPreload_Disable\r
1381   * @retval None\r
1382   */\r
1383 void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload)\r
1384 {\r
1385   uint16_t tmpccmr2 = 0;\r
1386   \r
1387   /* Check the parameters */\r
1388   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1389   assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));\r
1390   \r
1391   tmpccmr2 = TIMx->CCMR2;\r
1392   /* Reset the OC4PE Bit */\r
1393   tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4PE);\r
1394   /* Enable or Disable the Output Compare Preload feature */\r
1395   tmpccmr2 |= (uint16_t)(TIM_OCPreload << 8);\r
1396   /* Write to TIMx CCMR2 register */\r
1397   TIMx->CCMR2 = tmpccmr2;\r
1398 }\r
1399 \r
1400 /**\r
1401   * @brief  Configures the TIMx Output Compare 1 Fast feature.\r
1402   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
1403   * @param  TIM_OCFast: new state of the Output Compare Fast Enable Bit.\r
1404   *   This parameter can be one of the following values:\r
1405   *     @arg TIM_OCFast_Enable: TIM output compare fast enable\r
1406   *     @arg TIM_OCFast_Disable: TIM output compare fast disable\r
1407   * @retval None\r
1408   */\r
1409 void TIM_OC1FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)\r
1410 {\r
1411   uint16_t tmpccmr1 = 0;\r
1412   \r
1413   /* Check the parameters */\r
1414   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
1415   assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));\r
1416   \r
1417   /* Get the TIMx CCMR1 register value */\r
1418   tmpccmr1 = TIMx->CCMR1;\r
1419   /* Reset the OC1FE Bit */\r
1420   tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1FE);\r
1421   /* Enable or Disable the Output Compare Fast Bit */\r
1422   tmpccmr1 |= TIM_OCFast;\r
1423   /* Write to TIMx CCMR1 */\r
1424   TIMx->CCMR1 = tmpccmr1;\r
1425 }\r
1426 \r
1427 /**\r
1428   * @brief  Configures the TIMx Output Compare 2 Fast feature.\r
1429   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
1430   * @param  TIM_OCFast: new state of the Output Compare Fast Enable Bit.\r
1431   *   This parameter can be one of the following values:\r
1432   *     @arg TIM_OCFast_Enable: TIM output compare fast enable\r
1433   *     @arg TIM_OCFast_Disable: TIM output compare fast disable\r
1434   * @retval None\r
1435   */\r
1436 void TIM_OC2FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)\r
1437 {\r
1438   uint16_t tmpccmr1 = 0;\r
1439   \r
1440   /* Check the parameters */\r
1441   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
1442   assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));\r
1443   \r
1444   /* Get the TIMx CCMR1 register value */\r
1445   tmpccmr1 = TIMx->CCMR1;\r
1446   /* Reset the OC2FE Bit */\r
1447   tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2FE);\r
1448   /* Enable or Disable the Output Compare Fast Bit */\r
1449   tmpccmr1 |= (uint16_t)(TIM_OCFast << 8);\r
1450   /* Write to TIMx CCMR1 */\r
1451   TIMx->CCMR1 = tmpccmr1;\r
1452 }\r
1453 \r
1454 /**\r
1455   * @brief  Configures the TIMx Output Compare 3 Fast feature.\r
1456   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1457   * @param  TIM_OCFast: new state of the Output Compare Fast Enable Bit.\r
1458   *   This parameter can be one of the following values:\r
1459   *     @arg TIM_OCFast_Enable: TIM output compare fast enable\r
1460   *     @arg TIM_OCFast_Disable: TIM output compare fast disable\r
1461   * @retval None\r
1462   */\r
1463 void TIM_OC3FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)\r
1464 {\r
1465   uint16_t tmpccmr2 = 0;\r
1466   \r
1467   /* Check the parameters */\r
1468   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1469   assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));\r
1470   \r
1471   /* Get the TIMx CCMR2 register value */\r
1472   tmpccmr2 = TIMx->CCMR2;\r
1473   /* Reset the OC3FE Bit */\r
1474   tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3FE);\r
1475   /* Enable or Disable the Output Compare Fast Bit */\r
1476   tmpccmr2 |= TIM_OCFast;\r
1477   /* Write to TIMx CCMR2 */\r
1478   TIMx->CCMR2 = tmpccmr2;\r
1479 }\r
1480 \r
1481 /**\r
1482   * @brief  Configures the TIMx Output Compare 4 Fast feature.\r
1483   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1484   * @param  TIM_OCFast: new state of the Output Compare Fast Enable Bit.\r
1485   *   This parameter can be one of the following values:\r
1486   *     @arg TIM_OCFast_Enable: TIM output compare fast enable\r
1487   *     @arg TIM_OCFast_Disable: TIM output compare fast disable\r
1488   * @retval None\r
1489   */\r
1490 void TIM_OC4FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast)\r
1491 {\r
1492   uint16_t tmpccmr2 = 0;\r
1493   \r
1494   /* Check the parameters */\r
1495   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1496   assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast));\r
1497   \r
1498   /* Get the TIMx CCMR2 register value */\r
1499   tmpccmr2 = TIMx->CCMR2;\r
1500   /* Reset the OC4FE Bit */\r
1501   tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4FE);\r
1502   /* Enable or Disable the Output Compare Fast Bit */\r
1503   tmpccmr2 |= (uint16_t)(TIM_OCFast << 8);\r
1504   /* Write to TIMx CCMR2 */\r
1505   TIMx->CCMR2 = tmpccmr2;\r
1506 }\r
1507 \r
1508 /**\r
1509   * @brief  Clears or safeguards the OCREF1 signal on an external event\r
1510   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
1511   * @param  TIM_OCClear: new state of the Output Compare Clear Enable Bit.\r
1512   *   This parameter can be one of the following values:\r
1513   *     @arg TIM_OCClear_Enable: TIM Output clear enable\r
1514   *     @arg TIM_OCClear_Disable: TIM Output clear disable\r
1515   * @retval None\r
1516   */\r
1517 void TIM_ClearOC1Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)\r
1518 {\r
1519   uint16_t tmpccmr1 = 0;\r
1520   \r
1521   /* Check the parameters */\r
1522   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
1523   assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));\r
1524   \r
1525   tmpccmr1 = TIMx->CCMR1;\r
1526   /* Reset the OC1CE Bit */\r
1527   tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC1CE);\r
1528   /* Enable or Disable the Output Compare Clear Bit */\r
1529   tmpccmr1 |= TIM_OCClear;\r
1530   /* Write to TIMx CCMR1 register */\r
1531   TIMx->CCMR1 = tmpccmr1;\r
1532 }\r
1533 \r
1534 /**\r
1535   * @brief  Clears or safeguards the OCREF2 signal on an external event\r
1536   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
1537   * @param  TIM_OCClear: new state of the Output Compare Clear Enable Bit.\r
1538 \r
1539   *   This parameter can be one of the following values:\r
1540   *     @arg TIM_OCClear_Enable: TIM Output clear enable\r
1541   *     @arg TIM_OCClear_Disable: TIM Output clear disable\r
1542   * @retval None\r
1543   */\r
1544 void TIM_ClearOC2Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)\r
1545 {\r
1546   uint16_t tmpccmr1 = 0;\r
1547   \r
1548   /* Check the parameters */\r
1549   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
1550   assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));\r
1551   \r
1552   tmpccmr1 = TIMx->CCMR1;\r
1553   /* Reset the OC2CE Bit */\r
1554   tmpccmr1 &= (uint16_t)~((uint16_t)TIM_CCMR1_OC2CE);\r
1555   /* Enable or Disable the Output Compare Clear Bit */\r
1556   tmpccmr1 |= (uint16_t)(TIM_OCClear << 8);\r
1557   /* Write to TIMx CCMR1 register */\r
1558   TIMx->CCMR1 = tmpccmr1;\r
1559 }\r
1560 \r
1561 /**\r
1562   * @brief  Clears or safeguards the OCREF3 signal on an external event\r
1563   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1564   * @param  TIM_OCClear: new state of the Output Compare Clear Enable Bit.\r
1565   *   This parameter can be one of the following values:\r
1566   *     @arg TIM_OCClear_Enable: TIM Output clear enable\r
1567   *     @arg TIM_OCClear_Disable: TIM Output clear disable\r
1568   * @retval None\r
1569   */\r
1570 void TIM_ClearOC3Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)\r
1571 {\r
1572   uint16_t tmpccmr2 = 0;\r
1573   \r
1574   /* Check the parameters */\r
1575   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1576   assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));\r
1577   \r
1578   tmpccmr2 = TIMx->CCMR2;\r
1579   /* Reset the OC3CE Bit */\r
1580   tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC3CE);\r
1581   /* Enable or Disable the Output Compare Clear Bit */\r
1582   tmpccmr2 |= TIM_OCClear;\r
1583   /* Write to TIMx CCMR2 register */\r
1584   TIMx->CCMR2 = tmpccmr2;\r
1585 }\r
1586 \r
1587 /**\r
1588   * @brief  Clears or safeguards the OCREF4 signal on an external event\r
1589   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1590   * @param  TIM_OCClear: new state of the Output Compare Clear Enable Bit.\r
1591   *   This parameter can be one of the following values:\r
1592   *     @arg TIM_OCClear_Enable: TIM Output clear enable\r
1593   *     @arg TIM_OCClear_Disable: TIM Output clear disable\r
1594   * @retval None\r
1595   */\r
1596 void TIM_ClearOC4Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear)\r
1597 {\r
1598   uint16_t tmpccmr2 = 0;\r
1599   \r
1600   /* Check the parameters */\r
1601   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1602   assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));\r
1603   \r
1604   tmpccmr2 = TIMx->CCMR2;\r
1605   /* Reset the OC4CE Bit */\r
1606   tmpccmr2 &= (uint16_t)~((uint16_t)TIM_CCMR2_OC4CE);\r
1607   /* Enable or Disable the Output Compare Clear Bit */\r
1608   tmpccmr2 |= (uint16_t)(TIM_OCClear << 8);\r
1609   /* Write to TIMx CCMR2 register */\r
1610   TIMx->CCMR2 = tmpccmr2;\r
1611 }\r
1612 \r
1613 /**\r
1614   * @brief  Configures the TIMx channel 1 polarity.\r
1615   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
1616   * @param  TIM_OCPolarity: specifies the OC1 Polarity\r
1617   *   This parmeter can be one of the following values:\r
1618   *     @arg TIM_OCPolarity_High: Output Compare active high\r
1619   *     @arg TIM_OCPolarity_Low: Output Compare active low\r
1620   * @retval None\r
1621   */\r
1622 void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)\r
1623 {\r
1624   uint16_t tmpccer = 0;\r
1625   \r
1626   /* Check the parameters */\r
1627   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
1628   assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));\r
1629   \r
1630   tmpccer = TIMx->CCER;\r
1631   /* Set or Reset the CC1P Bit */\r
1632   tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC1P);\r
1633   tmpccer |= TIM_OCPolarity;\r
1634   /* Write to TIMx CCER register */\r
1635   TIMx->CCER = tmpccer;\r
1636 }\r
1637 \r
1638 /**\r
1639   * @brief  Configures the TIMx Channel 1N polarity.\r
1640   * @param  TIMx: where x can be 1, 15, 16 or 17 to select the TIM peripheral.\r
1641   * @param  TIM_OCNPolarity: specifies the OC1N Polarity\r
1642   *   This parmeter can be one of the following values:\r
1643   *     @arg TIM_OCNPolarity_High: Output Compare active high\r
1644   *     @arg TIM_OCNPolarity_Low: Output Compare active low\r
1645   * @retval None\r
1646   */\r
1647 void TIM_OC1NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)\r
1648 {\r
1649   uint16_t tmpccer = 0;\r
1650   /* Check the parameters */\r
1651   assert_param(IS_TIM_LIST2_PERIPH(TIMx));\r
1652   assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));\r
1653    \r
1654   tmpccer = TIMx->CCER;\r
1655   /* Set or Reset the CC1NP Bit */\r
1656   tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC1NP);\r
1657   tmpccer |= TIM_OCNPolarity;\r
1658   /* Write to TIMx CCER register */\r
1659   TIMx->CCER = tmpccer;\r
1660 }\r
1661 \r
1662 /**\r
1663   * @brief  Configures the TIMx channel 2 polarity.\r
1664   * @param  TIMx: where x can be 1, 2, 3, or 15 to select the TIM peripheral.\r
1665   * @param  TIM_OCPolarity: specifies the OC2 Polarity\r
1666   *   This parmeter can be one of the following values:\r
1667   *     @arg TIM_OCPolarity_High: Output Compare active high\r
1668   *     @arg TIM_OCPolarity_Low: Output Compare active low\r
1669   * @retval None\r
1670   */\r
1671 void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)\r
1672 {\r
1673   uint16_t tmpccer = 0;\r
1674   \r
1675   /* Check the parameters */\r
1676   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
1677   assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));\r
1678   \r
1679   tmpccer = TIMx->CCER;\r
1680   /* Set or Reset the CC2P Bit */\r
1681   tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC2P);\r
1682   tmpccer |= (uint16_t)(TIM_OCPolarity << 4);\r
1683   /* Write to TIMx CCER register */\r
1684   TIMx->CCER = tmpccer;\r
1685 }\r
1686 \r
1687 /**\r
1688   * @brief  Configures the TIMx Channel 2N polarity.\r
1689   * @param  TIMx: where x can be 1 to select the TIM peripheral.\r
1690   * @param  TIM_OCNPolarity: specifies the OC2N Polarity\r
1691   *   This parmeter can be one of the following values:\r
1692   *     @arg TIM_OCNPolarity_High: Output Compare active high\r
1693   *     @arg TIM_OCNPolarity_Low: Output Compare active low\r
1694   * @retval None\r
1695   */\r
1696 void TIM_OC2NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)\r
1697 {\r
1698   uint16_t tmpccer = 0;\r
1699   /* Check the parameters */\r
1700   assert_param(IS_TIM_LIST1_PERIPH(TIMx));\r
1701   assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));\r
1702   \r
1703   tmpccer = TIMx->CCER;\r
1704   /* Set or Reset the CC2NP Bit */\r
1705   tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC2NP);\r
1706   tmpccer |= (uint16_t)(TIM_OCNPolarity << 4);\r
1707   /* Write to TIMx CCER register */\r
1708   TIMx->CCER = tmpccer;\r
1709 }\r
1710 \r
1711 /**\r
1712   * @brief  Configures the TIMx channel 3 polarity.\r
1713   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1714   * @param  TIM_OCPolarity: specifies the OC3 Polarity\r
1715   *   This parmeter can be one of the following values:\r
1716   *     @arg TIM_OCPolarity_High: Output Compare active high\r
1717   *     @arg TIM_OCPolarity_Low: Output Compare active low\r
1718   * @retval None\r
1719   */\r
1720 void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)\r
1721 {\r
1722   uint16_t tmpccer = 0;\r
1723   \r
1724   /* Check the parameters */\r
1725   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1726   assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));\r
1727   \r
1728   tmpccer = TIMx->CCER;\r
1729   /* Set or Reset the CC3P Bit */\r
1730   tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC3P);\r
1731   tmpccer |= (uint16_t)(TIM_OCPolarity << 8);\r
1732   /* Write to TIMx CCER register */\r
1733   TIMx->CCER = tmpccer;\r
1734 }\r
1735 \r
1736 /**\r
1737   * @brief  Configures the TIMx Channel 3N polarity.\r
1738   * @param  TIMx: where x can be 1 to select the TIM peripheral.\r
1739   * @param  TIM_OCNPolarity: specifies the OC3N Polarity\r
1740   *   This parmeter can be one of the following values:\r
1741   *     @arg TIM_OCNPolarity_High: Output Compare active high\r
1742   *     @arg TIM_OCNPolarity_Low: Output Compare active low\r
1743   * @retval None\r
1744   */\r
1745 void TIM_OC3NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity)\r
1746 {\r
1747   uint16_t tmpccer = 0;\r
1748  \r
1749   /* Check the parameters */\r
1750   assert_param(IS_TIM_LIST1_PERIPH(TIMx));\r
1751   assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity));\r
1752     \r
1753   tmpccer = TIMx->CCER;\r
1754   /* Set or Reset the CC3NP Bit */\r
1755   tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC3NP);\r
1756   tmpccer |= (uint16_t)(TIM_OCNPolarity << 8);\r
1757   /* Write to TIMx CCER register */\r
1758   TIMx->CCER = tmpccer;\r
1759 }\r
1760 \r
1761 \r
1762 /**\r
1763   * @brief  Configures the TIMx channel 4 polarity.\r
1764   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1765   * @param  TIM_OCPolarity: specifies the OC4 Polarity\r
1766   *   This parmeter can be one of the following values:\r
1767   *     @arg TIM_OCPolarity_High: Output Compare active high\r
1768   *     @arg TIM_OCPolarity_Low: Output Compare active low\r
1769   * @retval None\r
1770   */\r
1771 void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity)\r
1772 {\r
1773   uint16_t tmpccer = 0;\r
1774   \r
1775   /* Check the parameters */\r
1776   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1777   assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));\r
1778   \r
1779   tmpccer = TIMx->CCER;\r
1780   /* Set or Reset the CC4P Bit */\r
1781   tmpccer &= (uint16_t)~((uint16_t)TIM_CCER_CC4P);\r
1782   tmpccer |= (uint16_t)(TIM_OCPolarity << 12);\r
1783   /* Write to TIMx CCER register */\r
1784   TIMx->CCER = tmpccer;\r
1785 }\r
1786 \r
1787 /**\r
1788   * @brief  Selects the OCReference Clear source.\r
1789   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
1790   * @param  TIM_OCReferenceClear: specifies the OCReference Clear source.\r
1791   *   This parameter can be one of the following values:\r
1792   *     @arg TIM_OCReferenceClear_ETRF: The internal OCreference clear input is connected to ETRF.\r
1793   *     @arg TIM_OCReferenceClear_OCREFCLR: The internal OCreference clear input is connected to OCREF_CLR input.  \r
1794   * @retval None\r
1795   */\r
1796 void TIM_SelectOCREFClear(TIM_TypeDef* TIMx, uint16_t TIM_OCReferenceClear)\r
1797 {\r
1798   /* Check the parameters */\r
1799   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1800   assert_param(TIM_OCREFERENCECECLEAR_SOURCE(TIM_OCReferenceClear));\r
1801 \r
1802   /* Set the TIM_OCReferenceClear source */\r
1803   TIMx->SMCR &=  (uint16_t)~((uint16_t)TIM_SMCR_OCCS);\r
1804   TIMx->SMCR |=  TIM_OCReferenceClear;\r
1805 }\r
1806 \r
1807 /**\r
1808   * @brief  Enables or disables the TIM Capture Compare Channel x.\r
1809   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
1810   * @param  TIM_Channel: specifies the TIM Channel\r
1811   *   This parameter can be one of the following values:\r
1812   *     @arg TIM_Channel_1: TIM Channel 1\r
1813   *     @arg TIM_Channel_2: TIM Channel 2\r
1814   *     @arg TIM_Channel_3: TIM Channel 3\r
1815   *     @arg TIM_Channel_4: TIM Channel 4\r
1816   * @param  TIM_CCx: specifies the TIM Channel CCxE bit new state.\r
1817   *   This parameter can be: TIM_CCx_Enable or TIM_CCx_Disable. \r
1818   * @retval None\r
1819   */\r
1820 void TIM_CCxCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCx)\r
1821 {\r
1822   uint16_t tmp = 0;\r
1823 \r
1824   /* Check the parameters */\r
1825   assert_param(IS_TIM_LIST4_PERIPH(TIMx)); \r
1826   assert_param(IS_TIM_CCX(TIM_CCx));\r
1827 \r
1828   tmp = CCER_CCE_SET << TIM_Channel;\r
1829 \r
1830   /* Reset the CCxE Bit */\r
1831   TIMx->CCER &= (uint16_t)~ tmp;\r
1832 \r
1833   /* Set or reset the CCxE Bit */ \r
1834   TIMx->CCER |=  (uint16_t)(TIM_CCx << TIM_Channel);\r
1835 }\r
1836 \r
1837 /**\r
1838   * @brief  Enables or disables the TIM Capture Compare Channel xN.\r
1839   * @param  TIMx: where x can be 1, 15, 16 or 17 to select the TIM peripheral.\r
1840   * @param  TIM_Channel: specifies the TIM Channel\r
1841   *   This parmeter can be one of the following values:\r
1842   *     @arg TIM_Channel_1: TIM Channel 1\r
1843   *     @arg TIM_Channel_2: TIM Channel 2\r
1844   *     @arg TIM_Channel_3: TIM Channel 3\r
1845   * @param  TIM_CCxN: specifies the TIM Channel CCxNE bit new state.\r
1846   *   This parameter can be: TIM_CCxN_Enable or TIM_CCxN_Disable. \r
1847   * @retval None\r
1848   */\r
1849 void TIM_CCxNCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCxN)\r
1850 {\r
1851   uint16_t tmp = 0;\r
1852 \r
1853   /* Check the parameters */\r
1854   assert_param(IS_TIM_LIST2_PERIPH(TIMx));\r
1855   assert_param(IS_TIM_COMPLEMENTARY_CHANNEL(TIM_Channel));\r
1856   assert_param(IS_TIM_CCXN(TIM_CCxN));\r
1857 \r
1858   tmp = CCER_CCNE_SET << TIM_Channel;\r
1859 \r
1860   /* Reset the CCxNE Bit */\r
1861   TIMx->CCER &= (uint16_t) ~tmp;\r
1862 \r
1863   /* Set or reset the CCxNE Bit */ \r
1864   TIMx->CCER |=  (uint16_t)(TIM_CCxN << TIM_Channel);\r
1865 }\r
1866 \r
1867 /**\r
1868   * @brief  Selects the TIM peripheral Commutation event.\r
1869   * @param  TIMx: where x can be  1, 15, 16 or 17 to select the TIMx peripheral\r
1870   * @param  NewState: new state of the Commutation event.\r
1871   *   This parameter can be: ENABLE or DISABLE.\r
1872   * @retval None\r
1873   */\r
1874 void TIM_SelectCOM(TIM_TypeDef* TIMx, FunctionalState NewState)\r
1875 {\r
1876   /* Check the parameters */\r
1877   assert_param(IS_TIM_LIST2_PERIPH(TIMx));\r
1878   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
1879   if (NewState != DISABLE)\r
1880   {\r
1881     /* Set the COM Bit */\r
1882     TIMx->CR2 |= TIM_CR2_CCUS;\r
1883   }\r
1884   else\r
1885   {\r
1886     /* Reset the COM Bit */\r
1887     TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCUS);\r
1888   }\r
1889 }\r
1890 \r
1891 /**\r
1892   * @}\r
1893   */\r
1894 \r
1895 /** @defgroup TIM_Group4 Input Capture management functions\r
1896  *  @brief    Input Capture management functions \r
1897  *\r
1898 @verbatim\r
1899  ===============================================================================\r
1900                ##### Input Capture management functions #####\r
1901  ===============================================================================\r
1902    \r
1903           *** TIM Driver: how to use it in Input Capture Mode ***\r
1904  ===============================================================================\r
1905     [..] To use the Timer in Input Capture mode, the following steps are mandatory:\r
1906          (#) Enable TIM clock using RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) \r
1907              function.\r
1908          (#) Configure the TIM pins by configuring the corresponding GPIO pins.\r
1909          (#) Configure the Time base unit as described in the first part of this \r
1910              driver, if needed, else the Timer will run with the default configuration:\r
1911              (++) Autoreload value = 0xFFFF.\r
1912              (++) Prescaler value = 0x0000.\r
1913              (++) Counter mode = Up counting.\r
1914              (++) Clock Division = TIM_CKD_DIV1.\r
1915          (#) Fill the TIM_ICInitStruct with the desired parameters including:\r
1916              (++) TIM Channel: TIM_Channel.\r
1917              (++) TIM Input Capture polarity: TIM_ICPolarity.\r
1918              (++) TIM Input Capture selection: TIM_ICSelection.\r
1919              (++) TIM Input Capture Prescaler: TIM_ICPrescaler.\r
1920              (++) TIM Input CApture filter value: TIM_ICFilter.\r
1921          (#) Call TIM_ICInit(TIMx, &TIM_ICInitStruct) to configure the desired \r
1922              channel with the corresponding configuration and to measure only \r
1923              frequency or duty cycle of the input signal,or, Call \r
1924              TIM_PWMIConfig(TIMx, &TIM_ICInitStruct) to configure the desired \r
1925              channels with the corresponding configuration and to measure the \r
1926              frequency and the duty cycle of the input signal.\r
1927          (#) Enable the NVIC or the DMA to read the measured frequency.\r
1928          (#) Enable the corresponding interrupt (or DMA request) to read \r
1929              the Captured value, using the function TIM_ITConfig(TIMx, TIM_IT_CCx)\r
1930              (or TIM_DMA_Cmd(TIMx, TIM_DMA_CCx)).\r
1931          (#) Call the TIM_Cmd(ENABLE) function to enable the TIM counter.\r
1932          (#) Use TIM_GetCapturex(TIMx); to read the captured value.\r
1933     [..]\r
1934         (@) All other functions can be used separately to modify, if needed,\r
1935             a specific feature of the Timer. \r
1936 \r
1937 @endverbatim\r
1938   * @{\r
1939   */\r
1940 \r
1941 /**\r
1942   * @brief  Initializes the TIM peripheral according to the specified\r
1943   *         parameters in the TIM_ICInitStruct.\r
1944   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
1945   * @param  TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure\r
1946   *         that contains the configuration information for the specified TIM \r
1947   *         peripheral.\r
1948   * @retval None\r
1949   */\r
1950 void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)\r
1951 {\r
1952   /* Check the parameters */\r
1953   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
1954   assert_param(IS_TIM_CHANNEL(TIM_ICInitStruct->TIM_Channel));  \r
1955   assert_param(IS_TIM_IC_SELECTION(TIM_ICInitStruct->TIM_ICSelection));\r
1956   assert_param(IS_TIM_IC_PRESCALER(TIM_ICInitStruct->TIM_ICPrescaler));\r
1957   assert_param(IS_TIM_IC_FILTER(TIM_ICInitStruct->TIM_ICFilter));\r
1958   assert_param(IS_TIM_IC_POLARITY(TIM_ICInitStruct->TIM_ICPolarity));\r
1959 \r
1960   if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)\r
1961   {\r
1962     assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
1963     /* TI1 Configuration */\r
1964     TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,\r
1965                TIM_ICInitStruct->TIM_ICSelection,\r
1966                TIM_ICInitStruct->TIM_ICFilter);\r
1967     /* Set the Input Capture Prescaler value */\r
1968     TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);\r
1969   }\r
1970   else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_2)\r
1971   {\r
1972     assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
1973     /* TI2 Configuration */\r
1974     TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,\r
1975                TIM_ICInitStruct->TIM_ICSelection,\r
1976                TIM_ICInitStruct->TIM_ICFilter);\r
1977     /* Set the Input Capture Prescaler value */\r
1978     TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);\r
1979   }\r
1980   else if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_3)\r
1981   {\r
1982     assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1983     /* TI3 Configuration */\r
1984     TI3_Config(TIMx,  TIM_ICInitStruct->TIM_ICPolarity,\r
1985                TIM_ICInitStruct->TIM_ICSelection,\r
1986                TIM_ICInitStruct->TIM_ICFilter);\r
1987     /* Set the Input Capture Prescaler value */\r
1988     TIM_SetIC3Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);\r
1989   }\r
1990   else\r
1991   {\r
1992     assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
1993     /* TI4 Configuration */\r
1994     TI4_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity,\r
1995                TIM_ICInitStruct->TIM_ICSelection,\r
1996                TIM_ICInitStruct->TIM_ICFilter);\r
1997     /* Set the Input Capture Prescaler value */\r
1998     TIM_SetIC4Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);\r
1999   }\r
2000 }\r
2001 \r
2002 /**\r
2003   * @brief  Fills each TIM_ICInitStruct member with its default value.\r
2004   * @param  TIM_ICInitStruct : pointer to a TIM_ICInitTypeDef structure which will\r
2005   *         be initialized.\r
2006   * @retval None\r
2007   */\r
2008 void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct)\r
2009 {\r
2010   /* Set the default configuration */\r
2011   TIM_ICInitStruct->TIM_Channel = TIM_Channel_1;\r
2012   TIM_ICInitStruct->TIM_ICPolarity = TIM_ICPolarity_Rising;\r
2013   TIM_ICInitStruct->TIM_ICSelection = TIM_ICSelection_DirectTI;\r
2014   TIM_ICInitStruct->TIM_ICPrescaler = TIM_ICPSC_DIV1;\r
2015   TIM_ICInitStruct->TIM_ICFilter = 0x00;\r
2016 }\r
2017 \r
2018 /**\r
2019   * @brief  Configures the TIM peripheral according to the specified\r
2020   *         parameters in the TIM_ICInitStruct to measure an external PWM signal.\r
2021   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
2022   * @param  TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure\r
2023   *         that contains the configuration information for the specified TIM \r
2024   *         peripheral.\r
2025   * @retval None\r
2026   */\r
2027 void TIM_PWMIConfig(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct)\r
2028 {\r
2029   uint16_t icoppositepolarity = TIM_ICPolarity_Rising;\r
2030   uint16_t icoppositeselection = TIM_ICSelection_DirectTI;\r
2031   /* Check the parameters */\r
2032   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
2033   /* Select the Opposite Input Polarity */\r
2034   if (TIM_ICInitStruct->TIM_ICPolarity == TIM_ICPolarity_Rising)\r
2035   {\r
2036     icoppositepolarity = TIM_ICPolarity_Falling;\r
2037   }\r
2038   else\r
2039   {\r
2040     icoppositepolarity = TIM_ICPolarity_Rising;\r
2041   }\r
2042   /* Select the Opposite Input */\r
2043   if (TIM_ICInitStruct->TIM_ICSelection == TIM_ICSelection_DirectTI)\r
2044   {\r
2045     icoppositeselection = TIM_ICSelection_IndirectTI;\r
2046   }\r
2047   else\r
2048   {\r
2049     icoppositeselection = TIM_ICSelection_DirectTI;\r
2050   }\r
2051   if (TIM_ICInitStruct->TIM_Channel == TIM_Channel_1)\r
2052   {\r
2053     /* TI1 Configuration */\r
2054     TI1_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,\r
2055                TIM_ICInitStruct->TIM_ICFilter);\r
2056     /* Set the Input Capture Prescaler value */\r
2057     TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);\r
2058     /* TI2 Configuration */\r
2059     TI2_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);\r
2060     /* Set the Input Capture Prescaler value */\r
2061     TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);\r
2062   }\r
2063   else\r
2064   { \r
2065     /* TI2 Configuration */\r
2066     TI2_Config(TIMx, TIM_ICInitStruct->TIM_ICPolarity, TIM_ICInitStruct->TIM_ICSelection,\r
2067                TIM_ICInitStruct->TIM_ICFilter);\r
2068     /* Set the Input Capture Prescaler value */\r
2069     TIM_SetIC2Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);\r
2070     /* TI1 Configuration */\r
2071     TI1_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->TIM_ICFilter);\r
2072     /* Set the Input Capture Prescaler value */\r
2073     TIM_SetIC1Prescaler(TIMx, TIM_ICInitStruct->TIM_ICPrescaler);\r
2074   }\r
2075 }\r
2076 \r
2077 /**\r
2078   * @brief  Gets the TIMx Input Capture 1 value.\r
2079   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
2080   * @retval Capture Compare 1 Register value.\r
2081   */\r
2082 uint32_t TIM_GetCapture1(TIM_TypeDef* TIMx)\r
2083 {\r
2084   /* Check the parameters */\r
2085   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
2086   \r
2087   /* Get the Capture 1 Register value */\r
2088   return TIMx->CCR1;\r
2089 }\r
2090 \r
2091 /**\r
2092   * @brief  Gets the TIMx Input Capture 2 value.\r
2093   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
2094   * @retval Capture Compare 2 Register value.\r
2095   */\r
2096 uint32_t TIM_GetCapture2(TIM_TypeDef* TIMx)\r
2097 {\r
2098   /* Check the parameters */\r
2099   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
2100   \r
2101   /* Get the Capture 2 Register value */\r
2102   return TIMx->CCR2;\r
2103 }\r
2104 \r
2105 /**\r
2106   * @brief  Gets the TIMx Input Capture 3 value.\r
2107   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
2108   * @retval Capture Compare 3 Register value.\r
2109   */\r
2110 uint32_t TIM_GetCapture3(TIM_TypeDef* TIMx)\r
2111 {\r
2112   /* Check the parameters */\r
2113   assert_param(IS_TIM_LIST3_PERIPH(TIMx)); \r
2114   \r
2115   /* Get the Capture 3 Register value */\r
2116   return TIMx->CCR3;\r
2117 }\r
2118 \r
2119 /**\r
2120   * @brief  Gets the TIMx Input Capture 4 value.\r
2121   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
2122   * @retval Capture Compare 4 Register value.\r
2123   */\r
2124 uint32_t TIM_GetCapture4(TIM_TypeDef* TIMx)\r
2125 {\r
2126   /* Check the parameters */\r
2127   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
2128   \r
2129   /* Get the Capture 4 Register value */\r
2130   return TIMx->CCR4;\r
2131 }\r
2132 \r
2133 /**\r
2134   * @brief  Sets the TIMx Input Capture 1 prescaler.\r
2135   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
2136   * @param  TIM_ICPSC: specifies the Input Capture1 prescaler new value.\r
2137   *   This parameter can be one of the following values:\r
2138   *     @arg TIM_ICPSC_DIV1: no prescaler\r
2139   *     @arg TIM_ICPSC_DIV2: capture is done once every 2 events\r
2140   *     @arg TIM_ICPSC_DIV4: capture is done once every 4 events\r
2141   *     @arg TIM_ICPSC_DIV8: capture is done once every 8 events\r
2142   * @retval None\r
2143   */\r
2144 void TIM_SetIC1Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)\r
2145 {\r
2146   /* Check the parameters */\r
2147   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
2148   assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));\r
2149   \r
2150   /* Reset the IC1PSC Bits */\r
2151   TIMx->CCMR1 &= (uint16_t)~((uint16_t)TIM_CCMR1_IC1PSC);\r
2152   /* Set the IC1PSC value */\r
2153   TIMx->CCMR1 |= TIM_ICPSC;\r
2154 }\r
2155 \r
2156 /**\r
2157   * @brief  Sets the TIMx Input Capture 2 prescaler.\r
2158   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
2159   * @param  TIM_ICPSC: specifies the Input Capture2 prescaler new value.\r
2160   *   This parameter can be one of the following values:\r
2161   *     @arg TIM_ICPSC_DIV1: no prescaler\r
2162   *     @arg TIM_ICPSC_DIV2: capture is done once every 2 events\r
2163   *     @arg TIM_ICPSC_DIV4: capture is done once every 4 events\r
2164   *     @arg TIM_ICPSC_DIV8: capture is done once every 8 events\r
2165   * @retval None\r
2166   */\r
2167 void TIM_SetIC2Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)\r
2168 {\r
2169   /* Check the parameters */\r
2170   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
2171   assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));\r
2172   \r
2173   /* Reset the IC2PSC Bits */\r
2174   TIMx->CCMR1 &= (uint16_t)~((uint16_t)TIM_CCMR1_IC2PSC);\r
2175   /* Set the IC2PSC value */\r
2176   TIMx->CCMR1 |= (uint16_t)(TIM_ICPSC << 8);\r
2177 }\r
2178 \r
2179 /**\r
2180   * @brief  Sets the TIMx Input Capture 3 prescaler.\r
2181   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
2182   * @param  TIM_ICPSC: specifies the Input Capture3 prescaler new value.\r
2183   *   This parameter can be one of the following values:\r
2184   *     @arg TIM_ICPSC_DIV1: no prescaler\r
2185   *     @arg TIM_ICPSC_DIV2: capture is done once every 2 events\r
2186   *     @arg TIM_ICPSC_DIV4: capture is done once every 4 events\r
2187   *     @arg TIM_ICPSC_DIV8: capture is done once every 8 events\r
2188   * @retval None\r
2189   */\r
2190 void TIM_SetIC3Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)\r
2191 {\r
2192   /* Check the parameters */\r
2193   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
2194   assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));\r
2195   \r
2196   /* Reset the IC3PSC Bits */\r
2197   TIMx->CCMR2 &= (uint16_t)~((uint16_t)TIM_CCMR2_IC3PSC);\r
2198   /* Set the IC3PSC value */\r
2199   TIMx->CCMR2 |= TIM_ICPSC;\r
2200 }\r
2201 \r
2202 /**\r
2203   * @brief  Sets the TIMx Input Capture 4 prescaler.\r
2204   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
2205   * @param  TIM_ICPSC: specifies the Input Capture4 prescaler new value.\r
2206   *   This parameter can be one of the following values:\r
2207   *     @arg TIM_ICPSC_DIV1: no prescaler\r
2208   *     @arg TIM_ICPSC_DIV2: capture is done once every 2 events\r
2209   *     @arg TIM_ICPSC_DIV4: capture is done once every 4 events\r
2210   *     @arg TIM_ICPSC_DIV8: capture is done once every 8 events\r
2211   * @retval None\r
2212   */\r
2213 void TIM_SetIC4Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC)\r
2214 {  \r
2215   /* Check the parameters */\r
2216   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
2217   assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC));\r
2218   \r
2219   /* Reset the IC4PSC Bits */\r
2220   TIMx->CCMR2 &= (uint16_t)~((uint16_t)TIM_CCMR2_IC4PSC);\r
2221   /* Set the IC4PSC value */\r
2222   TIMx->CCMR2 |= (uint16_t)(TIM_ICPSC << 8);\r
2223 }\r
2224 \r
2225 /**\r
2226   * @}\r
2227   */\r
2228 \r
2229 /** @defgroup TIM_Group5 Interrupts DMA and flags management functions\r
2230  *  @brief    Interrupts, DMA and flags management functions \r
2231  *\r
2232 @verbatim\r
2233  ===============================================================================\r
2234           ##### Interrupts, DMA and flags management functions #####\r
2235  ===============================================================================\r
2236 \r
2237 @endverbatim\r
2238   * @{\r
2239   */\r
2240 \r
2241 /**\r
2242   * @brief  Enables or disables the specified TIM interrupts.\r
2243   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 or 17 to select the TIMx peripheral.\r
2244   * @param  TIM_IT: specifies the TIM interrupts sources to be enabled or disabled.\r
2245   *   This parameter can be any combination of the following values:\r
2246   *     @arg TIM_IT_Update: TIM update Interrupt source\r
2247   *     @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source\r
2248   *     @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source\r
2249   *     @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source\r
2250   *     @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source\r
2251   *     @arg TIM_IT_COM: TIM Commutation Interrupt source\r
2252   *     @arg TIM_IT_Trigger: TIM Trigger Interrupt source\r
2253   *     @arg TIM_IT_Break: TIM Break Interrupt source\r
2254   * @note \r
2255   *   - TIM6 can only generate an update interrupt.\r
2256   *   - TIM15 can have only TIM_IT_Update, TIM_IT_CC1,\r
2257   *     TIM_IT_CC2 or TIM_IT_Trigger. \r
2258   *   - TIM14, TIM16 and TIM17 can have TIM_IT_Update or TIM_IT_CC1.   \r
2259   *   - TIM_IT_Break is used only with TIM1 and TIM15. \r
2260   *   - TIM_IT_COM is used only with TIM1, TIM15, TIM16 and TIM17.    \r
2261   * @param  NewState: new state of the TIM interrupts.\r
2262   *   This parameter can be: ENABLE or DISABLE.\r
2263   * @retval None\r
2264   */\r
2265 void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState)\r
2266 {  \r
2267   /* Check the parameters */\r
2268   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
2269   assert_param(IS_TIM_IT(TIM_IT));\r
2270   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
2271   \r
2272   if (NewState != DISABLE)\r
2273   {\r
2274     /* Enable the Interrupt sources */\r
2275     TIMx->DIER |= TIM_IT;\r
2276   }\r
2277   else\r
2278   {\r
2279     /* Disable the Interrupt sources */\r
2280     TIMx->DIER &= (uint16_t)~TIM_IT;\r
2281   }\r
2282 }\r
2283 \r
2284 /**\r
2285   * @brief  Configures the TIMx event to be generate by software.\r
2286   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 or 17 to select the \r
2287   *         TIM peripheral.\r
2288   * @param  TIM_EventSource: specifies the event source.\r
2289   *   This parameter can be one or more of the following values:  \r
2290   *     @arg TIM_EventSource_Update: Timer update Event source\r
2291   *     @arg TIM_EventSource_CC1: Timer Capture Compare 1 Event source\r
2292   *     @arg TIM_EventSource_CC2: Timer Capture Compare 2 Event source\r
2293   *     @arg TIM_EventSource_CC3: Timer Capture Compare 3 Event source\r
2294   *     @arg TIM_EventSource_CC4: Timer Capture Compare 4 Event source\r
2295   *     @arg TIM_EventSource_COM: Timer COM event source  \r
2296   *     @arg TIM_EventSource_Trigger: Timer Trigger Event source\r
2297   *     @arg TIM_EventSource_Break: Timer Break event source\r
2298   * @note \r
2299   *   - TIM6 can only generate an update event. \r
2300   *   - TIM9 can only generate an update event, Capture Compare 1 event, \r
2301   *     Capture Compare 2 event and TIM_EventSource_Trigger.  \r
2302   *   - TIM_EventSource_COM and TIM_EventSource_Break are used only with TIM1.          \r
2303   * @retval None\r
2304   */\r
2305 void TIM_GenerateEvent(TIM_TypeDef* TIMx, uint16_t TIM_EventSource)\r
2306\r
2307   /* Check the parameters */\r
2308   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
2309   assert_param(IS_TIM_EVENT_SOURCE(TIM_EventSource)); \r
2310   /* Set the event sources */\r
2311   TIMx->EGR = TIM_EventSource;\r
2312 }\r
2313 \r
2314 /**\r
2315   * @brief  Checks whether the specified TIM flag is set or not.\r
2316   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 or 17 to select the TIM peripheral.\r
2317   * @param  TIM_FLAG: specifies the flag to check.\r
2318   *   This parameter can be one of the following values:\r
2319   *     @arg TIM_FLAG_Update: TIM update Flag\r
2320   *     @arg TIM_FLAG_CC1: TIM Capture Compare 1 Flag\r
2321   *     @arg TIM_FLAG_CC2: TIM Capture Compare 2 Flag\r
2322   *     @arg TIM_FLAG_CC3: TIM Capture Compare 3 Flag\r
2323   *     @arg TIM_FLAG_CC4: TIM Capture Compare 4 Flag\r
2324   *     @arg TIM_FLAG_COM: TIM Commutation Flag\r
2325   *     @arg TIM_FLAG_Trigger: TIM Trigger Flag\r
2326   *     @arg TIM_FLAG_Break: TIM Break Flag\r
2327   *     @arg TIM_FLAG_CC1OF: TIM Capture Compare 1 overcapture Flag\r
2328   *     @arg TIM_FLAG_CC2OF: TIM Capture Compare 2 overcapture Flag\r
2329   *     @arg TIM_FLAG_CC3OF: TIM Capture Compare 3 overcapture Flag\r
2330   *     @arg TIM_FLAG_CC4OF: TIM Capture Compare 4 overcapture Flag\r
2331   * @note\r
2332   *   - TIM6 can have only one update flag. \r
2333   *   - TIM15 can have only TIM_FLAG_Update, TIM_FLAG_CC1, TIM_FLAG_CC2 or \r
2334   *     TIM_FLAG_Trigger. \r
2335   *   - TIM14, TIM16 and TIM17 can have TIM_FLAG_Update or TIM_FLAG_CC1.   \r
2336   *   - TIM_FLAG_Break is used only with TIM1 and TIM15. \r
2337   *   - TIM_FLAG_COM is used only with TIM1 TIM15, TIM16 and TIM17.        \r
2338   * @retval The new state of TIM_FLAG (SET or RESET).\r
2339   */\r
2340 FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, uint16_t TIM_FLAG)\r
2341\r
2342   ITStatus bitstatus = RESET; \r
2343    \r
2344   /* Check the parameters */\r
2345   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
2346   assert_param(IS_TIM_GET_FLAG(TIM_FLAG));\r
2347   \r
2348   if ((TIMx->SR & TIM_FLAG) != (uint16_t)RESET)\r
2349   {\r
2350     bitstatus = SET;\r
2351   }\r
2352   else\r
2353   {\r
2354     bitstatus = RESET;\r
2355   }\r
2356   return bitstatus;\r
2357 }\r
2358 \r
2359 /**\r
2360   * @brief  Clears the TIMx's pending flags.\r
2361   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 or 17 to select the TIM peripheral.\r
2362   * @param  TIM_FLAG: specifies the flag bit to clear.\r
2363   *   This parameter can be any combination of the following values:\r
2364   *     @arg TIM_FLAG_Update: TIM update Flag\r
2365   *     @arg TIM_FLAG_CC1: TIM Capture Compare 1 Flag\r
2366   *     @arg TIM_FLAG_CC2: TIM Capture Compare 2 Flag\r
2367   *     @arg TIM_FLAG_CC3: TIM Capture Compare 3 Flag\r
2368   *     @arg TIM_FLAG_CC4: TIM Capture Compare 4 Flag\r
2369   *     @arg TIM_FLAG_COM: TIM Commutation Flag\r
2370   *     @arg TIM_FLAG_Trigger: TIM Trigger Flag\r
2371   *     @arg TIM_FLAG_Break: TIM Break Flag\r
2372   *     @arg TIM_FLAG_CC1OF: TIM Capture Compare 1 overcapture Flag\r
2373   *     @arg TIM_FLAG_CC2OF: TIM Capture Compare 2 overcapture Flag\r
2374   *     @arg TIM_FLAG_CC3OF: TIM Capture Compare 3 overcapture Flag\r
2375   *     @arg TIM_FLAG_CC4OF: TIM Capture Compare 4 overcapture Flag\r
2376   * @note\r
2377   *   - TIM6 can have only one update flag. \r
2378   *   - TIM15 can have only TIM_FLAG_Update, TIM_FLAG_CC1,TIM_FLAG_CC2 or \r
2379   *     TIM_FLAG_Trigger. \r
2380   *   - TIM14, TIM16 and TIM17 can have TIM_FLAG_Update or TIM_FLAG_CC1.   \r
2381   *   - TIM_FLAG_Break is used only with TIM1 and TIM15. \r
2382   *   - TIM_FLAG_COM is used only with TIM1, TIM15, TIM16 and TIM17.\r
2383   * @retval None\r
2384   */\r
2385 void TIM_ClearFlag(TIM_TypeDef* TIMx, uint16_t TIM_FLAG)\r
2386 {  \r
2387   /* Check the parameters */\r
2388   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
2389   assert_param(IS_TIM_CLEAR_FLAG(TIM_FLAG));\r
2390    \r
2391   /* Clear the flags */\r
2392   TIMx->SR = (uint16_t)~TIM_FLAG;\r
2393 }\r
2394 \r
2395 /**\r
2396   * @brief  Checks whether the TIM interrupt has occurred or not.\r
2397   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 or 17 to select the TIM peripheral.\r
2398   * @param  TIM_IT: specifies the TIM interrupt source to check.\r
2399   *   This parameter can be one of the following values:\r
2400   *     @arg TIM_IT_Update: TIM update Interrupt source\r
2401   *     @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source\r
2402   *     @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source\r
2403   *     @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source\r
2404   *     @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source\r
2405   *     @arg TIM_IT_COM: TIM Commutation Interrupt source\r
2406   *     @arg TIM_IT_Trigger: TIM Trigger Interrupt source\r
2407   *     @arg TIM_IT_Break: TIM Break Interrupt source\r
2408   * @note\r
2409   *   - TIM6 can generate only an update interrupt.\r
2410   *   - TIM15 can have only TIM_IT_Update, TIM_IT_CC1, TIM_IT_CC2 or TIM_IT_Trigger. \r
2411   *   - TIM14, TIM16 and TIM17 can have TIM_IT_Update or TIM_IT_CC1.   \r
2412   *   - TIM_IT_Break is used only with TIM1 and TIM15. \r
2413   *   - TIM_IT_COM is used only with TIM1, TIM15, TIM16 and TIM17.\r
2414   * @retval The new state of the TIM_IT(SET or RESET).\r
2415   */\r
2416 ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t TIM_IT)\r
2417 {\r
2418   ITStatus bitstatus = RESET;  \r
2419   uint16_t itstatus = 0x0, itenable = 0x0;\r
2420   \r
2421   /* Check the parameters */\r
2422   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
2423   assert_param(IS_TIM_GET_IT(TIM_IT));\r
2424    \r
2425   itstatus = TIMx->SR & TIM_IT;\r
2426   \r
2427   itenable = TIMx->DIER & TIM_IT;\r
2428   if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))\r
2429   {\r
2430     bitstatus = SET;\r
2431   }\r
2432   else\r
2433   {\r
2434     bitstatus = RESET;\r
2435   }\r
2436   return bitstatus;\r
2437 }\r
2438 \r
2439 /**\r
2440   * @brief  Clears the TIMx's interrupt pending bits.\r
2441   * @param  TIMx: where x can be 1, 2, 3, 6, 14, 15, 16 or 17 to select the TIM peripheral.\r
2442   * @param  TIM_IT: specifies the pending bit to clear.\r
2443   *   This parameter can be any combination of the following values:\r
2444   *     @arg TIM_IT_Update: TIM1 update Interrupt source\r
2445   *     @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source\r
2446   *     @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source\r
2447   *     @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source\r
2448   *     @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source\r
2449   *     @arg TIM_IT_COM: TIM Commutation Interrupt source\r
2450   *     @arg TIM_IT_Trigger: TIM Trigger Interrupt source\r
2451   *     @arg TIM_IT_Break: TIM Break Interrupt source\r
2452   * @note\r
2453   *   - TIM6 can generate only an update interrupt.\r
2454   *   - TIM15 can have only TIM_IT_Update, TIM_IT_CC1, TIM_IT_CC2 or TIM_IT_Trigger. \r
2455   *   - TIM14, TIM16 and TIM17 can have TIM_IT_Update or TIM_IT_CC1.   \r
2456   *   - TIM_IT_Break is used only with TIM1 and TIM15. \r
2457   *   - TIM_IT_COM is used only with TIM1, TIM15, TIM16 and TIM17.\r
2458   * @retval None\r
2459   */\r
2460 void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, uint16_t TIM_IT)\r
2461 {\r
2462   /* Check the parameters */\r
2463   assert_param(IS_TIM_ALL_PERIPH(TIMx));\r
2464   assert_param(IS_TIM_IT(TIM_IT));\r
2465    \r
2466   /* Clear the IT pending Bit */\r
2467   TIMx->SR = (uint16_t)~TIM_IT;\r
2468 }\r
2469 \r
2470 /**\r
2471   * @brief  Configures the TIMx's DMA interface.\r
2472   * @param  TIMx: where x can be 1, 2, 3, 15, 16 or 17  to select the TIM peripheral.\r
2473   * @param  TIM_DMABase: DMA Base address.\r
2474   *   This parameter can be one of the following values:\r
2475   *     @arg TIM_DMABase_CR1, TIM_DMABase_CR2, TIM_DMABase_SMCR,\r
2476   *          TIM_DMABase_DIER, TIM_DMABase_SR, TIM_DMABase_EGR,\r
2477   *          TIM_DMABase_CCMR1, TIM_DMABase_CCMR2, TIM_DMABase_CCER,\r
2478   *          TIM_DMABase_CNT, TIM_DMABase_PSC, TIM_DMABase_ARR,\r
2479   *          TIM_DMABase_CCR1, TIM_DMABase_CCR2, TIM_DMABase_CCR3, \r
2480   *          TIM_DMABase_CCR4, TIM_DMABase_DCR, TIM_DMABase_OR.\r
2481   * @param  TIM_DMABurstLength: DMA Burst length.\r
2482   *   This parameter can be one value between:\r
2483   *   TIM_DMABurstLength_1Transfer and TIM_DMABurstLength_18Transfers.\r
2484   * @retval None\r
2485   */\r
2486 void TIM_DMAConfig(TIM_TypeDef* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength)\r
2487 {\r
2488   /* Check the parameters */\r
2489   assert_param(IS_TIM_LIST4_PERIPH(TIMx));\r
2490   assert_param(IS_TIM_DMA_BASE(TIM_DMABase)); \r
2491   assert_param(IS_TIM_DMA_LENGTH(TIM_DMABurstLength));\r
2492   /* Set the DMA Base and the DMA Burst Length */\r
2493   TIMx->DCR = TIM_DMABase | TIM_DMABurstLength;\r
2494 }\r
2495 \r
2496 /**\r
2497   * @brief  Enables or disables the TIMx's DMA Requests.\r
2498   * @param  TIMx: where x can be 1, 2, 3, 6, 15, 16 or 17 to select the TIM peripheral. \r
2499   * @param  TIM_DMASource: specifies the DMA Request sources.\r
2500   *   This parameter can be any combination of the following values:\r
2501   *     @arg TIM_DMA_Update: TIM update Interrupt source\r
2502   *     @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source\r
2503   *     @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source\r
2504   *     @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source\r
2505   *     @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source\r
2506   *     @arg TIM_DMA_COM: TIM Commutation DMA source\r
2507   *     @arg TIM_DMA_Trigger: TIM Trigger DMA source\r
2508   * @param  NewState: new state of the DMA Request sources.\r
2509   *   This parameter can be: ENABLE or DISABLE.\r
2510   * @retval None\r
2511   */\r
2512 void TIM_DMACmd(TIM_TypeDef* TIMx, uint16_t TIM_DMASource, FunctionalState NewState)\r
2513\r
2514   /* Check the parameters */\r
2515   assert_param(IS_TIM_LIST10_PERIPH(TIMx));\r
2516   assert_param(IS_TIM_DMA_SOURCE(TIM_DMASource));\r
2517   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
2518   \r
2519   if (NewState != DISABLE)\r
2520   {\r
2521     /* Enable the DMA sources */\r
2522     TIMx->DIER |= TIM_DMASource; \r
2523   }\r
2524   else\r
2525   {\r
2526     /* Disable the DMA sources */\r
2527     TIMx->DIER &= (uint16_t)~TIM_DMASource;\r
2528   }\r
2529 }\r
2530 \r
2531 /**\r
2532   * @brief  Selects the TIMx peripheral Capture Compare DMA source.\r
2533   * @param  TIMx: where x can be 1, 2, 3, 15, 16 or 17  to select the TIM peripheral.\r
2534   * @param  NewState: new state of the Capture Compare DMA source\r
2535   *   This parameter can be: ENABLE or DISABLE.\r
2536   * @retval None\r
2537   */\r
2538 void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState NewState)\r
2539 {\r
2540   /* Check the parameters */\r
2541   assert_param(IS_TIM_LIST5_PERIPH(TIMx));\r
2542   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
2543   \r
2544   if (NewState != DISABLE)\r
2545   {\r
2546     /* Set the CCDS Bit */\r
2547     TIMx->CR2 |= TIM_CR2_CCDS;\r
2548   }\r
2549   else\r
2550   {\r
2551     /* Reset the CCDS Bit */\r
2552     TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_CCDS);\r
2553   }\r
2554 }\r
2555 \r
2556 /**\r
2557   * @}\r
2558   */\r
2559 \r
2560 /** @defgroup TIM_Group6 Clocks management functions\r
2561  *  @brief    Clocks management functions\r
2562  *\r
2563 @verbatim\r
2564  ===============================================================================\r
2565                      ##### Clocks management functions #####\r
2566  ===============================================================================\r
2567 \r
2568 @endverbatim\r
2569   * @{\r
2570   */\r
2571 \r
2572 /**\r
2573   * @brief  Configures the TIMx internal Clock\r
2574   * @param  TIMx: where x can be 1, 2, 3, or 15 to select the TIM peripheral.\r
2575   * @retval None\r
2576   */\r
2577 void TIM_InternalClockConfig(TIM_TypeDef* TIMx)\r
2578 {\r
2579   /* Check the parameters */\r
2580   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
2581   /* Disable slave mode to clock the prescaler directly with the internal clock */\r
2582   TIMx->SMCR &=  (uint16_t)(~((uint16_t)TIM_SMCR_SMS));\r
2583 }\r
2584 \r
2585 /**\r
2586   * @brief  Configures the TIMx Internal Trigger as External Clock\r
2587   * @param  TIMx: where x can be 1, 2, 3, or 15 to select the TIM peripheral.\r
2588   * @param  TIM_ITRSource: Trigger source.\r
2589   *   This parameter can be one of the following values:\r
2590   *   @arg  TIM_TS_ITR0: Internal Trigger 0\r
2591   *   @arg  TIM_TS_ITR1: Internal Trigger 1\r
2592   *   @arg  TIM_TS_ITR2: Internal Trigger 2\r
2593   *   @arg  TIM_TS_ITR3: Internal Trigger 3\r
2594   * @retval None\r
2595   */\r
2596 void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource)\r
2597 {\r
2598   /* Check the parameters */\r
2599   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
2600   assert_param(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource));\r
2601   /* Select the Internal Trigger */\r
2602   TIM_SelectInputTrigger(TIMx, TIM_InputTriggerSource);\r
2603   /* Select the External clock mode1 */\r
2604   TIMx->SMCR |= TIM_SlaveMode_External1;\r
2605 }\r
2606 \r
2607 /**\r
2608   * @brief  Configures the TIMx Trigger as External Clock\r
2609   * @param  TIMx: where x can be 1, 2, 3, or 15 to select the TIM peripheral.\r
2610   * @param  TIM_TIxExternalCLKSource: Trigger source.\r
2611   *   This parameter can be one of the following values:\r
2612   *     @arg TIM_TIxExternalCLK1Source_TI1ED: TI1 Edge Detector\r
2613   *     @arg TIM_TIxExternalCLK1Source_TI1: Filtered Timer Input 1\r
2614   *     @arg TIM_TIxExternalCLK1Source_TI2: Filtered Timer Input 2\r
2615   * @param  TIM_ICPolarity: specifies the TIx Polarity.\r
2616   *   This parameter can be one of the following values:\r
2617   *     @arg TIM_ICPolarity_Rising\r
2618   *     @arg TIM_ICPolarity_Falling\r
2619   * @param  ICFilter : specifies the filter value.\r
2620   *   This parameter must be a value between 0x0 and 0xF.\r
2621   * @retval None\r
2622   */\r
2623 void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_TIxExternalCLKSource,\r
2624                                 uint16_t TIM_ICPolarity, uint16_t ICFilter)\r
2625 {\r
2626   /* Check the parameters */\r
2627   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
2628   assert_param(IS_TIM_IC_POLARITY(TIM_ICPolarity));\r
2629   assert_param(IS_TIM_IC_FILTER(ICFilter));\r
2630   \r
2631   /* Configure the Timer Input Clock Source */\r
2632   if (TIM_TIxExternalCLKSource == TIM_TIxExternalCLK1Source_TI2)\r
2633   {\r
2634     TI2_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);\r
2635   }\r
2636   else\r
2637   {\r
2638     TI1_Config(TIMx, TIM_ICPolarity, TIM_ICSelection_DirectTI, ICFilter);\r
2639   }\r
2640   /* Select the Trigger source */\r
2641   TIM_SelectInputTrigger(TIMx, TIM_TIxExternalCLKSource);\r
2642   /* Select the External clock mode1 */\r
2643   TIMx->SMCR |= TIM_SlaveMode_External1;\r
2644 }\r
2645 \r
2646 /**\r
2647   * @brief  Configures the External clock Mode1\r
2648   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
2649   * @param  TIM_ExtTRGPrescaler: The external Trigger Prescaler.\r
2650   *   This parameter can be one of the following values:\r
2651   *     @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.\r
2652   *     @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.\r
2653   *     @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.\r
2654   *     @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.\r
2655   * @param  TIM_ExtTRGPolarity: The external Trigger Polarity.\r
2656   *   This parameter can be one of the following values:\r
2657   *     @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.\r
2658   *     @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.\r
2659   * @param  ExtTRGFilter: External Trigger Filter.\r
2660   *   This parameter must be a value between 0x00 and 0x0F\r
2661   * @retval None\r
2662   */\r
2663 void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,\r
2664                              uint16_t ExtTRGFilter)\r
2665 {\r
2666   uint16_t tmpsmcr = 0;\r
2667   \r
2668   /* Check the parameters */\r
2669   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
2670   assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));\r
2671   assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));\r
2672   assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));\r
2673   \r
2674   /* Configure the ETR Clock source */\r
2675   TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);\r
2676   \r
2677   /* Get the TIMx SMCR register value */\r
2678   tmpsmcr = TIMx->SMCR;\r
2679   /* Reset the SMS Bits */\r
2680   tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS));\r
2681   /* Select the External clock mode1 */\r
2682   tmpsmcr |= TIM_SlaveMode_External1;\r
2683   /* Select the Trigger selection : ETRF */\r
2684   tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_TS));\r
2685   tmpsmcr |= TIM_TS_ETRF;\r
2686   /* Write to TIMx SMCR */\r
2687   TIMx->SMCR = tmpsmcr;\r
2688 }\r
2689 \r
2690 /**\r
2691   * @brief  Configures the External clock Mode2\r
2692   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
2693   * @param  TIM_ExtTRGPrescaler: The external Trigger Prescaler.\r
2694   *   This parameter can be one of the following values:\r
2695   *     @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.\r
2696   *     @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.\r
2697   *     @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.\r
2698   *     @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.\r
2699   * @param  TIM_ExtTRGPolarity: The external Trigger Polarity.\r
2700   *   This parameter can be one of the following values:\r
2701   *     @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.\r
2702   *     @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.\r
2703   * @param  ExtTRGFilter: External Trigger Filter.\r
2704   *   This parameter must be a value between 0x00 and 0x0F\r
2705   * @retval None\r
2706   */\r
2707 void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, \r
2708                              uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter)\r
2709 {\r
2710   /* Check the parameters */\r
2711   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
2712   assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));\r
2713   assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));\r
2714   assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));\r
2715   \r
2716   /* Configure the ETR Clock source */\r
2717   TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);\r
2718   /* Enable the External clock mode2 */\r
2719   TIMx->SMCR |= TIM_SMCR_ECE;\r
2720 }\r
2721 \r
2722 /**\r
2723   * @}\r
2724   */\r
2725 \r
2726 /** @defgroup TIM_Group7 Synchronization management functions\r
2727  *  @brief    Synchronization management functions \r
2728  *\r
2729 @verbatim\r
2730  ===============================================================================\r
2731                ##### Synchronization management functions #####\r
2732  ===============================================================================\r
2733         *** TIM Driver: how to use it in synchronization Mode ***\r
2734  ===============================================================================\r
2735     [..] Case of two/several Timers\r
2736          (#) Configure the Master Timers using the following functions:\r
2737              (++) void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx,\r
2738                   uint16_t TIM_TRGOSource).\r
2739              (++) void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx,\r
2740                   uint16_t TIM_MasterSlaveMode);  \r
2741          (#) Configure the Slave Timers using the following functions: \r
2742              (++) void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, \r
2743                   uint16_t TIM_InputTriggerSource);  \r
2744              (++) void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode);\r
2745     [..] Case of Timers and external trigger(ETR pin)\r
2746          (#) Configure the Etrenal trigger using this function:\r
2747              (++) void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler,\r
2748                   uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter);\r
2749          (#) Configure the Slave Timers using the following functions:\r
2750              (++) void TIM_SelectInputTrigger(TIM_TypeDef* TIMx,\r
2751                   uint16_t TIM_InputTriggerSource);\r
2752              (++) void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode);\r
2753 \r
2754 @endverbatim\r
2755   * @{\r
2756   */\r
2757 /**\r
2758   * @brief  Selects the Input Trigger source\r
2759   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
2760   * @param  TIM_InputTriggerSource: The Input Trigger source.\r
2761   *   This parameter can be one of the following values:\r
2762   *     @arg TIM_TS_ITR0: Internal Trigger 0\r
2763   *     @arg TIM_TS_ITR1: Internal Trigger 1\r
2764   *     @arg TIM_TS_ITR2: Internal Trigger 2\r
2765   *     @arg TIM_TS_ITR3: Internal Trigger 3\r
2766   *     @arg TIM_TS_TI1F_ED: TI1 Edge Detector\r
2767   *     @arg TIM_TS_TI1FP1: Filtered Timer Input 1\r
2768   *     @arg TIM_TS_TI2FP2: Filtered Timer Input 2\r
2769   *     @arg TIM_TS_ETRF: External Trigger input\r
2770   * @retval None\r
2771   */\r
2772 void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource)\r
2773 {\r
2774   uint16_t tmpsmcr = 0;\r
2775 \r
2776   /* Check the parameters */\r
2777   assert_param(IS_TIM_LIST6_PERIPH(TIMx)); \r
2778   assert_param(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource));\r
2779 \r
2780   /* Get the TIMx SMCR register value */\r
2781   tmpsmcr = TIMx->SMCR;\r
2782   /* Reset the TS Bits */\r
2783   tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_TS));\r
2784   /* Set the Input Trigger source */\r
2785   tmpsmcr |= TIM_InputTriggerSource;\r
2786   /* Write to TIMx SMCR */\r
2787   TIMx->SMCR = tmpsmcr;\r
2788 }\r
2789 \r
2790 /**\r
2791   * @brief  Selects the TIMx Trigger Output Mode.\r
2792   * @param  TIMx: where x can be 1, 2, 3, 6, or 15 to select the TIM peripheral.\r
2793   * @param  TIM_TRGOSource: specifies the Trigger Output source.\r
2794   *   This paramter can be one of the following values:\r
2795   *\r
2796   *   For all TIMx\r
2797   *     @arg TIM_TRGOSource_Reset:  The UG bit in the TIM_EGR register is used as the trigger output (TRGO).\r
2798   *     @arg TIM_TRGOSource_Enable: The Counter Enable CEN is used as the trigger output (TRGO).\r
2799   *     @arg TIM_TRGOSource_Update: The update event is selected as the trigger output (TRGO).\r
2800   *\r
2801   *   For all TIMx except TIM6 \r
2802   *     @arg TIM_TRGOSource_OC1: The trigger output sends a positive pulse when the CC1IF flag\r
2803   *                              is to be set, as soon as a capture or compare match occurs (TRGO).\r
2804   *     @arg TIM_TRGOSource_OC1Ref: OC1REF signal is used as the trigger output (TRGO).\r
2805   *     @arg TIM_TRGOSource_OC2Ref: OC2REF signal is used as the trigger output (TRGO).\r
2806   *     @arg TIM_TRGOSource_OC3Ref: OC3REF signal is used as the trigger output (TRGO).\r
2807   *     @arg TIM_TRGOSource_OC4Ref: OC4REF signal is used as the trigger output (TRGO).\r
2808   *\r
2809   * @retval None\r
2810   */\r
2811 void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource)\r
2812 {\r
2813   /* Check the parameters */\r
2814   assert_param(IS_TIM_LIST9_PERIPH(TIMx));\r
2815   assert_param(IS_TIM_TRGO_SOURCE(TIM_TRGOSource));\r
2816 \r
2817   /* Reset the MMS Bits */\r
2818   TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_MMS);\r
2819   /* Select the TRGO source */\r
2820   TIMx->CR2 |=  TIM_TRGOSource;\r
2821 }\r
2822 \r
2823 /**\r
2824   * @brief  Selects the TIMx Slave Mode.\r
2825   * @param  TIMx: where x can be 1, 2, 3 or 15 to select the TIM peripheral.\r
2826   * @param  TIM_SlaveMode: specifies the Timer Slave Mode.\r
2827   *   This paramter can be one of the following values:\r
2828   *     @arg TIM_SlaveMode_Reset: Rising edge of the selected trigger signal (TRGI) re-initializes\r
2829   *                               the counter and triggers an update of the registers.\r
2830   *     @arg TIM_SlaveMode_Gated:     The counter clock is enabled when the trigger signal (TRGI) is high.\r
2831   *     @arg TIM_SlaveMode_Trigger:   The counter starts at a rising edge of the trigger TRGI.\r
2832   *     @arg TIM_SlaveMode_External1: Rising edges of the selected trigger (TRGI) clock the counter.\r
2833   * @retval None\r
2834   */\r
2835 void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode)\r
2836 {\r
2837   /* Check the parameters */\r
2838   assert_param(IS_TIM_LIST6_PERIPH(TIMx)); \r
2839   assert_param(IS_TIM_SLAVE_MODE(TIM_SlaveMode));\r
2840   \r
2841   /* Reset the SMS Bits */\r
2842   TIMx->SMCR &= (uint16_t)~((uint16_t)TIM_SMCR_SMS);\r
2843   /* Select the Slave Mode */\r
2844   TIMx->SMCR |= TIM_SlaveMode;\r
2845 }\r
2846 \r
2847 /**\r
2848   * @brief  Sets or Resets the TIMx Master/Slave Mode.\r
2849   * @param  TIMx: where x can be 1, 2, 3, or 15 to select the TIM peripheral.\r
2850   * @param  TIM_MasterSlaveMode: specifies the Timer Master Slave Mode.\r
2851   *   This paramter can be one of the following values:\r
2852   *     @arg TIM_MasterSlaveMode_Enable: synchronization between the current timer\r
2853   *                                      and its slaves (through TRGO).\r
2854   *     @arg TIM_MasterSlaveMode_Disable: No action\r
2855   * @retval None\r
2856   */\r
2857 void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_MasterSlaveMode)\r
2858 {\r
2859   /* Check the parameters */\r
2860   assert_param(IS_TIM_LIST6_PERIPH(TIMx));\r
2861   assert_param(IS_TIM_MSM_STATE(TIM_MasterSlaveMode));\r
2862   \r
2863   /* Reset the MSM Bit */\r
2864   TIMx->SMCR &= (uint16_t)~((uint16_t)TIM_SMCR_MSM);\r
2865   \r
2866   /* Set or Reset the MSM Bit */\r
2867   TIMx->SMCR |= TIM_MasterSlaveMode;\r
2868 }\r
2869 \r
2870 /**\r
2871   * @brief  Configures the TIMx External Trigger (ETR).\r
2872   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
2873   * @param  TIM_ExtTRGPrescaler: The external Trigger Prescaler.\r
2874   *   This parameter can be one of the following values:\r
2875   *     @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.\r
2876   *     @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.\r
2877   *     @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.\r
2878   *     @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.\r
2879   * @param  TIM_ExtTRGPolarity: The external Trigger Polarity.\r
2880   *   This parameter can be one of the following values:\r
2881   *     @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.\r
2882   *     @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.\r
2883   * @param  ExtTRGFilter: External Trigger Filter.\r
2884   *   This parameter must be a value between 0x00 and 0x0F\r
2885   * @retval None\r
2886   */\r
2887 void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,\r
2888                    uint16_t ExtTRGFilter)\r
2889 {\r
2890   uint16_t tmpsmcr = 0;\r
2891   \r
2892   /* Check the parameters */\r
2893   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
2894   assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));\r
2895   assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));\r
2896   assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter));\r
2897   \r
2898   tmpsmcr = TIMx->SMCR;\r
2899   /* Reset the ETR Bits */\r
2900   tmpsmcr &= SMCR_ETR_MASK;\r
2901   /* Set the Prescaler, the Filter value and the Polarity */\r
2902   tmpsmcr |= (uint16_t)(TIM_ExtTRGPrescaler | (uint16_t)(TIM_ExtTRGPolarity | (uint16_t)(ExtTRGFilter << (uint16_t)8)));\r
2903   /* Write to TIMx SMCR */\r
2904   TIMx->SMCR = tmpsmcr;\r
2905 }\r
2906 \r
2907 /**\r
2908   * @}\r
2909   */\r
2910 \r
2911 /** @defgroup TIM_Group8 Specific interface management functions\r
2912  *  @brief    Specific interface management functions \r
2913  *\r
2914 @verbatim\r
2915  ===============================================================================\r
2916              ##### Specific interface management functions #####\r
2917  ===============================================================================\r
2918 \r
2919 @endverbatim\r
2920   * @{\r
2921   */\r
2922 \r
2923 /**\r
2924   * @brief  Configures the TIMx Encoder Interface.\r
2925   * @param  TIMx: where x can be  1, 2 or 3 to select the TIM peripheral.\r
2926   * @param  TIM_EncoderMode: specifies the TIMx Encoder Mode.\r
2927   *   This parameter can be one of the following values:\r
2928   *     @arg TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge depending on TI2FP2 level.\r
2929   *     @arg TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge depending on TI1FP1 level.\r
2930   *     @arg TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and TI2FP2 edges depending\r
2931   *                                on the level of the other input.\r
2932   * @param  TIM_IC1Polarity: specifies the IC1 Polarity\r
2933   *   This parmeter can be one of the following values:\r
2934   *     @arg TIM_ICPolarity_Falling: IC Falling edge.\r
2935   *     @arg TIM_ICPolarity_Rising: IC Rising edge.\r
2936   * @param  TIM_IC2Polarity: specifies the IC2 Polarity\r
2937   *   This parmeter can be one of the following values:\r
2938   *     @arg TIM_ICPolarity_Falling: IC Falling edge.\r
2939   *     @arg TIM_ICPolarity_Rising: IC Rising edge.\r
2940   * @retval None\r
2941   */\r
2942 void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode,\r
2943                                 uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity)\r
2944 {\r
2945   uint16_t tmpsmcr = 0;\r
2946   uint16_t tmpccmr1 = 0;\r
2947   uint16_t tmpccer = 0;\r
2948     \r
2949   /* Check the parameters */\r
2950   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
2951   assert_param(IS_TIM_ENCODER_MODE(TIM_EncoderMode));\r
2952   assert_param(IS_TIM_IC_POLARITY(TIM_IC1Polarity));\r
2953   assert_param(IS_TIM_IC_POLARITY(TIM_IC2Polarity));\r
2954   \r
2955   /* Get the TIMx SMCR register value */\r
2956   tmpsmcr = TIMx->SMCR;\r
2957   /* Get the TIMx CCMR1 register value */\r
2958   tmpccmr1 = TIMx->CCMR1;\r
2959   /* Get the TIMx CCER register value */\r
2960   tmpccer = TIMx->CCER;\r
2961   /* Set the encoder Mode */\r
2962   tmpsmcr &= (uint16_t)(~((uint16_t)TIM_SMCR_SMS));\r
2963   tmpsmcr |= TIM_EncoderMode;\r
2964   /* Select the Capture Compare 1 and the Capture Compare 2 as input */\r
2965   tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC1S)) & (uint16_t)(~((uint16_t)TIM_CCMR1_CC2S)));\r
2966   tmpccmr1 |= TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;\r
2967   /* Set the TI1 and the TI2 Polarities */\r
2968   tmpccer &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCER_CC1P)) & ((uint16_t)~((uint16_t)TIM_CCER_CC2P)));\r
2969    tmpccer |= (uint16_t)(TIM_IC1Polarity | (uint16_t)(TIM_IC2Polarity << (uint16_t)4));\r
2970   /* Write to TIMx SMCR */\r
2971   TIMx->SMCR = tmpsmcr;\r
2972   /* Write to TIMx CCMR1 */\r
2973   TIMx->CCMR1 = tmpccmr1;\r
2974   /* Write to TIMx CCER */\r
2975   TIMx->CCER = tmpccer;\r
2976 }\r
2977 \r
2978 /**\r
2979   * @brief  Enables or disables the TIMx's Hall sensor interface.\r
2980   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
2981   * @param  NewState: new state of the TIMx Hall sensor interface.\r
2982   *   This parameter can be: ENABLE or DISABLE.\r
2983   * @retval None\r
2984   */\r
2985 void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState NewState)\r
2986 {\r
2987   /* Check the parameters */\r
2988   assert_param(IS_TIM_LIST3_PERIPH(TIMx));\r
2989   assert_param(IS_FUNCTIONAL_STATE(NewState));\r
2990   \r
2991   if (NewState != DISABLE)\r
2992   {\r
2993     /* Set the TI1S Bit */\r
2994     TIMx->CR2 |= TIM_CR2_TI1S;\r
2995   }\r
2996   else\r
2997   {\r
2998     /* Reset the TI1S Bit */\r
2999     TIMx->CR2 &= (uint16_t)~((uint16_t)TIM_CR2_TI1S);\r
3000   }\r
3001 }\r
3002 \r
3003 /**\r
3004   * @}\r
3005   */\r
3006 \r
3007 /** @defgroup TIM_Group9 Specific remapping management function\r
3008  *  @brief   Specific remapping management function\r
3009  *\r
3010 @verbatim\r
3011  ===============================================================================\r
3012                ##### Specific remapping management function #####\r
3013  ===============================================================================\r
3014 \r
3015 @endverbatim\r
3016   * @{\r
3017   */\r
3018 /**\r
3019   * @brief  Configures the TIM14 Remapping input Capabilities.\r
3020   * @param TIMx: where x can be 14 to select the TIM peripheral.\r
3021   * @param TIM_Remap: specifies the TIM input reampping source.\r
3022   *   This parameter can be one of the following values:\r
3023   *   @arg TIM14_GPIO     : TIM14 Channel 1 is connected to GPIO.\r
3024   *   @arg TIM14_RTC_CLK  : TIM14 Channel 1 is connected to RTC input clock.\r
3025   *                       RTC input clock can be LSE, LSI or HSE/div128.\r
3026   * @retval : None\r
3027   */\r
3028 void TIM_RemapConfig(TIM_TypeDef* TIMx, uint16_t TIM_Remap)\r
3029 {\r
3030  /* Check the parameters */\r
3031   assert_param(IS_TIM_LIST11_PERIPH(TIMx));\r
3032   assert_param(IS_TIM_REMAP(TIM_Remap));\r
3033 \r
3034   /* Set the Timer remapping configuration */\r
3035   TIMx->OR =  TIM_Remap;\r
3036 }\r
3037 \r
3038 /**\r
3039   * @}\r
3040   */\r
3041 \r
3042 /**\r
3043   * @brief  Configure the TI1 as Input.\r
3044   * @param  TIMx: where x can be 1, 2, 3, 14, 15, 16 or 17 to select the TIM peripheral.\r
3045   * @param  TIM_ICPolarity : The Input Polarity.\r
3046   *   This parameter can be one of the following values:\r
3047   *     @arg TIM_ICPolarity_Rising\r
3048   *     @arg TIM_ICPolarity_Falling\r
3049   * @param  TIM_ICSelection: specifies the input to be used.\r
3050   *   This parameter can be one of the following values:\r
3051   *     @arg TIM_ICSelection_DirectTI: TIM Input 1 is selected to be connected to IC1.\r
3052   *     @arg TIM_ICSelection_IndirectTI: TIM Input 1 is selected to be connected to IC2.\r
3053   *     @arg TIM_ICSelection_TRC: TIM Input 1 is selected to be connected to TRC.\r
3054   * @param  TIM_ICFilter: Specifies the Input Capture Filter.\r
3055   *   This parameter must be a value between 0x00 and 0x0F.\r
3056   * @retval None\r
3057   */\r
3058 static void TI1_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,\r
3059                        uint16_t TIM_ICFilter)\r
3060 {\r
3061   uint16_t tmpccmr1 = 0, tmpccer = 0;\r
3062   /* Disable the Channel 1: Reset the CC1E Bit */\r
3063   TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC1E);\r
3064   tmpccmr1 = TIMx->CCMR1;\r
3065   tmpccer = TIMx->CCER;\r
3066   /* Select the Input and set the filter */\r
3067   tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC1S)) & ((uint16_t)~((uint16_t)TIM_CCMR1_IC1F)));\r
3068   tmpccmr1 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));\r
3069  \r
3070   /* Select the Polarity and set the CC1E Bit */\r
3071   tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC1P | TIM_CCER_CC1NP));\r
3072   tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)TIM_CCER_CC1E);\r
3073   /* Write to TIMx CCMR1 and CCER registers */\r
3074   TIMx->CCMR1 = tmpccmr1;\r
3075   TIMx->CCER = tmpccer;\r
3076 }\r
3077 \r
3078 /**\r
3079   * @brief  Configure the TI2 as Input.\r
3080   * @param  TIMx: where x can be 1, 2, 3, or 15 to select the TIM peripheral.\r
3081   * @param  TIM_ICPolarity : The Input Polarity.\r
3082   *   This parameter can be one of the following values:\r
3083   *     @arg TIM_ICPolarity_Rising\r
3084   *     @arg TIM_ICPolarity_Falling\r
3085   * @param  TIM_ICSelection: specifies the input to be used.\r
3086   *   This parameter can be one of the following values:\r
3087   *     @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.\r
3088   *     @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.\r
3089   *     @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.\r
3090   * @param  TIM_ICFilter: Specifies the Input Capture Filter.\r
3091   *   This parameter must be a value between 0x00 and 0x0F.\r
3092   * @retval None\r
3093   */\r
3094 static void TI2_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,\r
3095                        uint16_t TIM_ICFilter)\r
3096 {\r
3097   uint16_t tmpccmr1 = 0, tmpccer = 0, tmp = 0;\r
3098   /* Disable the Channel 2: Reset the CC2E Bit */\r
3099   TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC2E);\r
3100   tmpccmr1 = TIMx->CCMR1;\r
3101   tmpccer = TIMx->CCER;\r
3102   tmp = (uint16_t)(TIM_ICPolarity << 4);\r
3103   /* Select the Input and set the filter */\r
3104   tmpccmr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR1_CC2S)) & ((uint16_t)~((uint16_t)TIM_CCMR1_IC2F)));\r
3105   tmpccmr1 |= (uint16_t)(TIM_ICFilter << 12);\r
3106   tmpccmr1 |= (uint16_t)(TIM_ICSelection << 8); \r
3107   /* Select the Polarity and set the CC2E Bit */\r
3108   tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC2P | TIM_CCER_CC2NP));\r
3109   tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC2E);  \r
3110   /* Write to TIMx CCMR1 and CCER registers */\r
3111   TIMx->CCMR1 = tmpccmr1 ;\r
3112   TIMx->CCER = tmpccer;\r
3113 }\r
3114 \r
3115 /**\r
3116   * @brief  Configure the TI3 as Input.\r
3117   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
3118   * @param  TIM_ICPolarity : The Input Polarity.\r
3119   *   This parameter can be one of the following values:\r
3120   *     @arg TIM_ICPolarity_Rising\r
3121   *     @arg TIM_ICPolarity_Falling\r
3122   * @param  TIM_ICSelection: specifies the input to be used.\r
3123   *   This parameter can be one of the following values:\r
3124   *     @arg TIM_ICSelection_DirectTI: TIM Input 3 is selected to be connected to IC3.\r
3125   *     @arg TIM_ICSelection_IndirectTI: TIM Input 3 is selected to be connected to IC4.\r
3126   *     @arg TIM_ICSelection_TRC: TIM Input 3 is selected to be connected to TRC.\r
3127   * @param  TIM_ICFilter: Specifies the Input Capture Filter.\r
3128   *   This parameter must be a value between 0x00 and 0x0F.\r
3129   * @retval None\r
3130   */\r
3131 static void TI3_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,\r
3132                        uint16_t TIM_ICFilter)\r
3133 {\r
3134   uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0;\r
3135   /* Disable the Channel 3: Reset the CC3E Bit */\r
3136   TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC3E);\r
3137   tmpccmr2 = TIMx->CCMR2;\r
3138   tmpccer = TIMx->CCER;\r
3139   tmp = (uint16_t)(TIM_ICPolarity << 8);\r
3140   /* Select the Input and set the filter */\r
3141   tmpccmr2 &= (uint16_t)(((uint16_t)~((uint16_t)TIM_CCMR2_CC3S)) & ((uint16_t)~((uint16_t)TIM_CCMR2_IC3F)));\r
3142   tmpccmr2 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));\r
3143   /* Select the Polarity and set the CC3E Bit */\r
3144   tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC3P | TIM_CCER_CC3NP));\r
3145   tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC3E);  \r
3146   /* Write to TIMx CCMR2 and CCER registers */\r
3147   TIMx->CCMR2 = tmpccmr2;\r
3148   TIMx->CCER = tmpccer;\r
3149 }\r
3150 \r
3151 /**\r
3152   * @brief  Configure the TI4 as Input.\r
3153   * @param  TIMx: where x can be 1, 2 or 3 to select the TIM peripheral.\r
3154   * @param  TIM_ICPolarity : The Input Polarity.\r
3155   *   This parameter can be one of the following values:\r
3156   *     @arg TIM_ICPolarity_Rising\r
3157   *     @arg TIM_ICPolarity_Falling\r
3158   * @param  TIM_ICSelection: specifies the input to be used.\r
3159   *   This parameter can be one of the following values:\r
3160   *     @arg TIM_ICSelection_DirectTI: TIM Input 4 is selected to be connected to IC4.\r
3161   *     @arg TIM_ICSelection_IndirectTI: TIM Input 4 is selected to be connected to IC3.\r
3162   *     @arg TIM_ICSelection_TRC: TIM Input 4 is selected to be connected to TRC.\r
3163   * @param  TIM_ICFilter: Specifies the Input Capture Filter.\r
3164   *   This parameter must be a value between 0x00 and 0x0F.\r
3165   * @retval None\r
3166   */\r
3167 static void TI4_Config(TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,\r
3168                        uint16_t TIM_ICFilter)\r
3169 {\r
3170   uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0;\r
3171 \r
3172    /* Disable the Channel 4: Reset the CC4E Bit */\r
3173   TIMx->CCER &= (uint16_t)~((uint16_t)TIM_CCER_CC4E);\r
3174   tmpccmr2 = TIMx->CCMR2;\r
3175   tmpccer = TIMx->CCER;\r
3176   tmp = (uint16_t)(TIM_ICPolarity << 12);\r
3177   /* Select the Input and set the filter */\r
3178   tmpccmr2 &= (uint16_t)((uint16_t)(~(uint16_t)TIM_CCMR2_CC4S) & ((uint16_t)~((uint16_t)TIM_CCMR2_IC4F)));\r
3179   tmpccmr2 |= (uint16_t)(TIM_ICSelection << 8);\r
3180   tmpccmr2 |= (uint16_t)(TIM_ICFilter << 12);  \r
3181   /* Select the Polarity and set the CC4E Bit */\r
3182   tmpccer &= (uint16_t)~((uint16_t)(TIM_CCER_CC3P | TIM_CCER_CC4NP));\r
3183   tmpccer |= (uint16_t)(tmp | (uint16_t)TIM_CCER_CC4E);\r
3184   /* Write to TIMx CCMR2 and CCER registers */\r
3185   TIMx->CCMR2 = tmpccmr2;\r
3186   TIMx->CCER = tmpccer;\r
3187 }\r
3188 \r
3189 /**\r
3190   * @}\r
3191   */\r
3192 \r
3193 /**\r
3194   * @}\r
3195   */\r
3196 \r
3197 /**\r
3198   * @}\r
3199   */\r
3200 \r
3201 /******************* (C) COPYRIGHT 2012 STMicroelectronics *****END OF FILE****/\r