stm32f1xx_hal_tim.h 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_tim.h
  4. * @author MCD Application Team
  5. * @brief Header file of TIM HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32F1xx_HAL_TIM_H
  21. #define STM32F1xx_HAL_TIM_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f1xx_hal_def.h"
  27. /** @addtogroup STM32F1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup TIM
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup TIM_Exported_Types TIM Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief TIM Time base Configuration Structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  43. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  44. uint32_t CounterMode; /*!< Specifies the counter mode.
  45. This parameter can be a value of @ref TIM_Counter_Mode */
  46. uint32_t Period; /*!< Specifies the period value to be loaded into the active
  47. Auto-Reload Register at the next update event.
  48. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
  49. uint32_t ClockDivision; /*!< Specifies the clock division.
  50. This parameter can be a value of @ref TIM_ClockDivision */
  51. uint32_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  52. reaches zero, an update event is generated and counting restarts
  53. from the RCR value (N).
  54. This means in PWM mode that (N+1) corresponds to:
  55. - the number of PWM periods in edge-aligned mode
  56. - the number of half PWM period in center-aligned mode
  57. GP timers: this parameter must be a number between Min_Data = 0x00 and
  58. Max_Data = 0xFF.
  59. Advanced timers: this parameter must be a number between Min_Data = 0x0000 and
  60. Max_Data = 0xFFFF. */
  61. uint32_t AutoReloadPreload; /*!< Specifies the auto-reload preload.
  62. This parameter can be a value of @ref TIM_AutoReloadPreload */
  63. } TIM_Base_InitTypeDef;
  64. /**
  65. * @brief TIM Output Compare Configuration Structure definition
  66. */
  67. typedef struct
  68. {
  69. uint32_t OCMode; /*!< Specifies the TIM mode.
  70. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  71. uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  72. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  73. uint32_t OCPolarity; /*!< Specifies the output polarity.
  74. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  75. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  76. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  77. @note This parameter is valid only for timer instances supporting break feature. */
  78. uint32_t OCFastMode; /*!< Specifies the Fast mode state.
  79. This parameter can be a value of @ref TIM_Output_Fast_State
  80. @note This parameter is valid only in PWM1 and PWM2 mode. */
  81. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  82. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  83. @note This parameter is valid only for timer instances supporting break feature. */
  84. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  85. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  86. @note This parameter is valid only for timer instances supporting break feature. */
  87. } TIM_OC_InitTypeDef;
  88. /**
  89. * @brief TIM One Pulse Mode Configuration Structure definition
  90. */
  91. typedef struct
  92. {
  93. uint32_t OCMode; /*!< Specifies the TIM mode.
  94. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  95. uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  96. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  97. uint32_t OCPolarity; /*!< Specifies the output polarity.
  98. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  99. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  100. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  101. @note This parameter is valid only for timer instances supporting break feature. */
  102. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  103. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  104. @note This parameter is valid only for timer instances supporting break feature. */
  105. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  106. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  107. @note This parameter is valid only for timer instances supporting break feature. */
  108. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  109. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  110. uint32_t ICSelection; /*!< Specifies the input.
  111. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  112. uint32_t ICFilter; /*!< Specifies the input capture filter.
  113. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  114. } TIM_OnePulse_InitTypeDef;
  115. /**
  116. * @brief TIM Input Capture Configuration Structure definition
  117. */
  118. typedef struct
  119. {
  120. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  121. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  122. uint32_t ICSelection; /*!< Specifies the input.
  123. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  124. uint32_t ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  125. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  126. uint32_t ICFilter; /*!< Specifies the input capture filter.
  127. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  128. } TIM_IC_InitTypeDef;
  129. /**
  130. * @brief TIM Encoder Configuration Structure definition
  131. */
  132. typedef struct
  133. {
  134. uint32_t EncoderMode; /*!< Specifies the active edge of the input signal.
  135. This parameter can be a value of @ref TIM_Encoder_Mode */
  136. uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal.
  137. This parameter can be a value of @ref TIM_Encoder_Input_Polarity */
  138. uint32_t IC1Selection; /*!< Specifies the input.
  139. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  140. uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler.
  141. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  142. uint32_t IC1Filter; /*!< Specifies the input capture filter.
  143. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  144. uint32_t IC2Polarity; /*!< Specifies the active edge of the input signal.
  145. This parameter can be a value of @ref TIM_Encoder_Input_Polarity */
  146. uint32_t IC2Selection; /*!< Specifies the input.
  147. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  148. uint32_t IC2Prescaler; /*!< Specifies the Input Capture Prescaler.
  149. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  150. uint32_t IC2Filter; /*!< Specifies the input capture filter.
  151. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  152. } TIM_Encoder_InitTypeDef;
  153. /**
  154. * @brief Clock Configuration Handle Structure definition
  155. */
  156. typedef struct
  157. {
  158. uint32_t ClockSource; /*!< TIM clock sources
  159. This parameter can be a value of @ref TIM_Clock_Source */
  160. uint32_t ClockPolarity; /*!< TIM clock polarity
  161. This parameter can be a value of @ref TIM_Clock_Polarity */
  162. uint32_t ClockPrescaler; /*!< TIM clock prescaler
  163. This parameter can be a value of @ref TIM_Clock_Prescaler */
  164. uint32_t ClockFilter; /*!< TIM clock filter
  165. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  166. } TIM_ClockConfigTypeDef;
  167. /**
  168. * @brief TIM Clear Input Configuration Handle Structure definition
  169. */
  170. typedef struct
  171. {
  172. uint32_t ClearInputState; /*!< TIM clear Input state
  173. This parameter can be ENABLE or DISABLE */
  174. uint32_t ClearInputSource; /*!< TIM clear Input sources
  175. This parameter can be a value of @ref TIM_ClearInput_Source */
  176. uint32_t ClearInputPolarity; /*!< TIM Clear Input polarity
  177. This parameter can be a value of @ref TIM_ClearInput_Polarity */
  178. uint32_t ClearInputPrescaler; /*!< TIM Clear Input prescaler
  179. This parameter must be 0: When OCRef clear feature is used with ETR source,
  180. ETR prescaler must be off */
  181. uint32_t ClearInputFilter; /*!< TIM Clear Input filter
  182. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  183. } TIM_ClearInputConfigTypeDef;
  184. /**
  185. * @brief TIM Master configuration Structure definition
  186. */
  187. typedef struct
  188. {
  189. uint32_t MasterOutputTrigger; /*!< Trigger output (TRGO) selection
  190. This parameter can be a value of @ref TIM_Master_Mode_Selection */
  191. uint32_t MasterSlaveMode; /*!< Master/slave mode selection
  192. This parameter can be a value of @ref TIM_Master_Slave_Mode
  193. @note When the Master/slave mode is enabled, the effect of
  194. an event on the trigger input (TRGI) is delayed to allow a
  195. perfect synchronization between the current timer and its
  196. slaves (through TRGO). It is not mandatory in case of timer
  197. synchronization mode. */
  198. } TIM_MasterConfigTypeDef;
  199. /**
  200. * @brief TIM Slave configuration Structure definition
  201. */
  202. typedef struct
  203. {
  204. uint32_t SlaveMode; /*!< Slave mode selection
  205. This parameter can be a value of @ref TIM_Slave_Mode */
  206. uint32_t InputTrigger; /*!< Input Trigger source
  207. This parameter can be a value of @ref TIM_Trigger_Selection */
  208. uint32_t TriggerPolarity; /*!< Input Trigger polarity
  209. This parameter can be a value of @ref TIM_Trigger_Polarity */
  210. uint32_t TriggerPrescaler; /*!< Input trigger prescaler
  211. This parameter can be a value of @ref TIM_Trigger_Prescaler */
  212. uint32_t TriggerFilter; /*!< Input trigger filter
  213. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  214. } TIM_SlaveConfigTypeDef;
  215. /**
  216. * @brief TIM Break input(s) and Dead time configuration Structure definition
  217. * @note 2 break inputs can be configured (BKIN and BKIN2) with configurable
  218. * filter and polarity.
  219. */
  220. typedef struct
  221. {
  222. uint32_t OffStateRunMode; /*!< TIM off state in run mode, This parameter can be a value of @ref TIM_OSSR_Off_State_Selection_for_Run_mode_state */
  223. uint32_t OffStateIDLEMode; /*!< TIM off state in IDLE mode, This parameter can be a value of @ref TIM_OSSI_Off_State_Selection_for_Idle_mode_state */
  224. uint32_t LockLevel; /*!< TIM Lock level, This parameter can be a value of @ref TIM_Lock_level */
  225. uint32_t DeadTime; /*!< TIM dead Time, This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  226. uint32_t BreakState; /*!< TIM Break State, This parameter can be a value of @ref TIM_Break_Input_enable_disable */
  227. uint32_t BreakPolarity; /*!< TIM Break input polarity, This parameter can be a value of @ref TIM_Break_Polarity */
  228. uint32_t BreakFilter; /*!< Specifies the break input filter.This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  229. uint32_t AutomaticOutput; /*!< TIM Automatic Output Enable state, This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */
  230. } TIM_BreakDeadTimeConfigTypeDef;
  231. /**
  232. * @brief HAL State structures definition
  233. */
  234. typedef enum
  235. {
  236. HAL_TIM_STATE_RESET = 0x00U, /*!< Peripheral not yet initialized or disabled */
  237. HAL_TIM_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
  238. HAL_TIM_STATE_BUSY = 0x02U, /*!< An internal process is ongoing */
  239. HAL_TIM_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
  240. HAL_TIM_STATE_ERROR = 0x04U /*!< Reception process is ongoing */
  241. } HAL_TIM_StateTypeDef;
  242. /**
  243. * @brief TIM Channel States definition
  244. */
  245. typedef enum
  246. {
  247. HAL_TIM_CHANNEL_STATE_RESET = 0x00U, /*!< TIM Channel initial state */
  248. HAL_TIM_CHANNEL_STATE_READY = 0x01U, /*!< TIM Channel ready for use */
  249. HAL_TIM_CHANNEL_STATE_BUSY = 0x02U, /*!< An internal process is ongoing on the TIM channel */
  250. } HAL_TIM_ChannelStateTypeDef;
  251. /**
  252. * @brief DMA Burst States definition
  253. */
  254. typedef enum
  255. {
  256. HAL_DMA_BURST_STATE_RESET = 0x00U, /*!< DMA Burst initial state */
  257. HAL_DMA_BURST_STATE_READY = 0x01U, /*!< DMA Burst ready for use */
  258. HAL_DMA_BURST_STATE_BUSY = 0x02U, /*!< Ongoing DMA Burst */
  259. } HAL_TIM_DMABurstStateTypeDef;
  260. /**
  261. * @brief HAL Active channel structures definition
  262. */
  263. typedef enum
  264. {
  265. HAL_TIM_ACTIVE_CHANNEL_1 = 0x01U, /*!< The active channel is 1 */
  266. HAL_TIM_ACTIVE_CHANNEL_2 = 0x02U, /*!< The active channel is 2 */
  267. HAL_TIM_ACTIVE_CHANNEL_3 = 0x04U, /*!< The active channel is 3 */
  268. HAL_TIM_ACTIVE_CHANNEL_4 = 0x08U, /*!< The active channel is 4 */
  269. HAL_TIM_ACTIVE_CHANNEL_CLEARED = 0x00U /*!< All active channels cleared */
  270. } HAL_TIM_ActiveChannel;
  271. /**
  272. * @brief TIM Time Base Handle Structure definition
  273. */
  274. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  275. typedef struct __TIM_HandleTypeDef
  276. #else
  277. typedef struct
  278. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  279. {
  280. TIM_TypeDef *Instance; /*!< Register base address */
  281. TIM_Base_InitTypeDef Init; /*!< TIM Time Base required parameters */
  282. HAL_TIM_ActiveChannel Channel; /*!< Active channel */
  283. DMA_HandleTypeDef *hdma[7]; /*!< DMA Handlers array
  284. This array is accessed by a @ref DMA_Handle_index */
  285. HAL_LockTypeDef Lock; /*!< Locking object */
  286. __IO HAL_TIM_StateTypeDef State; /*!< TIM operation state */
  287. __IO HAL_TIM_ChannelStateTypeDef ChannelState[4]; /*!< TIM channel operation state */
  288. __IO HAL_TIM_ChannelStateTypeDef ChannelNState[4]; /*!< TIM complementary channel operation state */
  289. __IO HAL_TIM_DMABurstStateTypeDef DMABurstState; /*!< DMA burst operation state */
  290. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  291. void (* Base_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Base Msp Init Callback */
  292. void (* Base_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Base Msp DeInit Callback */
  293. void (* IC_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM IC Msp Init Callback */
  294. void (* IC_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM IC Msp DeInit Callback */
  295. void (* OC_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM OC Msp Init Callback */
  296. void (* OC_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM OC Msp DeInit Callback */
  297. void (* PWM_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM PWM Msp Init Callback */
  298. void (* PWM_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM PWM Msp DeInit Callback */
  299. void (* OnePulse_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM One Pulse Msp Init Callback */
  300. void (* OnePulse_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM One Pulse Msp DeInit Callback */
  301. void (* Encoder_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Encoder Msp Init Callback */
  302. void (* Encoder_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Encoder Msp DeInit Callback */
  303. void (* HallSensor_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Hall Sensor Msp Init Callback */
  304. void (* HallSensor_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Hall Sensor Msp DeInit Callback */
  305. void (* PeriodElapsedCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Period Elapsed Callback */
  306. void (* PeriodElapsedHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Period Elapsed half complete Callback */
  307. void (* TriggerCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Trigger Callback */
  308. void (* TriggerHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Trigger half complete Callback */
  309. void (* IC_CaptureCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Input Capture Callback */
  310. void (* IC_CaptureHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Input Capture half complete Callback */
  311. void (* OC_DelayElapsedCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Output Compare Delay Elapsed Callback */
  312. void (* PWM_PulseFinishedCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM PWM Pulse Finished Callback */
  313. void (* PWM_PulseFinishedHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM PWM Pulse Finished half complete Callback */
  314. void (* ErrorCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Error Callback */
  315. void (* CommutationCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Commutation Callback */
  316. void (* CommutationHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Commutation half complete Callback */
  317. void (* BreakCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Break Callback */
  318. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  319. } TIM_HandleTypeDef;
  320. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  321. /**
  322. * @brief HAL TIM Callback ID enumeration definition
  323. */
  324. typedef enum
  325. {
  326. HAL_TIM_BASE_MSPINIT_CB_ID = 0x00U /*!< TIM Base MspInit Callback ID */
  327. , HAL_TIM_BASE_MSPDEINIT_CB_ID = 0x01U /*!< TIM Base MspDeInit Callback ID */
  328. , HAL_TIM_IC_MSPINIT_CB_ID = 0x02U /*!< TIM IC MspInit Callback ID */
  329. , HAL_TIM_IC_MSPDEINIT_CB_ID = 0x03U /*!< TIM IC MspDeInit Callback ID */
  330. , HAL_TIM_OC_MSPINIT_CB_ID = 0x04U /*!< TIM OC MspInit Callback ID */
  331. , HAL_TIM_OC_MSPDEINIT_CB_ID = 0x05U /*!< TIM OC MspDeInit Callback ID */
  332. , HAL_TIM_PWM_MSPINIT_CB_ID = 0x06U /*!< TIM PWM MspInit Callback ID */
  333. , HAL_TIM_PWM_MSPDEINIT_CB_ID = 0x07U /*!< TIM PWM MspDeInit Callback ID */
  334. , HAL_TIM_ONE_PULSE_MSPINIT_CB_ID = 0x08U /*!< TIM One Pulse MspInit Callback ID */
  335. , HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID = 0x09U /*!< TIM One Pulse MspDeInit Callback ID */
  336. , HAL_TIM_ENCODER_MSPINIT_CB_ID = 0x0AU /*!< TIM Encoder MspInit Callback ID */
  337. , HAL_TIM_ENCODER_MSPDEINIT_CB_ID = 0x0BU /*!< TIM Encoder MspDeInit Callback ID */
  338. , HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID = 0x0CU /*!< TIM Hall Sensor MspDeInit Callback ID */
  339. , HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID = 0x0DU /*!< TIM Hall Sensor MspDeInit Callback ID */
  340. , HAL_TIM_PERIOD_ELAPSED_CB_ID = 0x0EU /*!< TIM Period Elapsed Callback ID */
  341. , HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID = 0x0FU /*!< TIM Period Elapsed half complete Callback ID */
  342. , HAL_TIM_TRIGGER_CB_ID = 0x10U /*!< TIM Trigger Callback ID */
  343. , HAL_TIM_TRIGGER_HALF_CB_ID = 0x11U /*!< TIM Trigger half complete Callback ID */
  344. , HAL_TIM_IC_CAPTURE_CB_ID = 0x12U /*!< TIM Input Capture Callback ID */
  345. , HAL_TIM_IC_CAPTURE_HALF_CB_ID = 0x13U /*!< TIM Input Capture half complete Callback ID */
  346. , HAL_TIM_OC_DELAY_ELAPSED_CB_ID = 0x14U /*!< TIM Output Compare Delay Elapsed Callback ID */
  347. , HAL_TIM_PWM_PULSE_FINISHED_CB_ID = 0x15U /*!< TIM PWM Pulse Finished Callback ID */
  348. , HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID = 0x16U /*!< TIM PWM Pulse Finished half complete Callback ID */
  349. , HAL_TIM_ERROR_CB_ID = 0x17U /*!< TIM Error Callback ID */
  350. , HAL_TIM_COMMUTATION_CB_ID = 0x18U /*!< TIM Commutation Callback ID */
  351. , HAL_TIM_COMMUTATION_HALF_CB_ID = 0x19U /*!< TIM Commutation half complete Callback ID */
  352. , HAL_TIM_BREAK_CB_ID = 0x1AU /*!< TIM Break Callback ID */
  353. } HAL_TIM_CallbackIDTypeDef;
  354. /**
  355. * @brief HAL TIM Callback pointer definition
  356. */
  357. typedef void (*pTIM_CallbackTypeDef)(TIM_HandleTypeDef *htim); /*!< pointer to the TIM callback function */
  358. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  359. /**
  360. * @}
  361. */
  362. /* End of exported types -----------------------------------------------------*/
  363. /* Exported constants --------------------------------------------------------*/
  364. /** @defgroup TIM_Exported_Constants TIM Exported Constants
  365. * @{
  366. */
  367. /** @defgroup TIM_ClearInput_Source TIM Clear Input Source
  368. * @{
  369. */
  370. #define TIM_CLEARINPUTSOURCE_NONE 0x00000000U /*!< OCREF_CLR is disabled */
  371. #define TIM_CLEARINPUTSOURCE_ETR 0x00000001U /*!< OCREF_CLR is connected to ETRF input */
  372. /**
  373. * @}
  374. */
  375. /** @defgroup TIM_DMA_Base_address TIM DMA Base Address
  376. * @{
  377. */
  378. #define TIM_DMABASE_CR1 0x00000000U
  379. #define TIM_DMABASE_CR2 0x00000001U
  380. #define TIM_DMABASE_SMCR 0x00000002U
  381. #define TIM_DMABASE_DIER 0x00000003U
  382. #define TIM_DMABASE_SR 0x00000004U
  383. #define TIM_DMABASE_EGR 0x00000005U
  384. #define TIM_DMABASE_CCMR1 0x00000006U
  385. #define TIM_DMABASE_CCMR2 0x00000007U
  386. #define TIM_DMABASE_CCER 0x00000008U
  387. #define TIM_DMABASE_CNT 0x00000009U
  388. #define TIM_DMABASE_PSC 0x0000000AU
  389. #define TIM_DMABASE_ARR 0x0000000BU
  390. #define TIM_DMABASE_RCR 0x0000000CU
  391. #define TIM_DMABASE_CCR1 0x0000000DU
  392. #define TIM_DMABASE_CCR2 0x0000000EU
  393. #define TIM_DMABASE_CCR3 0x0000000FU
  394. #define TIM_DMABASE_CCR4 0x00000010U
  395. #define TIM_DMABASE_BDTR 0x00000011U
  396. #define TIM_DMABASE_DCR 0x00000012U
  397. #define TIM_DMABASE_DMAR 0x00000013U
  398. /**
  399. * @}
  400. */
  401. /** @defgroup TIM_Event_Source TIM Event Source
  402. * @{
  403. */
  404. #define TIM_EVENTSOURCE_UPDATE TIM_EGR_UG /*!< Reinitialize the counter and generates an update of the registers */
  405. #define TIM_EVENTSOURCE_CC1 TIM_EGR_CC1G /*!< A capture/compare event is generated on channel 1 */
  406. #define TIM_EVENTSOURCE_CC2 TIM_EGR_CC2G /*!< A capture/compare event is generated on channel 2 */
  407. #define TIM_EVENTSOURCE_CC3 TIM_EGR_CC3G /*!< A capture/compare event is generated on channel 3 */
  408. #define TIM_EVENTSOURCE_CC4 TIM_EGR_CC4G /*!< A capture/compare event is generated on channel 4 */
  409. #define TIM_EVENTSOURCE_COM TIM_EGR_COMG /*!< A commutation event is generated */
  410. #define TIM_EVENTSOURCE_TRIGGER TIM_EGR_TG /*!< A trigger event is generated */
  411. #define TIM_EVENTSOURCE_BREAK TIM_EGR_BG /*!< A break event is generated */
  412. /**
  413. * @}
  414. */
  415. /** @defgroup TIM_Input_Channel_Polarity TIM Input Channel polarity
  416. * @{
  417. */
  418. #define TIM_INPUTCHANNELPOLARITY_RISING 0x00000000U /*!< Polarity for TIx source */
  419. #define TIM_INPUTCHANNELPOLARITY_FALLING TIM_CCER_CC1P /*!< Polarity for TIx source */
  420. #define TIM_INPUTCHANNELPOLARITY_BOTHEDGE (TIM_CCER_CC1P | TIM_CCER_CC1NP) /*!< Polarity for TIx source */
  421. /**
  422. * @}
  423. */
  424. /** @defgroup TIM_ETR_Polarity TIM ETR Polarity
  425. * @{
  426. */
  427. #define TIM_ETRPOLARITY_INVERTED TIM_SMCR_ETP /*!< Polarity for ETR source */
  428. #define TIM_ETRPOLARITY_NONINVERTED 0x00000000U /*!< Polarity for ETR source */
  429. /**
  430. * @}
  431. */
  432. /** @defgroup TIM_ETR_Prescaler TIM ETR Prescaler
  433. * @{
  434. */
  435. #define TIM_ETRPRESCALER_DIV1 0x00000000U /*!< No prescaler is used */
  436. #define TIM_ETRPRESCALER_DIV2 TIM_SMCR_ETPS_0 /*!< ETR input source is divided by 2 */
  437. #define TIM_ETRPRESCALER_DIV4 TIM_SMCR_ETPS_1 /*!< ETR input source is divided by 4 */
  438. #define TIM_ETRPRESCALER_DIV8 TIM_SMCR_ETPS /*!< ETR input source is divided by 8 */
  439. /**
  440. * @}
  441. */
  442. /** @defgroup TIM_Counter_Mode TIM Counter Mode
  443. * @{
  444. */
  445. #define TIM_COUNTERMODE_UP 0x00000000U /*!< Counter used as up-counter */
  446. #define TIM_COUNTERMODE_DOWN TIM_CR1_DIR /*!< Counter used as down-counter */
  447. #define TIM_COUNTERMODE_CENTERALIGNED1 TIM_CR1_CMS_0 /*!< Center-aligned mode 1 */
  448. #define TIM_COUNTERMODE_CENTERALIGNED2 TIM_CR1_CMS_1 /*!< Center-aligned mode 2 */
  449. #define TIM_COUNTERMODE_CENTERALIGNED3 TIM_CR1_CMS /*!< Center-aligned mode 3 */
  450. /**
  451. * @}
  452. */
  453. /** @defgroup TIM_ClockDivision TIM Clock Division
  454. * @{
  455. */
  456. #define TIM_CLOCKDIVISION_DIV1 0x00000000U /*!< Clock division: tDTS=tCK_INT */
  457. #define TIM_CLOCKDIVISION_DIV2 TIM_CR1_CKD_0 /*!< Clock division: tDTS=2*tCK_INT */
  458. #define TIM_CLOCKDIVISION_DIV4 TIM_CR1_CKD_1 /*!< Clock division: tDTS=4*tCK_INT */
  459. /**
  460. * @}
  461. */
  462. /** @defgroup TIM_Output_Compare_State TIM Output Compare State
  463. * @{
  464. */
  465. #define TIM_OUTPUTSTATE_DISABLE 0x00000000U /*!< Capture/Compare 1 output disabled */
  466. #define TIM_OUTPUTSTATE_ENABLE TIM_CCER_CC1E /*!< Capture/Compare 1 output enabled */
  467. /**
  468. * @}
  469. */
  470. /** @defgroup TIM_AutoReloadPreload TIM Auto-Reload Preload
  471. * @{
  472. */
  473. #define TIM_AUTORELOAD_PRELOAD_DISABLE 0x00000000U /*!< TIMx_ARR register is not buffered */
  474. #define TIM_AUTORELOAD_PRELOAD_ENABLE TIM_CR1_ARPE /*!< TIMx_ARR register is buffered */
  475. /**
  476. * @}
  477. */
  478. /** @defgroup TIM_Output_Fast_State TIM Output Fast State
  479. * @{
  480. */
  481. #define TIM_OCFAST_DISABLE 0x00000000U /*!< Output Compare fast disable */
  482. #define TIM_OCFAST_ENABLE TIM_CCMR1_OC1FE /*!< Output Compare fast enable */
  483. /**
  484. * @}
  485. */
  486. /** @defgroup TIM_Output_Compare_N_State TIM Complementary Output Compare State
  487. * @{
  488. */
  489. #define TIM_OUTPUTNSTATE_DISABLE 0x00000000U /*!< OCxN is disabled */
  490. #define TIM_OUTPUTNSTATE_ENABLE TIM_CCER_CC1NE /*!< OCxN is enabled */
  491. /**
  492. * @}
  493. */
  494. /** @defgroup TIM_Output_Compare_Polarity TIM Output Compare Polarity
  495. * @{
  496. */
  497. #define TIM_OCPOLARITY_HIGH 0x00000000U /*!< Capture/Compare output polarity */
  498. #define TIM_OCPOLARITY_LOW TIM_CCER_CC1P /*!< Capture/Compare output polarity */
  499. /**
  500. * @}
  501. */
  502. /** @defgroup TIM_Output_Compare_N_Polarity TIM Complementary Output Compare Polarity
  503. * @{
  504. */
  505. #define TIM_OCNPOLARITY_HIGH 0x00000000U /*!< Capture/Compare complementary output polarity */
  506. #define TIM_OCNPOLARITY_LOW TIM_CCER_CC1NP /*!< Capture/Compare complementary output polarity */
  507. /**
  508. * @}
  509. */
  510. /** @defgroup TIM_Output_Compare_Idle_State TIM Output Compare Idle State
  511. * @{
  512. */
  513. #define TIM_OCIDLESTATE_SET TIM_CR2_OIS1 /*!< Output Idle state: OCx=1 when MOE=0 */
  514. #define TIM_OCIDLESTATE_RESET 0x00000000U /*!< Output Idle state: OCx=0 when MOE=0 */
  515. /**
  516. * @}
  517. */
  518. /** @defgroup TIM_Output_Compare_N_Idle_State TIM Complementary Output Compare Idle State
  519. * @{
  520. */
  521. #define TIM_OCNIDLESTATE_SET TIM_CR2_OIS1N /*!< Complementary output Idle state: OCxN=1 when MOE=0 */
  522. #define TIM_OCNIDLESTATE_RESET 0x00000000U /*!< Complementary output Idle state: OCxN=0 when MOE=0 */
  523. /**
  524. * @}
  525. */
  526. /** @defgroup TIM_Input_Capture_Polarity TIM Input Capture Polarity
  527. * @{
  528. */
  529. #define TIM_ICPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Capture triggered by rising edge on timer input */
  530. #define TIM_ICPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Capture triggered by falling edge on timer input */
  531. #define TIM_ICPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Capture triggered by both rising and falling edges on timer input*/
  532. /**
  533. * @}
  534. */
  535. /** @defgroup TIM_Encoder_Input_Polarity TIM Encoder Input Polarity
  536. * @{
  537. */
  538. #define TIM_ENCODERINPUTPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Encoder input with rising edge polarity */
  539. #define TIM_ENCODERINPUTPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Encoder input with falling edge polarity */
  540. /**
  541. * @}
  542. */
  543. /** @defgroup TIM_Input_Capture_Selection TIM Input Capture Selection
  544. * @{
  545. */
  546. #define TIM_ICSELECTION_DIRECTTI TIM_CCMR1_CC1S_0 /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to IC1, IC2, IC3 or IC4, respectively */
  547. #define TIM_ICSELECTION_INDIRECTTI TIM_CCMR1_CC1S_1 /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to IC2, IC1, IC4 or IC3, respectively */
  548. #define TIM_ICSELECTION_TRC TIM_CCMR1_CC1S /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to TRC */
  549. /**
  550. * @}
  551. */
  552. /** @defgroup TIM_Input_Capture_Prescaler TIM Input Capture Prescaler
  553. * @{
  554. */
  555. #define TIM_ICPSC_DIV1 0x00000000U /*!< Capture performed each time an edge is detected on the capture input */
  556. #define TIM_ICPSC_DIV2 TIM_CCMR1_IC1PSC_0 /*!< Capture performed once every 2 events */
  557. #define TIM_ICPSC_DIV4 TIM_CCMR1_IC1PSC_1 /*!< Capture performed once every 4 events */
  558. #define TIM_ICPSC_DIV8 TIM_CCMR1_IC1PSC /*!< Capture performed once every 8 events */
  559. /**
  560. * @}
  561. */
  562. /** @defgroup TIM_One_Pulse_Mode TIM One Pulse Mode
  563. * @{
  564. */
  565. #define TIM_OPMODE_SINGLE TIM_CR1_OPM /*!< Counter stops counting at the next update event */
  566. #define TIM_OPMODE_REPETITIVE 0x00000000U /*!< Counter is not stopped at update event */
  567. /**
  568. * @}
  569. */
  570. /** @defgroup TIM_Encoder_Mode TIM Encoder Mode
  571. * @{
  572. */
  573. #define TIM_ENCODERMODE_TI1 TIM_SMCR_SMS_0 /*!< Quadrature encoder mode 1, x2 mode, counts up/down on TI1FP1 edge depending on TI2FP2 level */
  574. #define TIM_ENCODERMODE_TI2 TIM_SMCR_SMS_1 /*!< Quadrature encoder mode 2, x2 mode, counts up/down on TI2FP2 edge depending on TI1FP1 level. */
  575. #define TIM_ENCODERMODE_TI12 (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0) /*!< Quadrature encoder mode 3, x4 mode, counts up/down on both TI1FP1 and TI2FP2 edges depending on the level of the other input. */
  576. /**
  577. * @}
  578. */
  579. /** @defgroup TIM_Interrupt_definition TIM interrupt Definition
  580. * @{
  581. */
  582. #define TIM_IT_UPDATE TIM_DIER_UIE /*!< Update interrupt */
  583. #define TIM_IT_CC1 TIM_DIER_CC1IE /*!< Capture/Compare 1 interrupt */
  584. #define TIM_IT_CC2 TIM_DIER_CC2IE /*!< Capture/Compare 2 interrupt */
  585. #define TIM_IT_CC3 TIM_DIER_CC3IE /*!< Capture/Compare 3 interrupt */
  586. #define TIM_IT_CC4 TIM_DIER_CC4IE /*!< Capture/Compare 4 interrupt */
  587. #define TIM_IT_COM TIM_DIER_COMIE /*!< Commutation interrupt */
  588. #define TIM_IT_TRIGGER TIM_DIER_TIE /*!< Trigger interrupt */
  589. #define TIM_IT_BREAK TIM_DIER_BIE /*!< Break interrupt */
  590. /**
  591. * @}
  592. */
  593. /** @defgroup TIM_Commutation_Source TIM Commutation Source
  594. * @{
  595. */
  596. #define TIM_COMMUTATION_TRGI TIM_CR2_CCUS /*!< When Capture/compare control bits are preloaded, they are updated by setting the COMG bit or when an rising edge occurs on trigger input */
  597. #define TIM_COMMUTATION_SOFTWARE 0x00000000U /*!< When Capture/compare control bits are preloaded, they are updated by setting the COMG bit */
  598. /**
  599. * @}
  600. */
  601. /** @defgroup TIM_DMA_sources TIM DMA Sources
  602. * @{
  603. */
  604. #define TIM_DMA_UPDATE TIM_DIER_UDE /*!< DMA request is triggered by the update event */
  605. #define TIM_DMA_CC1 TIM_DIER_CC1DE /*!< DMA request is triggered by the capture/compare macth 1 event */
  606. #define TIM_DMA_CC2 TIM_DIER_CC2DE /*!< DMA request is triggered by the capture/compare macth 2 event event */
  607. #define TIM_DMA_CC3 TIM_DIER_CC3DE /*!< DMA request is triggered by the capture/compare macth 3 event event */
  608. #define TIM_DMA_CC4 TIM_DIER_CC4DE /*!< DMA request is triggered by the capture/compare macth 4 event event */
  609. #define TIM_DMA_COM TIM_DIER_COMDE /*!< DMA request is triggered by the commutation event */
  610. #define TIM_DMA_TRIGGER TIM_DIER_TDE /*!< DMA request is triggered by the trigger event */
  611. /**
  612. * @}
  613. */
  614. /** @defgroup TIM_Flag_definition TIM Flag Definition
  615. * @{
  616. */
  617. #define TIM_FLAG_UPDATE TIM_SR_UIF /*!< Update interrupt flag */
  618. #define TIM_FLAG_CC1 TIM_SR_CC1IF /*!< Capture/Compare 1 interrupt flag */
  619. #define TIM_FLAG_CC2 TIM_SR_CC2IF /*!< Capture/Compare 2 interrupt flag */
  620. #define TIM_FLAG_CC3 TIM_SR_CC3IF /*!< Capture/Compare 3 interrupt flag */
  621. #define TIM_FLAG_CC4 TIM_SR_CC4IF /*!< Capture/Compare 4 interrupt flag */
  622. #define TIM_FLAG_COM TIM_SR_COMIF /*!< Commutation interrupt flag */
  623. #define TIM_FLAG_TRIGGER TIM_SR_TIF /*!< Trigger interrupt flag */
  624. #define TIM_FLAG_BREAK TIM_SR_BIF /*!< Break interrupt flag */
  625. #define TIM_FLAG_CC1OF TIM_SR_CC1OF /*!< Capture 1 overcapture flag */
  626. #define TIM_FLAG_CC2OF TIM_SR_CC2OF /*!< Capture 2 overcapture flag */
  627. #define TIM_FLAG_CC3OF TIM_SR_CC3OF /*!< Capture 3 overcapture flag */
  628. #define TIM_FLAG_CC4OF TIM_SR_CC4OF /*!< Capture 4 overcapture flag */
  629. /**
  630. * @}
  631. */
  632. /** @defgroup TIM_Channel TIM Channel
  633. * @{
  634. */
  635. #define TIM_CHANNEL_1 0x00000000U /*!< Capture/compare channel 1 identifier */
  636. #define TIM_CHANNEL_2 0x00000004U /*!< Capture/compare channel 2 identifier */
  637. #define TIM_CHANNEL_3 0x00000008U /*!< Capture/compare channel 3 identifier */
  638. #define TIM_CHANNEL_4 0x0000000CU /*!< Capture/compare channel 4 identifier */
  639. #define TIM_CHANNEL_ALL 0x0000003CU /*!< Global Capture/compare channel identifier */
  640. /**
  641. * @}
  642. */
  643. /** @defgroup TIM_Clock_Source TIM Clock Source
  644. * @{
  645. */
  646. #define TIM_CLOCKSOURCE_ETRMODE2 TIM_SMCR_ETPS_1 /*!< External clock source mode 2 */
  647. #define TIM_CLOCKSOURCE_INTERNAL TIM_SMCR_ETPS_0 /*!< Internal clock source */
  648. #define TIM_CLOCKSOURCE_ITR0 TIM_TS_ITR0 /*!< External clock source mode 1 (ITR0) */
  649. #define TIM_CLOCKSOURCE_ITR1 TIM_TS_ITR1 /*!< External clock source mode 1 (ITR1) */
  650. #define TIM_CLOCKSOURCE_ITR2 TIM_TS_ITR2 /*!< External clock source mode 1 (ITR2) */
  651. #define TIM_CLOCKSOURCE_ITR3 TIM_TS_ITR3 /*!< External clock source mode 1 (ITR3) */
  652. #define TIM_CLOCKSOURCE_TI1ED TIM_TS_TI1F_ED /*!< External clock source mode 1 (TTI1FP1 + edge detect.) */
  653. #define TIM_CLOCKSOURCE_TI1 TIM_TS_TI1FP1 /*!< External clock source mode 1 (TTI1FP1) */
  654. #define TIM_CLOCKSOURCE_TI2 TIM_TS_TI2FP2 /*!< External clock source mode 1 (TTI2FP2) */
  655. #define TIM_CLOCKSOURCE_ETRMODE1 TIM_TS_ETRF /*!< External clock source mode 1 (ETRF) */
  656. /**
  657. * @}
  658. */
  659. /** @defgroup TIM_Clock_Polarity TIM Clock Polarity
  660. * @{
  661. */
  662. #define TIM_CLOCKPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx clock sources */
  663. #define TIM_CLOCKPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx clock sources */
  664. #define TIM_CLOCKPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIx clock sources */
  665. #define TIM_CLOCKPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIx clock sources */
  666. #define TIM_CLOCKPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIx clock sources */
  667. /**
  668. * @}
  669. */
  670. /** @defgroup TIM_Clock_Prescaler TIM Clock Prescaler
  671. * @{
  672. */
  673. #define TIM_CLOCKPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  674. #define TIM_CLOCKPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Clock: Capture performed once every 2 events. */
  675. #define TIM_CLOCKPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Clock: Capture performed once every 4 events. */
  676. #define TIM_CLOCKPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Clock: Capture performed once every 8 events. */
  677. /**
  678. * @}
  679. */
  680. /** @defgroup TIM_ClearInput_Polarity TIM Clear Input Polarity
  681. * @{
  682. */
  683. #define TIM_CLEARINPUTPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx pin */
  684. #define TIM_CLEARINPUTPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx pin */
  685. /**
  686. * @}
  687. */
  688. /** @defgroup TIM_ClearInput_Prescaler TIM Clear Input Prescaler
  689. * @{
  690. */
  691. #define TIM_CLEARINPUTPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  692. #define TIM_CLEARINPUTPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR pin: Capture performed once every 2 events. */
  693. #define TIM_CLEARINPUTPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR pin: Capture performed once every 4 events. */
  694. #define TIM_CLEARINPUTPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR pin: Capture performed once every 8 events. */
  695. /**
  696. * @}
  697. */
  698. /** @defgroup TIM_OSSR_Off_State_Selection_for_Run_mode_state TIM OSSR OffState Selection for Run mode state
  699. * @{
  700. */
  701. #define TIM_OSSR_ENABLE TIM_BDTR_OSSR /*!< When inactive, OC/OCN outputs are enabled (still controlled by the timer) */
  702. #define TIM_OSSR_DISABLE 0x00000000U /*!< When inactive, OC/OCN outputs are disabled (not controlled any longer by the timer) */
  703. /**
  704. * @}
  705. */
  706. /** @defgroup TIM_OSSI_Off_State_Selection_for_Idle_mode_state TIM OSSI OffState Selection for Idle mode state
  707. * @{
  708. */
  709. #define TIM_OSSI_ENABLE TIM_BDTR_OSSI /*!< When inactive, OC/OCN outputs are enabled (still controlled by the timer) */
  710. #define TIM_OSSI_DISABLE 0x00000000U /*!< When inactive, OC/OCN outputs are disabled (not controlled any longer by the timer) */
  711. /**
  712. * @}
  713. */
  714. /** @defgroup TIM_Lock_level TIM Lock level
  715. * @{
  716. */
  717. #define TIM_LOCKLEVEL_OFF 0x00000000U /*!< LOCK OFF */
  718. #define TIM_LOCKLEVEL_1 TIM_BDTR_LOCK_0 /*!< LOCK Level 1 */
  719. #define TIM_LOCKLEVEL_2 TIM_BDTR_LOCK_1 /*!< LOCK Level 2 */
  720. #define TIM_LOCKLEVEL_3 TIM_BDTR_LOCK /*!< LOCK Level 3 */
  721. /**
  722. * @}
  723. */
  724. /** @defgroup TIM_Break_Input_enable_disable TIM Break Input Enable
  725. * @{
  726. */
  727. #define TIM_BREAK_ENABLE TIM_BDTR_BKE /*!< Break input BRK is enabled */
  728. #define TIM_BREAK_DISABLE 0x00000000U /*!< Break input BRK is disabled */
  729. /**
  730. * @}
  731. */
  732. /** @defgroup TIM_Break_Polarity TIM Break Input Polarity
  733. * @{
  734. */
  735. #define TIM_BREAKPOLARITY_LOW 0x00000000U /*!< Break input BRK is active low */
  736. #define TIM_BREAKPOLARITY_HIGH TIM_BDTR_BKP /*!< Break input BRK is active high */
  737. /**
  738. * @}
  739. */
  740. /** @defgroup TIM_AOE_Bit_Set_Reset TIM Automatic Output Enable
  741. * @{
  742. */
  743. #define TIM_AUTOMATICOUTPUT_DISABLE 0x00000000U /*!< MOE can be set only by software */
  744. #define TIM_AUTOMATICOUTPUT_ENABLE TIM_BDTR_AOE /*!< MOE can be set by software or automatically at the next update event (if none of the break inputs BRK and BRK2 is active) */
  745. /**
  746. * @}
  747. */
  748. /** @defgroup TIM_Master_Mode_Selection TIM Master Mode Selection
  749. * @{
  750. */
  751. #define TIM_TRGO_RESET 0x00000000U /*!< TIMx_EGR.UG bit is used as trigger output (TRGO) */
  752. #define TIM_TRGO_ENABLE TIM_CR2_MMS_0 /*!< TIMx_CR1.CEN bit is used as trigger output (TRGO) */
  753. #define TIM_TRGO_UPDATE TIM_CR2_MMS_1 /*!< Update event is used as trigger output (TRGO) */
  754. #define TIM_TRGO_OC1 (TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< Capture or a compare match 1 is used as trigger output (TRGO) */
  755. #define TIM_TRGO_OC1REF TIM_CR2_MMS_2 /*!< OC1REF signal is used as trigger output (TRGO) */
  756. #define TIM_TRGO_OC2REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_0) /*!< OC2REF signal is used as trigger output(TRGO) */
  757. #define TIM_TRGO_OC3REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1) /*!< OC3REF signal is used as trigger output(TRGO) */
  758. #define TIM_TRGO_OC4REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< OC4REF signal is used as trigger output(TRGO) */
  759. /**
  760. * @}
  761. */
  762. /** @defgroup TIM_Master_Slave_Mode TIM Master/Slave Mode
  763. * @{
  764. */
  765. #define TIM_MASTERSLAVEMODE_ENABLE TIM_SMCR_MSM /*!< No action */
  766. #define TIM_MASTERSLAVEMODE_DISABLE 0x00000000U /*!< Master/slave mode is selected */
  767. /**
  768. * @}
  769. */
  770. /** @defgroup TIM_Slave_Mode TIM Slave mode
  771. * @{
  772. */
  773. #define TIM_SLAVEMODE_DISABLE 0x00000000U /*!< Slave mode disabled */
  774. #define TIM_SLAVEMODE_RESET TIM_SMCR_SMS_2 /*!< Reset Mode */
  775. #define TIM_SLAVEMODE_GATED (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_0) /*!< Gated Mode */
  776. #define TIM_SLAVEMODE_TRIGGER (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1) /*!< Trigger Mode */
  777. #define TIM_SLAVEMODE_EXTERNAL1 (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0) /*!< External Clock Mode 1 */
  778. /**
  779. * @}
  780. */
  781. /** @defgroup TIM_Output_Compare_and_PWM_modes TIM Output Compare and PWM Modes
  782. * @{
  783. */
  784. #define TIM_OCMODE_TIMING 0x00000000U /*!< Frozen */
  785. #define TIM_OCMODE_ACTIVE TIM_CCMR1_OC1M_0 /*!< Set channel to active level on match */
  786. #define TIM_OCMODE_INACTIVE TIM_CCMR1_OC1M_1 /*!< Set channel to inactive level on match */
  787. #define TIM_OCMODE_TOGGLE (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!< Toggle */
  788. #define TIM_OCMODE_PWM1 (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1) /*!< PWM mode 1 */
  789. #define TIM_OCMODE_PWM2 (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!< PWM mode 2 */
  790. #define TIM_OCMODE_FORCED_ACTIVE (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0) /*!< Force active level */
  791. #define TIM_OCMODE_FORCED_INACTIVE TIM_CCMR1_OC1M_2 /*!< Force inactive level */
  792. /**
  793. * @}
  794. */
  795. /** @defgroup TIM_Trigger_Selection TIM Trigger Selection
  796. * @{
  797. */
  798. #define TIM_TS_ITR0 0x00000000U /*!< Internal Trigger 0 (ITR0) */
  799. #define TIM_TS_ITR1 TIM_SMCR_TS_0 /*!< Internal Trigger 1 (ITR1) */
  800. #define TIM_TS_ITR2 TIM_SMCR_TS_1 /*!< Internal Trigger 2 (ITR2) */
  801. #define TIM_TS_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1) /*!< Internal Trigger 3 (ITR3) */
  802. #define TIM_TS_TI1F_ED TIM_SMCR_TS_2 /*!< TI1 Edge Detector (TI1F_ED) */
  803. #define TIM_TS_TI1FP1 (TIM_SMCR_TS_0 | TIM_SMCR_TS_2) /*!< Filtered Timer Input 1 (TI1FP1) */
  804. #define TIM_TS_TI2FP2 (TIM_SMCR_TS_1 | TIM_SMCR_TS_2) /*!< Filtered Timer Input 2 (TI2FP2) */
  805. #define TIM_TS_ETRF (TIM_SMCR_TS_0 | TIM_SMCR_TS_1 | TIM_SMCR_TS_2) /*!< Filtered External Trigger input (ETRF) */
  806. #define TIM_TS_NONE 0x0000FFFFU /*!< No trigger selected */
  807. /**
  808. * @}
  809. */
  810. /** @defgroup TIM_Trigger_Polarity TIM Trigger Polarity
  811. * @{
  812. */
  813. #define TIM_TRIGGERPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx trigger sources */
  814. #define TIM_TRIGGERPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx trigger sources */
  815. #define TIM_TRIGGERPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  816. #define TIM_TRIGGERPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  817. #define TIM_TRIGGERPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  818. /**
  819. * @}
  820. */
  821. /** @defgroup TIM_Trigger_Prescaler TIM Trigger Prescaler
  822. * @{
  823. */
  824. #define TIM_TRIGGERPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  825. #define TIM_TRIGGERPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Trigger: Capture performed once every 2 events. */
  826. #define TIM_TRIGGERPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Trigger: Capture performed once every 4 events. */
  827. #define TIM_TRIGGERPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Trigger: Capture performed once every 8 events. */
  828. /**
  829. * @}
  830. */
  831. /** @defgroup TIM_TI1_Selection TIM TI1 Input Selection
  832. * @{
  833. */
  834. #define TIM_TI1SELECTION_CH1 0x00000000U /*!< The TIMx_CH1 pin is connected to TI1 input */
  835. #define TIM_TI1SELECTION_XORCOMBINATION TIM_CR2_TI1S /*!< The TIMx_CH1, CH2 and CH3 pins are connected to the TI1 input (XOR combination) */
  836. /**
  837. * @}
  838. */
  839. /** @defgroup TIM_DMA_Burst_Length TIM DMA Burst Length
  840. * @{
  841. */
  842. #define TIM_DMABURSTLENGTH_1TRANSFER 0x00000000U /*!< The transfer is done to 1 register starting from TIMx_CR1 + TIMx_DCR.DBA */
  843. #define TIM_DMABURSTLENGTH_2TRANSFERS 0x00000100U /*!< The transfer is done to 2 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  844. #define TIM_DMABURSTLENGTH_3TRANSFERS 0x00000200U /*!< The transfer is done to 3 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  845. #define TIM_DMABURSTLENGTH_4TRANSFERS 0x00000300U /*!< The transfer is done to 4 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  846. #define TIM_DMABURSTLENGTH_5TRANSFERS 0x00000400U /*!< The transfer is done to 5 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  847. #define TIM_DMABURSTLENGTH_6TRANSFERS 0x00000500U /*!< The transfer is done to 6 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  848. #define TIM_DMABURSTLENGTH_7TRANSFERS 0x00000600U /*!< The transfer is done to 7 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  849. #define TIM_DMABURSTLENGTH_8TRANSFERS 0x00000700U /*!< The transfer is done to 8 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  850. #define TIM_DMABURSTLENGTH_9TRANSFERS 0x00000800U /*!< The transfer is done to 9 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  851. #define TIM_DMABURSTLENGTH_10TRANSFERS 0x00000900U /*!< The transfer is done to 10 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  852. #define TIM_DMABURSTLENGTH_11TRANSFERS 0x00000A00U /*!< The transfer is done to 11 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  853. #define TIM_DMABURSTLENGTH_12TRANSFERS 0x00000B00U /*!< The transfer is done to 12 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  854. #define TIM_DMABURSTLENGTH_13TRANSFERS 0x00000C00U /*!< The transfer is done to 13 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  855. #define TIM_DMABURSTLENGTH_14TRANSFERS 0x00000D00U /*!< The transfer is done to 14 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  856. #define TIM_DMABURSTLENGTH_15TRANSFERS 0x00000E00U /*!< The transfer is done to 15 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  857. #define TIM_DMABURSTLENGTH_16TRANSFERS 0x00000F00U /*!< The transfer is done to 16 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  858. #define TIM_DMABURSTLENGTH_17TRANSFERS 0x00001000U /*!< The transfer is done to 17 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  859. #define TIM_DMABURSTLENGTH_18TRANSFERS 0x00001100U /*!< The transfer is done to 18 registers starting from TIMx_CR1 + TIMx_DCR.DBA */
  860. /**
  861. * @}
  862. */
  863. /** @defgroup DMA_Handle_index TIM DMA Handle Index
  864. * @{
  865. */
  866. #define TIM_DMA_ID_UPDATE ((uint16_t) 0x0000) /*!< Index of the DMA handle used for Update DMA requests */
  867. #define TIM_DMA_ID_CC1 ((uint16_t) 0x0001) /*!< Index of the DMA handle used for Capture/Compare 1 DMA requests */
  868. #define TIM_DMA_ID_CC2 ((uint16_t) 0x0002) /*!< Index of the DMA handle used for Capture/Compare 2 DMA requests */
  869. #define TIM_DMA_ID_CC3 ((uint16_t) 0x0003) /*!< Index of the DMA handle used for Capture/Compare 3 DMA requests */
  870. #define TIM_DMA_ID_CC4 ((uint16_t) 0x0004) /*!< Index of the DMA handle used for Capture/Compare 4 DMA requests */
  871. #define TIM_DMA_ID_COMMUTATION ((uint16_t) 0x0005) /*!< Index of the DMA handle used for Commutation DMA requests */
  872. #define TIM_DMA_ID_TRIGGER ((uint16_t) 0x0006) /*!< Index of the DMA handle used for Trigger DMA requests */
  873. /**
  874. * @}
  875. */
  876. /** @defgroup Channel_CC_State TIM Capture/Compare Channel State
  877. * @{
  878. */
  879. #define TIM_CCx_ENABLE 0x00000001U /*!< Input or output channel is enabled */
  880. #define TIM_CCx_DISABLE 0x00000000U /*!< Input or output channel is disabled */
  881. #define TIM_CCxN_ENABLE 0x00000004U /*!< Complementary output channel is enabled */
  882. #define TIM_CCxN_DISABLE 0x00000000U /*!< Complementary output channel is enabled */
  883. /**
  884. * @}
  885. */
  886. /**
  887. * @}
  888. */
  889. /* End of exported constants -------------------------------------------------*/
  890. /* Exported macros -----------------------------------------------------------*/
  891. /** @defgroup TIM_Exported_Macros TIM Exported Macros
  892. * @{
  893. */
  894. /** @brief Reset TIM handle state.
  895. * @param __HANDLE__ TIM handle.
  896. * @retval None
  897. */
  898. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  899. #define __HAL_TIM_RESET_HANDLE_STATE(__HANDLE__) do { \
  900. (__HANDLE__)->State = HAL_TIM_STATE_RESET; \
  901. (__HANDLE__)->ChannelState[0] = HAL_TIM_CHANNEL_STATE_RESET; \
  902. (__HANDLE__)->ChannelState[1] = HAL_TIM_CHANNEL_STATE_RESET; \
  903. (__HANDLE__)->ChannelState[2] = HAL_TIM_CHANNEL_STATE_RESET; \
  904. (__HANDLE__)->ChannelState[3] = HAL_TIM_CHANNEL_STATE_RESET; \
  905. (__HANDLE__)->ChannelNState[0] = HAL_TIM_CHANNEL_STATE_RESET; \
  906. (__HANDLE__)->ChannelNState[1] = HAL_TIM_CHANNEL_STATE_RESET; \
  907. (__HANDLE__)->ChannelNState[2] = HAL_TIM_CHANNEL_STATE_RESET; \
  908. (__HANDLE__)->ChannelNState[3] = HAL_TIM_CHANNEL_STATE_RESET; \
  909. (__HANDLE__)->DMABurstState = HAL_DMA_BURST_STATE_RESET; \
  910. (__HANDLE__)->Base_MspInitCallback = NULL; \
  911. (__HANDLE__)->Base_MspDeInitCallback = NULL; \
  912. (__HANDLE__)->IC_MspInitCallback = NULL; \
  913. (__HANDLE__)->IC_MspDeInitCallback = NULL; \
  914. (__HANDLE__)->OC_MspInitCallback = NULL; \
  915. (__HANDLE__)->OC_MspDeInitCallback = NULL; \
  916. (__HANDLE__)->PWM_MspInitCallback = NULL; \
  917. (__HANDLE__)->PWM_MspDeInitCallback = NULL; \
  918. (__HANDLE__)->OnePulse_MspInitCallback = NULL; \
  919. (__HANDLE__)->OnePulse_MspDeInitCallback = NULL; \
  920. (__HANDLE__)->Encoder_MspInitCallback = NULL; \
  921. (__HANDLE__)->Encoder_MspDeInitCallback = NULL; \
  922. (__HANDLE__)->HallSensor_MspInitCallback = NULL; \
  923. (__HANDLE__)->HallSensor_MspDeInitCallback = NULL; \
  924. } while(0)
  925. #else
  926. #define __HAL_TIM_RESET_HANDLE_STATE(__HANDLE__) do { \
  927. (__HANDLE__)->State = HAL_TIM_STATE_RESET; \
  928. (__HANDLE__)->ChannelState[0] = HAL_TIM_CHANNEL_STATE_RESET; \
  929. (__HANDLE__)->ChannelState[1] = HAL_TIM_CHANNEL_STATE_RESET; \
  930. (__HANDLE__)->ChannelState[2] = HAL_TIM_CHANNEL_STATE_RESET; \
  931. (__HANDLE__)->ChannelState[3] = HAL_TIM_CHANNEL_STATE_RESET; \
  932. (__HANDLE__)->ChannelNState[0] = HAL_TIM_CHANNEL_STATE_RESET; \
  933. (__HANDLE__)->ChannelNState[1] = HAL_TIM_CHANNEL_STATE_RESET; \
  934. (__HANDLE__)->ChannelNState[2] = HAL_TIM_CHANNEL_STATE_RESET; \
  935. (__HANDLE__)->ChannelNState[3] = HAL_TIM_CHANNEL_STATE_RESET; \
  936. (__HANDLE__)->DMABurstState = HAL_DMA_BURST_STATE_RESET; \
  937. } while(0)
  938. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  939. /**
  940. * @brief Enable the TIM peripheral.
  941. * @param __HANDLE__ TIM handle
  942. * @retval None
  943. */
  944. #define __HAL_TIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(TIM_CR1_CEN))
  945. /**
  946. * @brief Enable the TIM main Output.
  947. * @param __HANDLE__ TIM handle
  948. * @retval None
  949. */
  950. #define __HAL_TIM_MOE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->BDTR|=(TIM_BDTR_MOE))
  951. /**
  952. * @brief Disable the TIM peripheral.
  953. * @param __HANDLE__ TIM handle
  954. * @retval None
  955. */
  956. #define __HAL_TIM_DISABLE(__HANDLE__) \
  957. do { \
  958. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0UL) \
  959. { \
  960. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0UL) \
  961. { \
  962. (__HANDLE__)->Instance->CR1 &= ~(TIM_CR1_CEN); \
  963. } \
  964. } \
  965. } while(0)
  966. /**
  967. * @brief Disable the TIM main Output.
  968. * @param __HANDLE__ TIM handle
  969. * @retval None
  970. * @note The Main Output Enable of a timer instance is disabled only if all the CCx and CCxN channels have been
  971. * disabled
  972. */
  973. #define __HAL_TIM_MOE_DISABLE(__HANDLE__) \
  974. do { \
  975. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0UL) \
  976. { \
  977. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0UL) \
  978. { \
  979. (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE); \
  980. } \
  981. } \
  982. } while(0)
  983. /**
  984. * @brief Disable the TIM main Output.
  985. * @param __HANDLE__ TIM handle
  986. * @retval None
  987. * @note The Main Output Enable of a timer instance is disabled unconditionally
  988. */
  989. #define __HAL_TIM_MOE_DISABLE_UNCONDITIONALLY(__HANDLE__) (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE)
  990. /** @brief Enable the specified TIM interrupt.
  991. * @param __HANDLE__ specifies the TIM Handle.
  992. * @param __INTERRUPT__ specifies the TIM interrupt source to enable.
  993. * This parameter can be one of the following values:
  994. * @arg TIM_IT_UPDATE: Update interrupt
  995. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  996. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  997. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  998. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  999. * @arg TIM_IT_COM: Commutation interrupt
  1000. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1001. * @arg TIM_IT_BREAK: Break interrupt
  1002. * @retval None
  1003. */
  1004. #define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER |= (__INTERRUPT__))
  1005. /** @brief Disable the specified TIM interrupt.
  1006. * @param __HANDLE__ specifies the TIM Handle.
  1007. * @param __INTERRUPT__ specifies the TIM interrupt source to disable.
  1008. * This parameter can be one of the following values:
  1009. * @arg TIM_IT_UPDATE: Update interrupt
  1010. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1011. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1012. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1013. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1014. * @arg TIM_IT_COM: Commutation interrupt
  1015. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1016. * @arg TIM_IT_BREAK: Break interrupt
  1017. * @retval None
  1018. */
  1019. #define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER &= ~(__INTERRUPT__))
  1020. /** @brief Enable the specified DMA request.
  1021. * @param __HANDLE__ specifies the TIM Handle.
  1022. * @param __DMA__ specifies the TIM DMA request to enable.
  1023. * This parameter can be one of the following values:
  1024. * @arg TIM_DMA_UPDATE: Update DMA request
  1025. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  1026. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  1027. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  1028. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  1029. * @arg TIM_DMA_COM: Commutation DMA request
  1030. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  1031. * @retval None
  1032. */
  1033. #define __HAL_TIM_ENABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER |= (__DMA__))
  1034. /** @brief Disable the specified DMA request.
  1035. * @param __HANDLE__ specifies the TIM Handle.
  1036. * @param __DMA__ specifies the TIM DMA request to disable.
  1037. * This parameter can be one of the following values:
  1038. * @arg TIM_DMA_UPDATE: Update DMA request
  1039. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  1040. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  1041. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  1042. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  1043. * @arg TIM_DMA_COM: Commutation DMA request
  1044. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  1045. * @retval None
  1046. */
  1047. #define __HAL_TIM_DISABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER &= ~(__DMA__))
  1048. /** @brief Check whether the specified TIM interrupt flag is set or not.
  1049. * @param __HANDLE__ specifies the TIM Handle.
  1050. * @param __FLAG__ specifies the TIM interrupt flag to check.
  1051. * This parameter can be one of the following values:
  1052. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1053. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1054. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1055. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1056. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1057. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1058. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1059. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1060. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1061. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1062. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1063. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1064. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1065. */
  1066. #define __HAL_TIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR &(__FLAG__)) == (__FLAG__))
  1067. /** @brief Clear the specified TIM interrupt flag.
  1068. * @param __HANDLE__ specifies the TIM Handle.
  1069. * @param __FLAG__ specifies the TIM interrupt flag to clear.
  1070. * This parameter can be one of the following values:
  1071. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1072. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1073. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1074. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1075. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1076. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1077. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1078. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1079. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1080. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1081. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1082. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1083. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1084. */
  1085. #define __HAL_TIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  1086. /**
  1087. * @brief Check whether the specified TIM interrupt source is enabled or not.
  1088. * @param __HANDLE__ TIM handle
  1089. * @param __INTERRUPT__ specifies the TIM interrupt source to check.
  1090. * This parameter can be one of the following values:
  1091. * @arg TIM_IT_UPDATE: Update interrupt
  1092. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1093. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1094. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1095. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1096. * @arg TIM_IT_COM: Commutation interrupt
  1097. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1098. * @arg TIM_IT_BREAK: Break interrupt
  1099. * @retval The state of TIM_IT (SET or RESET).
  1100. */
  1101. #define __HAL_TIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->DIER & (__INTERRUPT__)) \
  1102. == (__INTERRUPT__)) ? SET : RESET)
  1103. /** @brief Clear the TIM interrupt pending bits.
  1104. * @param __HANDLE__ TIM handle
  1105. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1106. * This parameter can be one of the following values:
  1107. * @arg TIM_IT_UPDATE: Update interrupt
  1108. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1109. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1110. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1111. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1112. * @arg TIM_IT_COM: Commutation interrupt
  1113. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1114. * @arg TIM_IT_BREAK: Break interrupt
  1115. * @retval None
  1116. */
  1117. #define __HAL_TIM_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->SR = ~(__INTERRUPT__))
  1118. /**
  1119. * @brief Indicates whether or not the TIM Counter is used as downcounter.
  1120. * @param __HANDLE__ TIM handle.
  1121. * @retval False (Counter used as upcounter) or True (Counter used as downcounter)
  1122. * @note This macro is particularly useful to get the counting mode when the timer operates in Center-aligned mode
  1123. * or Encoder mode.
  1124. */
  1125. #define __HAL_TIM_IS_TIM_COUNTING_DOWN(__HANDLE__) (((__HANDLE__)->Instance->CR1 &(TIM_CR1_DIR)) == (TIM_CR1_DIR))
  1126. /**
  1127. * @brief Set the TIM Prescaler on runtime.
  1128. * @param __HANDLE__ TIM handle.
  1129. * @param __PRESC__ specifies the Prescaler new value.
  1130. * @retval None
  1131. */
  1132. #define __HAL_TIM_SET_PRESCALER(__HANDLE__, __PRESC__) ((__HANDLE__)->Instance->PSC = (__PRESC__))
  1133. /**
  1134. * @brief Set the TIM Counter Register value on runtime.
  1135. * @param __HANDLE__ TIM handle.
  1136. * @param __COUNTER__ specifies the Counter register new value.
  1137. * @retval None
  1138. */
  1139. #define __HAL_TIM_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->CNT = (__COUNTER__))
  1140. /**
  1141. * @brief Get the TIM Counter Register value on runtime.
  1142. * @param __HANDLE__ TIM handle.
  1143. * @retval 16-bit or 32-bit value of the timer counter register (TIMx_CNT)
  1144. */
  1145. #define __HAL_TIM_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CNT)
  1146. /**
  1147. * @brief Set the TIM Autoreload Register value on runtime without calling another time any Init function.
  1148. * @param __HANDLE__ TIM handle.
  1149. * @param __AUTORELOAD__ specifies the Counter register new value.
  1150. * @retval None
  1151. */
  1152. #define __HAL_TIM_SET_AUTORELOAD(__HANDLE__, __AUTORELOAD__) \
  1153. do{ \
  1154. (__HANDLE__)->Instance->ARR = (__AUTORELOAD__); \
  1155. (__HANDLE__)->Init.Period = (__AUTORELOAD__); \
  1156. } while(0)
  1157. /**
  1158. * @brief Get the TIM Autoreload Register value on runtime.
  1159. * @param __HANDLE__ TIM handle.
  1160. * @retval 16-bit or 32-bit value of the timer auto-reload register(TIMx_ARR)
  1161. */
  1162. #define __HAL_TIM_GET_AUTORELOAD(__HANDLE__) ((__HANDLE__)->Instance->ARR)
  1163. /**
  1164. * @brief Set the TIM Clock Division value on runtime without calling another time any Init function.
  1165. * @param __HANDLE__ TIM handle.
  1166. * @param __CKD__ specifies the clock division value.
  1167. * This parameter can be one of the following value:
  1168. * @arg TIM_CLOCKDIVISION_DIV1: tDTS=tCK_INT
  1169. * @arg TIM_CLOCKDIVISION_DIV2: tDTS=2*tCK_INT
  1170. * @arg TIM_CLOCKDIVISION_DIV4: tDTS=4*tCK_INT
  1171. * @retval None
  1172. */
  1173. #define __HAL_TIM_SET_CLOCKDIVISION(__HANDLE__, __CKD__) \
  1174. do{ \
  1175. (__HANDLE__)->Instance->CR1 &= (~TIM_CR1_CKD); \
  1176. (__HANDLE__)->Instance->CR1 |= (__CKD__); \
  1177. (__HANDLE__)->Init.ClockDivision = (__CKD__); \
  1178. } while(0)
  1179. /**
  1180. * @brief Get the TIM Clock Division value on runtime.
  1181. * @param __HANDLE__ TIM handle.
  1182. * @retval The clock division can be one of the following values:
  1183. * @arg TIM_CLOCKDIVISION_DIV1: tDTS=tCK_INT
  1184. * @arg TIM_CLOCKDIVISION_DIV2: tDTS=2*tCK_INT
  1185. * @arg TIM_CLOCKDIVISION_DIV4: tDTS=4*tCK_INT
  1186. */
  1187. #define __HAL_TIM_GET_CLOCKDIVISION(__HANDLE__) ((__HANDLE__)->Instance->CR1 & TIM_CR1_CKD)
  1188. /**
  1189. * @brief Set the TIM Input Capture prescaler on runtime without calling another time HAL_TIM_IC_ConfigChannel()
  1190. * function.
  1191. * @param __HANDLE__ TIM handle.
  1192. * @param __CHANNEL__ TIM Channels to be configured.
  1193. * This parameter can be one of the following values:
  1194. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1195. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1196. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1197. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1198. * @param __ICPSC__ specifies the Input Capture4 prescaler new value.
  1199. * This parameter can be one of the following values:
  1200. * @arg TIM_ICPSC_DIV1: no prescaler
  1201. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  1202. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  1203. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  1204. * @retval None
  1205. */
  1206. #define __HAL_TIM_SET_ICPRESCALER(__HANDLE__, __CHANNEL__, __ICPSC__) \
  1207. do{ \
  1208. TIM_RESET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__)); \
  1209. TIM_SET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__), (__ICPSC__)); \
  1210. } while(0)
  1211. /**
  1212. * @brief Get the TIM Input Capture prescaler on runtime.
  1213. * @param __HANDLE__ TIM handle.
  1214. * @param __CHANNEL__ TIM Channels to be configured.
  1215. * This parameter can be one of the following values:
  1216. * @arg TIM_CHANNEL_1: get input capture 1 prescaler value
  1217. * @arg TIM_CHANNEL_2: get input capture 2 prescaler value
  1218. * @arg TIM_CHANNEL_3: get input capture 3 prescaler value
  1219. * @arg TIM_CHANNEL_4: get input capture 4 prescaler value
  1220. * @retval The input capture prescaler can be one of the following values:
  1221. * @arg TIM_ICPSC_DIV1: no prescaler
  1222. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  1223. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  1224. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  1225. */
  1226. #define __HAL_TIM_GET_ICPRESCALER(__HANDLE__, __CHANNEL__) \
  1227. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC1PSC) :\
  1228. ((__CHANNEL__) == TIM_CHANNEL_2) ? (((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC2PSC) >> 8U) :\
  1229. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC3PSC) :\
  1230. (((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC4PSC)) >> 8U)
  1231. /**
  1232. * @brief Set the TIM Capture Compare Register value on runtime without calling another time ConfigChannel function.
  1233. * @param __HANDLE__ TIM handle.
  1234. * @param __CHANNEL__ TIM Channels to be configured.
  1235. * This parameter can be one of the following values:
  1236. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1237. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1238. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1239. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1240. * @param __COMPARE__ specifies the Capture Compare register new value.
  1241. * @retval None
  1242. */
  1243. #define __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) \
  1244. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCR1 = (__COMPARE__)) :\
  1245. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCR2 = (__COMPARE__)) :\
  1246. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCR3 = (__COMPARE__)) :\
  1247. ((__HANDLE__)->Instance->CCR4 = (__COMPARE__)))
  1248. /**
  1249. * @brief Get the TIM Capture Compare Register value on runtime.
  1250. * @param __HANDLE__ TIM handle.
  1251. * @param __CHANNEL__ TIM Channel associated with the capture compare register
  1252. * This parameter can be one of the following values:
  1253. * @arg TIM_CHANNEL_1: get capture/compare 1 register value
  1254. * @arg TIM_CHANNEL_2: get capture/compare 2 register value
  1255. * @arg TIM_CHANNEL_3: get capture/compare 3 register value
  1256. * @arg TIM_CHANNEL_4: get capture/compare 4 register value
  1257. * @retval 16-bit or 32-bit value of the capture/compare register (TIMx_CCRy)
  1258. */
  1259. #define __HAL_TIM_GET_COMPARE(__HANDLE__, __CHANNEL__) \
  1260. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCR1) :\
  1261. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCR2) :\
  1262. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCR3) :\
  1263. ((__HANDLE__)->Instance->CCR4))
  1264. /**
  1265. * @brief Set the TIM Output compare preload.
  1266. * @param __HANDLE__ TIM handle.
  1267. * @param __CHANNEL__ TIM Channels to be configured.
  1268. * This parameter can be one of the following values:
  1269. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1270. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1271. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1272. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1273. * @retval None
  1274. */
  1275. #define __HAL_TIM_ENABLE_OCxPRELOAD(__HANDLE__, __CHANNEL__) \
  1276. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC1PE) :\
  1277. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC2PE) :\
  1278. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC3PE) :\
  1279. ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC4PE))
  1280. /**
  1281. * @brief Reset the TIM Output compare preload.
  1282. * @param __HANDLE__ TIM handle.
  1283. * @param __CHANNEL__ TIM Channels to be configured.
  1284. * This parameter can be one of the following values:
  1285. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1286. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1287. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1288. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1289. * @retval None
  1290. */
  1291. #define __HAL_TIM_DISABLE_OCxPRELOAD(__HANDLE__, __CHANNEL__) \
  1292. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_OC1PE) :\
  1293. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_OC2PE) :\
  1294. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_OC3PE) :\
  1295. ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_OC4PE))
  1296. /**
  1297. * @brief Enable fast mode for a given channel.
  1298. * @param __HANDLE__ TIM handle.
  1299. * @param __CHANNEL__ TIM Channels to be configured.
  1300. * This parameter can be one of the following values:
  1301. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1302. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1303. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1304. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1305. * @note When fast mode is enabled an active edge on the trigger input acts
  1306. * like a compare match on CCx output. Delay to sample the trigger
  1307. * input and to activate CCx output is reduced to 3 clock cycles.
  1308. * @note Fast mode acts only if the channel is configured in PWM1 or PWM2 mode.
  1309. * @retval None
  1310. */
  1311. #define __HAL_TIM_ENABLE_OCxFAST(__HANDLE__, __CHANNEL__) \
  1312. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC1FE) :\
  1313. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC2FE) :\
  1314. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC3FE) :\
  1315. ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC4FE))
  1316. /**
  1317. * @brief Disable fast mode for a given channel.
  1318. * @param __HANDLE__ TIM handle.
  1319. * @param __CHANNEL__ TIM Channels to be configured.
  1320. * This parameter can be one of the following values:
  1321. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1322. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1323. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1324. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1325. * @note When fast mode is disabled CCx output behaves normally depending
  1326. * on counter and CCRx values even when the trigger is ON. The minimum
  1327. * delay to activate CCx output when an active edge occurs on the
  1328. * trigger input is 5 clock cycles.
  1329. * @retval None
  1330. */
  1331. #define __HAL_TIM_DISABLE_OCxFAST(__HANDLE__, __CHANNEL__) \
  1332. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE) :\
  1333. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE) :\
  1334. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE) :\
  1335. ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE))
  1336. /**
  1337. * @brief Set the Update Request Source (URS) bit of the TIMx_CR1 register.
  1338. * @param __HANDLE__ TIM handle.
  1339. * @note When the URS bit of the TIMx_CR1 register is set, only counter
  1340. * overflow/underflow generates an update interrupt or DMA request (if
  1341. * enabled)
  1342. * @retval None
  1343. */
  1344. #define __HAL_TIM_URS_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|= TIM_CR1_URS)
  1345. /**
  1346. * @brief Reset the Update Request Source (URS) bit of the TIMx_CR1 register.
  1347. * @param __HANDLE__ TIM handle.
  1348. * @note When the URS bit of the TIMx_CR1 register is reset, any of the
  1349. * following events generate an update interrupt or DMA request (if
  1350. * enabled):
  1351. * _ Counter overflow underflow
  1352. * _ Setting the UG bit
  1353. * _ Update generation through the slave mode controller
  1354. * @retval None
  1355. */
  1356. #define __HAL_TIM_URS_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1&=~TIM_CR1_URS)
  1357. /**
  1358. * @brief Set the TIM Capture x input polarity on runtime.
  1359. * @param __HANDLE__ TIM handle.
  1360. * @param __CHANNEL__ TIM Channels to be configured.
  1361. * This parameter can be one of the following values:
  1362. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1363. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1364. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1365. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1366. * @param __POLARITY__ Polarity for TIx source
  1367. * @arg TIM_INPUTCHANNELPOLARITY_RISING: Rising Edge
  1368. * @arg TIM_INPUTCHANNELPOLARITY_FALLING: Falling Edge
  1369. * @arg TIM_INPUTCHANNELPOLARITY_BOTHEDGE: Rising and Falling Edge
  1370. * @retval None
  1371. */
  1372. #define __HAL_TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  1373. do{ \
  1374. TIM_RESET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__)); \
  1375. TIM_SET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__), (__POLARITY__)); \
  1376. }while(0)
  1377. /**
  1378. * @}
  1379. */
  1380. /* End of exported macros ----------------------------------------------------*/
  1381. /* Private constants ---------------------------------------------------------*/
  1382. /** @defgroup TIM_Private_Constants TIM Private Constants
  1383. * @{
  1384. */
  1385. /* The counter of a timer instance is disabled only if all the CCx and CCxN
  1386. channels have been disabled */
  1387. #define TIM_CCER_CCxE_MASK ((uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E))
  1388. #define TIM_CCER_CCxNE_MASK ((uint32_t)(TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE))
  1389. /**
  1390. * @}
  1391. */
  1392. /* End of private constants --------------------------------------------------*/
  1393. /* Private macros ------------------------------------------------------------*/
  1394. /** @defgroup TIM_Private_Macros TIM Private Macros
  1395. * @{
  1396. */
  1397. #define IS_TIM_CLEARINPUT_SOURCE(__MODE__) (((__MODE__) == TIM_CLEARINPUTSOURCE_NONE) || \
  1398. ((__MODE__) == TIM_CLEARINPUTSOURCE_ETR))
  1399. #define IS_TIM_DMA_BASE(__BASE__) (((__BASE__) == TIM_DMABASE_CR1) || \
  1400. ((__BASE__) == TIM_DMABASE_CR2) || \
  1401. ((__BASE__) == TIM_DMABASE_SMCR) || \
  1402. ((__BASE__) == TIM_DMABASE_DIER) || \
  1403. ((__BASE__) == TIM_DMABASE_SR) || \
  1404. ((__BASE__) == TIM_DMABASE_EGR) || \
  1405. ((__BASE__) == TIM_DMABASE_CCMR1) || \
  1406. ((__BASE__) == TIM_DMABASE_CCMR2) || \
  1407. ((__BASE__) == TIM_DMABASE_CCER) || \
  1408. ((__BASE__) == TIM_DMABASE_CNT) || \
  1409. ((__BASE__) == TIM_DMABASE_PSC) || \
  1410. ((__BASE__) == TIM_DMABASE_ARR) || \
  1411. ((__BASE__) == TIM_DMABASE_RCR) || \
  1412. ((__BASE__) == TIM_DMABASE_CCR1) || \
  1413. ((__BASE__) == TIM_DMABASE_CCR2) || \
  1414. ((__BASE__) == TIM_DMABASE_CCR3) || \
  1415. ((__BASE__) == TIM_DMABASE_CCR4) || \
  1416. ((__BASE__) == TIM_DMABASE_BDTR))
  1417. #define IS_TIM_EVENT_SOURCE(__SOURCE__) ((((__SOURCE__) & 0xFFFFFF00U) == 0x00000000U) && ((__SOURCE__) != 0x00000000U))
  1418. #define IS_TIM_COUNTER_MODE(__MODE__) (((__MODE__) == TIM_COUNTERMODE_UP) || \
  1419. ((__MODE__) == TIM_COUNTERMODE_DOWN) || \
  1420. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED1) || \
  1421. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED2) || \
  1422. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED3))
  1423. #define IS_TIM_CLOCKDIVISION_DIV(__DIV__) (((__DIV__) == TIM_CLOCKDIVISION_DIV1) || \
  1424. ((__DIV__) == TIM_CLOCKDIVISION_DIV2) || \
  1425. ((__DIV__) == TIM_CLOCKDIVISION_DIV4))
  1426. #define IS_TIM_AUTORELOAD_PRELOAD(PRELOAD) (((PRELOAD) == TIM_AUTORELOAD_PRELOAD_DISABLE) || \
  1427. ((PRELOAD) == TIM_AUTORELOAD_PRELOAD_ENABLE))
  1428. #define IS_TIM_FAST_STATE(__STATE__) (((__STATE__) == TIM_OCFAST_DISABLE) || \
  1429. ((__STATE__) == TIM_OCFAST_ENABLE))
  1430. #define IS_TIM_OC_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_OCPOLARITY_HIGH) || \
  1431. ((__POLARITY__) == TIM_OCPOLARITY_LOW))
  1432. #define IS_TIM_OCN_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_OCNPOLARITY_HIGH) || \
  1433. ((__POLARITY__) == TIM_OCNPOLARITY_LOW))
  1434. #define IS_TIM_OCIDLE_STATE(__STATE__) (((__STATE__) == TIM_OCIDLESTATE_SET) || \
  1435. ((__STATE__) == TIM_OCIDLESTATE_RESET))
  1436. #define IS_TIM_OCNIDLE_STATE(__STATE__) (((__STATE__) == TIM_OCNIDLESTATE_SET) || \
  1437. ((__STATE__) == TIM_OCNIDLESTATE_RESET))
  1438. #define IS_TIM_ENCODERINPUT_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_ENCODERINPUTPOLARITY_RISING) || \
  1439. ((__POLARITY__) == TIM_ENCODERINPUTPOLARITY_FALLING))
  1440. #define IS_TIM_IC_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_ICPOLARITY_RISING) || \
  1441. ((__POLARITY__) == TIM_ICPOLARITY_FALLING) || \
  1442. ((__POLARITY__) == TIM_ICPOLARITY_BOTHEDGE))
  1443. #define IS_TIM_IC_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_ICSELECTION_DIRECTTI) || \
  1444. ((__SELECTION__) == TIM_ICSELECTION_INDIRECTTI) || \
  1445. ((__SELECTION__) == TIM_ICSELECTION_TRC))
  1446. #define IS_TIM_IC_PRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_ICPSC_DIV1) || \
  1447. ((__PRESCALER__) == TIM_ICPSC_DIV2) || \
  1448. ((__PRESCALER__) == TIM_ICPSC_DIV4) || \
  1449. ((__PRESCALER__) == TIM_ICPSC_DIV8))
  1450. #define IS_TIM_OPM_MODE(__MODE__) (((__MODE__) == TIM_OPMODE_SINGLE) || \
  1451. ((__MODE__) == TIM_OPMODE_REPETITIVE))
  1452. #define IS_TIM_ENCODER_MODE(__MODE__) (((__MODE__) == TIM_ENCODERMODE_TI1) || \
  1453. ((__MODE__) == TIM_ENCODERMODE_TI2) || \
  1454. ((__MODE__) == TIM_ENCODERMODE_TI12))
  1455. #define IS_TIM_DMA_SOURCE(__SOURCE__) ((((__SOURCE__) & 0xFFFF80FFU) == 0x00000000U) && ((__SOURCE__) != 0x00000000U))
  1456. #define IS_TIM_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1457. ((__CHANNEL__) == TIM_CHANNEL_2) || \
  1458. ((__CHANNEL__) == TIM_CHANNEL_3) || \
  1459. ((__CHANNEL__) == TIM_CHANNEL_4) || \
  1460. ((__CHANNEL__) == TIM_CHANNEL_ALL))
  1461. #define IS_TIM_OPM_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1462. ((__CHANNEL__) == TIM_CHANNEL_2))
  1463. #define IS_TIM_COMPLEMENTARY_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1464. ((__CHANNEL__) == TIM_CHANNEL_2) || \
  1465. ((__CHANNEL__) == TIM_CHANNEL_3))
  1466. #define IS_TIM_CLOCKSOURCE(__CLOCK__) (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL) || \
  1467. ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2) || \
  1468. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0) || \
  1469. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1) || \
  1470. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2) || \
  1471. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3) || \
  1472. ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED) || \
  1473. ((__CLOCK__) == TIM_CLOCKSOURCE_TI1) || \
  1474. ((__CLOCK__) == TIM_CLOCKSOURCE_TI2) || \
  1475. ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1))
  1476. #define IS_TIM_CLOCKPOLARITY(__POLARITY__) (((__POLARITY__) == TIM_CLOCKPOLARITY_INVERTED) || \
  1477. ((__POLARITY__) == TIM_CLOCKPOLARITY_NONINVERTED) || \
  1478. ((__POLARITY__) == TIM_CLOCKPOLARITY_RISING) || \
  1479. ((__POLARITY__) == TIM_CLOCKPOLARITY_FALLING) || \
  1480. ((__POLARITY__) == TIM_CLOCKPOLARITY_BOTHEDGE))
  1481. #define IS_TIM_CLOCKPRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV1) || \
  1482. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV2) || \
  1483. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV4) || \
  1484. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV8))
  1485. #define IS_TIM_CLOCKFILTER(__ICFILTER__) ((__ICFILTER__) <= 0xFU)
  1486. #define IS_TIM_CLEARINPUT_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_CLEARINPUTPOLARITY_INVERTED) || \
  1487. ((__POLARITY__) == TIM_CLEARINPUTPOLARITY_NONINVERTED))
  1488. #define IS_TIM_CLEARINPUT_PRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV1) || \
  1489. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV2) || \
  1490. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV4) || \
  1491. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV8))
  1492. #define IS_TIM_CLEARINPUT_FILTER(__ICFILTER__) ((__ICFILTER__) <= 0xFU)
  1493. #define IS_TIM_OSSR_STATE(__STATE__) (((__STATE__) == TIM_OSSR_ENABLE) || \
  1494. ((__STATE__) == TIM_OSSR_DISABLE))
  1495. #define IS_TIM_OSSI_STATE(__STATE__) (((__STATE__) == TIM_OSSI_ENABLE) || \
  1496. ((__STATE__) == TIM_OSSI_DISABLE))
  1497. #define IS_TIM_LOCK_LEVEL(__LEVEL__) (((__LEVEL__) == TIM_LOCKLEVEL_OFF) || \
  1498. ((__LEVEL__) == TIM_LOCKLEVEL_1) || \
  1499. ((__LEVEL__) == TIM_LOCKLEVEL_2) || \
  1500. ((__LEVEL__) == TIM_LOCKLEVEL_3))
  1501. #define IS_TIM_BREAK_FILTER(__BRKFILTER__) ((__BRKFILTER__) <= 0xFUL)
  1502. #define IS_TIM_BREAK_STATE(__STATE__) (((__STATE__) == TIM_BREAK_ENABLE) || \
  1503. ((__STATE__) == TIM_BREAK_DISABLE))
  1504. #define IS_TIM_BREAK_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_BREAKPOLARITY_LOW) || \
  1505. ((__POLARITY__) == TIM_BREAKPOLARITY_HIGH))
  1506. #define IS_TIM_AUTOMATIC_OUTPUT_STATE(__STATE__) (((__STATE__) == TIM_AUTOMATICOUTPUT_ENABLE) || \
  1507. ((__STATE__) == TIM_AUTOMATICOUTPUT_DISABLE))
  1508. #define IS_TIM_TRGO_SOURCE(__SOURCE__) (((__SOURCE__) == TIM_TRGO_RESET) || \
  1509. ((__SOURCE__) == TIM_TRGO_ENABLE) || \
  1510. ((__SOURCE__) == TIM_TRGO_UPDATE) || \
  1511. ((__SOURCE__) == TIM_TRGO_OC1) || \
  1512. ((__SOURCE__) == TIM_TRGO_OC1REF) || \
  1513. ((__SOURCE__) == TIM_TRGO_OC2REF) || \
  1514. ((__SOURCE__) == TIM_TRGO_OC3REF) || \
  1515. ((__SOURCE__) == TIM_TRGO_OC4REF))
  1516. #define IS_TIM_MSM_STATE(__STATE__) (((__STATE__) == TIM_MASTERSLAVEMODE_ENABLE) || \
  1517. ((__STATE__) == TIM_MASTERSLAVEMODE_DISABLE))
  1518. #define IS_TIM_SLAVE_MODE(__MODE__) (((__MODE__) == TIM_SLAVEMODE_DISABLE) || \
  1519. ((__MODE__) == TIM_SLAVEMODE_RESET) || \
  1520. ((__MODE__) == TIM_SLAVEMODE_GATED) || \
  1521. ((__MODE__) == TIM_SLAVEMODE_TRIGGER) || \
  1522. ((__MODE__) == TIM_SLAVEMODE_EXTERNAL1))
  1523. #define IS_TIM_PWM_MODE(__MODE__) (((__MODE__) == TIM_OCMODE_PWM1) || \
  1524. ((__MODE__) == TIM_OCMODE_PWM2))
  1525. #define IS_TIM_OC_MODE(__MODE__) (((__MODE__) == TIM_OCMODE_TIMING) || \
  1526. ((__MODE__) == TIM_OCMODE_ACTIVE) || \
  1527. ((__MODE__) == TIM_OCMODE_INACTIVE) || \
  1528. ((__MODE__) == TIM_OCMODE_TOGGLE) || \
  1529. ((__MODE__) == TIM_OCMODE_FORCED_ACTIVE) || \
  1530. ((__MODE__) == TIM_OCMODE_FORCED_INACTIVE))
  1531. #define IS_TIM_TRIGGER_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_TS_ITR0) || \
  1532. ((__SELECTION__) == TIM_TS_ITR1) || \
  1533. ((__SELECTION__) == TIM_TS_ITR2) || \
  1534. ((__SELECTION__) == TIM_TS_ITR3) || \
  1535. ((__SELECTION__) == TIM_TS_TI1F_ED) || \
  1536. ((__SELECTION__) == TIM_TS_TI1FP1) || \
  1537. ((__SELECTION__) == TIM_TS_TI2FP2) || \
  1538. ((__SELECTION__) == TIM_TS_ETRF))
  1539. #define IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_TS_ITR0) || \
  1540. ((__SELECTION__) == TIM_TS_ITR1) || \
  1541. ((__SELECTION__) == TIM_TS_ITR2) || \
  1542. ((__SELECTION__) == TIM_TS_ITR3) || \
  1543. ((__SELECTION__) == TIM_TS_NONE))
  1544. #define IS_TIM_TRIGGERPOLARITY(__POLARITY__) (((__POLARITY__) == TIM_TRIGGERPOLARITY_INVERTED ) || \
  1545. ((__POLARITY__) == TIM_TRIGGERPOLARITY_NONINVERTED) || \
  1546. ((__POLARITY__) == TIM_TRIGGERPOLARITY_RISING ) || \
  1547. ((__POLARITY__) == TIM_TRIGGERPOLARITY_FALLING ) || \
  1548. ((__POLARITY__) == TIM_TRIGGERPOLARITY_BOTHEDGE ))
  1549. #define IS_TIM_TRIGGERPRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV1) || \
  1550. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV2) || \
  1551. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV4) || \
  1552. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV8))
  1553. #define IS_TIM_TRIGGERFILTER(__ICFILTER__) ((__ICFILTER__) <= 0xFU)
  1554. #define IS_TIM_TI1SELECTION(__TI1SELECTION__) (((__TI1SELECTION__) == TIM_TI1SELECTION_CH1) || \
  1555. ((__TI1SELECTION__) == TIM_TI1SELECTION_XORCOMBINATION))
  1556. #define IS_TIM_DMA_LENGTH(__LENGTH__) (((__LENGTH__) == TIM_DMABURSTLENGTH_1TRANSFER) || \
  1557. ((__LENGTH__) == TIM_DMABURSTLENGTH_2TRANSFERS) || \
  1558. ((__LENGTH__) == TIM_DMABURSTLENGTH_3TRANSFERS) || \
  1559. ((__LENGTH__) == TIM_DMABURSTLENGTH_4TRANSFERS) || \
  1560. ((__LENGTH__) == TIM_DMABURSTLENGTH_5TRANSFERS) || \
  1561. ((__LENGTH__) == TIM_DMABURSTLENGTH_6TRANSFERS) || \
  1562. ((__LENGTH__) == TIM_DMABURSTLENGTH_7TRANSFERS) || \
  1563. ((__LENGTH__) == TIM_DMABURSTLENGTH_8TRANSFERS) || \
  1564. ((__LENGTH__) == TIM_DMABURSTLENGTH_9TRANSFERS) || \
  1565. ((__LENGTH__) == TIM_DMABURSTLENGTH_10TRANSFERS) || \
  1566. ((__LENGTH__) == TIM_DMABURSTLENGTH_11TRANSFERS) || \
  1567. ((__LENGTH__) == TIM_DMABURSTLENGTH_12TRANSFERS) || \
  1568. ((__LENGTH__) == TIM_DMABURSTLENGTH_13TRANSFERS) || \
  1569. ((__LENGTH__) == TIM_DMABURSTLENGTH_14TRANSFERS) || \
  1570. ((__LENGTH__) == TIM_DMABURSTLENGTH_15TRANSFERS) || \
  1571. ((__LENGTH__) == TIM_DMABURSTLENGTH_16TRANSFERS) || \
  1572. ((__LENGTH__) == TIM_DMABURSTLENGTH_17TRANSFERS) || \
  1573. ((__LENGTH__) == TIM_DMABURSTLENGTH_18TRANSFERS))
  1574. #define IS_TIM_DMA_DATA_LENGTH(LENGTH) (((LENGTH) >= 0x1U) && ((LENGTH) < 0x10000U))
  1575. #define IS_TIM_IC_FILTER(__ICFILTER__) ((__ICFILTER__) <= 0xFU)
  1576. #define IS_TIM_DEADTIME(__DEADTIME__) ((__DEADTIME__) <= 0xFFU)
  1577. #define IS_TIM_SLAVEMODE_TRIGGER_ENABLED(__TRIGGER__) ((__TRIGGER__) == TIM_SLAVEMODE_TRIGGER)
  1578. #define TIM_SET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__, __ICPSC__) \
  1579. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= (__ICPSC__)) :\
  1580. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= ((__ICPSC__) << 8U)) :\
  1581. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= (__ICPSC__)) :\
  1582. ((__HANDLE__)->Instance->CCMR2 |= ((__ICPSC__) << 8U)))
  1583. #define TIM_RESET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__) \
  1584. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC) :\
  1585. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC) :\
  1586. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC) :\
  1587. ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC))
  1588. #define TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  1589. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER |= (__POLARITY__)) :\
  1590. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 4U)) :\
  1591. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 8U)) :\
  1592. ((__HANDLE__)->Instance->CCER |= (((__POLARITY__) << 12U))))
  1593. #define TIM_RESET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__) \
  1594. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP)) :\
  1595. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP)) :\
  1596. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC3P)) :\
  1597. ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC4P)))
  1598. #define TIM_CHANNEL_STATE_GET(__HANDLE__, __CHANNEL__)\
  1599. (((__CHANNEL__) == TIM_CHANNEL_1) ? (__HANDLE__)->ChannelState[0] :\
  1600. ((__CHANNEL__) == TIM_CHANNEL_2) ? (__HANDLE__)->ChannelState[1] :\
  1601. ((__CHANNEL__) == TIM_CHANNEL_3) ? (__HANDLE__)->ChannelState[2] :\
  1602. (__HANDLE__)->ChannelState[3])
  1603. #define TIM_CHANNEL_STATE_SET(__HANDLE__, __CHANNEL__, __CHANNEL_STATE__) \
  1604. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->ChannelState[0] = (__CHANNEL_STATE__)) :\
  1605. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->ChannelState[1] = (__CHANNEL_STATE__)) :\
  1606. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->ChannelState[2] = (__CHANNEL_STATE__)) :\
  1607. ((__HANDLE__)->ChannelState[3] = (__CHANNEL_STATE__)))
  1608. #define TIM_CHANNEL_STATE_SET_ALL(__HANDLE__, __CHANNEL_STATE__) do { \
  1609. (__HANDLE__)->ChannelState[0] = (__CHANNEL_STATE__); \
  1610. (__HANDLE__)->ChannelState[1] = (__CHANNEL_STATE__); \
  1611. (__HANDLE__)->ChannelState[2] = (__CHANNEL_STATE__); \
  1612. (__HANDLE__)->ChannelState[3] = (__CHANNEL_STATE__); \
  1613. } while(0)
  1614. #define TIM_CHANNEL_N_STATE_GET(__HANDLE__, __CHANNEL__)\
  1615. (((__CHANNEL__) == TIM_CHANNEL_1) ? (__HANDLE__)->ChannelNState[0] :\
  1616. ((__CHANNEL__) == TIM_CHANNEL_2) ? (__HANDLE__)->ChannelNState[1] :\
  1617. ((__CHANNEL__) == TIM_CHANNEL_3) ? (__HANDLE__)->ChannelNState[2] :\
  1618. (__HANDLE__)->ChannelNState[3])
  1619. #define TIM_CHANNEL_N_STATE_SET(__HANDLE__, __CHANNEL__, __CHANNEL_STATE__) \
  1620. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->ChannelNState[0] = (__CHANNEL_STATE__)) :\
  1621. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->ChannelNState[1] = (__CHANNEL_STATE__)) :\
  1622. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->ChannelNState[2] = (__CHANNEL_STATE__)) :\
  1623. ((__HANDLE__)->ChannelNState[3] = (__CHANNEL_STATE__)))
  1624. #define TIM_CHANNEL_N_STATE_SET_ALL(__HANDLE__, __CHANNEL_STATE__) do { \
  1625. (__HANDLE__)->ChannelNState[0] = \
  1626. (__CHANNEL_STATE__); \
  1627. (__HANDLE__)->ChannelNState[1] = \
  1628. (__CHANNEL_STATE__); \
  1629. (__HANDLE__)->ChannelNState[2] = \
  1630. (__CHANNEL_STATE__); \
  1631. (__HANDLE__)->ChannelNState[3] = \
  1632. (__CHANNEL_STATE__); \
  1633. } while(0)
  1634. /**
  1635. * @}
  1636. */
  1637. /* End of private macros -----------------------------------------------------*/
  1638. /* Include TIM HAL Extended module */
  1639. #include "stm32f1xx_hal_tim_ex.h"
  1640. /* Exported functions --------------------------------------------------------*/
  1641. /** @addtogroup TIM_Exported_Functions TIM Exported Functions
  1642. * @{
  1643. */
  1644. /** @addtogroup TIM_Exported_Functions_Group1 TIM Time Base functions
  1645. * @brief Time Base functions
  1646. * @{
  1647. */
  1648. /* Time Base functions ********************************************************/
  1649. HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim);
  1650. HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim);
  1651. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim);
  1652. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim);
  1653. /* Blocking mode: Polling */
  1654. HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim);
  1655. HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim);
  1656. /* Non-Blocking mode: Interrupt */
  1657. HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);
  1658. HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
  1659. /* Non-Blocking mode: DMA */
  1660. HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
  1661. HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim);
  1662. /**
  1663. * @}
  1664. */
  1665. /** @addtogroup TIM_Exported_Functions_Group2 TIM Output Compare functions
  1666. * @brief TIM Output Compare functions
  1667. * @{
  1668. */
  1669. /* Timer Output Compare functions *********************************************/
  1670. HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim);
  1671. HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim);
  1672. void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim);
  1673. void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim);
  1674. /* Blocking mode: Polling */
  1675. HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1676. HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1677. /* Non-Blocking mode: Interrupt */
  1678. HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1679. HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1680. /* Non-Blocking mode: DMA */
  1681. HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1682. HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1683. /**
  1684. * @}
  1685. */
  1686. /** @addtogroup TIM_Exported_Functions_Group3 TIM PWM functions
  1687. * @brief TIM PWM functions
  1688. * @{
  1689. */
  1690. /* Timer PWM functions ********************************************************/
  1691. HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim);
  1692. HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim);
  1693. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim);
  1694. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim);
  1695. /* Blocking mode: Polling */
  1696. HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1697. HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1698. /* Non-Blocking mode: Interrupt */
  1699. HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1700. HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1701. /* Non-Blocking mode: DMA */
  1702. HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1703. HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1704. /**
  1705. * @}
  1706. */
  1707. /** @addtogroup TIM_Exported_Functions_Group4 TIM Input Capture functions
  1708. * @brief TIM Input Capture functions
  1709. * @{
  1710. */
  1711. /* Timer Input Capture functions **********************************************/
  1712. HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim);
  1713. HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim);
  1714. void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim);
  1715. void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim);
  1716. /* Blocking mode: Polling */
  1717. HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1718. HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1719. /* Non-Blocking mode: Interrupt */
  1720. HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1721. HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1722. /* Non-Blocking mode: DMA */
  1723. HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1724. HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1725. /**
  1726. * @}
  1727. */
  1728. /** @addtogroup TIM_Exported_Functions_Group5 TIM One Pulse functions
  1729. * @brief TIM One Pulse functions
  1730. * @{
  1731. */
  1732. /* Timer One Pulse functions **************************************************/
  1733. HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode);
  1734. HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim);
  1735. void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim);
  1736. void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim);
  1737. /* Blocking mode: Polling */
  1738. HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1739. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1740. /* Non-Blocking mode: Interrupt */
  1741. HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1742. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1743. /**
  1744. * @}
  1745. */
  1746. /** @addtogroup TIM_Exported_Functions_Group6 TIM Encoder functions
  1747. * @brief TIM Encoder functions
  1748. * @{
  1749. */
  1750. /* Timer Encoder functions ****************************************************/
  1751. HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef *sConfig);
  1752. HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim);
  1753. void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim);
  1754. void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim);
  1755. /* Blocking mode: Polling */
  1756. HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1757. HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1758. /* Non-Blocking mode: Interrupt */
  1759. HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1760. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1761. /* Non-Blocking mode: DMA */
  1762. HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1,
  1763. uint32_t *pData2, uint16_t Length);
  1764. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1765. /**
  1766. * @}
  1767. */
  1768. /** @addtogroup TIM_Exported_Functions_Group7 TIM IRQ handler management
  1769. * @brief IRQ handler management
  1770. * @{
  1771. */
  1772. /* Interrupt Handler functions ***********************************************/
  1773. void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim);
  1774. /**
  1775. * @}
  1776. */
  1777. /** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions
  1778. * @brief Peripheral Control functions
  1779. * @{
  1780. */
  1781. /* Control functions *********************************************************/
  1782. HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef *sConfig, uint32_t Channel);
  1783. HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef *sConfig, uint32_t Channel);
  1784. HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef *sConfig, uint32_t Channel);
  1785. HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig,
  1786. uint32_t OutputChannel, uint32_t InputChannel);
  1787. HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef *sClearInputConfig,
  1788. uint32_t Channel);
  1789. HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig);
  1790. HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection);
  1791. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig);
  1792. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig);
  1793. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  1794. uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength);
  1795. HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  1796. uint32_t BurstRequestSrc, uint32_t *BurstBuffer,
  1797. uint32_t BurstLength, uint32_t DataLength);
  1798. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1799. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  1800. uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength);
  1801. HAL_StatusTypeDef HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  1802. uint32_t BurstRequestSrc, uint32_t *BurstBuffer,
  1803. uint32_t BurstLength, uint32_t DataLength);
  1804. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1805. HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource);
  1806. uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel);
  1807. /**
  1808. * @}
  1809. */
  1810. /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
  1811. * @brief TIM Callbacks functions
  1812. * @{
  1813. */
  1814. /* Callback in non blocking modes (Interrupt and DMA) *************************/
  1815. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
  1816. void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim);
  1817. void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim);
  1818. void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim);
  1819. void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim);
  1820. void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim);
  1821. void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim);
  1822. void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim);
  1823. void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim);
  1824. void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim);
  1825. /* Callbacks Register/UnRegister functions ***********************************/
  1826. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  1827. HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID,
  1828. pTIM_CallbackTypeDef pCallback);
  1829. HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID);
  1830. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  1831. /**
  1832. * @}
  1833. */
  1834. /** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions
  1835. * @brief Peripheral State functions
  1836. * @{
  1837. */
  1838. /* Peripheral State functions ************************************************/
  1839. HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim);
  1840. HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim);
  1841. HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim);
  1842. HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim);
  1843. HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim);
  1844. HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim);
  1845. /* Peripheral Channel state functions ************************************************/
  1846. HAL_TIM_ActiveChannel HAL_TIM_GetActiveChannel(TIM_HandleTypeDef *htim);
  1847. HAL_TIM_ChannelStateTypeDef HAL_TIM_GetChannelState(TIM_HandleTypeDef *htim, uint32_t Channel);
  1848. HAL_TIM_DMABurstStateTypeDef HAL_TIM_DMABurstState(TIM_HandleTypeDef *htim);
  1849. /**
  1850. * @}
  1851. */
  1852. /**
  1853. * @}
  1854. */
  1855. /* End of exported functions -------------------------------------------------*/
  1856. /* Private functions----------------------------------------------------------*/
  1857. /** @defgroup TIM_Private_Functions TIM Private Functions
  1858. * @{
  1859. */
  1860. void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure);
  1861. void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter);
  1862. void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1863. void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler,
  1864. uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter);
  1865. void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma);
  1866. void TIM_DMAError(DMA_HandleTypeDef *hdma);
  1867. void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma);
  1868. void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma);
  1869. void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState);
  1870. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  1871. void TIM_ResetCallback(TIM_HandleTypeDef *htim);
  1872. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  1873. /**
  1874. * @}
  1875. */
  1876. /* End of private functions --------------------------------------------------*/
  1877. /**
  1878. * @}
  1879. */
  1880. /**
  1881. * @}
  1882. */
  1883. #ifdef __cplusplus
  1884. }
  1885. #endif
  1886. #endif /* STM32F1xx_HAL_TIM_H */
  1887. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/