stm32f4xx_tim.h 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_tim.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 30-September-2011
  7. * @brief This file contains all the functions prototypes for the TIM firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  20. ******************************************************************************
  21. */
  22. /* Define to prevent recursive inclusion -------------------------------------*/
  23. #ifndef __STM32F4xx_TIM_H
  24. #define __STM32F4xx_TIM_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f4xx.h"
  30. /** @addtogroup STM32F4xx_StdPeriph_Driver
  31. * @{
  32. */
  33. /** @addtogroup TIM
  34. * @{
  35. */
  36. /* Exported types ------------------------------------------------------------*/
  37. /**
  38. * @brief TIM Time Base Init structure definition
  39. * @note This structure is used with all TIMx except for TIM6 and TIM7.
  40. */
  41. typedef struct
  42. {
  43. uint16_t TIM_Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  44. This parameter can be a number between 0x0000 and 0xFFFF */
  45. uint16_t TIM_CounterMode; /*!< Specifies the counter mode.
  46. This parameter can be a value of @ref TIM_Counter_Mode */
  47. uint32_t TIM_Period; /*!< Specifies the period value to be loaded into the active
  48. Auto-Reload Register at the next update event.
  49. This parameter must be a number between 0x0000 and 0xFFFF. */
  50. uint16_t TIM_ClockDivision; /*!< Specifies the clock division.
  51. This parameter can be a value of @ref TIM_Clock_Division_CKD */
  52. uint8_t TIM_RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  53. reaches zero, an update event is generated and counting restarts
  54. from the RCR value (N).
  55. This means in PWM mode that (N+1) corresponds to:
  56. - the number of PWM periods in edge-aligned mode
  57. - the number of half PWM period in center-aligned mode
  58. This parameter must be a number between 0x00 and 0xFF.
  59. @note This parameter is valid only for TIM1 and TIM8. */
  60. } TIM_TimeBaseInitTypeDef;
  61. /**
  62. * @brief TIM Output Compare Init structure definition
  63. */
  64. typedef struct
  65. {
  66. uint16_t TIM_OCMode; /*!< Specifies the TIM mode.
  67. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  68. uint16_t TIM_OutputState; /*!< Specifies the TIM Output Compare state.
  69. This parameter can be a value of @ref TIM_Output_Compare_State */
  70. uint16_t TIM_OutputNState; /*!< Specifies the TIM complementary Output Compare state.
  71. This parameter can be a value of @ref TIM_Output_Compare_N_State
  72. @note This parameter is valid only for TIM1 and TIM8. */
  73. uint32_t TIM_Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  74. This parameter can be a number between 0x0000 and 0xFFFF */
  75. uint16_t TIM_OCPolarity; /*!< Specifies the output polarity.
  76. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  77. uint16_t TIM_OCNPolarity; /*!< Specifies the complementary output polarity.
  78. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  79. @note This parameter is valid only for TIM1 and TIM8. */
  80. uint16_t TIM_OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  81. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  82. @note This parameter is valid only for TIM1 and TIM8. */
  83. uint16_t TIM_OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  84. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  85. @note This parameter is valid only for TIM1 and TIM8. */
  86. } TIM_OCInitTypeDef;
  87. /**
  88. * @brief TIM Input Capture Init structure definition
  89. */
  90. typedef struct
  91. {
  92. uint16_t TIM_Channel; /*!< Specifies the TIM channel.
  93. This parameter can be a value of @ref TIM_Channel */
  94. uint16_t TIM_ICPolarity; /*!< Specifies the active edge of the input signal.
  95. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  96. uint16_t TIM_ICSelection; /*!< Specifies the input.
  97. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  98. uint16_t TIM_ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  99. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  100. uint16_t TIM_ICFilter; /*!< Specifies the input capture filter.
  101. This parameter can be a number between 0x0 and 0xF */
  102. } TIM_ICInitTypeDef;
  103. /**
  104. * @brief BDTR structure definition
  105. * @note This structure is used only with TIM1 and TIM8.
  106. */
  107. typedef struct
  108. {
  109. uint16_t TIM_OSSRState; /*!< Specifies the Off-State selection used in Run mode.
  110. This parameter can be a value of @ref TIM_OSSR_Off_State_Selection_for_Run_mode_state */
  111. uint16_t TIM_OSSIState; /*!< Specifies the Off-State used in Idle state.
  112. This parameter can be a value of @ref TIM_OSSI_Off_State_Selection_for_Idle_mode_state */
  113. uint16_t TIM_LOCKLevel; /*!< Specifies the LOCK level parameters.
  114. This parameter can be a value of @ref TIM_Lock_level */
  115. uint16_t TIM_DeadTime; /*!< Specifies the delay time between the switching-off and the
  116. switching-on of the outputs.
  117. This parameter can be a number between 0x00 and 0xFF */
  118. uint16_t TIM_Break; /*!< Specifies whether the TIM Break input is enabled or not.
  119. This parameter can be a value of @ref TIM_Break_Input_enable_disable */
  120. uint16_t TIM_BreakPolarity; /*!< Specifies the TIM Break Input pin polarity.
  121. This parameter can be a value of @ref TIM_Break_Polarity */
  122. uint16_t TIM_AutomaticOutput; /*!< Specifies whether the TIM Automatic Output feature is enabled or not.
  123. This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */
  124. } TIM_BDTRInitTypeDef;
  125. /* Exported constants --------------------------------------------------------*/
  126. /** @defgroup TIM_Exported_constants
  127. * @{
  128. */
  129. #define IS_TIM_ALL_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  130. ((PERIPH) == TIM2) || \
  131. ((PERIPH) == TIM3) || \
  132. ((PERIPH) == TIM4) || \
  133. ((PERIPH) == TIM5) || \
  134. ((PERIPH) == TIM6) || \
  135. ((PERIPH) == TIM7) || \
  136. ((PERIPH) == TIM8) || \
  137. ((PERIPH) == TIM9) || \
  138. ((PERIPH) == TIM10) || \
  139. ((PERIPH) == TIM11) || \
  140. ((PERIPH) == TIM12) || \
  141. (((PERIPH) == TIM13) || \
  142. ((PERIPH) == TIM14)))
  143. /* LIST1: TIM1, TIM2, TIM3, TIM4, TIM5, TIM8, TIM9, TIM10, TIM11, TIM12, TIM13 and TIM14 */
  144. #define IS_TIM_LIST1_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  145. ((PERIPH) == TIM2) || \
  146. ((PERIPH) == TIM3) || \
  147. ((PERIPH) == TIM4) || \
  148. ((PERIPH) == TIM5) || \
  149. ((PERIPH) == TIM8) || \
  150. ((PERIPH) == TIM9) || \
  151. ((PERIPH) == TIM10) || \
  152. ((PERIPH) == TIM11) || \
  153. ((PERIPH) == TIM12) || \
  154. ((PERIPH) == TIM13) || \
  155. ((PERIPH) == TIM14))
  156. /* LIST2: TIM1, TIM2, TIM3, TIM4, TIM5, TIM8, TIM9 and TIM12 */
  157. #define IS_TIM_LIST2_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  158. ((PERIPH) == TIM2) || \
  159. ((PERIPH) == TIM3) || \
  160. ((PERIPH) == TIM4) || \
  161. ((PERIPH) == TIM5) || \
  162. ((PERIPH) == TIM8) || \
  163. ((PERIPH) == TIM9) || \
  164. ((PERIPH) == TIM12))
  165. /* LIST3: TIM1, TIM2, TIM3, TIM4, TIM5 and TIM8 */
  166. #define IS_TIM_LIST3_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  167. ((PERIPH) == TIM2) || \
  168. ((PERIPH) == TIM3) || \
  169. ((PERIPH) == TIM4) || \
  170. ((PERIPH) == TIM5) || \
  171. ((PERIPH) == TIM8))
  172. /* LIST4: TIM1 and TIM8 */
  173. #define IS_TIM_LIST4_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  174. ((PERIPH) == TIM8))
  175. /* LIST5: TIM1, TIM2, TIM3, TIM4, TIM5, TIM6, TIM7 and TIM8 */
  176. #define IS_TIM_LIST5_PERIPH(PERIPH) (((PERIPH) == TIM1) || \
  177. ((PERIPH) == TIM2) || \
  178. ((PERIPH) == TIM3) || \
  179. ((PERIPH) == TIM4) || \
  180. ((PERIPH) == TIM5) || \
  181. ((PERIPH) == TIM6) || \
  182. ((PERIPH) == TIM7) || \
  183. ((PERIPH) == TIM8))
  184. /* LIST6: TIM2, TIM5 and TIM11 */
  185. #define IS_TIM_LIST6_PERIPH(TIMx)(((TIMx) == TIM2) || \
  186. ((TIMx) == TIM5) || \
  187. ((TIMx) == TIM11))
  188. /** @defgroup TIM_Output_Compare_and_PWM_modes
  189. * @{
  190. */
  191. #define TIM_OCMode_Timing ((uint16_t)0x0000)
  192. #define TIM_OCMode_Active ((uint16_t)0x0010)
  193. #define TIM_OCMode_Inactive ((uint16_t)0x0020)
  194. #define TIM_OCMode_Toggle ((uint16_t)0x0030)
  195. #define TIM_OCMode_PWM1 ((uint16_t)0x0060)
  196. #define TIM_OCMode_PWM2 ((uint16_t)0x0070)
  197. #define IS_TIM_OC_MODE(MODE) (((MODE) == TIM_OCMode_Timing) || \
  198. ((MODE) == TIM_OCMode_Active) || \
  199. ((MODE) == TIM_OCMode_Inactive) || \
  200. ((MODE) == TIM_OCMode_Toggle)|| \
  201. ((MODE) == TIM_OCMode_PWM1) || \
  202. ((MODE) == TIM_OCMode_PWM2))
  203. #define IS_TIM_OCM(MODE) (((MODE) == TIM_OCMode_Timing) || \
  204. ((MODE) == TIM_OCMode_Active) || \
  205. ((MODE) == TIM_OCMode_Inactive) || \
  206. ((MODE) == TIM_OCMode_Toggle)|| \
  207. ((MODE) == TIM_OCMode_PWM1) || \
  208. ((MODE) == TIM_OCMode_PWM2) || \
  209. ((MODE) == TIM_ForcedAction_Active) || \
  210. ((MODE) == TIM_ForcedAction_InActive))
  211. /**
  212. * @}
  213. */
  214. /** @defgroup TIM_One_Pulse_Mode
  215. * @{
  216. */
  217. #define TIM_OPMode_Single ((uint16_t)0x0008)
  218. #define TIM_OPMode_Repetitive ((uint16_t)0x0000)
  219. #define IS_TIM_OPM_MODE(MODE) (((MODE) == TIM_OPMode_Single) || \
  220. ((MODE) == TIM_OPMode_Repetitive))
  221. /**
  222. * @}
  223. */
  224. /** @defgroup TIM_Channel
  225. * @{
  226. */
  227. #define TIM_Channel_1 ((uint16_t)0x0000)
  228. #define TIM_Channel_2 ((uint16_t)0x0004)
  229. #define TIM_Channel_3 ((uint16_t)0x0008)
  230. #define TIM_Channel_4 ((uint16_t)0x000C)
  231. #define IS_TIM_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
  232. ((CHANNEL) == TIM_Channel_2) || \
  233. ((CHANNEL) == TIM_Channel_3) || \
  234. ((CHANNEL) == TIM_Channel_4))
  235. #define IS_TIM_PWMI_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
  236. ((CHANNEL) == TIM_Channel_2))
  237. #define IS_TIM_COMPLEMENTARY_CHANNEL(CHANNEL) (((CHANNEL) == TIM_Channel_1) || \
  238. ((CHANNEL) == TIM_Channel_2) || \
  239. ((CHANNEL) == TIM_Channel_3))
  240. /**
  241. * @}
  242. */
  243. /** @defgroup TIM_Clock_Division_CKD
  244. * @{
  245. */
  246. #define TIM_CKD_DIV1 ((uint16_t)0x0000)
  247. #define TIM_CKD_DIV2 ((uint16_t)0x0100)
  248. #define TIM_CKD_DIV4 ((uint16_t)0x0200)
  249. #define IS_TIM_CKD_DIV(DIV) (((DIV) == TIM_CKD_DIV1) || \
  250. ((DIV) == TIM_CKD_DIV2) || \
  251. ((DIV) == TIM_CKD_DIV4))
  252. /**
  253. * @}
  254. */
  255. /** @defgroup TIM_Counter_Mode
  256. * @{
  257. */
  258. #define TIM_CounterMode_Up ((uint16_t)0x0000)
  259. #define TIM_CounterMode_Down ((uint16_t)0x0010)
  260. #define TIM_CounterMode_CenterAligned1 ((uint16_t)0x0020)
  261. #define TIM_CounterMode_CenterAligned2 ((uint16_t)0x0040)
  262. #define TIM_CounterMode_CenterAligned3 ((uint16_t)0x0060)
  263. #define IS_TIM_COUNTER_MODE(MODE) (((MODE) == TIM_CounterMode_Up) || \
  264. ((MODE) == TIM_CounterMode_Down) || \
  265. ((MODE) == TIM_CounterMode_CenterAligned1) || \
  266. ((MODE) == TIM_CounterMode_CenterAligned2) || \
  267. ((MODE) == TIM_CounterMode_CenterAligned3))
  268. /**
  269. * @}
  270. */
  271. /** @defgroup TIM_Output_Compare_Polarity
  272. * @{
  273. */
  274. #define TIM_OCPolarity_High ((uint16_t)0x0000)
  275. #define TIM_OCPolarity_Low ((uint16_t)0x0002)
  276. #define IS_TIM_OC_POLARITY(POLARITY) (((POLARITY) == TIM_OCPolarity_High) || \
  277. ((POLARITY) == TIM_OCPolarity_Low))
  278. /**
  279. * @}
  280. */
  281. /** @defgroup TIM_Output_Compare_N_Polarity
  282. * @{
  283. */
  284. #define TIM_OCNPolarity_High ((uint16_t)0x0000)
  285. #define TIM_OCNPolarity_Low ((uint16_t)0x0008)
  286. #define IS_TIM_OCN_POLARITY(POLARITY) (((POLARITY) == TIM_OCNPolarity_High) || \
  287. ((POLARITY) == TIM_OCNPolarity_Low))
  288. /**
  289. * @}
  290. */
  291. /** @defgroup TIM_Output_Compare_State
  292. * @{
  293. */
  294. #define TIM_OutputState_Disable ((uint16_t)0x0000)
  295. #define TIM_OutputState_Enable ((uint16_t)0x0001)
  296. #define IS_TIM_OUTPUT_STATE(STATE) (((STATE) == TIM_OutputState_Disable) || \
  297. ((STATE) == TIM_OutputState_Enable))
  298. /**
  299. * @}
  300. */
  301. /** @defgroup TIM_Output_Compare_N_State
  302. * @{
  303. */
  304. #define TIM_OutputNState_Disable ((uint16_t)0x0000)
  305. #define TIM_OutputNState_Enable ((uint16_t)0x0004)
  306. #define IS_TIM_OUTPUTN_STATE(STATE) (((STATE) == TIM_OutputNState_Disable) || \
  307. ((STATE) == TIM_OutputNState_Enable))
  308. /**
  309. * @}
  310. */
  311. /** @defgroup TIM_Capture_Compare_State
  312. * @{
  313. */
  314. #define TIM_CCx_Enable ((uint16_t)0x0001)
  315. #define TIM_CCx_Disable ((uint16_t)0x0000)
  316. #define IS_TIM_CCX(CCX) (((CCX) == TIM_CCx_Enable) || \
  317. ((CCX) == TIM_CCx_Disable))
  318. /**
  319. * @}
  320. */
  321. /** @defgroup TIM_Capture_Compare_N_State
  322. * @{
  323. */
  324. #define TIM_CCxN_Enable ((uint16_t)0x0004)
  325. #define TIM_CCxN_Disable ((uint16_t)0x0000)
  326. #define IS_TIM_CCXN(CCXN) (((CCXN) == TIM_CCxN_Enable) || \
  327. ((CCXN) == TIM_CCxN_Disable))
  328. /**
  329. * @}
  330. */
  331. /** @defgroup TIM_Break_Input_enable_disable
  332. * @{
  333. */
  334. #define TIM_Break_Enable ((uint16_t)0x1000)
  335. #define TIM_Break_Disable ((uint16_t)0x0000)
  336. #define IS_TIM_BREAK_STATE(STATE) (((STATE) == TIM_Break_Enable) || \
  337. ((STATE) == TIM_Break_Disable))
  338. /**
  339. * @}
  340. */
  341. /** @defgroup TIM_Break_Polarity
  342. * @{
  343. */
  344. #define TIM_BreakPolarity_Low ((uint16_t)0x0000)
  345. #define TIM_BreakPolarity_High ((uint16_t)0x2000)
  346. #define IS_TIM_BREAK_POLARITY(POLARITY) (((POLARITY) == TIM_BreakPolarity_Low) || \
  347. ((POLARITY) == TIM_BreakPolarity_High))
  348. /**
  349. * @}
  350. */
  351. /** @defgroup TIM_AOE_Bit_Set_Reset
  352. * @{
  353. */
  354. #define TIM_AutomaticOutput_Enable ((uint16_t)0x4000)
  355. #define TIM_AutomaticOutput_Disable ((uint16_t)0x0000)
  356. #define IS_TIM_AUTOMATIC_OUTPUT_STATE(STATE) (((STATE) == TIM_AutomaticOutput_Enable) || \
  357. ((STATE) == TIM_AutomaticOutput_Disable))
  358. /**
  359. * @}
  360. */
  361. /** @defgroup TIM_Lock_level
  362. * @{
  363. */
  364. #define TIM_LOCKLevel_OFF ((uint16_t)0x0000)
  365. #define TIM_LOCKLevel_1 ((uint16_t)0x0100)
  366. #define TIM_LOCKLevel_2 ((uint16_t)0x0200)
  367. #define TIM_LOCKLevel_3 ((uint16_t)0x0300)
  368. #define IS_TIM_LOCK_LEVEL(LEVEL) (((LEVEL) == TIM_LOCKLevel_OFF) || \
  369. ((LEVEL) == TIM_LOCKLevel_1) || \
  370. ((LEVEL) == TIM_LOCKLevel_2) || \
  371. ((LEVEL) == TIM_LOCKLevel_3))
  372. /**
  373. * @}
  374. */
  375. /** @defgroup TIM_OSSI_Off_State_Selection_for_Idle_mode_state
  376. * @{
  377. */
  378. #define TIM_OSSIState_Enable ((uint16_t)0x0400)
  379. #define TIM_OSSIState_Disable ((uint16_t)0x0000)
  380. #define IS_TIM_OSSI_STATE(STATE) (((STATE) == TIM_OSSIState_Enable) || \
  381. ((STATE) == TIM_OSSIState_Disable))
  382. /**
  383. * @}
  384. */
  385. /** @defgroup TIM_OSSR_Off_State_Selection_for_Run_mode_state
  386. * @{
  387. */
  388. #define TIM_OSSRState_Enable ((uint16_t)0x0800)
  389. #define TIM_OSSRState_Disable ((uint16_t)0x0000)
  390. #define IS_TIM_OSSR_STATE(STATE) (((STATE) == TIM_OSSRState_Enable) || \
  391. ((STATE) == TIM_OSSRState_Disable))
  392. /**
  393. * @}
  394. */
  395. /** @defgroup TIM_Output_Compare_Idle_State
  396. * @{
  397. */
  398. #define TIM_OCIdleState_Set ((uint16_t)0x0100)
  399. #define TIM_OCIdleState_Reset ((uint16_t)0x0000)
  400. #define IS_TIM_OCIDLE_STATE(STATE) (((STATE) == TIM_OCIdleState_Set) || \
  401. ((STATE) == TIM_OCIdleState_Reset))
  402. /**
  403. * @}
  404. */
  405. /** @defgroup TIM_Output_Compare_N_Idle_State
  406. * @{
  407. */
  408. #define TIM_OCNIdleState_Set ((uint16_t)0x0200)
  409. #define TIM_OCNIdleState_Reset ((uint16_t)0x0000)
  410. #define IS_TIM_OCNIDLE_STATE(STATE) (((STATE) == TIM_OCNIdleState_Set) || \
  411. ((STATE) == TIM_OCNIdleState_Reset))
  412. /**
  413. * @}
  414. */
  415. /** @defgroup TIM_Input_Capture_Polarity
  416. * @{
  417. */
  418. #define TIM_ICPolarity_Rising ((uint16_t)0x0000)
  419. #define TIM_ICPolarity_Falling ((uint16_t)0x0002)
  420. #define TIM_ICPolarity_BothEdge ((uint16_t)0x000A)
  421. #define IS_TIM_IC_POLARITY(POLARITY) (((POLARITY) == TIM_ICPolarity_Rising) || \
  422. ((POLARITY) == TIM_ICPolarity_Falling)|| \
  423. ((POLARITY) == TIM_ICPolarity_BothEdge))
  424. /**
  425. * @}
  426. */
  427. /** @defgroup TIM_Input_Capture_Selection
  428. * @{
  429. */
  430. #define TIM_ICSelection_DirectTI ((uint16_t)0x0001) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  431. connected to IC1, IC2, IC3 or IC4, respectively */
  432. #define TIM_ICSelection_IndirectTI ((uint16_t)0x0002) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  433. connected to IC2, IC1, IC4 or IC3, respectively. */
  434. #define TIM_ICSelection_TRC ((uint16_t)0x0003) /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to TRC. */
  435. #define IS_TIM_IC_SELECTION(SELECTION) (((SELECTION) == TIM_ICSelection_DirectTI) || \
  436. ((SELECTION) == TIM_ICSelection_IndirectTI) || \
  437. ((SELECTION) == TIM_ICSelection_TRC))
  438. /**
  439. * @}
  440. */
  441. /** @defgroup TIM_Input_Capture_Prescaler
  442. * @{
  443. */
  444. #define TIM_ICPSC_DIV1 ((uint16_t)0x0000) /*!< Capture performed each time an edge is detected on the capture input. */
  445. #define TIM_ICPSC_DIV2 ((uint16_t)0x0004) /*!< Capture performed once every 2 events. */
  446. #define TIM_ICPSC_DIV4 ((uint16_t)0x0008) /*!< Capture performed once every 4 events. */
  447. #define TIM_ICPSC_DIV8 ((uint16_t)0x000C) /*!< Capture performed once every 8 events. */
  448. #define IS_TIM_IC_PRESCALER(PRESCALER) (((PRESCALER) == TIM_ICPSC_DIV1) || \
  449. ((PRESCALER) == TIM_ICPSC_DIV2) || \
  450. ((PRESCALER) == TIM_ICPSC_DIV4) || \
  451. ((PRESCALER) == TIM_ICPSC_DIV8))
  452. /**
  453. * @}
  454. */
  455. /** @defgroup TIM_interrupt_sources
  456. * @{
  457. */
  458. #define TIM_IT_Update ((uint16_t)0x0001)
  459. #define TIM_IT_CC1 ((uint16_t)0x0002)
  460. #define TIM_IT_CC2 ((uint16_t)0x0004)
  461. #define TIM_IT_CC3 ((uint16_t)0x0008)
  462. #define TIM_IT_CC4 ((uint16_t)0x0010)
  463. #define TIM_IT_COM ((uint16_t)0x0020)
  464. #define TIM_IT_Trigger ((uint16_t)0x0040)
  465. #define TIM_IT_Break ((uint16_t)0x0080)
  466. #define IS_TIM_IT(IT) ((((IT) & (uint16_t)0xFF00) == 0x0000) && ((IT) != 0x0000))
  467. #define IS_TIM_GET_IT(IT) (((IT) == TIM_IT_Update) || \
  468. ((IT) == TIM_IT_CC1) || \
  469. ((IT) == TIM_IT_CC2) || \
  470. ((IT) == TIM_IT_CC3) || \
  471. ((IT) == TIM_IT_CC4) || \
  472. ((IT) == TIM_IT_COM) || \
  473. ((IT) == TIM_IT_Trigger) || \
  474. ((IT) == TIM_IT_Break))
  475. /**
  476. * @}
  477. */
  478. /** @defgroup TIM_DMA_Base_address
  479. * @{
  480. */
  481. #define TIM_DMABase_CR1 ((uint16_t)0x0000)
  482. #define TIM_DMABase_CR2 ((uint16_t)0x0001)
  483. #define TIM_DMABase_SMCR ((uint16_t)0x0002)
  484. #define TIM_DMABase_DIER ((uint16_t)0x0003)
  485. #define TIM_DMABase_SR ((uint16_t)0x0004)
  486. #define TIM_DMABase_EGR ((uint16_t)0x0005)
  487. #define TIM_DMABase_CCMR1 ((uint16_t)0x0006)
  488. #define TIM_DMABase_CCMR2 ((uint16_t)0x0007)
  489. #define TIM_DMABase_CCER ((uint16_t)0x0008)
  490. #define TIM_DMABase_CNT ((uint16_t)0x0009)
  491. #define TIM_DMABase_PSC ((uint16_t)0x000A)
  492. #define TIM_DMABase_ARR ((uint16_t)0x000B)
  493. #define TIM_DMABase_RCR ((uint16_t)0x000C)
  494. #define TIM_DMABase_CCR1 ((uint16_t)0x000D)
  495. #define TIM_DMABase_CCR2 ((uint16_t)0x000E)
  496. #define TIM_DMABase_CCR3 ((uint16_t)0x000F)
  497. #define TIM_DMABase_CCR4 ((uint16_t)0x0010)
  498. #define TIM_DMABase_BDTR ((uint16_t)0x0011)
  499. #define TIM_DMABase_DCR ((uint16_t)0x0012)
  500. #define TIM_DMABase_OR ((uint16_t)0x0013)
  501. #define IS_TIM_DMA_BASE(BASE) (((BASE) == TIM_DMABase_CR1) || \
  502. ((BASE) == TIM_DMABase_CR2) || \
  503. ((BASE) == TIM_DMABase_SMCR) || \
  504. ((BASE) == TIM_DMABase_DIER) || \
  505. ((BASE) == TIM_DMABase_SR) || \
  506. ((BASE) == TIM_DMABase_EGR) || \
  507. ((BASE) == TIM_DMABase_CCMR1) || \
  508. ((BASE) == TIM_DMABase_CCMR2) || \
  509. ((BASE) == TIM_DMABase_CCER) || \
  510. ((BASE) == TIM_DMABase_CNT) || \
  511. ((BASE) == TIM_DMABase_PSC) || \
  512. ((BASE) == TIM_DMABase_ARR) || \
  513. ((BASE) == TIM_DMABase_RCR) || \
  514. ((BASE) == TIM_DMABase_CCR1) || \
  515. ((BASE) == TIM_DMABase_CCR2) || \
  516. ((BASE) == TIM_DMABase_CCR3) || \
  517. ((BASE) == TIM_DMABase_CCR4) || \
  518. ((BASE) == TIM_DMABase_BDTR) || \
  519. ((BASE) == TIM_DMABase_DCR) || \
  520. ((BASE) == TIM_DMABase_OR))
  521. /**
  522. * @}
  523. */
  524. /** @defgroup TIM_DMA_Burst_Length
  525. * @{
  526. */
  527. #define TIM_DMABurstLength_1Transfer ((uint16_t)0x0000)
  528. #define TIM_DMABurstLength_2Transfers ((uint16_t)0x0100)
  529. #define TIM_DMABurstLength_3Transfers ((uint16_t)0x0200)
  530. #define TIM_DMABurstLength_4Transfers ((uint16_t)0x0300)
  531. #define TIM_DMABurstLength_5Transfers ((uint16_t)0x0400)
  532. #define TIM_DMABurstLength_6Transfers ((uint16_t)0x0500)
  533. #define TIM_DMABurstLength_7Transfers ((uint16_t)0x0600)
  534. #define TIM_DMABurstLength_8Transfers ((uint16_t)0x0700)
  535. #define TIM_DMABurstLength_9Transfers ((uint16_t)0x0800)
  536. #define TIM_DMABurstLength_10Transfers ((uint16_t)0x0900)
  537. #define TIM_DMABurstLength_11Transfers ((uint16_t)0x0A00)
  538. #define TIM_DMABurstLength_12Transfers ((uint16_t)0x0B00)
  539. #define TIM_DMABurstLength_13Transfers ((uint16_t)0x0C00)
  540. #define TIM_DMABurstLength_14Transfers ((uint16_t)0x0D00)
  541. #define TIM_DMABurstLength_15Transfers ((uint16_t)0x0E00)
  542. #define TIM_DMABurstLength_16Transfers ((uint16_t)0x0F00)
  543. #define TIM_DMABurstLength_17Transfers ((uint16_t)0x1000)
  544. #define TIM_DMABurstLength_18Transfers ((uint16_t)0x1100)
  545. #define IS_TIM_DMA_LENGTH(LENGTH) (((LENGTH) == TIM_DMABurstLength_1Transfer) || \
  546. ((LENGTH) == TIM_DMABurstLength_2Transfers) || \
  547. ((LENGTH) == TIM_DMABurstLength_3Transfers) || \
  548. ((LENGTH) == TIM_DMABurstLength_4Transfers) || \
  549. ((LENGTH) == TIM_DMABurstLength_5Transfers) || \
  550. ((LENGTH) == TIM_DMABurstLength_6Transfers) || \
  551. ((LENGTH) == TIM_DMABurstLength_7Transfers) || \
  552. ((LENGTH) == TIM_DMABurstLength_8Transfers) || \
  553. ((LENGTH) == TIM_DMABurstLength_9Transfers) || \
  554. ((LENGTH) == TIM_DMABurstLength_10Transfers) || \
  555. ((LENGTH) == TIM_DMABurstLength_11Transfers) || \
  556. ((LENGTH) == TIM_DMABurstLength_12Transfers) || \
  557. ((LENGTH) == TIM_DMABurstLength_13Transfers) || \
  558. ((LENGTH) == TIM_DMABurstLength_14Transfers) || \
  559. ((LENGTH) == TIM_DMABurstLength_15Transfers) || \
  560. ((LENGTH) == TIM_DMABurstLength_16Transfers) || \
  561. ((LENGTH) == TIM_DMABurstLength_17Transfers) || \
  562. ((LENGTH) == TIM_DMABurstLength_18Transfers))
  563. /**
  564. * @}
  565. */
  566. /** @defgroup TIM_DMA_sources
  567. * @{
  568. */
  569. #define TIM_DMA_Update ((uint16_t)0x0100)
  570. #define TIM_DMA_CC1 ((uint16_t)0x0200)
  571. #define TIM_DMA_CC2 ((uint16_t)0x0400)
  572. #define TIM_DMA_CC3 ((uint16_t)0x0800)
  573. #define TIM_DMA_CC4 ((uint16_t)0x1000)
  574. #define TIM_DMA_COM ((uint16_t)0x2000)
  575. #define TIM_DMA_Trigger ((uint16_t)0x4000)
  576. #define IS_TIM_DMA_SOURCE(SOURCE) ((((SOURCE) & (uint16_t)0x80FF) == 0x0000) && ((SOURCE) != 0x0000))
  577. /**
  578. * @}
  579. */
  580. /** @defgroup TIM_External_Trigger_Prescaler
  581. * @{
  582. */
  583. #define TIM_ExtTRGPSC_OFF ((uint16_t)0x0000)
  584. #define TIM_ExtTRGPSC_DIV2 ((uint16_t)0x1000)
  585. #define TIM_ExtTRGPSC_DIV4 ((uint16_t)0x2000)
  586. #define TIM_ExtTRGPSC_DIV8 ((uint16_t)0x3000)
  587. #define IS_TIM_EXT_PRESCALER(PRESCALER) (((PRESCALER) == TIM_ExtTRGPSC_OFF) || \
  588. ((PRESCALER) == TIM_ExtTRGPSC_DIV2) || \
  589. ((PRESCALER) == TIM_ExtTRGPSC_DIV4) || \
  590. ((PRESCALER) == TIM_ExtTRGPSC_DIV8))
  591. /**
  592. * @}
  593. */
  594. /** @defgroup TIM_Internal_Trigger_Selection
  595. * @{
  596. */
  597. #define TIM_TS_ITR0 ((uint16_t)0x0000)
  598. #define TIM_TS_ITR1 ((uint16_t)0x0010)
  599. #define TIM_TS_ITR2 ((uint16_t)0x0020)
  600. #define TIM_TS_ITR3 ((uint16_t)0x0030)
  601. #define TIM_TS_TI1F_ED ((uint16_t)0x0040)
  602. #define TIM_TS_TI1FP1 ((uint16_t)0x0050)
  603. #define TIM_TS_TI2FP2 ((uint16_t)0x0060)
  604. #define TIM_TS_ETRF ((uint16_t)0x0070)
  605. #define IS_TIM_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  606. ((SELECTION) == TIM_TS_ITR1) || \
  607. ((SELECTION) == TIM_TS_ITR2) || \
  608. ((SELECTION) == TIM_TS_ITR3) || \
  609. ((SELECTION) == TIM_TS_TI1F_ED) || \
  610. ((SELECTION) == TIM_TS_TI1FP1) || \
  611. ((SELECTION) == TIM_TS_TI2FP2) || \
  612. ((SELECTION) == TIM_TS_ETRF))
  613. #define IS_TIM_INTERNAL_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  614. ((SELECTION) == TIM_TS_ITR1) || \
  615. ((SELECTION) == TIM_TS_ITR2) || \
  616. ((SELECTION) == TIM_TS_ITR3))
  617. /**
  618. * @}
  619. */
  620. /** @defgroup TIM_TIx_External_Clock_Source
  621. * @{
  622. */
  623. #define TIM_TIxExternalCLK1Source_TI1 ((uint16_t)0x0050)
  624. #define TIM_TIxExternalCLK1Source_TI2 ((uint16_t)0x0060)
  625. #define TIM_TIxExternalCLK1Source_TI1ED ((uint16_t)0x0040)
  626. /**
  627. * @}
  628. */
  629. /** @defgroup TIM_External_Trigger_Polarity
  630. * @{
  631. */
  632. #define TIM_ExtTRGPolarity_Inverted ((uint16_t)0x8000)
  633. #define TIM_ExtTRGPolarity_NonInverted ((uint16_t)0x0000)
  634. #define IS_TIM_EXT_POLARITY(POLARITY) (((POLARITY) == TIM_ExtTRGPolarity_Inverted) || \
  635. ((POLARITY) == TIM_ExtTRGPolarity_NonInverted))
  636. /**
  637. * @}
  638. */
  639. /** @defgroup TIM_Prescaler_Reload_Mode
  640. * @{
  641. */
  642. #define TIM_PSCReloadMode_Update ((uint16_t)0x0000)
  643. #define TIM_PSCReloadMode_Immediate ((uint16_t)0x0001)
  644. #define IS_TIM_PRESCALER_RELOAD(RELOAD) (((RELOAD) == TIM_PSCReloadMode_Update) || \
  645. ((RELOAD) == TIM_PSCReloadMode_Immediate))
  646. /**
  647. * @}
  648. */
  649. /** @defgroup TIM_Forced_Action
  650. * @{
  651. */
  652. #define TIM_ForcedAction_Active ((uint16_t)0x0050)
  653. #define TIM_ForcedAction_InActive ((uint16_t)0x0040)
  654. #define IS_TIM_FORCED_ACTION(ACTION) (((ACTION) == TIM_ForcedAction_Active) || \
  655. ((ACTION) == TIM_ForcedAction_InActive))
  656. /**
  657. * @}
  658. */
  659. /** @defgroup TIM_Encoder_Mode
  660. * @{
  661. */
  662. #define TIM_EncoderMode_TI1 ((uint16_t)0x0001)
  663. #define TIM_EncoderMode_TI2 ((uint16_t)0x0002)
  664. #define TIM_EncoderMode_TI12 ((uint16_t)0x0003)
  665. #define IS_TIM_ENCODER_MODE(MODE) (((MODE) == TIM_EncoderMode_TI1) || \
  666. ((MODE) == TIM_EncoderMode_TI2) || \
  667. ((MODE) == TIM_EncoderMode_TI12))
  668. /**
  669. * @}
  670. */
  671. /** @defgroup TIM_Event_Source
  672. * @{
  673. */
  674. #define TIM_EventSource_Update ((uint16_t)0x0001)
  675. #define TIM_EventSource_CC1 ((uint16_t)0x0002)
  676. #define TIM_EventSource_CC2 ((uint16_t)0x0004)
  677. #define TIM_EventSource_CC3 ((uint16_t)0x0008)
  678. #define TIM_EventSource_CC4 ((uint16_t)0x0010)
  679. #define TIM_EventSource_COM ((uint16_t)0x0020)
  680. #define TIM_EventSource_Trigger ((uint16_t)0x0040)
  681. #define TIM_EventSource_Break ((uint16_t)0x0080)
  682. #define IS_TIM_EVENT_SOURCE(SOURCE) ((((SOURCE) & (uint16_t)0xFF00) == 0x0000) && ((SOURCE) != 0x0000))
  683. /**
  684. * @}
  685. */
  686. /** @defgroup TIM_Update_Source
  687. * @{
  688. */
  689. #define TIM_UpdateSource_Global ((uint16_t)0x0000) /*!< Source of update is the counter overflow/underflow
  690. or the setting of UG bit, or an update generation
  691. through the slave mode controller. */
  692. #define TIM_UpdateSource_Regular ((uint16_t)0x0001) /*!< Source of update is counter overflow/underflow. */
  693. #define IS_TIM_UPDATE_SOURCE(SOURCE) (((SOURCE) == TIM_UpdateSource_Global) || \
  694. ((SOURCE) == TIM_UpdateSource_Regular))
  695. /**
  696. * @}
  697. */
  698. /** @defgroup TIM_Output_Compare_Preload_State
  699. * @{
  700. */
  701. #define TIM_OCPreload_Enable ((uint16_t)0x0008)
  702. #define TIM_OCPreload_Disable ((uint16_t)0x0000)
  703. #define IS_TIM_OCPRELOAD_STATE(STATE) (((STATE) == TIM_OCPreload_Enable) || \
  704. ((STATE) == TIM_OCPreload_Disable))
  705. /**
  706. * @}
  707. */
  708. /** @defgroup TIM_Output_Compare_Fast_State
  709. * @{
  710. */
  711. #define TIM_OCFast_Enable ((uint16_t)0x0004)
  712. #define TIM_OCFast_Disable ((uint16_t)0x0000)
  713. #define IS_TIM_OCFAST_STATE(STATE) (((STATE) == TIM_OCFast_Enable) || \
  714. ((STATE) == TIM_OCFast_Disable))
  715. /**
  716. * @}
  717. */
  718. /** @defgroup TIM_Output_Compare_Clear_State
  719. * @{
  720. */
  721. #define TIM_OCClear_Enable ((uint16_t)0x0080)
  722. #define TIM_OCClear_Disable ((uint16_t)0x0000)
  723. #define IS_TIM_OCCLEAR_STATE(STATE) (((STATE) == TIM_OCClear_Enable) || \
  724. ((STATE) == TIM_OCClear_Disable))
  725. /**
  726. * @}
  727. */
  728. /** @defgroup TIM_Trigger_Output_Source
  729. * @{
  730. */
  731. #define TIM_TRGOSource_Reset ((uint16_t)0x0000)
  732. #define TIM_TRGOSource_Enable ((uint16_t)0x0010)
  733. #define TIM_TRGOSource_Update ((uint16_t)0x0020)
  734. #define TIM_TRGOSource_OC1 ((uint16_t)0x0030)
  735. #define TIM_TRGOSource_OC1Ref ((uint16_t)0x0040)
  736. #define TIM_TRGOSource_OC2Ref ((uint16_t)0x0050)
  737. #define TIM_TRGOSource_OC3Ref ((uint16_t)0x0060)
  738. #define TIM_TRGOSource_OC4Ref ((uint16_t)0x0070)
  739. #define IS_TIM_TRGO_SOURCE(SOURCE) (((SOURCE) == TIM_TRGOSource_Reset) || \
  740. ((SOURCE) == TIM_TRGOSource_Enable) || \
  741. ((SOURCE) == TIM_TRGOSource_Update) || \
  742. ((SOURCE) == TIM_TRGOSource_OC1) || \
  743. ((SOURCE) == TIM_TRGOSource_OC1Ref) || \
  744. ((SOURCE) == TIM_TRGOSource_OC2Ref) || \
  745. ((SOURCE) == TIM_TRGOSource_OC3Ref) || \
  746. ((SOURCE) == TIM_TRGOSource_OC4Ref))
  747. /**
  748. * @}
  749. */
  750. /** @defgroup TIM_Slave_Mode
  751. * @{
  752. */
  753. #define TIM_SlaveMode_Reset ((uint16_t)0x0004)
  754. #define TIM_SlaveMode_Gated ((uint16_t)0x0005)
  755. #define TIM_SlaveMode_Trigger ((uint16_t)0x0006)
  756. #define TIM_SlaveMode_External1 ((uint16_t)0x0007)
  757. #define IS_TIM_SLAVE_MODE(MODE) (((MODE) == TIM_SlaveMode_Reset) || \
  758. ((MODE) == TIM_SlaveMode_Gated) || \
  759. ((MODE) == TIM_SlaveMode_Trigger) || \
  760. ((MODE) == TIM_SlaveMode_External1))
  761. /**
  762. * @}
  763. */
  764. /** @defgroup TIM_Master_Slave_Mode
  765. * @{
  766. */
  767. #define TIM_MasterSlaveMode_Enable ((uint16_t)0x0080)
  768. #define TIM_MasterSlaveMode_Disable ((uint16_t)0x0000)
  769. #define IS_TIM_MSM_STATE(STATE) (((STATE) == TIM_MasterSlaveMode_Enable) || \
  770. ((STATE) == TIM_MasterSlaveMode_Disable))
  771. /**
  772. * @}
  773. */
  774. /** @defgroup TIM_Remap
  775. * @{
  776. */
  777. #define TIM2_TIM8_TRGO ((uint16_t)0x0000)
  778. #define TIM2_ETH_PTP ((uint16_t)0x0400)
  779. #define TIM2_USBFS_SOF ((uint16_t)0x0800)
  780. #define TIM2_USBHS_SOF ((uint16_t)0x0C00)
  781. #define TIM5_GPIO ((uint16_t)0x0000)
  782. #define TIM5_LSI ((uint16_t)0x0040)
  783. #define TIM5_LSE ((uint16_t)0x0080)
  784. #define TIM5_RTC ((uint16_t)0x00C0)
  785. #define TIM11_GPIO ((uint16_t)0x0000)
  786. #define TIM11_HSE ((uint16_t)0x0002)
  787. #define IS_TIM_REMAP(TIM_REMAP) (((TIM_REMAP) == TIM2_TIM8_TRGO)||\
  788. ((TIM_REMAP) == TIM2_ETH_PTP)||\
  789. ((TIM_REMAP) == TIM2_USBFS_SOF)||\
  790. ((TIM_REMAP) == TIM2_USBHS_SOF)||\
  791. ((TIM_REMAP) == TIM5_GPIO)||\
  792. ((TIM_REMAP) == TIM5_LSI)||\
  793. ((TIM_REMAP) == TIM5_LSE)||\
  794. ((TIM_REMAP) == TIM5_RTC)||\
  795. ((TIM_REMAP) == TIM11_GPIO)||\
  796. ((TIM_REMAP) == TIM11_HSE))
  797. /**
  798. * @}
  799. */
  800. /** @defgroup TIM_Flags
  801. * @{
  802. */
  803. #define TIM_FLAG_Update ((uint16_t)0x0001)
  804. #define TIM_FLAG_CC1 ((uint16_t)0x0002)
  805. #define TIM_FLAG_CC2 ((uint16_t)0x0004)
  806. #define TIM_FLAG_CC3 ((uint16_t)0x0008)
  807. #define TIM_FLAG_CC4 ((uint16_t)0x0010)
  808. #define TIM_FLAG_COM ((uint16_t)0x0020)
  809. #define TIM_FLAG_Trigger ((uint16_t)0x0040)
  810. #define TIM_FLAG_Break ((uint16_t)0x0080)
  811. #define TIM_FLAG_CC1OF ((uint16_t)0x0200)
  812. #define TIM_FLAG_CC2OF ((uint16_t)0x0400)
  813. #define TIM_FLAG_CC3OF ((uint16_t)0x0800)
  814. #define TIM_FLAG_CC4OF ((uint16_t)0x1000)
  815. #define IS_TIM_GET_FLAG(FLAG) (((FLAG) == TIM_FLAG_Update) || \
  816. ((FLAG) == TIM_FLAG_CC1) || \
  817. ((FLAG) == TIM_FLAG_CC2) || \
  818. ((FLAG) == TIM_FLAG_CC3) || \
  819. ((FLAG) == TIM_FLAG_CC4) || \
  820. ((FLAG) == TIM_FLAG_COM) || \
  821. ((FLAG) == TIM_FLAG_Trigger) || \
  822. ((FLAG) == TIM_FLAG_Break) || \
  823. ((FLAG) == TIM_FLAG_CC1OF) || \
  824. ((FLAG) == TIM_FLAG_CC2OF) || \
  825. ((FLAG) == TIM_FLAG_CC3OF) || \
  826. ((FLAG) == TIM_FLAG_CC4OF))
  827. /**
  828. * @}
  829. */
  830. /** @defgroup TIM_Input_Capture_Filer_Value
  831. * @{
  832. */
  833. #define IS_TIM_IC_FILTER(ICFILTER) ((ICFILTER) <= 0xF)
  834. /**
  835. * @}
  836. */
  837. /** @defgroup TIM_External_Trigger_Filter
  838. * @{
  839. */
  840. #define IS_TIM_EXT_FILTER(EXTFILTER) ((EXTFILTER) <= 0xF)
  841. /**
  842. * @}
  843. */
  844. /** @defgroup TIM_Legacy
  845. * @{
  846. */
  847. #define TIM_DMABurstLength_1Byte TIM_DMABurstLength_1Transfer
  848. #define TIM_DMABurstLength_2Bytes TIM_DMABurstLength_2Transfers
  849. #define TIM_DMABurstLength_3Bytes TIM_DMABurstLength_3Transfers
  850. #define TIM_DMABurstLength_4Bytes TIM_DMABurstLength_4Transfers
  851. #define TIM_DMABurstLength_5Bytes TIM_DMABurstLength_5Transfers
  852. #define TIM_DMABurstLength_6Bytes TIM_DMABurstLength_6Transfers
  853. #define TIM_DMABurstLength_7Bytes TIM_DMABurstLength_7Transfers
  854. #define TIM_DMABurstLength_8Bytes TIM_DMABurstLength_8Transfers
  855. #define TIM_DMABurstLength_9Bytes TIM_DMABurstLength_9Transfers
  856. #define TIM_DMABurstLength_10Bytes TIM_DMABurstLength_10Transfers
  857. #define TIM_DMABurstLength_11Bytes TIM_DMABurstLength_11Transfers
  858. #define TIM_DMABurstLength_12Bytes TIM_DMABurstLength_12Transfers
  859. #define TIM_DMABurstLength_13Bytes TIM_DMABurstLength_13Transfers
  860. #define TIM_DMABurstLength_14Bytes TIM_DMABurstLength_14Transfers
  861. #define TIM_DMABurstLength_15Bytes TIM_DMABurstLength_15Transfers
  862. #define TIM_DMABurstLength_16Bytes TIM_DMABurstLength_16Transfers
  863. #define TIM_DMABurstLength_17Bytes TIM_DMABurstLength_17Transfers
  864. #define TIM_DMABurstLength_18Bytes TIM_DMABurstLength_18Transfers
  865. /**
  866. * @}
  867. */
  868. /**
  869. * @}
  870. */
  871. /* Exported macro ------------------------------------------------------------*/
  872. /* Exported functions --------------------------------------------------------*/
  873. /* TimeBase management ********************************************************/
  874. void TIM_DeInit(TIM_TypeDef* TIMx);
  875. void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct);
  876. void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct);
  877. void TIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode);
  878. void TIM_CounterModeConfig(TIM_TypeDef* TIMx, uint16_t TIM_CounterMode);
  879. void TIM_SetCounter(TIM_TypeDef* TIMx, uint32_t Counter);
  880. void TIM_SetAutoreload(TIM_TypeDef* TIMx, uint32_t Autoreload);
  881. uint32_t TIM_GetCounter(TIM_TypeDef* TIMx);
  882. uint16_t TIM_GetPrescaler(TIM_TypeDef* TIMx);
  883. void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState NewState);
  884. void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, uint16_t TIM_UpdateSource);
  885. void TIM_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState NewState);
  886. void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, uint16_t TIM_OPMode);
  887. void TIM_SetClockDivision(TIM_TypeDef* TIMx, uint16_t TIM_CKD);
  888. void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState);
  889. /* Output Compare management **************************************************/
  890. void TIM_OC1Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct);
  891. void TIM_OC2Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct);
  892. void TIM_OC3Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct);
  893. void TIM_OC4Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct);
  894. void TIM_OCStructInit(TIM_OCInitTypeDef* TIM_OCInitStruct);
  895. void TIM_SelectOCxM(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_OCMode);
  896. void TIM_SetCompare1(TIM_TypeDef* TIMx, uint32_t Compare1);
  897. void TIM_SetCompare2(TIM_TypeDef* TIMx, uint32_t Compare2);
  898. void TIM_SetCompare3(TIM_TypeDef* TIMx, uint32_t Compare3);
  899. void TIM_SetCompare4(TIM_TypeDef* TIMx, uint32_t Compare4);
  900. void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction);
  901. void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction);
  902. void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction);
  903. void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, uint16_t TIM_ForcedAction);
  904. void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
  905. void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
  906. void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
  907. void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPreload);
  908. void TIM_OC1FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast);
  909. void TIM_OC2FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast);
  910. void TIM_OC3FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast);
  911. void TIM_OC4FastConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCFast);
  912. void TIM_ClearOC1Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear);
  913. void TIM_ClearOC2Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear);
  914. void TIM_ClearOC3Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear);
  915. void TIM_ClearOC4Ref(TIM_TypeDef* TIMx, uint16_t TIM_OCClear);
  916. void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity);
  917. void TIM_OC1NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity);
  918. void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity);
  919. void TIM_OC2NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity);
  920. void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity);
  921. void TIM_OC3NPolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCNPolarity);
  922. void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, uint16_t TIM_OCPolarity);
  923. void TIM_CCxCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCx);
  924. void TIM_CCxNCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCxN);
  925. /* Input Capture management ***************************************************/
  926. void TIM_ICInit(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct);
  927. void TIM_ICStructInit(TIM_ICInitTypeDef* TIM_ICInitStruct);
  928. void TIM_PWMIConfig(TIM_TypeDef* TIMx, TIM_ICInitTypeDef* TIM_ICInitStruct);
  929. uint32_t TIM_GetCapture1(TIM_TypeDef* TIMx);
  930. uint32_t TIM_GetCapture2(TIM_TypeDef* TIMx);
  931. uint32_t TIM_GetCapture3(TIM_TypeDef* TIMx);
  932. uint32_t TIM_GetCapture4(TIM_TypeDef* TIMx);
  933. void TIM_SetIC1Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC);
  934. void TIM_SetIC2Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC);
  935. void TIM_SetIC3Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC);
  936. void TIM_SetIC4Prescaler(TIM_TypeDef* TIMx, uint16_t TIM_ICPSC);
  937. /* Advanced-control timers (TIM1 and TIM8) specific features ******************/
  938. void TIM_BDTRConfig(TIM_TypeDef* TIMx, TIM_BDTRInitTypeDef *TIM_BDTRInitStruct);
  939. void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* TIM_BDTRInitStruct);
  940. void TIM_CtrlPWMOutputs(TIM_TypeDef* TIMx, FunctionalState NewState);
  941. void TIM_SelectCOM(TIM_TypeDef* TIMx, FunctionalState NewState);
  942. void TIM_CCPreloadControl(TIM_TypeDef* TIMx, FunctionalState NewState);
  943. /* Interrupts, DMA and flags management ***************************************/
  944. void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState);
  945. void TIM_GenerateEvent(TIM_TypeDef* TIMx, uint16_t TIM_EventSource);
  946. FlagStatus TIM_GetFlagStatus(TIM_TypeDef* TIMx, uint16_t TIM_FLAG);
  947. void TIM_ClearFlag(TIM_TypeDef* TIMx, uint16_t TIM_FLAG);
  948. ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t TIM_IT);
  949. void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, uint16_t TIM_IT);
  950. void TIM_DMAConfig(TIM_TypeDef* TIMx, uint16_t TIM_DMABase, uint16_t TIM_DMABurstLength);
  951. void TIM_DMACmd(TIM_TypeDef* TIMx, uint16_t TIM_DMASource, FunctionalState NewState);
  952. void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState NewState);
  953. /* Clocks management **********************************************************/
  954. void TIM_InternalClockConfig(TIM_TypeDef* TIMx);
  955. void TIM_ITRxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource);
  956. void TIM_TIxExternalClockConfig(TIM_TypeDef* TIMx, uint16_t TIM_TIxExternalCLKSource,
  957. uint16_t TIM_ICPolarity, uint16_t ICFilter);
  958. void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
  959. uint16_t ExtTRGFilter);
  960. void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler,
  961. uint16_t TIM_ExtTRGPolarity, uint16_t ExtTRGFilter);
  962. /* Synchronization management *************************************************/
  963. void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource);
  964. void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource);
  965. void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode);
  966. void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_MasterSlaveMode);
  967. void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
  968. uint16_t ExtTRGFilter);
  969. /* Specific interface management **********************************************/
  970. void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, uint16_t TIM_EncoderMode,
  971. uint16_t TIM_IC1Polarity, uint16_t TIM_IC2Polarity);
  972. void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState NewState);
  973. /* Specific remapping management **********************************************/
  974. void TIM_RemapConfig(TIM_TypeDef* TIMx, uint16_t TIM_Remap);
  975. #ifdef __cplusplus
  976. }
  977. #endif
  978. #endif /*__STM32F4xx_TIM_H */
  979. /**
  980. * @}
  981. */
  982. /**
  983. * @}
  984. */
  985. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/