hal_tim.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file hal_tim.h
  3. /// @author AE TEAM
  4. /// @brief THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE TIM
  5. /// FIRMWARE LIBRARY.
  6. ////////////////////////////////////////////////////////////////////////////////
  7. /// @attention
  8. ///
  9. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  10. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  11. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  12. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  13. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  14. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  15. ///
  16. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Define to prevent recursive inclusion
  19. #ifndef __HAL_TIM_H
  20. #define __HAL_TIM_H
  21. // Files includes
  22. #include "types.h"
  23. #include "reg_tim.h"
  24. ////////////////////////////////////////////////////////////////////////////////
  25. /// @addtogroup MM32_Hardware_Abstract_Layer
  26. /// @{
  27. ////////////////////////////////////////////////////////////////////////////////
  28. /// @defgroup TIM_HAL
  29. /// @brief TIM HAL modules
  30. /// @{
  31. ////////////////////////////////////////////////////////////////////////////////
  32. /// @defgroup TIM_Exported_Types
  33. /// @{
  34. ////////////////////////////////////////////////////////////////////////////////
  35. /// @brief TIM_Channel
  36. /// @anchor TIM_Channel
  37. typedef enum {
  38. TIM_Channel_1 = 0x0000, ///< TIM Channel 1
  39. TIM_Channel_2 = 0x0004, ///< TIM Channel 2
  40. TIM_Channel_3 = 0x0008, ///< TIM Channel 3
  41. TIM_Channel_4 = 0x000C, ///< TIM Channel 4
  42. TIM_Channel_5 = 0x0010 ///< TIM Channel 5
  43. } TIMCHx_Typedef;
  44. ////////////////////////////////////////////////////////////////////////////////
  45. /// @brief TIM_Counter_Mode
  46. /// @anchor TIM_Counter_Mode
  47. typedef enum {
  48. TIM_CounterMode_Up = 0x0000, ///< TIM Up Counting Mode
  49. TIM_CounterMode_Down = TIM_CR1_DIR, ///< TIM Down Counting Mode
  50. TIM_CounterMode_CenterAligned1 = TIM_CR1_CMS_CENTERALIGNED1, ///< TIM Center Aligned Mode1
  51. TIM_CounterMode_CenterAligned2 = TIM_CR1_CMS_CENTERALIGNED2, ///< TIM Center Aligned Mode2
  52. TIM_CounterMode_CenterAligned3 = TIM_CR1_CMS_CENTERALIGNED3 ///< TIM Center Aligned Mode3
  53. } TIMCOUNTMODE_Typedef;
  54. ////////////////////////////////////////////////////////////////////////////////
  55. /// @brief TIM_Output_Compare_and_PWM_modes_and_Forced_Action
  56. /// @anchor TIM_Output_Compare_and_PWM_modes_and_Forced_Action
  57. typedef enum {
  58. TIM_OCMode_Timing = 0x0000, ///< Output compare mode: Timing
  59. TIM_OCMode_Active = 0x0010, ///< Output compare mode: Active
  60. TIM_OCMode_Inactive = 0x0020, ///< Output compare mode: Inactive
  61. TIM_OCMode_Toggle = 0x0030, ///< Output compare mode: Toggle
  62. TIM_OCMode_PWM1 = 0x0060, ///< Output compare mode: PWM1
  63. TIM_OCMode_PWM2 = 0x0070, ///< Output compare mode: PWM2
  64. TIM_ForcedAction_Active = 0x0050, ///< Force active level on OCnREF
  65. TIM_ForcedAction_InActive = 0x0040 ///< Force inactive level on OCnREF
  66. } TIMOCMODE_Typedef;
  67. ////////////////////////////////////////////////////////////////////////////////
  68. /// @brief TIM_Clock_Division_CKD
  69. /// @anchor TIM_Clock_Division_CKD
  70. typedef enum {
  71. TIM_CKD_DIV1 = TIM_CR1_CKD_DIV1, ///< TDTS = Tck_tim
  72. TIM_CKD_DIV2 = TIM_CR1_CKD_DIV2, ///< TDTS = 2 * Tck_tim
  73. TIM_CKD_DIV4 = TIM_CR1_CKD_DIV4 ///< TDTS = 4 * Tck_tim
  74. } TIMCKD_TypeDef;
  75. ////////////////////////////////////////////////////////////////////////////////
  76. /// @brief TIM_Internal_Trigger_Selection
  77. /// @anchor TIM_Internal_Trigger_Selection
  78. typedef enum {
  79. TIM_TS_ITR0 = TIM_SMCR_TS_ITR0, ///< Internal Trigger 0
  80. TIM_TS_ITR1 = TIM_SMCR_TS_ITR1, ///< Internal Trigger 1
  81. TIM_TS_ITR2 = TIM_SMCR_TS_ITR2, ///< Internal Trigger 2
  82. TIM_TS_ITR3 = TIM_SMCR_TS_ITR3, ///< Internal Trigger 3
  83. TIM_TS_TI1F_ED = TIM_SMCR_TS_TI1F_ED, ///< TI1 Edge Detector
  84. TIM_TS_TI1FP1 = TIM_SMCR_TS_TI1FP1, ///< Filtered Timer Input 1
  85. TIM_TS_TI2FP2 = TIM_SMCR_TS_TI2FP2, ///< Filtered Timer Input 2
  86. TIM_TS_ETRF = TIM_SMCR_TS_ETRF ///< TI1 Edge Detector
  87. } TIMTS_TypeDef;
  88. ////////////////////////////////////////////////////////////////////////////////
  89. /// @brief TIM_Trigger_Output_Source
  90. /// @anchor TIM_Trigger_Output_Source
  91. typedef enum {
  92. TIM_TRIGSource_Reset = TIM_CR2_MMS_RESET, ///< The UG bit in the TIM_EGR register is used as the trigger output (TRIG).
  93. TIM_TRIGSource_Enable = TIM_CR2_MMS_ENABLE, ///< The Counter Enable CEN is used as the trigger output (TRIG).
  94. TIM_TRIGSource_Update = TIM_CR2_MMS_UPDATE, ///< The update event is used as the trigger output (TRIG).
  95. TIM_TRIGSource_OC1 = TIM_CR2_MMS_OC1, ///< The trigger output sends a positive pulse when the CC1IF flag
  96. ///< is to be set, as soon as a capture or compare match occurs (TRIG).
  97. TIM_TRIGSource_OC1Ref = TIM_CR2_MMS_OC1REF, ///< OC1REF signal is used as the trigger output (TRIG).
  98. TIM_TRIGSource_OC2Ref = TIM_CR2_MMS_OC2REF, ///< OC2REF signal is used as the trigger output (TRIG).
  99. TIM_TRIGSource_OC3Ref = TIM_CR2_MMS_OC3REF, ///< OC3REF signal is used as the trigger output (TRIG).
  100. TIM_TRIGSource_OC4Ref = TIM_CR2_MMS_OC4REF ///< OC4REF signal is used as the trigger output (TRIG).
  101. } TIMMMS_Typedef;
  102. ////////////////////////////////////////////////////////////////////////////////
  103. /// @brief TIM_Slave_Mode
  104. /// @anchor TIM_Slave_Mode
  105. typedef enum {
  106. TIM_SlaveMode_Reset = TIM_SMCR_SMS_RESET, ///< Rising edge of the selected trigger signal (TRGI) re-initializes
  107. ///< the counter and triggers an update of the registers.
  108. TIM_SlaveMode_Gated = TIM_SMCR_SMS_GATED, ///< The counter clock is enabled when the trigger signal (TRGI) is high.
  109. TIM_SlaveMode_Trigger = TIM_SMCR_SMS_TRIGGER, ///< The counter starts at a rising edge of the trigger TRGI.
  110. TIM_SlaveMode_External1 = TIM_SMCR_SMS_EXTERNAL1 ///< Rising edges of the selected trigger (TRGI) clock the counter.
  111. } TIMSMSMODE_Typedef;
  112. ////////////////////////////////////////////////////////////////////////////////
  113. /// @brief TIM_Event_Source
  114. /// @anchor TIM_Event_Source
  115. typedef enum {
  116. TIM_EventSource_Update = TIM_EGR_UG, ///< Timer update Event source
  117. TIM_EventSource_CC1 = TIM_EGR_CC1G, ///< Timer Capture Compare 1 Event source
  118. TIM_EventSource_CC2 = TIM_EGR_CC2G, ///< Timer Capture Compare 2 Event source
  119. TIM_EventSource_CC3 = TIM_EGR_CC3G, ///< Timer Capture Compare 3 Event source
  120. TIM_EventSource_CC4 = TIM_EGR_CC4G, ///< Timer Capture Compare 4 Event source
  121. TIM_EventSource_COM = TIM_EGR_COMG, ///< Timer COM event source
  122. TIM_EventSource_Trigger = TIM_EGR_TG, ///< Timer Trigger Event source
  123. TIM_EventSource_Break = TIM_EGR_BG, ///< Timer Break event source
  124. TIM_EventSource_CC5 = (s32)0x00010000, ///< Timer Capture Compare 5 Event source
  125. } TIMEGR_Typedef;
  126. ////////////////////////////////////////////////////////////////////////////////
  127. /// @brief TIM_External_Trigger_Prescaler
  128. /// @anchor TIM_External_Trigger_Prescaler
  129. typedef enum {
  130. TIM_ExtTRGPSC_OFF = TIM_SMCR_ETPS_OFF, ///< ETRP Prescaler OFF
  131. TIM_ExtTRGPSC_DIV2 = TIM_SMCR_ETPS_DIV2, ///< ETRP frequency divided by 2
  132. TIM_ExtTRGPSC_DIV4 = TIM_SMCR_ETPS_DIV4, ///< ETRP frequency divided by 4
  133. TIM_ExtTRGPSC_DIV8 = TIM_SMCR_ETPS_DIV8 ///< ETRP frequency divided by 8
  134. } TIMEXTTRGPSC_Typedef;
  135. ////////////////////////////////////////////////////////////////////////////////
  136. /// @brief TIM_TIx_External_Clock_Source
  137. /// @anchor TIM_TIx_External_Clock_Source
  138. typedef enum {
  139. TIM_TIxExternalCLK1Source_TI1 = TIM_SMCR_TS_TI1FP1, ///< Filtered Timer Input 1
  140. TIM_TIxExternalCLK1Source_TI2 = TIM_SMCR_TS_TI2FP2, ///< Filtered Timer Input 2
  141. TIM_TIxExternalCLK1Source_TI1ED = TIM_SMCR_TS_TI1F_ED ///< TI1 Edge Detector
  142. } TIM_TIEXTCLKSRC_Typedef;
  143. ////////////////////////////////////////////////////////////////////////////////
  144. /// @brief Lock_level
  145. /// @anchor Lock_level
  146. typedef enum {
  147. TIM_LOCKLevel_OFF = TIM_BDTR_LOCK_OFF, ///< No bit is write protected.
  148. TIM_LOCKLevel_1 = TIM_BDTR_LOCK_1, ///< DTG bits in TIMx_BDTR register, OISx and OISxN bits in TIMx_CR2
  149. ///< register and BKE/BKP/AOE bits in TIMx_BDTR register can no longer be written.
  150. TIM_LOCKLevel_2 = TIM_BDTR_LOCK_2, ///< LOCK Level 1 + CC Polarity bits (CCxP/CCxNP bits in TIMx_CCER
  151. ///< register, as s32 as the related channel is configured in output through the CCxS
  152. ///< bits) as well as OSSR and OSSI bits can no longer be written.
  153. TIM_LOCKLevel_3 = TIM_BDTR_LOCK_3 ///< LOCK Level 2 + CC Control bits (OCxM and OCxPE bits in TIMx_CCMRx registers,
  154. ///< as s32 as the related channel is configured in output through the CCxS bits)
  155. ///< can no longer be written.
  156. } TIMLOCKLEVEL_Typedef;
  157. ////////////////////////////////////////////////////////////////////////////////
  158. /// @brief TIM_One_Pulse_Mode
  159. /// @anchor TIM_One_Pulse_Mode
  160. typedef enum {
  161. TIM_OPMode_Repetitive = 0, ///< Counter is not stopped at update event
  162. TIM_OPMode_Single = TIM_CR1_OPM ///< Counter stops counting at the next update event (clearing the bit CEN)
  163. } TIMOPMODE_Typedef;
  164. ////////////////////////////////////////////////////////////////////////////////
  165. /// @brief TIM_Output_Compare_Polarity
  166. /// @anchor TIM_Output_Compare_Polarity
  167. typedef enum {
  168. TIM_OCPolarity_High, ///< Output Compare active high
  169. TIM_OCPolarity_Low = TIM_CCER_CC1P ///< Output Compare active low
  170. } TIMCCxP_Typedef;
  171. ////////////////////////////////////////////////////////////////////////////////
  172. /// @brief TIM_Output_Compare_N_Polarity
  173. /// @anchor TIM_Output_Compare_N_Polarity
  174. typedef enum {
  175. TIM_OCNPolarity_High, ///< Output Compare active high
  176. TIM_OCNPolarity_Low = TIM_CCER_CC1NP ///< Output Compare active low
  177. } TIMCCxNP_Typedef;
  178. ////////////////////////////////////////////////////////////////////////////////
  179. /// @brief TIM_Output_Compare_state
  180. /// @anchor TIM_Output_Compare_state
  181. typedef enum {
  182. TIM_OutputState_Disable = 0, ///< Output Compare Disable
  183. TIM_OutputState_Enable = TIM_CCER_CC1EN ///< Output Compare Enable
  184. } TIMOUTPUTSTATE_Typedef;
  185. ////////////////////////////////////////////////////////////////////////////////
  186. /// @brief TIM_Output_Compare_N_state
  187. /// @anchor TIM_Output_Compare_N_state
  188. typedef enum {
  189. TIM_OutputNState_Disable = 0, ///< Output Compare N Disable
  190. TIM_OutputNState_Enable = TIM_CCER_CC1NEN ///< Output Compare N Enable
  191. } TIMOUTPUTNSTATE_Typedef;
  192. ////////////////////////////////////////////////////////////////////////////////
  193. /// @brief TIM_Capture_Compare_state
  194. /// @anchor TIM_Capture_Compare_state
  195. typedef enum {
  196. TIM_CCx_Disable = 0, ///< Capture/Compare Enable
  197. TIM_CCx_Enable = TIM_CCER_CC1EN ///< Capture/Compare Enable
  198. } TIMCCxE_Typedef;
  199. ////////////////////////////////////////////////////////////////////////////////
  200. /// @brief TIM_Capture_Compare_N_state
  201. /// @anchor TIM_Capture_Compare_N_state
  202. typedef enum {
  203. TIM_CCxN_Disable = 0, ///< Capture/Compare N Enable
  204. TIM_CCxN_Enable = TIM_CCER_CC1NEN ///< Capture/Compare N Enable
  205. } TIMCCxNE_Typedef;
  206. ////////////////////////////////////////////////////////////////////////////////
  207. /// @brief Break_Input_enable_disable
  208. /// @anchor Break_Input_enable_disable
  209. typedef enum {
  210. TIM_Break_Disable = 0, ///< Break inputs (BRK and CSS clock failure event) disabled
  211. TIM_Break_Enable = TIM_BDTR_BKEN ///< Break inputs (BRK and CSS clock failure event) enabled
  212. } TIMBKE_Typedef;
  213. ////////////////////////////////////////////////////////////////////////////////
  214. /// @brief Break_Polarity
  215. /// @anchor Break_Polarity
  216. typedef enum {
  217. TIM_BreakPolarity_Low = 0, ///< Break input BRK is active low
  218. TIM_BreakPolarity_High = TIM_BDTR_BKP ///< Break input BRK is active high
  219. } TIMBKP_Typedef;
  220. ////////////////////////////////////////////////////////////////////////////////
  221. /// @brief TIM_AOE_Bit_Set_Reset
  222. /// @anchor TIM_AOE_Bit_Set_Reset
  223. typedef enum {
  224. TIM_AutomaticOutput_Disable = 0, ///< MOE can be set only by software.
  225. TIM_AutomaticOutput_Enable = TIM_BDTR_AOEN ///< MOE can be set by software or automatically at the next
  226. ///< update event (if the break input is not be active).
  227. } TIMAOE_Typedef;
  228. ////////////////////////////////////////////////////////////////////////////////
  229. /// @brief TIM_DOE_Bit_Set_Reset
  230. /// @anchor TIM_DOE_Bit_Set_Reset
  231. typedef enum {
  232. TIM_DirectOutput_Disable = 0, ///< Direct output disable, output waiting for dead time
  233. TIM_DirectOutput_Enable = TIM_BDTR_DOEN ///< Direct output enable, no longer waiting for output after dead time
  234. } TIMDOE_Typedef;
  235. ////////////////////////////////////////////////////////////////////////////////
  236. /// @brief OSSI_Off_State_Selection_for_Idle_mode_state
  237. /// @anchor OSSI_Off_State_Selection_for_Idle_mode_state
  238. typedef enum {
  239. TIM_OSSIState_Disable = 0, ///< When inactive, OC/OCN outputs are disabled (OC/OCN enable output signal=0).
  240. TIM_OSSIState_Enable = TIM_BDTR_OSSI ///< When inactive, OC/OCN outputs are forced first with their idle level
  241. ///< as soon as CCxE=1 or CCxNE=1. OC/OCN enable output signal=1).
  242. } TIMOSSI_Typedef;
  243. ////////////////////////////////////////////////////////////////////////////////
  244. /// @brief OSSR_Off_State_Selection_for_Run_mode_state
  245. /// @anchor OSSR_Off_State_Selection_for_Run_mode_state
  246. typedef enum {
  247. TIM_OSSRState_Disable = 0, ///< When inactive, OC/OCN outputs are disabled (OC/OCN enable output signal=0).
  248. TIM_OSSRState_Enable = TIM_BDTR_OSSR ///< When inactive, OC/OCN outputs are enabled with their inactive level
  249. ///< as soon as CCxE=1 or CCxNE=1. Then, OC/OCN enable output signal=1.
  250. } TIMOSSR_Typedef;
  251. ////////////////////////////////////////////////////////////////////////////////
  252. /// @brief TIM_Output_Compare_Idle_State
  253. /// @anchor TIM_Output_Compare_Idle_State
  254. typedef enum {
  255. TIM_OCIdleState_Reset = 0, ///< OCn=0 (after a dead-time if OCnN is implemented) when MOE=0.(n= 0 : 4)
  256. TIM_OCIdleState_Set = TIM_CR2_OIS1 ///< OCn=1 (after a dead-time if OCnN is implemented) when MOE=0.(n= 0 : 4)
  257. } TIMOIS_Typedef;
  258. ////////////////////////////////////////////////////////////////////////////////
  259. /// @brief TIM_Output_Compare_N_Idle_State
  260. /// @anchor TIM_Output_Compare_N_Idle_State
  261. typedef enum {
  262. TIM_OCNIdleState_Reset = 0, ///< OCnN=0 after a dead-time when MOE=0.(n= 0 : 4)
  263. TIM_OCNIdleState_Set = TIM_CR2_OIS1N ///< OCnN=1 after a dead-time when MOE=0.(n= 0 : 4)
  264. } TIMOISN_Typedef;
  265. ////////////////////////////////////////////////////////////////////////////////
  266. /// @brief TIM_Input_Capture_Selection
  267. /// @anchor TIM_Input_Capture_Selection
  268. typedef enum {
  269. TIM_ICSelection_DirectTI = TIM_CCMR1_CC1S_DIRECTTI,
  270. TIM_ICSelection_IndirectTI = TIM_CCMR1_CC1S_INDIRECTTI,
  271. TIM_ICSelection_TRC = TIM_CCMR1_CC1S_TRC ///< TIM Input is selected to be connected to TRC.
  272. } TIMICSEL_Typedef;
  273. ////////////////////////////////////////////////////////////////////////////////
  274. /// @brief TIM_Input_Capture_Prescaler
  275. /// @anchor TIM_Input_Capture_Prescaler
  276. typedef enum {
  277. TIM_ICPSC_DIV1 = 0x0000, ///< no prescaler
  278. TIM_ICPSC_DIV2 = 0x0004, ///< capture is done once every 2 events
  279. TIM_ICPSC_DIV4 = 0x0008, ///< capture is done once every 4 events
  280. TIM_ICPSC_DIV8 = 0x000C ///< capture is done once every 8 events
  281. } TIMICPSC_Typedef;
  282. ////////////////////////////////////////////////////////////////////////////////
  283. /// @brief TIM_Input_Capture_Polarity
  284. /// @anchor TIM_Input_Capture_Polarity
  285. typedef enum {
  286. TIM_ICPolarity_Rising = 0, ///< IC Rising edge
  287. TIM_ICPolarity_Falling = TIM_CCER_CC1P, ///< IC Falling edge
  288. TIM_ICPolarity_BothEdge = TIM_CCER_CC1P | TIM_CCER_CC1NP
  289. } TIMICP_Typedef;
  290. ////////////////////////////////////////////////////////////////////////////////
  291. /// @brief TIM_External_Trigger_Polarity
  292. /// @anchor TIM_External_Trigger_Polarity
  293. typedef enum {
  294. TIM_ExtTRGPolarity_NonInverted = 0, ///< Active high or rising edge active
  295. TIM_ExtTRGPolarity_Inverted = TIM_SMCR_ETP ///< Active low or falling edge active
  296. } TIMETP_Typedef;
  297. ////////////////////////////////////////////////////////////////////////////////
  298. /// @brief TIM_Prescaler_Reload_Mode
  299. /// @anchor TIM_Prescaler_Reload_Mode
  300. typedef enum {
  301. TIM_PSCReloadMode_Update = 0, ///< The Prescaler is loaded at the update event
  302. TIM_PSCReloadMode_Immediate = TIM_EGR_UG ///< The Prescaler is loaded immediately
  303. } TIMUG_Typedef;
  304. ////////////////////////////////////////////////////////////////////////////////
  305. /// @brief TIM_Encoder_Mode
  306. /// @anchor TIM_Encoder_Mode
  307. typedef enum {
  308. TIM_EncoderMode_TI1 = TIM_SMCR_SMS_ENCODER1, ///< Counter counts on TI1FP1 edge depending on TI2FP2 level.
  309. TIM_EncoderMode_TI2 = TIM_SMCR_SMS_ENCODER2, ///< Counter counts on TI2FP2 edge depending on TI1FP1 level.
  310. TIM_EncoderMode_TI12 = TIM_SMCR_SMS_ENCODER3 ///< Counter counts on both TI1FP1 and TI2FP2 edges depending
  311. ///< on the level of the other input.
  312. } TIMSMSENCODER_Typedef;
  313. ////////////////////////////////////////////////////////////////////////////////
  314. /// @brief TIM_Update_Source
  315. /// @anchor TIM_Update_Source
  316. typedef enum {
  317. TIM_UpdateSource_Global = 0, ///< Source of update is counter overflow/underflow.
  318. TIM_UpdateSource_Regular = TIM_CR1_URS ///< Source of update is the counter overflow/underflow
  319. ///< or the setting of UG bit, or an update generation
  320. ///< through the slave mode controller.
  321. } TIMURS_Typedef;
  322. ////////////////////////////////////////////////////////////////////////////////
  323. /// @brief TIM_Output_Compare_Preload_State
  324. /// @anchor TIM_Output_Compare_Preload_State
  325. typedef enum {
  326. TIM_OCPreload_Disable = 0, ///< TIM output compare preload disable
  327. TIM_OCPreload_Enable = TIM_CCMR1_OC1PEN ///< TIM output compare preload enable
  328. } TIMOCPE_Typedef;
  329. ////////////////////////////////////////////////////////////////////////////////
  330. /// @brief TIM_Output_Compare_Fast_State
  331. /// @anchor TIM_Output_Compare_Fast_State
  332. typedef enum {
  333. TIM_OCFast_Disable = 0, ///< TIM output compare fast disable
  334. TIM_OCFast_Enable = TIM_CCMR1_OC1FEN, ///< TIM output compare fast enable
  335. } TIMOCFE_Typedef;
  336. ////////////////////////////////////////////////////////////////////////////////
  337. /// @brief TIM_Output_Compare_Clear_State
  338. /// @anchor TIM_Output_Compare_Clear_State
  339. typedef enum {
  340. TIM_OCClear_Disable = 0, ///< TIM Output clear disable
  341. TIM_OCClear_Enable = TIM_CCMR1_OC1CEN ///< TIM Output clear enable
  342. } TIMOCCE_Typedef;
  343. ////////////////////////////////////////////////////////////////////////////////
  344. /// @brief TIM_Master_Slave_Mode
  345. /// @anchor TIM_Master_Slave_Mode
  346. typedef enum {
  347. TIM_MasterSlaveMode_Disable = 0, ///< No action
  348. TIM_MasterSlaveMode_Enable = TIM_SMCR_MSM ///< synchronization between the current timer and its slaves (through TRIG)
  349. } TIMMSM_Typedef;
  350. ////////////////////////////////////////////////////////////////////////////////
  351. /// @brief TIM_interrupt_sources
  352. /// @anchor TIM_Master_Slave_Mode
  353. typedef enum {
  354. TIM_IT_Update = TIM_DIER_UI, ///< TIM update Interrupt source
  355. TIM_IT_CC1 = TIM_DIER_CC1I, ///< TIM Capture Compare 1 Interrupt source
  356. TIM_IT_CC2 = TIM_DIER_CC2I, ///< TIM Capture Compare 2 Interrupt source
  357. TIM_IT_CC3 = TIM_DIER_CC3I, ///< TIM Capture Compare 3 Interrupt source
  358. TIM_IT_CC4 = TIM_DIER_CC4I, ///< TIM Capture Compare 4 Interrupt source
  359. TIM_IT_COM = TIM_DIER_COMI, ///< TIM Commutation Interrupt source
  360. TIM_IT_Trigger = TIM_DIER_TI, ///< TIM Trigger Interrupt source
  361. TIM_IT_Break = TIM_DIER_BI ///< TIM Break Interrupt source
  362. , TIM_IT_CC5 = TIM_DIER_CC5I ///< TIM Capture Compare 5 Interrupt source
  363. } TIMIT_TypeDef;
  364. ////////////////////////////////////////////////////////////////////////////////
  365. /// @brief TIM_Flags
  366. /// @anchor TIM_Flags
  367. typedef enum {
  368. TIM_FLAG_Update = TIM_SR_UI, ///< TIM update Flag
  369. TIM_FLAG_CC1 = TIM_SR_CC1I, ///< TIM Capture Compare 1 Flag
  370. TIM_FLAG_CC2 = TIM_SR_CC2I, ///< TIM Capture Compare 2 Flag
  371. TIM_FLAG_CC3 = TIM_SR_CC3I, ///< TIM Capture Compare 3 Flag
  372. TIM_FLAG_CC4 = TIM_SR_CC4I, ///< TIM Capture Compare 4 Flag
  373. TIM_FLAG_COM = TIM_SR_COMI, ///< TIM Commutation Flag
  374. TIM_FLAG_Trigger = TIM_SR_TI, ///< TIM Trigger Flag
  375. TIM_FLAG_Break = TIM_SR_BI, ///< TIM Break Flag
  376. TIM_FLAG_CC1OF = TIM_SR_CC1O, ///< TIM Capture Compare 1 overcapture Flag
  377. TIM_FLAG_CC2OF = TIM_SR_CC2O, ///< TIM Capture Compare 2 overcapture Flag
  378. TIM_FLAG_CC3OF = TIM_SR_CC3O, ///< TIM Capture Compare 3 overcapture Flag
  379. TIM_FLAG_CC4OF = TIM_SR_CC4O ///< TIM Capture Compare 4 overcapture Flag
  380. , TIM_FLAG_CC5 = TIM_SR_CC5I ///< TIM Capture Compare 5 Flag
  381. } TIMFLAG_Typedef;
  382. ////////////////////////////////////////////////////////////////////////////////
  383. /// @brief TIM_DMA_sources
  384. /// @anchor TIM_DMA_sources
  385. typedef enum {
  386. TIM_DMA_Update = TIM_DIER_UD, ///< TIM update Interrupt source
  387. TIM_DMA_CC1 = TIM_DIER_CC1D, ///< TIM Capture Compare 1 DMA source
  388. TIM_DMA_CC2 = TIM_DIER_CC2D, ///< TIM Capture Compare 2 DMA source
  389. TIM_DMA_CC3 = TIM_DIER_CC3D, ///< TIM Capture Compare 3 DMA source
  390. TIM_DMA_CC4 = TIM_DIER_CC4D, ///< TIM Capture Compare 4 DMA source
  391. TIM_DMA_COM = TIM_DIER_COMD, ///< TIM Commutation DMA source
  392. TIM_DMA_Trigger = TIM_DIER_TD ///< TIM Trigger DMA source
  393. } TIMDMASRC_Typedef;
  394. ////////////////////////////////////////////////////////////////////////////////
  395. /// @brief TIM_DMA_Base_address
  396. /// @anchor TIM_DMA_Base_address
  397. typedef enum {
  398. TIM_DMABase_CR1 = 0x0000,
  399. TIM_DMABase_CR2 = 0x0001,
  400. TIM_DMABase_SMCR = 0x0002,
  401. TIM_DMABase_DIER = 0x0003,
  402. TIM_DMABase_SR = 0x0004,
  403. TIM_DMABase_EGR = 0x0005,
  404. TIM_DMABase_CCMR1 = 0x0006,
  405. TIM_DMABase_CCMR2 = 0x0007,
  406. TIM_DMABase_CCER = 0x0008,
  407. TIM_DMABase_CNT = 0x0009,
  408. TIM_DMABase_PSC = 0x000A,
  409. TIM_DMABase_ARR = 0x000B,
  410. TIM_DMABase_RCR = 0x000C,
  411. TIM_DMABase_CCR1 = 0x000D,
  412. TIM_DMABase_CCR2 = 0x000E,
  413. TIM_DMABase_CCR3 = 0x000F,
  414. TIM_DMABase_CCR4 = 0x0010,
  415. TIM_DMABase_BDTR = 0x0011,
  416. TIM_DMABase_DCR = 0x0012
  417. } TIMDMABASE_Typedef;
  418. ////////////////////////////////////////////////////////////////////////////////
  419. /// @brief TIM_DMA_Burst_Length
  420. /// @anchor TIM_DMA_Burst_Length
  421. typedef enum {
  422. TIM_DMABurstLength_1Byte = 0x0000,
  423. TIM_DMABurstLength_2Bytes = 0x0100,
  424. TIM_DMABurstLength_3Bytes = 0x0200,
  425. TIM_DMABurstLength_4Bytes = 0x0300,
  426. TIM_DMABurstLength_5Bytes = 0x0400,
  427. TIM_DMABurstLength_6Bytes = 0x0500,
  428. TIM_DMABurstLength_7Bytes = 0x0600,
  429. TIM_DMABurstLength_8Bytes = 0x0700,
  430. TIM_DMABurstLength_9Bytes = 0x0800,
  431. TIM_DMABurstLength_10Bytes = 0x0900,
  432. TIM_DMABurstLength_11Bytes = 0x0A00,
  433. TIM_DMABurstLength_12Bytes = 0x0B00,
  434. TIM_DMABurstLength_13Bytes = 0x0C00,
  435. TIM_DMABurstLength_14Bytes = 0x0D00,
  436. TIM_DMABurstLength_15Bytes = 0x0E00,
  437. TIM_DMABurstLength_16Bytes = 0x0F00,
  438. TIM_DMABurstLength_17Bytes = 0x1000,
  439. TIM_DMABurstLength_18Bytes = 0x1100
  440. } TIMDMABURSTLENGTH_Typedef;
  441. ////////////////////////////////////////////////////////////////////////////////
  442. /// @brief TIM Time Base Init structure definition
  443. /// @note This structure is used with all tim.
  444. ////////////////////////////////////////////////////////////////////////////////
  445. typedef struct {
  446. u16 TIM_Prescaler; ///< Specifies the prescaler value used to divide the TIM clock.
  447. ///< This parameter can be a number between 0x0000 and 0xFFFF
  448. TIMCOUNTMODE_Typedef TIM_CounterMode; ///< Specifies the counter mode.
  449. ///< This parameter can be a value of @ref TIM_Counter_Mode
  450. u32 TIM_Period; ///< Specifies the period value to be loaded into the active
  451. ///< Auto-Reload Register at the next update event.
  452. ///< This parameter must be a number between 0x0000 and 0xFFFF/0xFFFFFFFF.
  453. ///< @note 0xFFFFFFFF is valid only for MM32 32bit Timers: eg.TIM2 or TIM5.
  454. TIMCKD_TypeDef TIM_ClockDivision; ///< Specifies the clock division.
  455. ///< This parameter can be a value of @ref TIM_Clock_Division_CKD
  456. u8 TIM_RepetitionCounter; ///< Specifies the repetition counter value. Each time the RCR downcounter
  457. ///< reaches zero, an update event is generated and counting restarts
  458. ///< from the RCR value (N).
  459. ///< This means in PWM mode that (N+1) corresponds to:
  460. ///< - the number of PWM periods in edge-aligned mode
  461. ///< - the number of half PWM period in center-aligned mode
  462. ///< This parameter must be a number between 0x00 and 0xFF.
  463. ///< @note This parameter is valid only for TIM1 and TIM8.
  464. } TIM_TimeBaseInitTypeDef;
  465. ////////////////////////////////////////////////////////////////////////////////
  466. /// @brief TIM Output Compare Init structure definition
  467. ////////////////////////////////////////////////////////////////////////////////
  468. typedef struct {
  469. TIMOCMODE_Typedef TIM_OCMode; ///< Specifies the TIM mode.
  470. ///< This parameter can be a value of TIM_Output_Compare_and_PWM_modes
  471. TIMOUTPUTSTATE_Typedef TIM_OutputState; ///< Specifies the TIM Output Compare state.
  472. ///< This parameter can be a value of TIM_Output_Compare_state
  473. TIMOUTPUTNSTATE_Typedef TIM_OutputNState; ///< Specifies the TIM complementary Output Compare state.
  474. ///< This parameter can be a value of TIM_Output_Compare_N_state
  475. ///< @note This parameter is valid only for TIM1 and TIM8.
  476. u32 TIM_Pulse; ///< Specifies the pulse value to be loaded into the Capture Compare Register.
  477. ///< This parameter can be a number between 0x0000 and 0xFFFF/0xFFFFFFFF
  478. ///< @note 0xFFFFFFFF is valid only for MM32 32bit Timers: eg.TIM2 or TIM5.
  479. TIMCCxP_Typedef TIM_OCPolarity; ///< Specifies the output polarity.
  480. ///< This parameter can be a value of @ref TIM_Output_Compare_Polarity
  481. TIMCCxNP_Typedef TIM_OCNPolarity; ///< Specifies the complementary output polarity.
  482. ///< This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  483. ///< @note This parameter is valid only for TIM1 and TIM8.
  484. TIMOIS_Typedef TIM_OCIdleState; ///< Specifies the TIM Output Compare pin state during Idle state.
  485. ///< This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  486. ///< @note This parameter is valid only for TIM1 and TIM8.
  487. TIMOISN_Typedef TIM_OCNIdleState; ///< Specifies the TIM Output Compare pin state during Idle state.
  488. ///< This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  489. ///< @note This parameter is valid only for TIM1 and TIM8.
  490. } TIM_OCInitTypeDef;
  491. ////////////////////////////////////////////////////////////////////////////////
  492. /// @brief TIM Input Capture Init structure definition
  493. ////////////////////////////////////////////////////////////////////////////////
  494. typedef struct {
  495. TIMCHx_Typedef TIM_Channel; ///< Specifies the TIM channel.
  496. ///< This parameter can be a value of @ref TIM_Channel
  497. TIMICP_Typedef TIM_ICPolarity; ///< Specifies the active edge of the input signal.
  498. ///< This parameter can be a value of @ref TIM_Input_Capture_Polarity
  499. TIMICSEL_Typedef TIM_ICSelection; ///< Specifies the input.
  500. ///< This parameter can be a value of @ref TIM_Input_Capture_Selection
  501. TIMICPSC_Typedef TIM_ICPrescaler; ///< Specifies the Input Capture Prescaler.
  502. ///< This parameter can be a value of @ref TIM_Input_Capture_Prescaler
  503. u16 TIM_ICFilter; ///< Specifies the input capture filter.
  504. ///< This parameter can be a number between 0x0 and 0xF
  505. } TIM_ICInitTypeDef;
  506. ////////////////////////////////////////////////////////////////////////////////
  507. /// @brief BDTR structure definition
  508. /// @note This structure is used only with TIM1 and TIM8.
  509. ////////////////////////////////////////////////////////////////////////////////
  510. typedef struct {
  511. TIMOSSR_Typedef TIM_OSSRState; ///< Specifies the Off-State selection used in Run mode.
  512. ///< This parameter can be a value of @ref OSSR_Off_State_Selection_for_Run_mode_state
  513. TIMOSSI_Typedef TIM_OSSIState; ///< Specifies the Off-State used in Idle state.
  514. ///< This parameter can be a value of @ref OSSI_Off_State_Selection_for_Idle_mode_state
  515. TIMLOCKLEVEL_Typedef TIM_LOCKLevel; ///< Specifies the LOCK level parameters.
  516. ///< This parameter can be a value of @ref Lock_level
  517. u16 TIM_DeadTime; ///< Specifies the delay time between the switching-off and
  518. ///< the switching-on of the outputs.
  519. ///< This parameter can be a number between 0x00 and 0xFF
  520. TIMBKE_Typedef TIM_Break; ///< Specifies whether the TIM Break input is enabled or not.
  521. ///< This parameter can be a value of @ref Break_Input_enable_disable
  522. TIMBKP_Typedef TIM_BreakPolarity; ///< Specifies the TIM Break Input pin polarity.
  523. ///< This parameter can be a value of @ref Break_Polarity
  524. TIMAOE_Typedef TIM_AutomaticOutput; ///< Specifies whether the TIM Automatic Output feature is enabled or not.
  525. ///< This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset
  526. } TIM_BDTRInitTypeDef;
  527. /// @}
  528. ////////////////////////////////////////////////////////////////////////////////
  529. /// @defgroup TIM_Exported_Variables
  530. /// @{
  531. #ifdef _HAL_TIM_C_
  532. #define GLOBAL
  533. static void TI1_Configure(TIM_TypeDef* tim, u16 polarity, u16 selection, u16 filter);
  534. static void TI2_Configure(TIM_TypeDef* tim, u16 polarity, u16 selection, u16 filter);
  535. static void TI3_Configure(TIM_TypeDef* tim, u16 polarity, u16 selection, u16 filter);
  536. static void TI4_Configure(TIM_TypeDef* tim, u16 polarity, u16 selection, u16 filter);
  537. #else
  538. #define GLOBAL extern
  539. #endif
  540. #undef GLOBAL
  541. /// @}
  542. ////////////////////////////////////////////////////////////////////////////////
  543. /// @defgroup TIM_Exported_Functions
  544. /// @{
  545. ////////////////////////////////////////////////////////////////////////////////
  546. //================= TimeBase management ======================================
  547. void TIM_DeInit(TIM_TypeDef* tim);
  548. void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef* init_struct);
  549. void TIM_TimeBaseInit(TIM_TypeDef* tim, TIM_TimeBaseInitTypeDef* init_struct);
  550. void TIM_PrescalerConfig(TIM_TypeDef* tim, u16 prescaler, TIMUG_Typedef reload_mode);
  551. void TIM_CounterModeConfig(TIM_TypeDef* tim, TIMCOUNTMODE_Typedef counter_mode);
  552. void TIM_SetCounter(TIM_TypeDef* tim, u32 counter);
  553. void TIM_SetAutoreload(TIM_TypeDef* tim, u16 auto_reload);
  554. void TIM_UpdateDisableConfig(TIM_TypeDef* tim, FunctionalState state);
  555. void TIM_UpdateRequestConfig(TIM_TypeDef* tim, TIMURS_Typedef source);
  556. void TIM_ARRPreloadConfig(TIM_TypeDef* tim, FunctionalState state);
  557. void TIM_SelectOnePulseMode(TIM_TypeDef* tim, TIMOPMODE_Typedef mode);
  558. void TIM_SetClockDivision(TIM_TypeDef* tim, TIMCKD_TypeDef clock_div);
  559. void TIM_Cmd(TIM_TypeDef* tim, FunctionalState state);
  560. u32 TIM_GetCounter(TIM_TypeDef* tim);
  561. u16 TIM_GetPrescaler(TIM_TypeDef* tim);
  562. //================= Advanced-control timers specific features ================
  563. void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* init_struct);
  564. void TIM_BDTRConfig(TIM_TypeDef* tim, TIM_BDTRInitTypeDef* init_struct);
  565. void TIM_CtrlPWMOutputs(TIM_TypeDef* tim, FunctionalState state);
  566. //================= Output Compare management ================================
  567. void TIM_OCStructInit(TIM_OCInitTypeDef* init_struct);
  568. void TIM_OC1Init(TIM_TypeDef* tim, TIM_OCInitTypeDef* init_struct);
  569. void TIM_OC2Init(TIM_TypeDef* tim, TIM_OCInitTypeDef* init_struct);
  570. void TIM_OC3Init(TIM_TypeDef* tim, TIM_OCInitTypeDef* init_struct);
  571. void TIM_OC4Init(TIM_TypeDef* tim, TIM_OCInitTypeDef* init_struct);
  572. void TIM_SelectOCxM(TIM_TypeDef* tim, TIMCHx_Typedef channel, TIMOCMODE_Typedef mode);
  573. void TIM_SetCompare1(TIM_TypeDef* tim, u32 compare);
  574. void TIM_SetCompare2(TIM_TypeDef* tim, u32 compare);
  575. void TIM_SetCompare3(TIM_TypeDef* tim, u32 compare);
  576. void TIM_SetCompare4(TIM_TypeDef* tim, u32 compare);
  577. void TIM_ForcedOC1Config(TIM_TypeDef* tim, TIMOCMODE_Typedef forced_action);
  578. void TIM_ForcedOC2Config(TIM_TypeDef* tim, TIMOCMODE_Typedef forced_action);
  579. void TIM_ForcedOC3Config(TIM_TypeDef* tim, TIMOCMODE_Typedef forced_action);
  580. void TIM_ForcedOC4Config(TIM_TypeDef* tim, TIMOCMODE_Typedef forced_action);
  581. void TIM_CCPreloadControl(TIM_TypeDef* tim, FunctionalState state);
  582. void TIM_OC1PreloadConfig(TIM_TypeDef* tim, TIMOCPE_Typedef preload);
  583. void TIM_OC2PreloadConfig(TIM_TypeDef* tim, TIMOCPE_Typedef preload);
  584. void TIM_OC3PreloadConfig(TIM_TypeDef* tim, TIMOCPE_Typedef preload);
  585. void TIM_OC4PreloadConfig(TIM_TypeDef* tim, TIMOCPE_Typedef preload);
  586. void TIM_OC1FastConfig(TIM_TypeDef* tim, TIMOCFE_Typedef fast);
  587. void TIM_OC2FastConfig(TIM_TypeDef* tim, TIMOCFE_Typedef fast);
  588. void TIM_OC3FastConfig(TIM_TypeDef* tim, TIMOCFE_Typedef fast);
  589. void TIM_OC4FastConfig(TIM_TypeDef* tim, TIMOCFE_Typedef fast);
  590. void TIM_ClearOC1Ref(TIM_TypeDef* tim, TIMOCCE_Typedef clear);
  591. void TIM_ClearOC2Ref(TIM_TypeDef* tim, TIMOCCE_Typedef clear);
  592. void TIM_ClearOC3Ref(TIM_TypeDef* tim, TIMOCCE_Typedef clear);
  593. void TIM_ClearOC4Ref(TIM_TypeDef* tim, TIMOCCE_Typedef clear);
  594. void TIM_OC1PolarityConfig(TIM_TypeDef* tim, TIMCCxP_Typedef polarity);
  595. void TIM_OC1NPolarityConfig(TIM_TypeDef* tim, TIMCCxNP_Typedef polarity);
  596. void TIM_OC2PolarityConfig(TIM_TypeDef* tim, TIMCCxP_Typedef polarity);
  597. void TIM_OC2NPolarityConfig(TIM_TypeDef* tim, TIMCCxNP_Typedef polarity);
  598. void TIM_OC3PolarityConfig(TIM_TypeDef* tim, TIMCCxP_Typedef polarity);
  599. void TIM_OC3NPolarityConfig(TIM_TypeDef* tim, TIMCCxNP_Typedef polarity);
  600. void TIM_OC4PolarityConfig(TIM_TypeDef* tim, TIMCCxP_Typedef polarity);
  601. void TIM_CCxCmd(TIM_TypeDef* tim, TIMCHx_Typedef channel, TIMCCxE_Typedef ccx_en);
  602. void TIM_CCxNCmd(TIM_TypeDef* tim, TIMCHx_Typedef channel, TIMCCxNE_Typedef ccxn_en);
  603. void TIM_SelectCOM(TIM_TypeDef* tim, FunctionalState state);
  604. //================= Input Capture management =================================
  605. void TIM_ICStructInit(TIM_ICInitTypeDef* init_struct);
  606. void TIM_ICInit(TIM_TypeDef* tim, TIM_ICInitTypeDef* init_struct);
  607. void TIM_PWMIConfig(TIM_TypeDef* tim, TIM_ICInitTypeDef* init_struct);
  608. void TIM_SetIC1Prescaler(TIM_TypeDef* tim, TIMICPSC_Typedef psc);
  609. void TIM_SetIC2Prescaler(TIM_TypeDef* tim, TIMICPSC_Typedef psc);
  610. void TIM_SetIC3Prescaler(TIM_TypeDef* tim, TIMICPSC_Typedef psc);
  611. void TIM_SetIC4Prescaler(TIM_TypeDef* tim, TIMICPSC_Typedef psc);
  612. u32 TIM_GetCapture1(TIM_TypeDef* tim);
  613. u32 TIM_GetCapture2(TIM_TypeDef* tim);
  614. u32 TIM_GetCapture3(TIM_TypeDef* tim);
  615. u32 TIM_GetCapture4(TIM_TypeDef* tim);
  616. //================= Interrupts, DMA and flags management =====================
  617. void TIM_ITConfig(TIM_TypeDef* tim, u32 it, FunctionalState state);//TIMIT_TypeDef
  618. void TIM_GenerateEvent(TIM_TypeDef* tim, TIMEGR_Typedef source);
  619. void TIM_ClearFlag(TIM_TypeDef* tim, TIMFLAG_Typedef flag);
  620. void TIM_ClearITPendingBit(TIM_TypeDef* tim, u32 it);//TIMIT_TypeDef
  621. void TIM_DMAConfig(TIM_TypeDef* tim, TIMDMABASE_Typedef dma_base, TIMDMABURSTLENGTH_Typedef length);
  622. void TIM_DMACmd(TIM_TypeDef* tim, TIMDMASRC_Typedef source, FunctionalState state);
  623. void TIM_SelectCCDMA(TIM_TypeDef* tim, FunctionalState state);
  624. FlagStatus TIM_GetFlagStatus(TIM_TypeDef* tim, TIMFLAG_Typedef flag);
  625. ITStatus TIM_GetITStatus(TIM_TypeDef* tim, TIMIT_TypeDef it);
  626. //================= Clocks management ========================================
  627. void TIM_InternalClockConfig(TIM_TypeDef* tim);
  628. void TIM_ITRxExternalClockConfig(TIM_TypeDef* tim, TIMTS_TypeDef source);
  629. void TIM_TIxExternalClockConfig(TIM_TypeDef* tim, TIM_TIEXTCLKSRC_Typedef source, TIMICP_Typedef polarity, u16 filter);
  630. void TIM_ETRClockMode1Config(TIM_TypeDef* tim, TIMEXTTRGPSC_Typedef psc, TIMETP_Typedef polarity, u16 filter);
  631. void TIM_ETRClockMode2Config(TIM_TypeDef* tim, TIMEXTTRGPSC_Typedef psc, TIMETP_Typedef polarity, u16 filter);
  632. //================= Synchronization management ===============================
  633. void TIM_SelectInputTrigger(TIM_TypeDef* tim, TIMTS_TypeDef source);
  634. void TIM_SelectOutputTrigger(TIM_TypeDef* tim, TIMMMS_Typedef source);
  635. void TIM_SelectSlaveMode(TIM_TypeDef* tim, TIMSMSMODE_Typedef mode);
  636. void TIM_SelectMasterSlaveMode(TIM_TypeDef* tim, TIMMSM_Typedef mode);
  637. void TIM_ETRConfig(TIM_TypeDef* tim, TIMEXTTRGPSC_Typedef psc, TIMETP_Typedef polarity, u16 filter);
  638. //================= Specific interface management ============================
  639. void TIM_EncoderInterfaceConfig(TIM_TypeDef* tim,
  640. TIMSMSENCODER_Typedef encoder_mode,
  641. TIMICP_Typedef ic1_polarity,
  642. TIMICP_Typedef iC2_polarity);
  643. void TIM_SelectHallSensor(TIM_TypeDef* tim, FunctionalState state);
  644. //================= extend Channel IC management ==============================
  645. void TIM_SetIC1Plority(TIM_TypeDef* tim, TIMICP_Typedef pol);
  646. void TIM_SetIC2Plority(TIM_TypeDef* tim, TIMICP_Typedef pol);
  647. void TIM_SetIC3Plority(TIM_TypeDef* tim, TIMICP_Typedef pol);
  648. void TIM_SetIC4Plority(TIM_TypeDef* tim, TIMICP_Typedef pol);
  649. #define exTIM_SetIC1Plority TIM_SetIC1Plority
  650. #define exTIM_SetIC2Plority TIM_SetIC2Plority
  651. #define exTIM_SetIC3Plority TIM_SetIC3Plority
  652. #define exTIM_SetIC4Plority TIM_SetIC4Plority
  653. //================= extend Channel 5 management ==============================
  654. void TIM_SetCompare5(TIM_TypeDef* tim, u32 compare);
  655. void TIM_OC5Init(TIM_TypeDef* tim, TIM_OCInitTypeDef* init_struct);
  656. void TIM_OC5PreloadConfig(TIM_TypeDef* tim, TIMOCPE_Typedef preload);
  657. void TIM_OC5PolarityConfig(TIM_TypeDef* tim, TIMCCxP_Typedef polarity);
  658. void TIM_OC5FastConfig(TIM_TypeDef* tim, TIMOCFE_Typedef fast);
  659. void TIM_ClearOC5Ref(TIM_TypeDef* tim, TIMOCCE_Typedef clear);
  660. u32 TIM_GetCapture5(TIM_TypeDef* tim);
  661. #define exTIM_SetCompare5 TIM_SetCompare5
  662. #define exTIM_OC5Init TIM_OC5Init
  663. #define exTIM_OC5PreloadConfig TIM_OC5PreloadConfig
  664. #define exTIM_OC5PolarityConfig TIM_OC5PolarityConfig
  665. #define exTIM_OC5FastConfig TIM_OC5FastConfig
  666. #define exTIM_ClearOC5Ref TIM_ClearOC5Ref
  667. #define exTIM_GetCapture5 TIM_GetCapture5
  668. //============= extend Advanced-control timers specific features ==============
  669. void TIM_DirectOutput(TIM_TypeDef* tim, FunctionalState state);
  670. #define exTIM_DirectOutput TIM_DirectOutput
  671. void TIM_PWMShiftConfig(TIM_TypeDef* tim, u32 it, FunctionalState state);
  672. void TIM_SetCCR1FALL(TIM_TypeDef* tim, u32 shift);
  673. void TIM_SetCCR2FALL(TIM_TypeDef* tim, u32 shift);
  674. void TIM_SetCCR3FALL(TIM_TypeDef* tim, u32 shift);
  675. void TIM_SetCCR4FALL(TIM_TypeDef* tim, u32 shift);
  676. void TIM_SetCCR5FALL(TIM_TypeDef* tim, u32 shift);
  677. /// @}
  678. /// @}
  679. /// @}
  680. ////////////////////////////////////////////////////////////////////////////////
  681. #endif // __HAL_TIM_H
  682. ////////////////////////////////////////////////////////////////////////////////