48 #define SMCR_ETR_Mask ((uint16_t)0x00FF)
49 #define CCMR_Offset ((uint16_t)0x0018)
50 #define CCER_CCE_Set ((uint16_t)0x0001)
51 #define CCER_CCNE_Set ((uint16_t)0x0004)
77 static void TI1_Config(
TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
78 uint16_t TIM_ICFilter);
79 static void TI2_Config(
TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
80 uint16_t TIM_ICFilter);
81 static void TI3_Config(
TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
82 uint16_t TIM_ICFilter);
83 static void TI4_Config(
TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
84 uint16_t TIM_ICFilter);
132 else if (TIMx ==
TIM2)
137 else if (TIMx ==
TIM3)
142 else if (TIMx ==
TIM4)
147 else if (TIMx ==
TIM5)
152 else if (TIMx ==
TIM6)
157 else if (TIMx ==
TIM7)
162 else if (TIMx ==
TIM8)
167 else if (TIMx ==
TIM9)
172 else if (TIMx ==
TIM10)
177 else if (TIMx ==
TIM11)
182 else if (TIMx ==
TIM12)
187 else if (TIMx ==
TIM13)
192 else if (TIMx ==
TIM14)
197 else if (TIMx ==
TIM15)
202 else if (TIMx ==
TIM16)
245 if((TIMx !=
TIM6) && (TIMx !=
TIM7))
281 uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
291 tmpccer = TIMx->
CCER;
296 tmpccmrx = TIMx->
CCMR1;
344 TIMx->
CCMR1 = tmpccmrx;
350 TIMx->
CCER = tmpccer;
364 uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
375 tmpccer = TIMx->
CCER;
380 tmpccmrx = TIMx->
CCMR1;
387 tmpccmrx |= (uint16_t)(TIM_OCInitStruct->
TIM_OCMode << 8);
397 if((TIMx ==
TIM1) || (TIMx ==
TIM8))
427 TIMx->
CCMR1 = tmpccmrx;
433 TIMx->
CCER = tmpccer;
446 uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
457 tmpccer = TIMx->
CCER;
462 tmpccmrx = TIMx->
CCMR2;
478 if((TIMx ==
TIM1) || (TIMx ==
TIM8))
506 TIMx->
CCMR2 = tmpccmrx;
512 TIMx->
CCER = tmpccer;
525 uint16_t tmpccmrx = 0, tmpccer = 0, tmpcr2 = 0;
536 tmpccer = TIMx->
CCER;
541 tmpccmrx = TIMx->
CCMR2;
548 tmpccmrx |= (uint16_t)(TIM_OCInitStruct->
TIM_OCMode << 8);
558 if((TIMx ==
TIM1) || (TIMx ==
TIM8))
570 TIMx->
CCMR2 = tmpccmrx;
576 TIMx->
CCER = tmpccer;
686 TI2_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->
TIM_ICFilter);
698 TI1_Config(TIMx, icoppositepolarity, icoppositeselection, TIM_ICInitStruct->
TIM_ICFilter);
882 TIMx->
DIER |= TIM_IT;
887 TIMx->
DIER &= (uint16_t)~TIM_IT;
916 TIMx->
EGR = TIM_EventSource;
944 TIMx->
DCR = TIM_DMABase | TIM_DMABurstLength;
974 TIMx->
DIER |= TIM_DMASource;
979 TIMx->
DIER &= (uint16_t)~TIM_DMASource;
1036 uint16_t TIM_ICPolarity, uint16_t ICFilter)
1076 uint16_t ExtTRGFilter)
1078 uint16_t tmpsmcr = 0;
1085 TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
1088 tmpsmcr = TIMx->
SMCR;
1097 TIMx->
SMCR = tmpsmcr;
1118 uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter)
1126 TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
1149 uint16_t ExtTRGFilter)
1151 uint16_t tmpsmcr = 0;
1157 tmpsmcr = TIMx->
SMCR;
1161 tmpsmcr |= (uint16_t)(TIM_ExtTRGPrescaler | (uint16_t)(TIM_ExtTRGPolarity | (uint16_t)(ExtTRGFilter << (uint16_t)8)));
1163 TIMx->
SMCR = tmpsmcr;
1182 TIMx->
PSC = Prescaler;
1184 TIMx->
EGR = TIM_PSCReloadMode;
1201 uint16_t tmpcr1 = 0;
1209 tmpcr1 |= TIM_CounterMode;
1231 uint16_t tmpsmcr = 0;
1236 tmpsmcr = TIMx->
SMCR;
1240 tmpsmcr |= TIM_InputTriggerSource;
1242 TIMx->
SMCR = tmpsmcr;
1265 uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity)
1267 uint16_t tmpsmcr = 0;
1268 uint16_t tmpccmr1 = 0;
1269 uint16_t tmpccer = 0;
1278 tmpsmcr = TIMx->
SMCR;
1281 tmpccmr1 = TIMx->
CCMR1;
1284 tmpccer = TIMx->
CCER;
1288 tmpsmcr |= TIM_EncoderMode;
1296 tmpccer |= (uint16_t)(TIM_IC1Polarity | (uint16_t)(TIM_IC2Polarity << (uint16_t)4));
1299 TIMx->
SMCR = tmpsmcr;
1301 TIMx->
CCMR1 = tmpccmr1;
1303 TIMx->
CCER = tmpccer;
1317 uint16_t tmpccmr1 = 0;
1321 tmpccmr1 = TIMx->
CCMR1;
1325 tmpccmr1 |= TIM_ForcedAction;
1327 TIMx->
CCMR1 = tmpccmr1;
1341 uint16_t tmpccmr1 = 0;
1345 tmpccmr1 = TIMx->
CCMR1;
1349 tmpccmr1 |= (uint16_t)(TIM_ForcedAction << 8);
1351 TIMx->
CCMR1 = tmpccmr1;
1365 uint16_t tmpccmr2 = 0;
1369 tmpccmr2 = TIMx->
CCMR2;
1373 tmpccmr2 |= TIM_ForcedAction;
1375 TIMx->
CCMR2 = tmpccmr2;
1389 uint16_t tmpccmr2 = 0;
1393 tmpccmr2 = TIMx->
CCMR2;
1397 tmpccmr2 |= (uint16_t)(TIM_ForcedAction << 8);
1399 TIMx->
CCMR2 = tmpccmr2;
1511 uint16_t tmpccmr1 = 0;
1515 tmpccmr1 = TIMx->
CCMR1;
1519 tmpccmr1 |= TIM_OCPreload;
1521 TIMx->
CCMR1 = tmpccmr1;
1536 uint16_t tmpccmr1 = 0;
1540 tmpccmr1 = TIMx->
CCMR1;
1544 tmpccmr1 |= (uint16_t)(TIM_OCPreload << 8);
1546 TIMx->
CCMR1 = tmpccmr1;
1560 uint16_t tmpccmr2 = 0;
1564 tmpccmr2 = TIMx->
CCMR2;
1568 tmpccmr2 |= TIM_OCPreload;
1570 TIMx->
CCMR2 = tmpccmr2;
1584 uint16_t tmpccmr2 = 0;
1588 tmpccmr2 = TIMx->
CCMR2;
1592 tmpccmr2 |= (uint16_t)(TIM_OCPreload << 8);
1594 TIMx->
CCMR2 = tmpccmr2;
1608 uint16_t tmpccmr1 = 0;
1613 tmpccmr1 = TIMx->
CCMR1;
1617 tmpccmr1 |= TIM_OCFast;
1619 TIMx->
CCMR1 = tmpccmr1;
1634 uint16_t tmpccmr1 = 0;
1639 tmpccmr1 = TIMx->
CCMR1;
1643 tmpccmr1 |= (uint16_t)(TIM_OCFast << 8);
1645 TIMx->
CCMR1 = tmpccmr1;
1659 uint16_t tmpccmr2 = 0;
1664 tmpccmr2 = TIMx->
CCMR2;
1668 tmpccmr2 |= TIM_OCFast;
1670 TIMx->
CCMR2 = tmpccmr2;
1684 uint16_t tmpccmr2 = 0;
1689 tmpccmr2 = TIMx->
CCMR2;
1693 tmpccmr2 |= (uint16_t)(TIM_OCFast << 8);
1695 TIMx->
CCMR2 = tmpccmr2;
1709 uint16_t tmpccmr1 = 0;
1714 tmpccmr1 = TIMx->
CCMR1;
1719 tmpccmr1 |= TIM_OCClear;
1721 TIMx->
CCMR1 = tmpccmr1;
1735 uint16_t tmpccmr1 = 0;
1739 tmpccmr1 = TIMx->
CCMR1;
1743 tmpccmr1 |= (uint16_t)(TIM_OCClear << 8);
1745 TIMx->
CCMR1 = tmpccmr1;
1759 uint16_t tmpccmr2 = 0;
1763 tmpccmr2 = TIMx->
CCMR2;
1767 tmpccmr2 |= TIM_OCClear;
1769 TIMx->
CCMR2 = tmpccmr2;
1783 uint16_t tmpccmr2 = 0;
1787 tmpccmr2 = TIMx->
CCMR2;
1791 tmpccmr2 |= (uint16_t)(TIM_OCClear << 8);
1793 TIMx->
CCMR2 = tmpccmr2;
1807 uint16_t tmpccer = 0;
1811 tmpccer = TIMx->
CCER;
1814 tmpccer |= TIM_OCPolarity;
1816 TIMx->
CCER = tmpccer;
1830 uint16_t tmpccer = 0;
1835 tmpccer = TIMx->
CCER;
1838 tmpccer |= TIM_OCNPolarity;
1840 TIMx->
CCER = tmpccer;
1854 uint16_t tmpccer = 0;
1858 tmpccer = TIMx->
CCER;
1861 tmpccer |= (uint16_t)(TIM_OCPolarity << 4);
1863 TIMx->
CCER = tmpccer;
1877 uint16_t tmpccer = 0;
1882 tmpccer = TIMx->
CCER;
1885 tmpccer |= (uint16_t)(TIM_OCNPolarity << 4);
1887 TIMx->
CCER = tmpccer;
1901 uint16_t tmpccer = 0;
1905 tmpccer = TIMx->
CCER;
1908 tmpccer |= (uint16_t)(TIM_OCPolarity << 8);
1910 TIMx->
CCER = tmpccer;
1924 uint16_t tmpccer = 0;
1930 tmpccer = TIMx->
CCER;
1933 tmpccer |= (uint16_t)(TIM_OCNPolarity << 8);
1935 TIMx->
CCER = tmpccer;
1949 uint16_t tmpccer = 0;
1953 tmpccer = TIMx->
CCER;
1956 tmpccer |= (uint16_t)(TIM_OCPolarity << 12);
1958 TIMx->
CCER = tmpccer;
1986 TIMx->
CCER &= (uint16_t)~ tmp;
1989 TIMx->
CCER |= (uint16_t)(TIM_CCx << TIM_Channel);
2016 TIMx->
CCER &= (uint16_t) ~tmp;
2019 TIMx->
CCER |= (uint16_t)(TIM_CCxN << TIM_Channel);
2055 tmp = (uint32_t) TIMx;
2061 TIMx->
CCER &= (uint16_t) ~tmp1;
2065 tmp += (TIM_Channel>>1);
2071 *(
__IO uint32_t *) tmp |= TIM_OCMode;
2075 tmp += (uint16_t)(TIM_Channel - (uint16_t)4)>> (uint16_t)1;
2081 *(
__IO uint32_t *) tmp |= (uint16_t)(TIM_OCMode << 8);
2178 TIMx->
CR1 |= TIM_OPMode;
2210 TIMx->
CR2 |= TIM_TRGOSource;
2233 TIMx->
SMCR |= TIM_SlaveMode;
2255 TIMx->
SMCR |= TIM_MasterSlaveMode;
2269 TIMx->
CNT = Counter;
2283 TIMx->
ARR = Autoreload;
2297 TIMx->
CCR1 = Compare1;
2311 TIMx->
CCR2 = Compare2;
2325 TIMx->
CCR3 = Compare3;
2339 TIMx->
CCR4 = Compare4;
2361 TIMx->
CCMR1 |= TIM_ICPSC;
2383 TIMx->
CCMR1 |= (uint16_t)(TIM_ICPSC << 8);
2405 TIMx->
CCMR2 |= TIM_ICPSC;
2427 TIMx->
CCMR2 |= (uint16_t)(TIM_ICPSC << 8);
2449 TIMx->
CR1 |= TIM_CKD;
2563 if ((TIMx->
SR & TIM_FLAG) != (uint16_t)
RESET)
2607 TIMx->
SR = (uint16_t)~TIM_FLAG;
2635 uint16_t itstatus = 0x0, itenable = 0x0;
2640 itstatus = TIMx->
SR & TIM_IT;
2642 itenable = TIMx->
DIER & TIM_IT;
2643 if ((itstatus != (uint16_t)
RESET) && (itenable != (uint16_t)RESET))
2682 TIMx->
SR = (uint16_t)~TIM_IT;
2701 static void TI1_Config(
TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
2702 uint16_t TIM_ICFilter)
2704 uint16_t tmpccmr1 = 0, tmpccer = 0;
2707 tmpccmr1 = TIMx->
CCMR1;
2708 tmpccer = TIMx->
CCER;
2711 tmpccmr1 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));
2718 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)
TIM_CCER_CC1E);
2724 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)
TIM_CCER_CC1E);
2728 TIMx->
CCMR1 = tmpccmr1;
2729 TIMx->
CCER = tmpccer;
2748 static void TI2_Config(
TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
2749 uint16_t TIM_ICFilter)
2751 uint16_t tmpccmr1 = 0, tmpccer = 0, tmp = 0;
2754 tmpccmr1 = TIMx->
CCMR1;
2755 tmpccer = TIMx->
CCER;
2756 tmp = (uint16_t)(TIM_ICPolarity << 4);
2759 tmpccmr1 |= (uint16_t)(TIM_ICFilter << 12);
2760 tmpccmr1 |= (uint16_t)(TIM_ICSelection << 8);
2773 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)
TIM_CCER_CC2E);
2777 TIMx->
CCMR1 = tmpccmr1 ;
2778 TIMx->
CCER = tmpccer;
2797 static void TI3_Config(
TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
2798 uint16_t TIM_ICFilter)
2800 uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0;
2803 tmpccmr2 = TIMx->
CCMR2;
2804 tmpccer = TIMx->
CCER;
2805 tmp = (uint16_t)(TIM_ICPolarity << 8);
2808 tmpccmr2 |= (uint16_t)(TIM_ICSelection | (uint16_t)(TIM_ICFilter << (uint16_t)4));
2821 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)
TIM_CCER_CC3E);
2825 TIMx->
CCMR2 = tmpccmr2;
2826 TIMx->
CCER = tmpccer;
2845 static void TI4_Config(
TIM_TypeDef* TIMx, uint16_t TIM_ICPolarity, uint16_t TIM_ICSelection,
2846 uint16_t TIM_ICFilter)
2848 uint16_t tmpccmr2 = 0, tmpccer = 0, tmp = 0;
2852 tmpccmr2 = TIMx->
CCMR2;
2853 tmpccer = TIMx->
CCER;
2854 tmp = (uint16_t)(TIM_ICPolarity << 12);
2857 tmpccmr2 |= (uint16_t)(TIM_ICSelection << 8);
2858 tmpccmr2 |= (uint16_t)(TIM_ICFilter << 12);
2871 tmpccer |= (uint16_t)(TIM_ICPolarity | (uint16_t)
TIM_CCER_CC4E);
2874 TIMx->
CCMR2 = tmpccmr2;
2875 TIMx->
CCER = tmpccer;