gd32f10x_timer.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /**
  2. ******************************************************************************
  3. * @brief TIMER header file of the firmware library
  4. ******************************************************************************
  5. */
  6. /* Define to prevent recursive inclusion -------------------------------------*/
  7. #ifndef __GD32F10X_TIMER_H
  8. #define __GD32F10X_TIMER_H
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /* Includes ------------------------------------------------------------------*/
  13. #include "gd32f10x.h"
  14. /** @addtogroup GD32F10x_Firmware
  15. * @{
  16. */
  17. /** @addtogroup TIMER
  18. * @{
  19. */
  20. /** @defgroup TIMER_Exported_Types
  21. * @{
  22. */
  23. /**
  24. * @brief Timer base init structure
  25. */
  26. typedef struct {
  27. uint16_t TIMER_Prescaler; /*!< Clock prescaler value . */
  28. uint16_t TIMER_CounterMode; /*!< Counter mode ,
  29. a value of @ref TIMER_Counter_Mode. */
  30. uint32_t TIMER_Period; /*!< Value to be loaded into the active CARL at the next update event. */
  31. uint16_t TIMER_ClockDivision; /*!< Clock division ,
  32. a value of @ref TIMER_Clock_Division_CDIV. */
  33. uint8_t TIMER_RepetitionCounter; /*!< Repetition counter value , only valid in TIMER1/8. */
  34. } TIMER_BaseInitPara;
  35. /**
  36. * @brief Timer output compare init structure
  37. */
  38. typedef struct {
  39. uint16_t TIMER_OCMode; /*!< Out mode,
  40. a value of @ref TIMER_Output_Compare_and_PWM_modes */
  41. uint16_t TIMER_OutputState; /*!< Output Compare state ,
  42. a value of @ref TIMER_Output_Compare_State */
  43. uint16_t TIMER_OutputNState; /*!< Complementary Output Compare state ,
  44. a value of @ref TIMER_Output_Compare_N_State,
  45. valid only for TIMER1. */
  46. uint32_t TIMER_Pulse; /*!< Pulse value to be loaded into the CHCCx. */
  47. uint16_t TIMER_OCPolarity; /*!< Output polarity ,
  48. a value of @ref TIMER_Output_Compare_Polarity */
  49. uint16_t TIMER_OCNPolarity; /*!< Complementary output polarity ,
  50. a value of @ref TIMER_Output_Compare_N_Polarity */
  51. uint16_t TIMER_OCIdleState; /*!< TIM Output Compare pin state during Idle state ,
  52. a value of @ref TIMER_Output_Compare_Idle_State,
  53. valid only for TIMER1. */
  54. uint16_t TIMER_OCNIdleState; /*!< TIM Complementary Output Compare pin state during Idle state.
  55. a value of @ref TIMER_Output_Compare_N_Idle_State ,
  56. valid only for TIMER1. */
  57. } TIMER_OCInitPara;
  58. /**
  59. * @brief Timer input capture init structure
  60. */
  61. typedef struct {
  62. uint16_t TIMER_CH; /*!< TIMER channel ,
  63. a value of @ref TIMER_Channel */
  64. uint16_t TIMER_ICPolarity; /*!< Active edge of the input signal ,
  65. a value of @ref TIMER_Input_Capture_Polarity */
  66. uint16_t TIMER_ICSelection; /*!< Input Selection ,
  67. a value of @ref TIMER_Input_Capture_Selection */
  68. uint16_t TIMER_ICPrescaler; /*!< Input Capture Prescaler ,
  69. a value of @ref TIMER_Input_Capture_Prescaler */
  70. uint16_t TIMER_ICFilter; /*!< Input capture filter ,
  71. a number between 0x0 and 0xF */
  72. } TIMER_ICInitPara;
  73. /**
  74. * @brief Timer break and dead-time structure , valid only for TIMER1.
  75. */
  76. typedef struct {
  77. uint16_t TIMER_ROSState; /*!< Off-State selection used in Run mode ,
  78. a value of @ref TIMER_ROS_Off_State_Selection_for_Run_mode_State */
  79. uint16_t TIMER_IOSState; /*!< Off-State used in Idle state ,
  80. a value of @ref TIMER_IOS_Off_State_Selection_for_Idle_mode_State */
  81. uint16_t TIMER_LOCKLevel; /*!< LOCK level ,
  82. a value of @ref TIMER_Lock_level */
  83. uint16_t TIMER_DeadTime; /*!< delay time between the switching off and on of the outputs.
  84. a number between 0x00 and 0xFF */
  85. uint16_t TIMER_Break; /*!< Break input is enabled or disable,
  86. a value of @ref TIMER_Break_Input_State */
  87. uint16_t TIMER_BreakPolarity; /*!< Break Input pin polarity ,
  88. a value of @ref TIMER_Break_Input_Polarity */
  89. uint16_t TIMER_OutAuto; /*!< Automatic Output is enabled or disable.
  90. a value of @ref TIMER_OAE_Bit_State */
  91. } TIMER_BKDTInitPara;
  92. /**
  93. * @}
  94. */
  95. /** @defgroup TIMER_Exported_Constants
  96. * @{
  97. */
  98. /** @defgroup TIMER_Output_Compare_and_PWM_modes
  99. * @{
  100. */
  101. #define TIMER_OC_MODE_TIMING ((uint16_t)0x0000)
  102. #define TIMER_OC_MODE_ACTIVE ((uint16_t)0x0010)
  103. #define TIMER_OC_MODE_INACTIVE ((uint16_t)0x0020)
  104. #define TIMER_OC_MODE_TOGGLE ((uint16_t)0x0030)
  105. #define TIMER_OC_MODE_PWM1 ((uint16_t)0x0060)
  106. #define TIMER_OC_MODE_PWM2 ((uint16_t)0x0070)
  107. /**
  108. * @}
  109. */
  110. /** @defgroup TIMER_Single_Pulse_Mode
  111. * @{
  112. */
  113. #define TIMER_SP_MODE_SINGLE ((uint16_t)0x0008)
  114. #define TIMER_SP_MODE_REPETITIVE ((uint16_t)0x0000)
  115. /**
  116. * @}
  117. */
  118. /** @defgroup TIMER_Channel
  119. * @{
  120. */
  121. #define TIMER_CH_1 ((uint16_t)0x0000)
  122. #define TIMER_CH_2 ((uint16_t)0x0004)
  123. #define TIMER_CH_3 ((uint16_t)0x0008)
  124. #define TIMER_CH_4 ((uint16_t)0x000C)
  125. /**
  126. * @}
  127. */
  128. /** @defgroup TIMER_Clock_Division_CDIV
  129. * @{
  130. */
  131. #define TIMER_CDIV_DIV1 ((uint16_t)0x0000)
  132. #define TIMER_CDIV_DIV2 ((uint16_t)0x0100)
  133. #define TIMER_CDIV_DIV4 ((uint16_t)0x0200)
  134. /**
  135. * @}
  136. */
  137. /** @defgroup TIMER_Counter_Mode
  138. * @{
  139. */
  140. #define TIMER_COUNTER_UP ((uint16_t)0x0000)
  141. #define TIMER_COUNTER_DOWN ((uint16_t)0x0010)
  142. #define TIMER_COUNTER_CENTER_ALIGNED1 ((uint16_t)0x0020)
  143. #define TIMER_COUNTER_CENTER_ALIGNED2 ((uint16_t)0x0040)
  144. #define TIMER_COUNTER_CENTER_ALIGNED3 ((uint16_t)0x0060)
  145. /**
  146. * @}
  147. */
  148. /** @defgroup TIMER_Output_Compare_Polarity
  149. * @{
  150. */
  151. #define TIMER_OC_POLARITY_HIGH ((uint16_t)0x0000)
  152. #define TIMER_OC_POLARITY_LOW ((uint16_t)0x0002)
  153. /**
  154. * @}
  155. */
  156. /** @defgroup TIMER_Output_Compare_N_Polarity
  157. * @{
  158. */
  159. #define TIMER_OCN_POLARITY_HIGH ((uint16_t)0x0000)
  160. #define TIMER_OCN_POLARITY_LOW ((uint16_t)0x0008)
  161. /**
  162. * @}
  163. */
  164. /** @defgroup TIMER_Output_Compare_State
  165. * @{
  166. */
  167. #define TIMER_OUTPUT_STATE_DISABLE ((uint16_t)0x0000)
  168. #define TIMER_OUTPUT_STATE_ENABLE ((uint16_t)0x0001)
  169. /**
  170. * @}
  171. */
  172. /** @defgroup TIMER_Output_Compare_N_State
  173. * @{
  174. */
  175. #define TIMER_OUTPUTN_STATE_DISABLE ((uint16_t)0x0000)
  176. #define TIMER_OUTPUTN_STATE_ENABLE ((uint16_t)0x0004)
  177. /**
  178. * @}
  179. */
  180. /** @defgroup TIMER_Capture_Compare_State
  181. * @{
  182. */
  183. #define TIMER_CCX_ENABLE ((uint16_t)0x0001)
  184. #define TIMER_CCX_DISABLE ((uint16_t)0x0000)
  185. /**
  186. * @}
  187. */
  188. /** @defgroup TIMER_Capture_Compare_N_State
  189. * @{
  190. */
  191. #define TIMER_CCXN_ENABLE ((uint16_t)0x0004)
  192. #define TIMER_CCXN_DISABLE ((uint16_t)0x0000)
  193. /**
  194. * @}
  195. */
  196. /** @defgroup TIMER_Break_Input_State
  197. * @{
  198. */
  199. #define TIMER_BREAK_ENABLE ((uint16_t)0x1000)
  200. #define TIMER_BREAK_DISABLE ((uint16_t)0x0000)
  201. /**
  202. * @}
  203. */
  204. /** @defgroup TIMER_Break_Input_Polarity
  205. * @{
  206. */
  207. #define TIMER_BREAK_POLARITY_LOW ((uint16_t)0x0000)
  208. #define TIMER_BREAK_POLARITY_HIGH ((uint16_t)0x2000)
  209. /**
  210. * @}
  211. */
  212. /** @defgroup TIMER_OAE_Bit_State
  213. * @{
  214. */
  215. #define TIMER_OUTAUTO_ENABLE ((uint16_t)0x4000)
  216. #define TIMER_OUTAUTO_DISABLE ((uint16_t)0x0000)
  217. /**
  218. * @}
  219. */
  220. /** @defgroup TIMER_Lock_level
  221. * @{
  222. */
  223. #define TIMER_LOCK_LEVEL_OFF ((uint16_t)0x0000)
  224. #define TIMER_LOCK_LEVEL_1 ((uint16_t)0x0100)
  225. #define TIMER_LOCK_LEVEL_2 ((uint16_t)0x0200)
  226. #define TIMER_LOCK_LEVEL_3 ((uint16_t)0x0300)
  227. /**
  228. * @}
  229. */
  230. /** @defgroup TIMER_IOS_Off_State_Selection_for_Idle_mode_State
  231. * @{
  232. */
  233. #define TIMER_IOS_STATE_ENABLE ((uint16_t)0x0400)
  234. #define TIMER_IOS_STATE_DISABLE ((uint16_t)0x0000)
  235. /**
  236. * @}
  237. */
  238. /** @defgroup TIMER_ROS_Off_State_Selection_for_Run_mode_State
  239. * @{
  240. */
  241. #define TIMER_ROS_STATE_ENABLE ((uint16_t)0x0800)
  242. #define TIMER_ROS_STATE_DISABLE ((uint16_t)0x0000)
  243. /**
  244. * @}
  245. */
  246. /** @defgroup TIMER_Output_Compare_Idle_State
  247. * @{
  248. */
  249. #define TIMER_OC_IDLE_STATE_SET ((uint16_t)0x0100)
  250. #define TIMER_OC_IDLE_STATE_RESET ((uint16_t)0x0000)
  251. /**
  252. * @}
  253. */
  254. /** @defgroup TIMER_Output_Compare_N_Idle_State
  255. * @{
  256. */
  257. #define TIMER_OCN_IDLE_STATE_SET ((uint16_t)0x0200)
  258. #define TIMER_OCN_IDLE_STATE_RESET ((uint16_t)0x0000)
  259. /**
  260. * @}
  261. */
  262. /** @defgroup TIMER_Input_Capture_Polarity
  263. * @{
  264. */
  265. #define TIMER_IC_POLARITY_RISING ((uint16_t)0x0000)
  266. #define TIMER_IC_POLARITY_FALLING ((uint16_t)0x0002)
  267. /**
  268. * @}
  269. */
  270. /** @defgroup TIMER_Input_Capture_Selection
  271. * @{
  272. */
  273. #define TIMER_IC_SELECTION_DIRECTTI ((uint16_t)0x0001)
  274. #define TIMER_IC_SELECTION_INDIRECTTI ((uint16_t)0x0002)
  275. #define TIMER_IC_SELECTION_TRC ((uint16_t)0x0003)
  276. /**
  277. * @}
  278. */
  279. /** @defgroup TIMER_Input_Capture_Prescaler
  280. * @{
  281. */
  282. #define TIMER_IC_PSC_DIV1 ((uint16_t)0x0000)
  283. #define TIMER_IC_PSC_DIV2 ((uint16_t)0x0004)
  284. #define TIMER_IC_PSC_DIV4 ((uint16_t)0x0008)
  285. #define TIMER_IC_PSC_DIV8 ((uint16_t)0x000C)
  286. /**
  287. * @}
  288. */
  289. /** @defgroup TIMER_interrupt_sources
  290. * @{
  291. */
  292. #define TIMER_INT_UPDATE ((uint16_t)0x0001)
  293. #define TIMER_INT_CH1 ((uint16_t)0x0002)
  294. #define TIMER_INT_CH2 ((uint16_t)0x0004)
  295. #define TIMER_INT_CH3 ((uint16_t)0x0008)
  296. #define TIMER_INT_CH4 ((uint16_t)0x0010)
  297. #define TIMER_INT_CCUG ((uint16_t)0x0020)
  298. #define TIMER_INT_TRIGGER ((uint16_t)0x0040)
  299. #define TIMER_INT_BREAK ((uint16_t)0x0080)
  300. /**
  301. * @}
  302. */
  303. /** @defgroup TIMER_DMA_Base_address
  304. * @{
  305. */
  306. #define TIMER_DMA_BASE_ADDR_CTLR1 ((uint16_t)0x0000)
  307. #define TIMER_DMA_BASE_ADDR_CTLR2 ((uint16_t)0x0001)
  308. #define TIMER_DMA_BASE_ADDR_SMC ((uint16_t)0x0002)
  309. #define TIMER_DMA_BASE_ADDR_DIE ((uint16_t)0x0003)
  310. #define TIMER_DMA_BASE_ADDR_STR ((uint16_t)0x0004)
  311. #define TIMER_DMA_BASE_ADDR_EVG ((uint16_t)0x0005)
  312. #define TIMER_DMA_BASE_ADDR_CHCTLR1 ((uint16_t)0x0006)
  313. #define TIMER_DMA_BASE_ADDR_CHCTLR2 ((uint16_t)0x0007)
  314. #define TIMER_DMA_BASE_ADDR_CHE ((uint16_t)0x0008)
  315. #define TIMER_DMA_BASE_ADDR_CNT ((uint16_t)0x0009)
  316. #define TIMER_DMA_BASE_ADDR_PSC ((uint16_t)0x000A)
  317. #define TIMER_DMA_BASE_ADDR_CARL ((uint16_t)0x000B)
  318. #define TIMER_DMA_BASE_ADDR_CREP ((uint16_t)0x000C)
  319. #define TIMER_DMA_BASE_ADDR_CHCC1 ((uint16_t)0x000D)
  320. #define TIMER_DMA_BASE_ADDR_CHCC2 ((uint16_t)0x000E)
  321. #define TIMER_DMA_BASE_ADDR_CHCC3 ((uint16_t)0x000F)
  322. #define TIMER_DMA_BASE_ADDR_CHCC4 ((uint16_t)0x0010)
  323. #define TIMER_DMA_BASE_ADDR_BKDT ((uint16_t)0x0011)
  324. #define TIMER_DMA_BASE_ADDR_DCTLR ((uint16_t)0x0012)
  325. /**
  326. * @}
  327. */
  328. /** @defgroup TIMER_DMA_Burst_Transfer_Length
  329. * @{
  330. */
  331. #define TIMER_DMA_BURST_1TRANSFER ((uint16_t)0x0000)
  332. #define TIMER_DMA_BURST_2TRANSFERS ((uint16_t)0x0100)
  333. #define TIMER_DMA_BURST_3TRANSFERS ((uint16_t)0x0200)
  334. #define TIMER_DMA_BURST_4TRANSFERS ((uint16_t)0x0300)
  335. #define TIMER_DMA_BURST_5TRANSFERS ((uint16_t)0x0400)
  336. #define TIMER_DMA_BURST_6TRANSFERS ((uint16_t)0x0500)
  337. #define TIMER_DMA_BURST_7TRANSFERS ((uint16_t)0x0600)
  338. #define TIMER_DMA_BURST_8TRANSFERS ((uint16_t)0x0700)
  339. #define TIMER_DMA_BURST_9TRANSFERS ((uint16_t)0x0800)
  340. #define TIMER_DMA_BURST_10TRANSFERS ((uint16_t)0x0900)
  341. #define TIMER_DMA_BURST_11TRANSFERS ((uint16_t)0x0A00)
  342. #define TIMER_DMA_BURST_12TRANSFERS ((uint16_t)0x0B00)
  343. #define TIMER_DMA_BURST_13TRANSFERS ((uint16_t)0x0C00)
  344. #define TIMER_DMA_BURST_14TRANSFERS ((uint16_t)0x0D00)
  345. #define TIMER_DMA_BURST_15TRANSFERS ((uint16_t)0x0E00)
  346. #define TIMER_DMA_BURST_16TRANSFERS ((uint16_t)0x0F00)
  347. #define TIMER_DMA_BURST_17TRANSFERS ((uint16_t)0x1000)
  348. #define TIMER_DMA_BURST_18TRANSFERS ((uint16_t)0x1100)
  349. /**
  350. * @}
  351. */
  352. /** @defgroup TIMER_DMA_sources
  353. * @{
  354. */
  355. #define TIMER_DMA_UPDATE ((uint16_t)0x0100)
  356. #define TIMER_DMA_CH1 ((uint16_t)0x0200)
  357. #define TIMER_DMA_CH2 ((uint16_t)0x0400)
  358. #define TIMER_DMA_CH3 ((uint16_t)0x0800)
  359. #define TIMER_DMA_CH4 ((uint16_t)0x1000)
  360. #define TIMER_DMA_COM ((uint16_t)0x2000)
  361. #define TIMER_DMA_TRIGGER ((uint16_t)0x4000)
  362. /**
  363. * @}
  364. */
  365. /** @defgroup TIMER_External_Trigger_Prescaler
  366. * @{
  367. */
  368. #define TIMER_EXT_TRI_PSC_OFF ((uint16_t)0x0000)
  369. #define TIMER_EXT_TRI_PSC_DIV2 ((uint16_t)0x1000)
  370. #define TIMER_EXT_TRI_PSC_DIV4 ((uint16_t)0x2000)
  371. #define TIMER_EXT_TRI_PSC_DIV8 ((uint16_t)0x3000)
  372. /**
  373. * @}
  374. */
  375. /** @defgroup TIMER_Internal_Trigger_Selection
  376. * @{
  377. */
  378. #define TIMER_TS_ITR0 ((uint16_t)0x0000)
  379. #define TIMER_TS_ITR1 ((uint16_t)0x0010)
  380. #define TIMER_TS_ITR2 ((uint16_t)0x0020)
  381. #define TIMER_TS_ITR3 ((uint16_t)0x0030)
  382. #define TIMER_TS_TI1F_ED ((uint16_t)0x0040)
  383. #define TIMER_TS_TI1FP1 ((uint16_t)0x0050)
  384. #define TIMER_TS_TI2FP2 ((uint16_t)0x0060)
  385. #define TIMER_TS_ETRF ((uint16_t)0x0070)
  386. /**
  387. * @}
  388. */
  389. /** @defgroup TIMER_TIx_External_Clock_Source
  390. * @{
  391. */
  392. #define TIMER_TIX_EXCLK1_SRC_TI1 ((uint16_t)0x0050)
  393. #define TIMER_TIX_EXCLK1_SRC_TI2 ((uint16_t)0x0060)
  394. #define TIMER_TIX_EXCLK1_SRC_TI1ED ((uint16_t)0x0040)
  395. /**
  396. * @}
  397. */
  398. /** @defgroup TIMER_External_Trigger_Polarity
  399. * @{
  400. */
  401. #define TIMER_EXT_TRI_POLARITY_INVERTED ((uint16_t)0x8000)
  402. #define TIMER_EXT_TRI_POLARITY_NONINVERTED ((uint16_t)0x0000)
  403. /**
  404. * @}
  405. */
  406. /** @defgroup TIMER_Prescaler_Reload_Mode
  407. * @{
  408. */
  409. #define TIMER_PSC_RELOAD_UPDATE ((uint16_t)0x0000)
  410. #define TIMER_PSC_RELOAD_NOW ((uint16_t)0x0001)
  411. /**
  412. * @}
  413. */
  414. /** @defgroup TIMER_Forced_Output
  415. * @{
  416. */
  417. #define TIMER_FORCED_HIGH ((uint16_t)0x0050)
  418. #define TIMER_FORCED_LOW ((uint16_t)0x0040)
  419. /**
  420. * @}
  421. */
  422. /** @defgroup TIMER_Encoder_Mode
  423. * @{
  424. */
  425. #define TIMER_ENCODER_MODE_TI1 ((uint16_t)0x0001)
  426. #define TIMER_ENCODER_MODE_TI2 ((uint16_t)0x0002)
  427. #define TIMER_ENCODER_MODE_TI12 ((uint16_t)0x0003)
  428. /**
  429. * @}
  430. */
  431. /** @defgroup TIMER_Event_Source
  432. * @{
  433. */
  434. #define TIMER_EVENT_SRC_UPDATE ((uint16_t)0x0001)
  435. #define TIMER_EVENT_SRC_CH1 ((uint16_t)0x0002)
  436. #define TIMER_EVENT_SRC_CH2 ((uint16_t)0x0004)
  437. #define TIMER_EVENT_SRC_CH3 ((uint16_t)0x0008)
  438. #define TIMER_EVENT_SRC_CH4 ((uint16_t)0x0010)
  439. #define TIMER_EVENT_SRC_COM ((uint16_t)0x0020)
  440. #define TIMER_EVENT_SRC_TRIGGER ((uint16_t)0x0040)
  441. #define TIMER_EVENT_SRC_BREAK ((uint16_t)0x0080)
  442. /**
  443. * @}
  444. */
  445. /** @defgroup TIMER_Update_Source
  446. * @{
  447. */
  448. #define TIMER_UPDATE_SRC_GLOBAL ((uint16_t)0x0000)
  449. #define TIMER_UPDATE_SRC_REGULAR ((uint16_t)0x0001)
  450. /**
  451. * @}
  452. */
  453. /** @defgroup TIMER_Output_Compare_Preload_State
  454. * @{
  455. */
  456. #define TIMER_OC_PRELOAD_ENABLE ((uint16_t)0x0008)
  457. #define TIMER_OC_PRELOAD_DISABLE ((uint16_t)0x0000)
  458. /**
  459. * @}
  460. */
  461. /** @defgroup TIMER_Output_Compare_Fast_State
  462. * @{
  463. */
  464. #define TIMER_OC_FAST_ENABLE ((uint16_t)0x0004)
  465. #define TIMER_OC_FAST_DISABLE ((uint16_t)0x0000)
  466. /**
  467. * @}
  468. */
  469. /** @defgroup TIMER_Output_Compare_Clear_State
  470. * @{
  471. */
  472. #define TIMER_OC_CLEAR_ENABLE ((uint16_t)0x0080)
  473. #define TIMER_OC_CLEAR_DISABLE ((uint16_t)0x0000)
  474. /**
  475. * @}
  476. */
  477. /** @defgroup TIMER_Trigger_Output_Source
  478. * @{
  479. */
  480. #define TIMER_TRI_OUT_SRC_RESET ((uint16_t)0x0000)
  481. #define TIMER_TRI_OUT_SRC_ENABLE ((uint16_t)0x0010)
  482. #define TIMER_TRI_OUT_SRC_UPDATE ((uint16_t)0x0020)
  483. #define TIMER_TRI_OUT_SRC_OC1 ((uint16_t)0x0030)
  484. #define TIMER_TRI_OUT_SRC_OC1REF ((uint16_t)0x0040)
  485. #define TIMER_TRI_OUT_SRC_OC2REF ((uint16_t)0x0050)
  486. #define TIMER_TRI_OUT_SRC_OC3REF ((uint16_t)0x0060)
  487. #define TIMER_TRI_OUT_SRC_OC4REF ((uint16_t)0x0070)
  488. /**
  489. * @}
  490. */
  491. /** @defgroup TIMER_Slave_Mode
  492. * @{
  493. */
  494. #define TIMER_SLAVE_MODE_RESET ((uint16_t)0x0004)
  495. #define TIMER_SLAVE_MODE_GATED ((uint16_t)0x0005)
  496. #define TIMER_SLAVE_MODE_TRIGGER ((uint16_t)0x0006)
  497. #define TIMER_SLAVE_MODE_EXTERNAL1 ((uint16_t)0x0007)
  498. /**
  499. * @}
  500. */
  501. /** @defgroup TIMER_Master_Slave_Mode
  502. * @{
  503. */
  504. #define TIMER_MASTER_SLAVE_MODE_ENABLE ((uint16_t)0x0080)
  505. #define TIMER_MASTER_SLAVE_MODE_DISABLE ((uint16_t)0x0000)
  506. /**
  507. * @}
  508. */
  509. /** @defgroup TIMER_Flags
  510. * @{
  511. */
  512. #define TIMER_FLAG_UPDATE ((uint16_t)0x0001)
  513. #define TIMER_FLAG_CH1 ((uint16_t)0x0002)
  514. #define TIMER_FLAG_CH2 ((uint16_t)0x0004)
  515. #define TIMER_FLAG_CH3 ((uint16_t)0x0008)
  516. #define TIMER_FLAG_CH4 ((uint16_t)0x0010)
  517. #define TIMER_FLAG_COM ((uint16_t)0x0020)
  518. #define TIMER_FLAG_TRIGGER ((uint16_t)0x0040)
  519. #define TIMER_FLAG_BREAK ((uint16_t)0x0080)
  520. #define TIMER_FLAG_CH1OF ((uint16_t)0x0200)
  521. #define TIMER_FLAG_CH2OF ((uint16_t)0x0400)
  522. #define TIMER_FLAG_CH3OF ((uint16_t)0x0800)
  523. #define TIMER_FLAG_CH4OF ((uint16_t)0x1000)
  524. /**
  525. * @}
  526. */
  527. /**
  528. * @}
  529. */
  530. /** @defgroup TIMER_Exported_Functions
  531. * @{
  532. */
  533. /* TimeBase management ********************************************************/
  534. void TIMER_DeInit(TIMER_TypeDef *TIMERx);
  535. void TIMER_BaseInit(TIMER_TypeDef *TIMERx, TIMER_BaseInitPara *TIMER_Init);
  536. void TIMER_BaseStructInit(TIMER_BaseInitPara *TIMER_Init);
  537. void TIMER_PrescalerConfig(TIMER_TypeDef *TIMERx, uint16_t Prescaler, uint16_t TIMER_PSCReloadMode);
  538. void TIMER_CounterMode(TIMER_TypeDef *TIMERx, uint16_t TIMER_CounterMode);
  539. void TIMER_SetCounter(TIMER_TypeDef *TIMERx, uint32_t Counter);
  540. void TIMER_SetAutoreload(TIMER_TypeDef *TIMERx, uint32_t AutoReloadValue);
  541. uint32_t TIMER_GetCounter(TIMER_TypeDef *TIMERx);
  542. uint16_t TIMER_GetPrescaler(TIMER_TypeDef *TIMERx);
  543. void TIMER_UpdateDisableConfig(TIMER_TypeDef *TIMERx, TypeState NewValue);
  544. void TIMER_UpdateRequestConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_UpdateSrc);
  545. void TIMER_CARLPreloadConfig(TIMER_TypeDef *TIMERx, TypeState NewValue);
  546. void TIMER_SinglePulseMode(TIMER_TypeDef *TIMERx, uint16_t TIMER_SPMode);
  547. void TIMER_SetClockDivision(TIMER_TypeDef *TIMERx, uint16_t TIMER_CDIV);
  548. void TIMER_Enable(TIMER_TypeDef *TIMERx, TypeState NewValue);
  549. /* Advanced timer features*******************/
  550. void TIMER_BKDTConfig(TIMER_TypeDef *TIMERx, TIMER_BKDTInitPara *TIMER_BKDTInit);
  551. void TIMER_BKDTStructInit(TIMER_BKDTInitPara *TIMER_BKDTInit);
  552. void TIMER_CtrlPWMOutputs(TIMER_TypeDef *TIMERx, TypeState NewValue);
  553. /* Output Compare management **************************************************/
  554. void TIMER_OC1_Init(TIMER_TypeDef *TIMERx, TIMER_OCInitPara *TIMER_OCInit);
  555. void TIMER_OC2_Init(TIMER_TypeDef *TIMERx, TIMER_OCInitPara *TIMER_OCInit);
  556. void TIMER_OC3_Init(TIMER_TypeDef *TIMERx, TIMER_OCInitPara *TIMER_OCInit);
  557. void TIMER_OC4_Init(TIMER_TypeDef *TIMERx, TIMER_OCInitPara *TIMER_OCInit);
  558. void TIMER_OCStructInit(TIMER_OCInitPara *TIMER_OCInit);
  559. void TIMER_OCxModeConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_Ch, uint16_t TIMER_OCMode);
  560. void TIMER_Compare1Config(TIMER_TypeDef *TIMERx, uint32_t CompValue1);
  561. void TIMER_Compare2Config(TIMER_TypeDef *TIMERx, uint32_t CompValue2);
  562. void TIMER_Compare3Config(TIMER_TypeDef *TIMERx, uint32_t CompValue3);
  563. void TIMER_Compare4Config(TIMER_TypeDef *TIMERx, uint32_t CompValue4);
  564. void TIMER_Forced_OC1(TIMER_TypeDef *TIMERx, uint16_t TIMER_Forced);
  565. void TIMER_Forced_OC2(TIMER_TypeDef *TIMERx, uint16_t TIMER_Forced);
  566. void TIMER_Forced_OC3(TIMER_TypeDef *TIMERx, uint16_t TIMER_Forced);
  567. void TIMER_Forced_OC4(TIMER_TypeDef *TIMERx, uint16_t TIMER_Forced);
  568. void TIMER_CC_PreloadControl(TIMER_TypeDef *TIMERx, TypeState NewValue);
  569. void TIMER_OC1_Preload(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPreload);
  570. void TIMER_OC2_Preload(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPreload);
  571. void TIMER_OC3_Preload(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPreload);
  572. void TIMER_OC4_Preload(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPreload);
  573. void TIMER_OC1_FastConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCFast);
  574. void TIMER_OC2_FastConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCFast);
  575. void TIMER_OC3_FastConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCFast);
  576. void TIMER_OC4_FastConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCFast);
  577. void TIMER_OC1_RefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCClear);
  578. void TIMER_OC2_RefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCClear);
  579. void TIMER_OC3_RefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCClear);
  580. void TIMER_OC4_RefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCClear);
  581. void TIMER_OC1_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPolarity);
  582. void TIMER_OC1N_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCNPolarity);
  583. void TIMER_OC2_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPolarity);
  584. void TIMER_OC2N_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCNPolarity);
  585. void TIMER_OC3_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPolarity);
  586. void TIMER_OC3N_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCNPolarity);
  587. void TIMER_OC4_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPolarity);
  588. void TIMER_SelectOCRefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCRef_Clear);
  589. void TIMER_CCxCmd(TIMER_TypeDef *TIMERx, uint16_t TIMER_Ch, uint16_t TIMER_CCx);
  590. void TIMER_CCxNCmd(TIMER_TypeDef *TIMERx, uint16_t TIMER_Ch, uint16_t TIMER_CCxN);
  591. void TIMER_SelectCOM(TIMER_TypeDef *TIMERx, TypeState NewValue);
  592. /* Input Capture management ***************************************************/
  593. void TIMER_ICInit(TIMER_TypeDef *TIMERx, TIMER_ICInitPara *TIMER_ICInit);
  594. void TIMER_ICStructInit(TIMER_ICInitPara *TIMER_ICInit);
  595. void TIMER_PWMCaptureConfig(TIMER_TypeDef *TIMERx, TIMER_ICInitPara *TIMER_ICInit);
  596. uint32_t TIMER_GetCapture1(TIMER_TypeDef *TIMERx);
  597. uint32_t TIMER_GetCapture2(TIMER_TypeDef *TIMERx);
  598. uint32_t TIMER_GetCapture3(TIMER_TypeDef *TIMERx);
  599. uint32_t TIMER_GetCapture4(TIMER_TypeDef *TIMERx);
  600. void TIMER_Set_IC1_Prescaler(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPSC);
  601. void TIMER_Set_IC2_Prescaler(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPSC);
  602. void TIMER_Set_IC3_Prescaler(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPSC);
  603. void TIMER_Set_IC4_Prescaler(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPSC);
  604. /* Interrupts, DMA and flags management ***************************************/
  605. void TIMER_INTConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_INT, TypeState NewValue);
  606. void TIMER_GenerateEvent(TIMER_TypeDef *TIMERx, uint16_t TIMER_EventSrc);
  607. TypeState TIMER_GetBitState(TIMER_TypeDef *TIMERx, uint16_t TIMER_FLAG);
  608. void TIMER_ClearBitState(TIMER_TypeDef *TIMERx, uint16_t TIMER_FLAG);
  609. TypeState TIMER_GetIntBitState(TIMER_TypeDef *TIMERx, uint16_t TIMER_INT);
  610. void TIMER_ClearIntBitState(TIMER_TypeDef *TIMERx, uint16_t TIMER_INT);
  611. void TIMER_DMAConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_DMABase, uint16_t TIMER_DMABurstLength);
  612. void TIMER_DMACmd(TIMER_TypeDef *TIMERx, uint16_t TIMER_DMASrc, TypeState NewValue);
  613. void TIMER_CC_DMA(TIMER_TypeDef *TIMERx, TypeState NewValue);
  614. /* Clocks management **********************************************************/
  615. void TIMER_InternalClockConfig(TIMER_TypeDef *TIMERx);
  616. void TIMER_ITRxExtClock(TIMER_TypeDef *TIMERx, uint16_t TIMER_InputTriSrc);
  617. void TIMER_TIxExtCLkConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_TIxExCLKSrc,
  618. uint16_t TIMER_ICPolarity, uint16_t ICFilter);
  619. void TIMER_ETRClockMode1Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ExTriPrescaler, uint16_t TIMER_ExTriPolarity,
  620. uint16_t ExtTriFilter);
  621. void TIMER_ETRClockMode2Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ExTriPrescaler,
  622. uint16_t TIMER_ExTriPolarity, uint16_t ExtTriFilter);
  623. /* Synchronization management *************************************************/
  624. void TIMER_SelectInputTrigger(TIMER_TypeDef *TIMERx, uint16_t TIMER_InputTriSrc);
  625. void TIMER_SelectOutputTrigger(TIMER_TypeDef *TIMERx, uint16_t TIMER_TriOutSrc);
  626. void TIMER_SelectSlaveMode(TIMER_TypeDef *TIMERx, uint16_t TIMER_SlaveMode);
  627. void TIMER_SelectMasterSlaveMode(TIMER_TypeDef *TIMERx, uint16_t TIMER_MasterSlaveMode);
  628. void TIMER_ETRConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_ExTriPrescaler, uint16_t TIMER_ExTriPolarity,
  629. uint16_t ExtTriFilter);
  630. /* Specific interface management **********************************************/
  631. void TIMER_EncoderInterfaceConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_EncoderMode,
  632. uint16_t TIMER_IC1Polarity, uint16_t TIMER_IC2Polarity);
  633. void TIMER_SelectHallSensor(TIMER_TypeDef *TIMERx, TypeState NewValue);
  634. /**
  635. * @}
  636. */
  637. #ifdef __cplusplus
  638. }
  639. #endif
  640. #endif /*__GD32F10X_TIMER_H */
  641. /**
  642. * @}
  643. */
  644. /**
  645. * @}
  646. */