23 #ifndef __STM32F10x_TIM_H
24 #define __STM32F10x_TIM_H
31 #include "stm32f10x.h"
52 uint16_t TIM_Prescaler;
55 uint16_t TIM_CounterMode;
62 uint16_t TIM_ClockDivision;
65 uint8_t TIM_RepetitionCounter;
84 uint16_t TIM_OutputState;
87 uint16_t TIM_OutputNState;
94 uint16_t TIM_OCPolarity;
97 uint16_t TIM_OCNPolarity;
101 uint16_t TIM_OCIdleState;
105 uint16_t TIM_OCNIdleState;
117 uint16_t TIM_Channel;
120 uint16_t TIM_ICPolarity;
123 uint16_t TIM_ICSelection;
126 uint16_t TIM_ICPrescaler;
129 uint16_t TIM_ICFilter;
141 uint16_t TIM_OSSRState;
144 uint16_t TIM_OSSIState;
147 uint16_t TIM_LOCKLevel;
150 uint16_t TIM_DeadTime;
157 uint16_t TIM_BreakPolarity;
160 uint16_t TIM_AutomaticOutput;
168 #define IS_TIM_ALL_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
169 ((PERIPH) == TIM2) || \
170 ((PERIPH) == TIM3) || \
171 ((PERIPH) == TIM4) || \
172 ((PERIPH) == TIM5) || \
173 ((PERIPH) == TIM6) || \
174 ((PERIPH) == TIM7) || \
175 ((PERIPH) == TIM8) || \
176 ((PERIPH) == TIM9) || \
177 ((PERIPH) == TIM10)|| \
178 ((PERIPH) == TIM11)|| \
179 ((PERIPH) == TIM12)|| \
180 ((PERIPH) == TIM13)|| \
181 ((PERIPH) == TIM14)|| \
182 ((PERIPH) == TIM15)|| \
183 ((PERIPH) == TIM16)|| \
187 #define IS_TIM_LIST1_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
191 #define IS_TIM_LIST2_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
192 ((PERIPH) == TIM8) || \
193 ((PERIPH) == TIM15)|| \
194 ((PERIPH) == TIM16)|| \
198 #define IS_TIM_LIST3_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
199 ((PERIPH) == TIM2) || \
200 ((PERIPH) == TIM3) || \
201 ((PERIPH) == TIM4) || \
202 ((PERIPH) == TIM5) || \
206 #define IS_TIM_LIST4_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
207 ((PERIPH) == TIM2) || \
208 ((PERIPH) == TIM3) || \
209 ((PERIPH) == TIM4) || \
210 ((PERIPH) == TIM5) || \
211 ((PERIPH) == TIM8) || \
212 ((PERIPH) == TIM15)|| \
213 ((PERIPH) == TIM16)|| \
217 #define IS_TIM_LIST5_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
218 ((PERIPH) == TIM2) || \
219 ((PERIPH) == TIM3) || \
220 ((PERIPH) == TIM4) || \
221 ((PERIPH) == TIM5) || \
222 ((PERIPH) == TIM8) || \
226 #define IS_TIM_LIST6_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
227 ((PERIPH) == TIM2) || \
228 ((PERIPH) == TIM3) || \
229 ((PERIPH) == TIM4) || \
230 ((PERIPH) == TIM5) || \
231 ((PERIPH) == TIM8) || \
232 ((PERIPH) == TIM9) || \
233 ((PERIPH) == TIM12)|| \
237 #define IS_TIM_LIST7_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
238 ((PERIPH) == TIM2) || \
239 ((PERIPH) == TIM3) || \
240 ((PERIPH) == TIM4) || \
241 ((PERIPH) == TIM5) || \
242 ((PERIPH) == TIM6) || \
243 ((PERIPH) == TIM7) || \
244 ((PERIPH) == TIM8) || \
245 ((PERIPH) == TIM9) || \
246 ((PERIPH) == TIM12)|| \
250 #define IS_TIM_LIST8_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
251 ((PERIPH) == TIM2) || \
252 ((PERIPH) == TIM3) || \
253 ((PERIPH) == TIM4) || \
254 ((PERIPH) == TIM5) || \
255 ((PERIPH) == TIM8) || \
256 ((PERIPH) == TIM9) || \
257 ((PERIPH) == TIM10)|| \
258 ((PERIPH) == TIM11)|| \
259 ((PERIPH) == TIM12)|| \
260 ((PERIPH) == TIM13)|| \
261 ((PERIPH) == TIM14)|| \
262 ((PERIPH) == TIM15)|| \
263 ((PERIPH) == TIM16)|| \
267 #define IS_TIM_LIST9_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
268 ((PERIPH) == TIM2) || \
269 ((PERIPH) == TIM3) || \
270 ((PERIPH) == TIM4) || \
271 ((PERIPH) == TIM5) || \
272 ((PERIPH) == TIM6) || \
273 ((PERIPH) == TIM7) || \
274 ((PERIPH) == TIM8) || \
275 ((PERIPH) == TIM15)|| \
276 ((PERIPH) == TIM16)|| \
287 #define TIM_OCMode_Timing ((uint16_t)0x0000)
288 #define TIM_OCMode_Active ((uint16_t)0x0010)
289 #define TIM_OCMode_Inactive ((uint16_t)0x0020)
290 #define TIM_OCMode_Toggle ((uint16_t)0x0030)
291 #define TIM_OCMode_PWM1 ((uint16_t)0x0060)
292 #define TIM_OCMode_PWM2 ((uint16_t)0x0070)
293 #define IS_TIM_OC_MODE(MODE) (((MODE) == TIM_OCMode_Timing) || \
294 ((MODE) == TIM_OCMode_Active) || \
295 ((MODE) == TIM_OCMode_Inactive) || \
296 ((MODE) == TIM_OCMode_Toggle)|| \
297 ((MODE) == TIM_OCMode_PWM1) || \
298 ((MODE) == TIM_OCMode_PWM2))
299 #define IS_TIM_OCM(MODE) (((MODE) == TIM_OCMode_Timing) || \
300 ((MODE) == TIM_OCMode_Active) || \
301 ((MODE) == TIM_OCMode_Inactive) || \
302 ((MODE) == TIM_OCMode_Toggle)|| \
303 ((MODE) == TIM_OCMode_PWM1) || \
304 ((MODE) == TIM_OCMode_PWM2) || \
305 ((MODE) == TIM_ForcedAction_Active) || \
306 ((MODE) == TIM_ForcedAction_InActive))
315 #define TIM_OPMode_Single ((uint16_t)0x0008)
316 #define TIM_OPMode_Repetitive ((uint16_t)0x0000)
317 #define IS_TIM_OPM_MODE(MODE) (((MODE) == TIM_OPMode_Single) || \
318 ((MODE) == TIM_OPMode_Repetitive))
327 #define TIM_Channel_1 ((uint16_t)0x0000)
328 #define TIM_Channel_2 ((uint16_t)0x0004)
329 #define TIM_Channel_3 ((uint16_t)0x0008)
330 #define TIM_Channel_4 ((uint16_t)0x000C)
331 #define IS_TIM_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
332 ((CHANNEL) == TIM_Channel_2) || \
333 ((CHANNEL) == TIM_Channel_3) || \
334 ((CHANNEL) == TIM_Channel_4))
335 #define IS_TIM_PWMI_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
336 ((CHANNEL) == TIM_Channel_2))
337 #define IS_TIM_COMPLEMENTARY_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
338 ((CHANNEL) == TIM_Channel_2) || \
339 ((CHANNEL) == TIM_Channel_3))
348 #define TIM_CKD_DIV1 ((uint16_t)0x0000)
349 #define TIM_CKD_DIV2 ((uint16_t)0x0100)
350 #define TIM_CKD_DIV4 ((uint16_t)0x0200)
351 #define IS_TIM_CKD_DIV(DIV) (((DIV) == TIM_CKD_DIV1) || \
352 ((DIV) == TIM_CKD_DIV2) || \
353 ((DIV) == TIM_CKD_DIV4))
362 #define TIM_CounterMode_Up ((uint16_t)0x0000)
363 #define TIM_CounterMode_Down ((uint16_t)0x0010)
364 #define TIM_CounterMode_CenterAligned1 ((uint16_t)0x0020)
365 #define TIM_CounterMode_CenterAligned2 ((uint16_t)0x0040)
366 #define TIM_CounterMode_CenterAligned3 ((uint16_t)0x0060)
367 #define IS_TIM_COUNTER_MODE(MODE) (((MODE) == TIM_CounterMode_Up) || \
368 ((MODE) == TIM_CounterMode_Down) || \
369 ((MODE) == TIM_CounterMode_CenterAligned1) || \
370 ((MODE) == TIM_CounterMode_CenterAligned2) || \
371 ((MODE) == TIM_CounterMode_CenterAligned3))
380 #define TIM_OCPolarity_High ((uint16_t)0x0000)
381 #define TIM_OCPolarity_Low ((uint16_t)0x0002)
382 #define IS_TIM_OC_POLARITY(POLARITY) (((POLARITY) == TIM_OCPolarity_High) || \
383 ((POLARITY) == TIM_OCPolarity_Low))
392 #define TIM_OCNPolarity_High ((uint16_t)0x0000)
393 #define TIM_OCNPolarity_Low ((uint16_t)0x0008)
394 #define IS_TIM_OCN_POLARITY(POLARITY) (((POLARITY) == TIM_OCNPolarity_High) || \
395 ((POLARITY) == TIM_OCNPolarity_Low))
404 #define TIM_OutputState_Disable ((uint16_t)0x0000)
405 #define TIM_OutputState_Enable ((uint16_t)0x0001)
406 #define IS_TIM_OUTPUT_STATE(STATE) (((STATE) == TIM_OutputState_Disable) || \
407 ((STATE) == TIM_OutputState_Enable))
416 #define TIM_OutputNState_Disable ((uint16_t)0x0000)
417 #define TIM_OutputNState_Enable ((uint16_t)0x0004)
418 #define IS_TIM_OUTPUTN_STATE(STATE) (((STATE) == TIM_OutputNState_Disable) || \
419 ((STATE) == TIM_OutputNState_Enable))
428 #define TIM_CCx_Enable ((uint16_t)0x0001)
429 #define TIM_CCx_Disable ((uint16_t)0x0000)
430 #define IS_TIM_CCX(CCX) (((CCX) == TIM_CCx_Enable) || \
431 ((CCX) == TIM_CCx_Disable))
440 #define TIM_CCxN_Enable ((uint16_t)0x0004)
441 #define TIM_CCxN_Disable ((uint16_t)0x0000)
442 #define IS_TIM_CCXN(CCXN) (((CCXN) == TIM_CCxN_Enable) || \
443 ((CCXN) == TIM_CCxN_Disable))
452 #define TIM_Break_Enable ((uint16_t)0x1000)
453 #define TIM_Break_Disable ((uint16_t)0x0000)
454 #define IS_TIM_BREAK_STATE(STATE) (((STATE) == TIM_Break_Enable) || \
455 ((STATE) == TIM_Break_Disable))
464 #define TIM_BreakPolarity_Low ((uint16_t)0x0000)
465 #define TIM_BreakPolarity_High ((uint16_t)0x2000)
466 #define IS_TIM_BREAK_POLARITY(POLARITY) (((POLARITY) == TIM_BreakPolarity_Low) || \
467 ((POLARITY) == TIM_BreakPolarity_High))
476 #define TIM_AutomaticOutput_Enable ((uint16_t)0x4000)
477 #define TIM_AutomaticOutput_Disable ((uint16_t)0x0000)
478 #define IS_TIM_AUTOMATIC_OUTPUT_STATE(STATE) (((STATE) == TIM_AutomaticOutput_Enable) || \
479 ((STATE) == TIM_AutomaticOutput_Disable))
488 #define TIM_LOCKLevel_OFF ((uint16_t)0x0000)
489 #define TIM_LOCKLevel_1 ((uint16_t)0x0100)
490 #define TIM_LOCKLevel_2 ((uint16_t)0x0200)
491 #define TIM_LOCKLevel_3 ((uint16_t)0x0300)
492 #define IS_TIM_LOCK_LEVEL(LEVEL) (((LEVEL) == TIM_LOCKLevel_OFF) || \
493 ((LEVEL) == TIM_LOCKLevel_1) || \
494 ((LEVEL) == TIM_LOCKLevel_2) || \
495 ((LEVEL) == TIM_LOCKLevel_3))
504 #define TIM_OSSIState_Enable ((uint16_t)0x0400)
505 #define TIM_OSSIState_Disable ((uint16_t)0x0000)
506 #define IS_TIM_OSSI_STATE(STATE) (((STATE) == TIM_OSSIState_Enable) || \
507 ((STATE) == TIM_OSSIState_Disable))
516 #define TIM_OSSRState_Enable ((uint16_t)0x0800)
517 #define TIM_OSSRState_Disable ((uint16_t)0x0000)
518 #define IS_TIM_OSSR_STATE(STATE) (((STATE) == TIM_OSSRState_Enable) || \
519 ((STATE) == TIM_OSSRState_Disable))
528 #define TIM_OCIdleState_Set ((uint16_t)0x0100)
529 #define TIM_OCIdleState_Reset ((uint16_t)0x0000)
530 #define IS_TIM_OCIDLE_STATE(STATE) (((STATE) == TIM_OCIdleState_Set) || \
531 ((STATE) == TIM_OCIdleState_Reset))
540 #define TIM_OCNIdleState_Set ((uint16_t)0x0200)
541 #define TIM_OCNIdleState_Reset ((uint16_t)0x0000)
542 #define IS_TIM_OCNIDLE_STATE(STATE) (((STATE) == TIM_OCNIdleState_Set) || \
543 ((STATE) == TIM_OCNIdleState_Reset))
552 #define TIM_ICPolarity_Rising ((uint16_t)0x0000)
553 #define TIM_ICPolarity_Falling ((uint16_t)0x0002)
554 #define IS_TIM_IC_POLARITY(POLARITY) (((POLARITY) == TIM_ICPolarity_Rising) || \
555 ((POLARITY) == TIM_ICPolarity_Falling))
564 #define TIM_ICSelection_DirectTI ((uint16_t)0x0001)
566 #define TIM_ICSelection_IndirectTI ((uint16_t)0x0002)
568 #define TIM_ICSelection_TRC ((uint16_t)0x0003)
569 #define IS_TIM_IC_SELECTION(SELECTION) (((SELECTION) == TIM_ICSelection_DirectTI) || \
570 ((SELECTION) == TIM_ICSelection_IndirectTI) || \
571 ((SELECTION) == TIM_ICSelection_TRC))
580 #define TIM_ICPSC_DIV1 ((uint16_t)0x0000)
581 #define TIM_ICPSC_DIV2 ((uint16_t)0x0004)
582 #define TIM_ICPSC_DIV4 ((uint16_t)0x0008)
583 #define TIM_ICPSC_DIV8 ((uint16_t)0x000C)
584 #define IS_TIM_IC_PRESCALER(PRESCALER) (((PRESCALER) == TIM_ICPSC_DIV1) || \
585 ((PRESCALER) == TIM_ICPSC_DIV2) || \
586 ((PRESCALER) == TIM_ICPSC_DIV4) || \
587 ((PRESCALER) == TIM_ICPSC_DIV8))
596 #define TIM_IT_Update ((uint16_t)0x0001)
597 #define TIM_IT_CC1 ((uint16_t)0x0002)
598 #define TIM_IT_CC2 ((uint16_t)0x0004)
599 #define TIM_IT_CC3 ((uint16_t)0x0008)
600 #define TIM_IT_CC4 ((uint16_t)0x0010)
601 #define TIM_IT_COM ((uint16_t)0x0020)
602 #define TIM_IT_Trigger ((uint16_t)0x0040)
603 #define TIM_IT_Break ((uint16_t)0x0080)
604 #define IS_TIM_IT(IT) ((((IT) & (uint16_t)0xFF00) == 0x0000) && ((IT) != 0x0000))
606 #define IS_TIM_GET_IT(IT) (((IT) == TIM_IT_Update) || \
607 ((IT) == TIM_IT_CC1) || \
608 ((IT) == TIM_IT_CC2) || \
609 ((IT) == TIM_IT_CC3) || \
610 ((IT) == TIM_IT_CC4) || \
611 ((IT) == TIM_IT_COM) || \
612 ((IT) == TIM_IT_Trigger) || \
613 ((IT) == TIM_IT_Break))
622 #define TIM_DMABase_CR1 ((uint16_t)0x0000)
623 #define TIM_DMABase_CR2 ((uint16_t)0x0001)
624 #define TIM_DMABase_SMCR ((uint16_t)0x0002)
625 #define TIM_DMABase_DIER ((uint16_t)0x0003)
626 #define TIM_DMABase_SR ((uint16_t)0x0004)
627 #define TIM_DMABase_EGR ((uint16_t)0x0005)
628 #define TIM_DMABase_CCMR1 ((uint16_t)0x0006)
629 #define TIM_DMABase_CCMR2 ((uint16_t)0x0007)
630 #define TIM_DMABase_CCER ((uint16_t)0x0008)
631 #define TIM_DMABase_CNT ((uint16_t)0x0009)
632 #define TIM_DMABase_PSC ((uint16_t)0x000A)
633 #define TIM_DMABase_ARR ((uint16_t)0x000B)
634 #define TIM_DMABase_RCR ((uint16_t)0x000C)
635 #define TIM_DMABase_CCR1 ((uint16_t)0x000D)
636 #define TIM_DMABase_CCR2 ((uint16_t)0x000E)
637 #define TIM_DMABase_CCR3 ((uint16_t)0x000F)
638 #define TIM_DMABase_CCR4 ((uint16_t)0x0010)
639 #define TIM_DMABase_BDTR ((uint16_t)0x0011)
640 #define TIM_DMABase_DCR ((uint16_t)0x0012)
641 #define IS_TIM_DMA_BASE(BASE) (((BASE) == TIM_DMABase_CR1) || \
642 ((BASE) == TIM_DMABase_CR2) || \
643 ((BASE) == TIM_DMABase_SMCR) || \
644 ((BASE) == TIM_DMABase_DIER) || \
645 ((BASE) == TIM_DMABase_SR) || \
646 ((BASE) == TIM_DMABase_EGR) || \
647 ((BASE) == TIM_DMABase_CCMR1) || \
648 ((BASE) == TIM_DMABase_CCMR2) || \
649 ((BASE) == TIM_DMABase_CCER) || \
650 ((BASE) == TIM_DMABase_CNT) || \
651 ((BASE) == TIM_DMABase_PSC) || \
652 ((BASE) == TIM_DMABase_ARR) || \
653 ((BASE) == TIM_DMABase_RCR) || \
654 ((BASE) == TIM_DMABase_CCR1) || \
655 ((BASE) == TIM_DMABase_CCR2) || \
656 ((BASE) == TIM_DMABase_CCR3) || \
657 ((BASE) == TIM_DMABase_CCR4) || \
658 ((BASE) == TIM_DMABase_BDTR) || \
659 ((BASE) == TIM_DMABase_DCR))
668 #define TIM_DMABurstLength_1Byte ((uint16_t)0x0000)
669 #define TIM_DMABurstLength_2Bytes ((uint16_t)0x0100)
670 #define TIM_DMABurstLength_3Bytes ((uint16_t)0x0200)
671 #define TIM_DMABurstLength_4Bytes ((uint16_t)0x0300)
672 #define TIM_DMABurstLength_5Bytes ((uint16_t)0x0400)
673 #define TIM_DMABurstLength_6Bytes ((uint16_t)0x0500)
674 #define TIM_DMABurstLength_7Bytes ((uint16_t)0x0600)
675 #define TIM_DMABurstLength_8Bytes ((uint16_t)0x0700)
676 #define TIM_DMABurstLength_9Bytes ((uint16_t)0x0800)
677 #define TIM_DMABurstLength_10Bytes ((uint16_t)0x0900)
678 #define TIM_DMABurstLength_11Bytes ((uint16_t)0x0A00)
679 #define TIM_DMABurstLength_12Bytes ((uint16_t)0x0B00)
680 #define TIM_DMABurstLength_13Bytes ((uint16_t)0x0C00)
681 #define TIM_DMABurstLength_14Bytes ((uint16_t)0x0D00)
682 #define TIM_DMABurstLength_15Bytes ((uint16_t)0x0E00)
683 #define TIM_DMABurstLength_16Bytes ((uint16_t)0x0F00)
684 #define TIM_DMABurstLength_17Bytes ((uint16_t)0x1000)
685 #define TIM_DMABurstLength_18Bytes ((uint16_t)0x1100)
686 #define IS_TIM_DMA_LENGTH(LENGTH) (((LENGTH) == TIM_DMABurstLength_1Byte) || \
687 ((LENGTH) == TIM_DMABurstLength_2Bytes) || \
688 ((LENGTH) == TIM_DMABurstLength_3Bytes) || \
689 ((LENGTH) == TIM_DMABurstLength_4Bytes) || \
690 ((LENGTH) == TIM_DMABurstLength_5Bytes) || \
691 ((LENGTH) == TIM_DMABurstLength_6Bytes) || \
692 ((LENGTH) == TIM_DMABurstLength_7Bytes) || \
693 ((LENGTH) == TIM_DMABurstLength_8Bytes) || \
694 ((LENGTH) == TIM_DMABurstLength_9Bytes) || \
695 ((LENGTH) == TIM_DMABurstLength_10Bytes) || \
696 ((LENGTH) == TIM_DMABurstLength_11Bytes) || \
697 ((LENGTH) == TIM_DMABurstLength_12Bytes) || \
698 ((LENGTH) == TIM_DMABurstLength_13Bytes) || \
699 ((LENGTH) == TIM_DMABurstLength_14Bytes) || \
700 ((LENGTH) == TIM_DMABurstLength_15Bytes) || \
701 ((LENGTH) == TIM_DMABurstLength_16Bytes) || \
702 ((LENGTH) == TIM_DMABurstLength_17Bytes) || \
703 ((LENGTH) == TIM_DMABurstLength_18Bytes))
712 #define TIM_DMA_Update ((uint16_t)0x0100)
713 #define TIM_DMA_CC1 ((uint16_t)0x0200)
714 #define TIM_DMA_CC2 ((uint16_t)0x0400)
715 #define TIM_DMA_CC3 ((uint16_t)0x0800)
716 #define TIM_DMA_CC4 ((uint16_t)0x1000)
717 #define TIM_DMA_COM ((uint16_t)0x2000)
718 #define TIM_DMA_Trigger ((uint16_t)0x4000)
719 #define IS_TIM_DMA_SOURCE(SOURCE) ((((SOURCE) & (uint16_t)0x80FF) == 0x0000) && ((SOURCE) != 0x0000))
729 #define TIM_ExtTRGPSC_OFF ((uint16_t)0x0000)
730 #define TIM_ExtTRGPSC_DIV2 ((uint16_t)0x1000)
731 #define TIM_ExtTRGPSC_DIV4 ((uint16_t)0x2000)
732 #define TIM_ExtTRGPSC_DIV8 ((uint16_t)0x3000)
733 #define IS_TIM_EXT_PRESCALER(PRESCALER) (((PRESCALER) == TIM_ExtTRGPSC_OFF) || \
734 ((PRESCALER) == TIM_ExtTRGPSC_DIV2) || \
735 ((PRESCALER) == TIM_ExtTRGPSC_DIV4) || \
736 ((PRESCALER) == TIM_ExtTRGPSC_DIV8))
745 #define TIM_TS_ITR0 ((uint16_t)0x0000)
746 #define TIM_TS_ITR1 ((uint16_t)0x0010)
747 #define TIM_TS_ITR2 ((uint16_t)0x0020)
748 #define TIM_TS_ITR3 ((uint16_t)0x0030)
749 #define TIM_TS_TI1F_ED ((uint16_t)0x0040)
750 #define TIM_TS_TI1FP1 ((uint16_t)0x0050)
751 #define TIM_TS_TI2FP2 ((uint16_t)0x0060)
752 #define TIM_TS_ETRF ((uint16_t)0x0070)
753 #define IS_TIM_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
754 ((SELECTION) == TIM_TS_ITR1) || \
755 ((SELECTION) == TIM_TS_ITR2) || \
756 ((SELECTION) == TIM_TS_ITR3) || \
757 ((SELECTION) == TIM_TS_TI1F_ED) || \
758 ((SELECTION) == TIM_TS_TI1FP1) || \
759 ((SELECTION) == TIM_TS_TI2FP2) || \
760 ((SELECTION) == TIM_TS_ETRF))
761 #define IS_TIM_INTERNAL_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
762 ((SELECTION) == TIM_TS_ITR1) || \
763 ((SELECTION) == TIM_TS_ITR2) || \
764 ((SELECTION) == TIM_TS_ITR3))
773 #define TIM_TIxExternalCLK1Source_TI1 ((uint16_t)0x0050)
774 #define TIM_TIxExternalCLK1Source_TI2 ((uint16_t)0x0060)
775 #define TIM_TIxExternalCLK1Source_TI1ED ((uint16_t)0x0040)
776 #define IS_TIM_TIXCLK_SOURCE(SOURCE) (((SOURCE) == TIM_TIxExternalCLK1Source_TI1) || \
777 ((SOURCE) == TIM_TIxExternalCLK1Source_TI2) || \
778 ((SOURCE) == TIM_TIxExternalCLK1Source_TI1ED))
786 #define TIM_ExtTRGPolarity_Inverted ((uint16_t)0x8000)
787 #define TIM_ExtTRGPolarity_NonInverted ((uint16_t)0x0000)
788 #define IS_TIM_EXT_POLARITY(POLARITY) (((POLARITY) == TIM_ExtTRGPolarity_Inverted) || \
789 ((POLARITY) == TIM_ExtTRGPolarity_NonInverted))
798 #define TIM_PSCReloadMode_Update ((uint16_t)0x0000)
799 #define TIM_PSCReloadMode_Immediate ((uint16_t)0x0001)
800 #define IS_TIM_PRESCALER_RELOAD(RELOAD) (((RELOAD) == TIM_PSCReloadMode_Update) || \
801 ((RELOAD) == TIM_PSCReloadMode_Immediate))
810 #define TIM_ForcedAction_Active ((uint16_t)0x0050)
811 #define TIM_ForcedAction_InActive ((uint16_t)0x0040)
812 #define IS_TIM_FORCED_ACTION(ACTION) (((ACTION) == TIM_ForcedAction_Active) || \
813 ((ACTION) == TIM_ForcedAction_InActive))
822 #define TIM_EncoderMode_TI1 ((uint16_t)0x0001)
823 #define TIM_EncoderMode_TI2 ((uint16_t)0x0002)
824 #define TIM_EncoderMode_TI12 ((uint16_t)0x0003)
825 #define IS_TIM_ENCODER_MODE(MODE) (((MODE) == TIM_EncoderMode_TI1) || \
826 ((MODE) == TIM_EncoderMode_TI2) || \
827 ((MODE) == TIM_EncoderMode_TI12))
837 #define TIM_EventSource_Update ((uint16_t)0x0001)
838 #define TIM_EventSource_CC1 ((uint16_t)0x0002)
839 #define TIM_EventSource_CC2 ((uint16_t)0x0004)
840 #define TIM_EventSource_CC3 ((uint16_t)0x0008)
841 #define TIM_EventSource_CC4 ((uint16_t)0x0010)
842 #define TIM_EventSource_COM ((uint16_t)0x0020)
843 #define TIM_EventSource_Trigger ((uint16_t)0x0040)
844 #define TIM_EventSource_Break ((uint16_t)0x0080)
845 #define IS_TIM_EVENT_SOURCE(SOURCE) ((((SOURCE) & (uint16_t)0xFF00) == 0x0000) && ((SOURCE) != 0x0000))
855 #define TIM_UpdateSource_Global ((uint16_t)0x0000)
858 #define TIM_UpdateSource_Regular ((uint16_t)0x0001)
859 #define IS_TIM_UPDATE_SOURCE(SOURCE) (((SOURCE) == TIM_UpdateSource_Global) || \
860 ((SOURCE) == TIM_UpdateSource_Regular))
869 #define TIM_OCPreload_Enable ((uint16_t)0x0008)
870 #define TIM_OCPreload_Disable ((uint16_t)0x0000)
871 #define IS_TIM_OCPRELOAD_STATE(STATE) (((STATE) == TIM_OCPreload_Enable) || \
872 ((STATE) == TIM_OCPreload_Disable))
881 #define TIM_OCFast_Enable ((uint16_t)0x0004)
882 #define TIM_OCFast_Disable ((uint16_t)0x0000)
883 #define IS_TIM_OCFAST_STATE(STATE) (((STATE) == TIM_OCFast_Enable) || \
884 ((STATE) == TIM_OCFast_Disable))
894 #define TIM_OCClear_Enable ((uint16_t)0x0080)
895 #define TIM_OCClear_Disable ((uint16_t)0x0000)
896 #define IS_TIM_OCCLEAR_STATE(STATE) (((STATE) == TIM_OCClear_Enable) || \
897 ((STATE) == TIM_OCClear_Disable))
906 #define TIM_TRGOSource_Reset ((uint16_t)0x0000)
907 #define TIM_TRGOSource_Enable ((uint16_t)0x0010)
908 #define TIM_TRGOSource_Update ((uint16_t)0x0020)
909 #define TIM_TRGOSource_OC1 ((uint16_t)0x0030)
910 #define TIM_TRGOSource_OC1Ref ((uint16_t)0x0040)
911 #define TIM_TRGOSource_OC2Ref ((uint16_t)0x0050)
912 #define TIM_TRGOSource_OC3Ref ((uint16_t)0x0060)
913 #define TIM_TRGOSource_OC4Ref ((uint16_t)0x0070)
914 #define IS_TIM_TRGO_SOURCE(SOURCE) (((SOURCE) == TIM_TRGOSource_Reset) || \
915 ((SOURCE) == TIM_TRGOSource_Enable) || \
916 ((SOURCE) == TIM_TRGOSource_Update) || \
917 ((SOURCE) == TIM_TRGOSource_OC1) || \
918 ((SOURCE) == TIM_TRGOSource_OC1Ref) || \
919 ((SOURCE) == TIM_TRGOSource_OC2Ref) || \
920 ((SOURCE) == TIM_TRGOSource_OC3Ref) || \
921 ((SOURCE) == TIM_TRGOSource_OC4Ref))
930 #define TIM_SlaveMode_Reset ((uint16_t)0x0004)
931 #define TIM_SlaveMode_Gated ((uint16_t)0x0005)
932 #define TIM_SlaveMode_Trigger ((uint16_t)0x0006)
933 #define TIM_SlaveMode_External1 ((uint16_t)0x0007)
934 #define IS_TIM_SLAVE_MODE(MODE) (((MODE) == TIM_SlaveMode_Reset) || \
935 ((MODE) == TIM_SlaveMode_Gated) || \
936 ((MODE) == TIM_SlaveMode_Trigger) || \
937 ((MODE) == TIM_SlaveMode_External1))
946 #define TIM_MasterSlaveMode_Enable ((uint16_t)0x0080)
947 #define TIM_MasterSlaveMode_Disable ((uint16_t)0x0000)
948 #define IS_TIM_MSM_STATE(STATE) (((STATE) == TIM_MasterSlaveMode_Enable) || \
949 ((STATE) == TIM_MasterSlaveMode_Disable))
958 #define TIM_FLAG_Update ((uint16_t)0x0001)
959 #define TIM_FLAG_CC1 ((uint16_t)0x0002)
960 #define TIM_FLAG_CC2 ((uint16_t)0x0004)
961 #define TIM_FLAG_CC3 ((uint16_t)0x0008)
962 #define TIM_FLAG_CC4 ((uint16_t)0x0010)
963 #define TIM_FLAG_COM ((uint16_t)0x0020)
964 #define TIM_FLAG_Trigger ((uint16_t)0x0040)
965 #define TIM_FLAG_Break ((uint16_t)0x0080)
966 #define TIM_FLAG_CC1OF ((uint16_t)0x0200)
967 #define TIM_FLAG_CC2OF ((uint16_t)0x0400)
968 #define TIM_FLAG_CC3OF ((uint16_t)0x0800)
969 #define TIM_FLAG_CC4OF ((uint16_t)0x1000)
970 #define IS_TIM_GET_FLAG(FLAG) (((FLAG) == TIM_FLAG_Update) || \
971 ((FLAG) == TIM_FLAG_CC1) || \
972 ((FLAG) == TIM_FLAG_CC2) || \
973 ((FLAG) == TIM_FLAG_CC3) || \
974 ((FLAG) == TIM_FLAG_CC4) || \
975 ((FLAG) == TIM_FLAG_COM) || \
976 ((FLAG) == TIM_FLAG_Trigger) || \
977 ((FLAG) == TIM_FLAG_Break) || \
978 ((FLAG) == TIM_FLAG_CC1OF) || \
979 ((FLAG) == TIM_FLAG_CC2OF) || \
980 ((FLAG) == TIM_FLAG_CC3OF) || \
981 ((FLAG) == TIM_FLAG_CC4OF))
984 #define IS_TIM_CLEAR_FLAG(TIM_FLAG) ((((TIM_FLAG) & (uint16_t)0xE100) == 0x0000) && ((TIM_FLAG) != 0x0000))
993 #define IS_TIM_IC_FILTER(ICFILTER) ((ICFILTER) <= 0xF)
1002 #define IS_TIM_EXT_FILTER(EXTFILTER) ((EXTFILTER) <= 0xF)
1036 void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState);
1038 void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState);
1040 void TIM_DMAConfig(TIM_TypeDef* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength);
1041 void TIM_DMACmd(TIM_TypeDef* TIMx, uint16_t TIM_DMASource, FunctionalState NewState);
1045 uint16_t TIM_ICPolarity, uint16_t ICFilter);
1047 uint16_t ExtTRGFilter);
1049 uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter);
1050 void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
1051 uint16_t ExtTRGFilter);
1052 void TIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode);
1056 uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity);
1062 void TIM_SelectCOM(TIM_TypeDef* TIMx, FunctionalState NewState);
1084 void TIM_CCxCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCx);
1085 void TIM_CCxNCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCxN);
1086 void TIM_SelectOCxM(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode);