You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1984 lines
96 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_tim.h
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 21-April-2017
  7. * @brief Header file of TIM HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32L4xx_HAL_TIM_H
  39. #define __STM32L4xx_HAL_TIM_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx_hal_def.h"
  45. /** @addtogroup STM32L4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup TIM
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup TIM_Exported_Types TIM Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief TIM Time base Configuration Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  61. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  62. uint32_t CounterMode; /*!< Specifies the counter mode.
  63. This parameter can be a value of @ref TIM_Counter_Mode */
  64. uint32_t Period; /*!< Specifies the period value to be loaded into the active
  65. Auto-Reload Register at the next update event.
  66. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
  67. uint32_t ClockDivision; /*!< Specifies the clock division.
  68. This parameter can be a value of @ref TIM_ClockDivision */
  69. uint32_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  70. reaches zero, an update event is generated and counting restarts
  71. from the RCR value (N).
  72. This means in PWM mode that (N+1) corresponds to:
  73. - the number of PWM periods in edge-aligned mode
  74. - the number of half PWM period in center-aligned mode
  75. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF.
  76. @note This parameter is valid only for TIM1 and TIM8. */
  77. } TIM_Base_InitTypeDef;
  78. /**
  79. * @brief TIM Output Compare Configuration Structure definition
  80. */
  81. typedef struct
  82. {
  83. uint32_t OCMode; /*!< Specifies the TIM mode.
  84. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  85. uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  86. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  87. uint32_t OCPolarity; /*!< Specifies the output polarity.
  88. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  89. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  90. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  91. @note This parameter is valid only for TIM1 and TIM8. */
  92. uint32_t OCFastMode; /*!< Specifies the Fast mode state.
  93. This parameter can be a value of @ref TIM_Output_Fast_State
  94. @note This parameter is valid only in PWM1 and PWM2 mode. */
  95. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  96. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  97. @note This parameter is valid only for TIM1 and TIM8. */
  98. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  99. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  100. @note This parameter is valid only for TIM1 and TIM8. */
  101. } TIM_OC_InitTypeDef;
  102. /**
  103. * @brief TIM One Pulse Mode Configuration Structure definition
  104. */
  105. typedef struct
  106. {
  107. uint32_t OCMode; /*!< Specifies the TIM mode.
  108. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  109. uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  110. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  111. uint32_t OCPolarity; /*!< Specifies the output polarity.
  112. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  113. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  114. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  115. @note This parameter is valid only for TIM1 and TIM8. */
  116. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  117. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  118. @note This parameter is valid only for TIM1 and TIM8. */
  119. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  120. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  121. @note This parameter is valid only for TIM1 and TIM8. */
  122. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  123. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  124. uint32_t ICSelection; /*!< Specifies the input.
  125. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  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_OnePulse_InitTypeDef;
  129. /**
  130. * @brief TIM Input Capture Configuration Structure definition
  131. */
  132. typedef struct
  133. {
  134. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  135. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  136. uint32_t ICSelection; /*!< Specifies the input.
  137. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  138. uint32_t ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  139. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  140. uint32_t ICFilter; /*!< Specifies the input capture filter.
  141. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  142. } TIM_IC_InitTypeDef;
  143. /**
  144. * @brief TIM Encoder Configuration Structure definition
  145. */
  146. typedef struct
  147. {
  148. uint32_t EncoderMode; /*!< Specifies the active edge of the input signal.
  149. This parameter can be a value of @ref TIM_Encoder_Mode */
  150. uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal.
  151. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  152. uint32_t IC1Selection; /*!< Specifies the input.
  153. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  154. uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler.
  155. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  156. uint32_t IC1Filter; /*!< Specifies the input capture filter.
  157. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  158. uint32_t IC2Polarity; /*!< Specifies the active edge of the input signal.
  159. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  160. uint32_t IC2Selection; /*!< Specifies the input.
  161. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  162. uint32_t IC2Prescaler; /*!< Specifies the Input Capture Prescaler.
  163. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  164. uint32_t IC2Filter; /*!< Specifies the input capture filter.
  165. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  166. } TIM_Encoder_InitTypeDef;
  167. /**
  168. * @brief Clock Configuration Handle Structure definition
  169. */
  170. typedef struct
  171. {
  172. uint32_t ClockSource; /*!< TIM clock sources
  173. This parameter can be a value of @ref TIM_Clock_Source */
  174. uint32_t ClockPolarity; /*!< TIM clock polarity
  175. This parameter can be a value of @ref TIM_Clock_Polarity */
  176. uint32_t ClockPrescaler; /*!< TIM clock prescaler
  177. This parameter can be a value of @ref TIM_Clock_Prescaler */
  178. uint32_t ClockFilter; /*!< TIM clock filter
  179. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  180. }TIM_ClockConfigTypeDef;
  181. /**
  182. * @brief Clear Input Configuration Handle Structure definition
  183. */
  184. typedef struct
  185. {
  186. uint32_t ClearInputState; /*!< TIM clear Input state
  187. This parameter can be ENABLE or DISABLE */
  188. uint32_t ClearInputSource; /*!< TIM clear Input sources
  189. This parameter can be a value of @ref TIM_ClearInput_Source */
  190. uint32_t ClearInputPolarity; /*!< TIM Clear Input polarity
  191. This parameter can be a value of @ref TIM_ClearInput_Polarity */
  192. uint32_t ClearInputPrescaler; /*!< TIM Clear Input prescaler
  193. This parameter can be a value of @ref TIM_ClearInput_Prescaler */
  194. uint32_t ClearInputFilter; /*!< TIM Clear Input filter
  195. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  196. }TIM_ClearInputConfigTypeDef;
  197. /**
  198. * @brief TIM Master configuration Structure definition
  199. * @note Advanced timers provide TRGO2 internal line which is redirected
  200. * to the ADC
  201. */
  202. typedef struct {
  203. uint32_t MasterOutputTrigger; /*!< Trigger output (TRGO) selection
  204. This parameter can be a value of @ref TIM_Master_Mode_Selection */
  205. uint32_t MasterOutputTrigger2; /*!< Trigger output2 (TRGO2) selection
  206. This parameter can be a value of @ref TIM_Master_Mode_Selection_2 */
  207. uint32_t MasterSlaveMode; /*!< Master/slave mode selection
  208. This parameter can be a value of @ref TIM_Master_Slave_Mode */
  209. }TIM_MasterConfigTypeDef;
  210. /**
  211. * @brief TIM Slave configuration Structure definition
  212. */
  213. typedef struct {
  214. uint32_t SlaveMode; /*!< Slave mode selection
  215. This parameter can be a value of @ref TIM_Slave_Mode */
  216. uint32_t InputTrigger; /*!< Input Trigger source
  217. This parameter can be a value of @ref TIM_Trigger_Selection */
  218. uint32_t TriggerPolarity; /*!< Input Trigger polarity
  219. This parameter can be a value of @ref TIM_Trigger_Polarity */
  220. uint32_t TriggerPrescaler; /*!< Input trigger prescaler
  221. This parameter can be a value of @ref TIM_Trigger_Prescaler */
  222. uint32_t TriggerFilter; /*!< Input trigger filter
  223. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  224. }TIM_SlaveConfigTypeDef;
  225. /**
  226. * @brief TIM Break input(s) and Dead time configuration Structure definition
  227. * @note 2 break inputs can be configured (BKIN and BKIN2) with configurable
  228. * filter and polarity.
  229. */
  230. typedef struct
  231. {
  232. uint32_t OffStateRunMode; /*!< TIM off state in run mode
  233. This parameter can be a value of @ref TIM_OSSR_Off_State_Selection_for_Run_mode_state */
  234. uint32_t OffStateIDLEMode; /*!< TIM off state in IDLE mode
  235. This parameter can be a value of @ref TIM_OSSI_Off_State_Selection_for_Idle_mode_state */
  236. uint32_t LockLevel; /*!< TIM Lock level
  237. This parameter can be a value of @ref TIM_Lock_level */
  238. uint32_t DeadTime; /*!< TIM dead Time
  239. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  240. uint32_t BreakState; /*!< TIM Break State
  241. This parameter can be a value of @ref TIM_Break_Input_enable_disable */
  242. uint32_t BreakPolarity; /*!< TIM Break input polarity
  243. This parameter can be a value of @ref TIM_Break_Polarity */
  244. uint32_t BreakFilter; /*!< Specifies the break input filter.
  245. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  246. uint32_t Break2State; /*!< TIM Break2 State
  247. This parameter can be a value of @ref TIM_Break2_Input_enable_disable */
  248. uint32_t Break2Polarity; /*!< TIM Break2 input polarity
  249. This parameter can be a value of @ref TIM_Break2_Polarity */
  250. uint32_t Break2Filter; /*!< TIM break2 input filter.
  251. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  252. uint32_t AutomaticOutput; /*!< TIM Automatic Output Enable state
  253. This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */
  254. } TIM_BreakDeadTimeConfigTypeDef;
  255. /**
  256. * @brief HAL State structures definition
  257. */
  258. typedef enum
  259. {
  260. HAL_TIM_STATE_RESET = 0x00, /*!< Peripheral not yet initialized or disabled */
  261. HAL_TIM_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
  262. HAL_TIM_STATE_BUSY = 0x02, /*!< An internal process is ongoing */
  263. HAL_TIM_STATE_TIMEOUT = 0x03, /*!< Timeout state */
  264. HAL_TIM_STATE_ERROR = 0x04 /*!< Reception process is ongoing */
  265. }HAL_TIM_StateTypeDef;
  266. /**
  267. * @brief HAL Active channel structures definition
  268. */
  269. typedef enum
  270. {
  271. HAL_TIM_ACTIVE_CHANNEL_1 = 0x01, /*!< The active channel is 1 */
  272. HAL_TIM_ACTIVE_CHANNEL_2 = 0x02, /*!< The active channel is 2 */
  273. HAL_TIM_ACTIVE_CHANNEL_3 = 0x04, /*!< The active channel is 3 */
  274. HAL_TIM_ACTIVE_CHANNEL_4 = 0x08, /*!< The active channel is 4 */
  275. HAL_TIM_ACTIVE_CHANNEL_5 = 0x10, /*!< The active channel is 5 */
  276. HAL_TIM_ACTIVE_CHANNEL_6 = 0x20, /*!< The active channel is 6 */
  277. HAL_TIM_ACTIVE_CHANNEL_CLEARED = 0x00 /*!< All active channels cleared */
  278. }HAL_TIM_ActiveChannel;
  279. /**
  280. * @brief TIM Time Base Handle Structure definition
  281. */
  282. typedef struct
  283. {
  284. TIM_TypeDef *Instance; /*!< Register base address */
  285. TIM_Base_InitTypeDef Init; /*!< TIM Time Base required parameters */
  286. HAL_TIM_ActiveChannel Channel; /*!< Active channel */
  287. DMA_HandleTypeDef *hdma[7]; /*!< DMA Handlers array
  288. This array is accessed by a @ref DMA_Handle_index */
  289. HAL_LockTypeDef Lock; /*!< Locking object */
  290. __IO HAL_TIM_StateTypeDef State; /*!< TIM operation state */
  291. }TIM_HandleTypeDef;
  292. /**
  293. * @}
  294. */
  295. /* End of exported types -----------------------------------------------------*/
  296. /* Exported constants --------------------------------------------------------*/
  297. /** @defgroup TIM_Exported_Constants TIM Exported Constants
  298. * @{
  299. */
  300. /** @defgroup TIM_ClearInput_Source TIM Clear Input Source
  301. * @{
  302. */
  303. #define TIM_CLEARINPUTSOURCE_ETR ((uint32_t)0x0001)
  304. #define TIM_CLEARINPUTSOURCE_OCREFCLR ((uint32_t)0x0002)
  305. #define TIM_CLEARINPUTSOURCE_NONE ((uint32_t)0x0000)
  306. /**
  307. * @}
  308. */
  309. /** @defgroup TIM_DMA_Base_address TIM DMA Base Address
  310. * @{
  311. */
  312. #define TIM_DMABASE_CR1 (0x00000000)
  313. #define TIM_DMABASE_CR2 (0x00000001)
  314. #define TIM_DMABASE_SMCR (0x00000002)
  315. #define TIM_DMABASE_DIER (0x00000003)
  316. #define TIM_DMABASE_SR (0x00000004)
  317. #define TIM_DMABASE_EGR (0x00000005)
  318. #define TIM_DMABASE_CCMR1 (0x00000006)
  319. #define TIM_DMABASE_CCMR2 (0x00000007)
  320. #define TIM_DMABASE_CCER (0x00000008)
  321. #define TIM_DMABASE_CNT (0x00000009)
  322. #define TIM_DMABASE_PSC (0x0000000A)
  323. #define TIM_DMABASE_ARR (0x0000000B)
  324. #define TIM_DMABASE_RCR (0x0000000C)
  325. #define TIM_DMABASE_CCR1 (0x0000000D)
  326. #define TIM_DMABASE_CCR2 (0x0000000E)
  327. #define TIM_DMABASE_CCR3 (0x0000000F)
  328. #define TIM_DMABASE_CCR4 (0x00000010)
  329. #define TIM_DMABASE_BDTR (0x00000011)
  330. #define TIM_DMABASE_DCR (0x00000012)
  331. #define TIM_DMABASE_DMAR (0x00000013)
  332. #define TIM_DMABASE_OR1 (0x00000014)
  333. #define TIM_DMABASE_CCMR3 (0x00000015)
  334. #define TIM_DMABASE_CCR5 (0x00000016)
  335. #define TIM_DMABASE_CCR6 (0x00000017)
  336. #define TIM_DMABASE_OR2 (0x00000018)
  337. #define TIM_DMABASE_OR3 (0x00000019)
  338. /**
  339. * @}
  340. */
  341. /** @defgroup TIM_Event_Source TIM Extended Event Source
  342. * @{
  343. */
  344. #define TIM_EVENTSOURCE_UPDATE TIM_EGR_UG /*!< Reinitialize the counter and generates an update of the registers */
  345. #define TIM_EVENTSOURCE_CC1 TIM_EGR_CC1G /*!< A capture/compare event is generated on channel 1 */
  346. #define TIM_EVENTSOURCE_CC2 TIM_EGR_CC2G /*!< A capture/compare event is generated on channel 2 */
  347. #define TIM_EVENTSOURCE_CC3 TIM_EGR_CC3G /*!< A capture/compare event is generated on channel 3 */
  348. #define TIM_EVENTSOURCE_CC4 TIM_EGR_CC4G /*!< A capture/compare event is generated on channel 4 */
  349. #define TIM_EVENTSOURCE_COM TIM_EGR_COMG /*!< A commutation event is generated */
  350. #define TIM_EVENTSOURCE_TRIGGER TIM_EGR_TG /*!< A trigger event is generated */
  351. #define TIM_EVENTSOURCE_BREAK TIM_EGR_BG /*!< A break event is generated */
  352. #define TIM_EVENTSOURCE_BREAK2 TIM_EGR_B2G /*!< A break 2 event is generated */
  353. /**
  354. * @}
  355. */
  356. /** @defgroup TIM_Input_Channel_Polarity TIM Input Channel polarity
  357. * @{
  358. */
  359. #define TIM_INPUTCHANNELPOLARITY_RISING ((uint32_t)0x00000000) /*!< Polarity for TIx source */
  360. #define TIM_INPUTCHANNELPOLARITY_FALLING (TIM_CCER_CC1P) /*!< Polarity for TIx source */
  361. #define TIM_INPUTCHANNELPOLARITY_BOTHEDGE (TIM_CCER_CC1P | TIM_CCER_CC1NP) /*!< Polarity for TIx source */
  362. /**
  363. * @}
  364. */
  365. /** @defgroup TIM_ETR_Polarity TIM ETR Polarity
  366. * @{
  367. */
  368. #define TIM_ETRPOLARITY_INVERTED (TIM_SMCR_ETP) /*!< Polarity for ETR source */
  369. #define TIM_ETRPOLARITY_NONINVERTED ((uint32_t)0x0000) /*!< Polarity for ETR source */
  370. /**
  371. * @}
  372. */
  373. /** @defgroup TIM_ETR_Prescaler TIM ETR Prescaler
  374. * @{
  375. */
  376. #define TIM_ETRPRESCALER_DIV1 ((uint32_t)0x0000) /*!< No prescaler is used */
  377. #define TIM_ETRPRESCALER_DIV2 (TIM_SMCR_ETPS_0) /*!< ETR input source is divided by 2 */
  378. #define TIM_ETRPRESCALER_DIV4 (TIM_SMCR_ETPS_1) /*!< ETR input source is divided by 4 */
  379. #define TIM_ETRPRESCALER_DIV8 (TIM_SMCR_ETPS) /*!< ETR input source is divided by 8 */
  380. /**
  381. * @}
  382. */
  383. /** @defgroup TIM_Counter_Mode TIM Counter Mode
  384. * @{
  385. */
  386. #define TIM_COUNTERMODE_UP ((uint32_t)0x0000)
  387. #define TIM_COUNTERMODE_DOWN TIM_CR1_DIR
  388. #define TIM_COUNTERMODE_CENTERALIGNED1 TIM_CR1_CMS_0
  389. #define TIM_COUNTERMODE_CENTERALIGNED2 TIM_CR1_CMS_1
  390. #define TIM_COUNTERMODE_CENTERALIGNED3 TIM_CR1_CMS
  391. /**
  392. * @}
  393. */
  394. /** @defgroup TIM_ClockDivision TIM Clock Division
  395. * @{
  396. */
  397. #define TIM_CLOCKDIVISION_DIV1 ((uint32_t)0x0000)
  398. #define TIM_CLOCKDIVISION_DIV2 (TIM_CR1_CKD_0)
  399. #define TIM_CLOCKDIVISION_DIV4 (TIM_CR1_CKD_1)
  400. /**
  401. * @}
  402. */
  403. /** @defgroup TIM_Output_Compare_State TIM Output Compare State
  404. * @{
  405. */
  406. #define TIM_OUTPUTSTATE_DISABLE ((uint32_t)0x0000)
  407. #define TIM_OUTPUTSTATE_ENABLE (TIM_CCER_CC1E)
  408. /**
  409. * @}
  410. */
  411. /** @defgroup TIM_Output_Fast_State TIM Output Fast State
  412. * @{
  413. */
  414. #define TIM_OCFAST_DISABLE ((uint32_t)0x0000)
  415. #define TIM_OCFAST_ENABLE (TIM_CCMR1_OC1FE)
  416. /**
  417. * @}
  418. */
  419. /** @defgroup TIM_Output_Compare_N_State TIM Complementary Output Compare State
  420. * @{
  421. */
  422. #define TIM_OUTPUTNSTATE_DISABLE ((uint32_t)0x0000)
  423. #define TIM_OUTPUTNSTATE_ENABLE (TIM_CCER_CC1NE)
  424. /**
  425. * @}
  426. */
  427. /** @defgroup TIM_Output_Compare_Polarity TIM Output Compare Polarity
  428. * @{
  429. */
  430. #define TIM_OCPOLARITY_HIGH ((uint32_t)0x0000)
  431. #define TIM_OCPOLARITY_LOW (TIM_CCER_CC1P)
  432. /**
  433. * @}
  434. */
  435. /** @defgroup TIM_Output_Compare_N_Polarity TIM Complementary Output Compare Polarity
  436. * @{
  437. */
  438. #define TIM_OCNPOLARITY_HIGH ((uint32_t)0x0000)
  439. #define TIM_OCNPOLARITY_LOW (TIM_CCER_CC1NP)
  440. /**
  441. * @}
  442. */
  443. /** @defgroup TIM_Output_Compare_Idle_State TIM Output Compare Idle State
  444. * @{
  445. */
  446. #define TIM_OCIDLESTATE_SET (TIM_CR2_OIS1)
  447. #define TIM_OCIDLESTATE_RESET ((uint32_t)0x0000)
  448. /**
  449. * @}
  450. */
  451. /** @defgroup TIM_Output_Compare_N_Idle_State TIM Complementary Output Compare Idle State
  452. * @{
  453. */
  454. #define TIM_OCNIDLESTATE_SET (TIM_CR2_OIS1N)
  455. #define TIM_OCNIDLESTATE_RESET ((uint32_t)0x0000)
  456. /**
  457. * @}
  458. */
  459. /** @defgroup TIM_Input_Capture_Polarity TIM Input Capture Polarity
  460. * @{
  461. */
  462. #define TIM_ICPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING
  463. #define TIM_ICPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING
  464. #define TIM_ICPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE
  465. /**
  466. * @}
  467. */
  468. /** @defgroup TIM_Input_Capture_Selection TIM Input Capture Selection
  469. * @{
  470. */
  471. #define TIM_ICSELECTION_DIRECTTI (TIM_CCMR1_CC1S_0) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  472. connected to IC1, IC2, IC3 or IC4, respectively */
  473. #define TIM_ICSELECTION_INDIRECTTI (TIM_CCMR1_CC1S_1) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  474. connected to IC2, IC1, IC4 or IC3, respectively */
  475. #define TIM_ICSELECTION_TRC (TIM_CCMR1_CC1S) /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to TRC */
  476. /**
  477. * @}
  478. */
  479. /** @defgroup TIM_Input_Capture_Prescaler TIM Input Capture Prescaler
  480. * @{
  481. */
  482. #define TIM_ICPSC_DIV1 ((uint32_t)0x0000) /*!< Capture performed each time an edge is detected on the capture input */
  483. #define TIM_ICPSC_DIV2 (TIM_CCMR1_IC1PSC_0) /*!< Capture performed once every 2 events */
  484. #define TIM_ICPSC_DIV4 (TIM_CCMR1_IC1PSC_1) /*!< Capture performed once every 4 events */
  485. #define TIM_ICPSC_DIV8 (TIM_CCMR1_IC1PSC) /*!< Capture performed once every 8 events */
  486. /**
  487. * @}
  488. */
  489. /** @defgroup TIM_One_Pulse_Mode TIM One Pulse Mode
  490. * @{
  491. */
  492. #define TIM_OPMODE_SINGLE (TIM_CR1_OPM)
  493. #define TIM_OPMODE_REPETITIVE ((uint32_t)0x0000)
  494. /**
  495. * @}
  496. */
  497. /** @defgroup TIM_Encoder_Mode TIM Encoder Mode
  498. * @{
  499. */
  500. #define TIM_ENCODERMODE_TI1 (TIM_SMCR_SMS_0)
  501. #define TIM_ENCODERMODE_TI2 (TIM_SMCR_SMS_1)
  502. #define TIM_ENCODERMODE_TI12 (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0)
  503. /**
  504. * @}
  505. */
  506. /** @defgroup TIM_Interrupt_definition TIM interrupt Definition
  507. * @{
  508. */
  509. #define TIM_IT_UPDATE (TIM_DIER_UIE)
  510. #define TIM_IT_CC1 (TIM_DIER_CC1IE)
  511. #define TIM_IT_CC2 (TIM_DIER_CC2IE)
  512. #define TIM_IT_CC3 (TIM_DIER_CC3IE)
  513. #define TIM_IT_CC4 (TIM_DIER_CC4IE)
  514. #define TIM_IT_COM (TIM_DIER_COMIE)
  515. #define TIM_IT_TRIGGER (TIM_DIER_TIE)
  516. #define TIM_IT_BREAK (TIM_DIER_BIE)
  517. /**
  518. * @}
  519. */
  520. /** @defgroup TIM_Commutation_Source TIM Commutation Source
  521. * @{
  522. */
  523. #define TIM_COMMUTATION_TRGI (TIM_CR2_CCUS)
  524. #define TIM_COMMUTATION_SOFTWARE ((uint32_t)0x0000)
  525. /**
  526. * @}
  527. */
  528. /** @defgroup TIM_DMA_sources TIM DMA Sources
  529. * @{
  530. */
  531. #define TIM_DMA_UPDATE (TIM_DIER_UDE)
  532. #define TIM_DMA_CC1 (TIM_DIER_CC1DE)
  533. #define TIM_DMA_CC2 (TIM_DIER_CC2DE)
  534. #define TIM_DMA_CC3 (TIM_DIER_CC3DE)
  535. #define TIM_DMA_CC4 (TIM_DIER_CC4DE)
  536. #define TIM_DMA_COM (TIM_DIER_COMDE)
  537. #define TIM_DMA_TRIGGER (TIM_DIER_TDE)
  538. /**
  539. * @}
  540. */
  541. /** @defgroup TIM_Flag_definition TIM Flag Definition
  542. * @{
  543. */
  544. #define TIM_FLAG_UPDATE (TIM_SR_UIF)
  545. #define TIM_FLAG_CC1 (TIM_SR_CC1IF)
  546. #define TIM_FLAG_CC2 (TIM_SR_CC2IF)
  547. #define TIM_FLAG_CC3 (TIM_SR_CC3IF)
  548. #define TIM_FLAG_CC4 (TIM_SR_CC4IF)
  549. #define TIM_FLAG_CC5 (TIM_SR_CC5IF)
  550. #define TIM_FLAG_CC6 (TIM_SR_CC6IF)
  551. #define TIM_FLAG_COM (TIM_SR_COMIF)
  552. #define TIM_FLAG_TRIGGER (TIM_SR_TIF)
  553. #define TIM_FLAG_BREAK (TIM_SR_BIF)
  554. #define TIM_FLAG_BREAK2 (TIM_SR_B2IF)
  555. #define TIM_FLAG_SYSTEM_BREAK (TIM_SR_SBIF)
  556. #define TIM_FLAG_CC1OF (TIM_SR_CC1OF)
  557. #define TIM_FLAG_CC2OF (TIM_SR_CC2OF)
  558. #define TIM_FLAG_CC3OF (TIM_SR_CC3OF)
  559. #define TIM_FLAG_CC4OF (TIM_SR_CC4OF)
  560. /**
  561. * @}
  562. */
  563. /** @defgroup TIM_Channel TIM Channel
  564. * @{
  565. */
  566. #define TIM_CHANNEL_1 ((uint32_t)0x0000)
  567. #define TIM_CHANNEL_2 ((uint32_t)0x0004)
  568. #define TIM_CHANNEL_3 ((uint32_t)0x0008)
  569. #define TIM_CHANNEL_4 ((uint32_t)0x000C)
  570. #define TIM_CHANNEL_5 ((uint32_t)0x0010)
  571. #define TIM_CHANNEL_6 ((uint32_t)0x0014)
  572. #define TIM_CHANNEL_ALL ((uint32_t)0x003C)
  573. /**
  574. * @}
  575. */
  576. /** @defgroup TIM_Clock_Source TIM Clock Source
  577. * @{
  578. */
  579. #define TIM_CLOCKSOURCE_ETRMODE2 (TIM_SMCR_ETPS_1)
  580. #define TIM_CLOCKSOURCE_INTERNAL (TIM_SMCR_ETPS_0)
  581. #define TIM_CLOCKSOURCE_ITR0 ((uint32_t)0x0000)
  582. #define TIM_CLOCKSOURCE_ITR1 (TIM_SMCR_TS_0)
  583. #define TIM_CLOCKSOURCE_ITR2 (TIM_SMCR_TS_1)
  584. #define TIM_CLOCKSOURCE_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1)
  585. #define TIM_CLOCKSOURCE_TI1ED (TIM_SMCR_TS_2)
  586. #define TIM_CLOCKSOURCE_TI1 (TIM_SMCR_TS_0 | TIM_SMCR_TS_2)
  587. #define TIM_CLOCKSOURCE_TI2 (TIM_SMCR_TS_1 | TIM_SMCR_TS_2)
  588. #define TIM_CLOCKSOURCE_ETRMODE1 (TIM_SMCR_TS)
  589. /**
  590. * @}
  591. */
  592. /** @defgroup TIM_Clock_Polarity TIM Clock Polarity
  593. * @{
  594. */
  595. #define TIM_CLOCKPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx clock sources */
  596. #define TIM_CLOCKPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx clock sources */
  597. #define TIM_CLOCKPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIx clock sources */
  598. #define TIM_CLOCKPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIx clock sources */
  599. #define TIM_CLOCKPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIx clock sources */
  600. /**
  601. * @}
  602. */
  603. /** @defgroup TIM_Clock_Prescaler TIM Clock Prescaler
  604. * @{
  605. */
  606. #define TIM_CLOCKPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  607. #define TIM_CLOCKPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Clock: Capture performed once every 2 events. */
  608. #define TIM_CLOCKPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Clock: Capture performed once every 4 events. */
  609. #define TIM_CLOCKPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Clock: Capture performed once every 8 events. */
  610. /**
  611. * @}
  612. */
  613. /** @defgroup TIM_ClearInput_Polarity TIM Clear Input Polarity
  614. * @{
  615. */
  616. #define TIM_CLEARINPUTPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx pin */
  617. #define TIM_CLEARINPUTPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx pin */
  618. /**
  619. * @}
  620. */
  621. /** @defgroup TIM_ClearInput_Prescaler TIM Clear Input Prescaler
  622. * @{
  623. */
  624. #define TIM_CLEARINPUTPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  625. #define TIM_CLEARINPUTPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR pin: Capture performed once every 2 events. */
  626. #define TIM_CLEARINPUTPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR pin: Capture performed once every 4 events. */
  627. #define TIM_CLEARINPUTPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR pin: Capture performed once every 8 events. */
  628. /**
  629. * @}
  630. */
  631. /** @defgroup TIM_OSSR_Off_State_Selection_for_Run_mode_state TIM OSSR OffState Selection for Run mode state
  632. * @{
  633. */
  634. #define TIM_OSSR_ENABLE (TIM_BDTR_OSSR)
  635. #define TIM_OSSR_DISABLE ((uint32_t)0x0000)
  636. /**
  637. * @}
  638. */
  639. /** @defgroup TIM_OSSI_Off_State_Selection_for_Idle_mode_state TIM OSSI OffState Selection for Idle mode state
  640. * @{
  641. */
  642. #define TIM_OSSI_ENABLE (TIM_BDTR_OSSI)
  643. #define TIM_OSSI_DISABLE ((uint32_t)0x0000)
  644. /**
  645. * @}
  646. */
  647. /** @defgroup TIM_Lock_level TIM Lock level
  648. * @{
  649. */
  650. #define TIM_LOCKLEVEL_OFF ((uint32_t)0x0000)
  651. #define TIM_LOCKLEVEL_1 (TIM_BDTR_LOCK_0)
  652. #define TIM_LOCKLEVEL_2 (TIM_BDTR_LOCK_1)
  653. #define TIM_LOCKLEVEL_3 (TIM_BDTR_LOCK)
  654. /**
  655. * @}
  656. */
  657. /** @defgroup TIM_Break_Input_enable_disable TIM Break Input Enable
  658. * @{
  659. */
  660. #define TIM_BREAK_ENABLE (TIM_BDTR_BKE)
  661. #define TIM_BREAK_DISABLE ((uint32_t)0x0000)
  662. /**
  663. * @}
  664. */
  665. /** @defgroup TIM_Break_Polarity TIM Break Input Polarity
  666. * @{
  667. */
  668. #define TIM_BREAKPOLARITY_LOW ((uint32_t)0x0000)
  669. #define TIM_BREAKPOLARITY_HIGH (TIM_BDTR_BKP)
  670. /**
  671. * @}
  672. */
  673. /** @defgroup TIM_Break2_Input_enable_disable TIM Break input 2 Enable
  674. * @{
  675. */
  676. #define TIM_BREAK2_DISABLE ((uint32_t)0x00000000)
  677. #define TIM_BREAK2_ENABLE ((uint32_t)TIM_BDTR_BK2E)
  678. /**
  679. * @}
  680. */
  681. /** @defgroup TIM_Break2_Polarity TIM Break Input 2 Polarity
  682. * @{
  683. */
  684. #define TIM_BREAK2POLARITY_LOW ((uint32_t)0x00000000)
  685. #define TIM_BREAK2POLARITY_HIGH ((uint32_t)TIM_BDTR_BK2P)
  686. /**
  687. * @}
  688. */
  689. /** @defgroup TIM_AOE_Bit_Set_Reset TIM Automatic Output Enable
  690. * @{
  691. */
  692. #define TIM_AUTOMATICOUTPUT_ENABLE (TIM_BDTR_AOE)
  693. #define TIM_AUTOMATICOUTPUT_DISABLE ((uint32_t)0x0000)
  694. /**
  695. * @}
  696. */
  697. /** @defgroup TIM_Group_Channel5 Group Channel 5 and Channel 1, 2 or 3
  698. * @{
  699. */
  700. #define TIM_GROUPCH5_NONE (uint32_t)0x00000000 /* !< No effect of OC5REF on OC1REFC, OC2REFC and OC3REFC */
  701. #define TIM_GROUPCH5_OC1REFC (TIM_CCR5_GC5C1) /* !< OC1REFC is the logical AND of OC1REFC and OC5REF */
  702. #define TIM_GROUPCH5_OC2REFC (TIM_CCR5_GC5C2) /* !< OC2REFC is the logical AND of OC2REFC and OC5REF */
  703. #define TIM_GROUPCH5_OC3REFC (TIM_CCR5_GC5C3) /* !< OC3REFC is the logical AND of OC3REFC and OC5REF */
  704. /**
  705. * @}
  706. */
  707. /** @defgroup TIM_Master_Mode_Selection TIM Master Mode Selection
  708. * @{
  709. */
  710. #define TIM_TRGO_RESET ((uint32_t)0x0000)
  711. #define TIM_TRGO_ENABLE (TIM_CR2_MMS_0)
  712. #define TIM_TRGO_UPDATE (TIM_CR2_MMS_1)
  713. #define TIM_TRGO_OC1 ((TIM_CR2_MMS_1 | TIM_CR2_MMS_0))
  714. #define TIM_TRGO_OC1REF (TIM_CR2_MMS_2)
  715. #define TIM_TRGO_OC2REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_0))
  716. #define TIM_TRGO_OC3REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_1))
  717. #define TIM_TRGO_OC4REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0))
  718. /**
  719. * @}
  720. */
  721. /** @defgroup TIM_Master_Mode_Selection_2 TIM Master Mode Selection 2 (TRGO2)
  722. * @{
  723. */
  724. #define TIM_TRGO2_RESET ((uint32_t)0x00000000)
  725. #define TIM_TRGO2_ENABLE ((uint32_t)(TIM_CR2_MMS2_0))
  726. #define TIM_TRGO2_UPDATE ((uint32_t)(TIM_CR2_MMS2_1))
  727. #define TIM_TRGO2_OC1 ((uint32_t)(TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0))
  728. #define TIM_TRGO2_OC1REF ((uint32_t)(TIM_CR2_MMS2_2))
  729. #define TIM_TRGO2_OC2REF ((uint32_t)(TIM_CR2_MMS2_2 | TIM_CR2_MMS2_0))
  730. #define TIM_TRGO2_OC3REF ((uint32_t)(TIM_CR2_MMS2_2 | TIM_CR2_MMS2_1))
  731. #define TIM_TRGO2_OC4REF ((uint32_t)(TIM_CR2_MMS2_2 | TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0))
  732. #define TIM_TRGO2_OC5REF ((uint32_t)(TIM_CR2_MMS2_3))
  733. #define TIM_TRGO2_OC6REF ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_0))
  734. #define TIM_TRGO2_OC4REF_RISINGFALLING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_1))
  735. #define TIM_TRGO2_OC6REF_RISINGFALLING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0))
  736. #define TIM_TRGO2_OC4REF_RISING_OC6REF_RISING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_2))
  737. #define TIM_TRGO2_OC4REF_RISING_OC6REF_FALLING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_2 | TIM_CR2_MMS2_0))
  738. #define TIM_TRGO2_OC5REF_RISING_OC6REF_RISING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_2 |TIM_CR2_MMS2_1))
  739. #define TIM_TRGO2_OC5REF_RISING_OC6REF_FALLING ((uint32_t)(TIM_CR2_MMS2_3 | TIM_CR2_MMS2_2 | TIM_CR2_MMS2_1 | TIM_CR2_MMS2_0))
  740. /**
  741. * @}
  742. */
  743. /** @defgroup TIM_Master_Slave_Mode TIM Master/Slave Mode
  744. * @{
  745. */
  746. #define TIM_MASTERSLAVEMODE_ENABLE ((uint32_t)0x0080)
  747. #define TIM_MASTERSLAVEMODE_DISABLE ((uint32_t)0x0000)
  748. /**
  749. * @}
  750. */
  751. /** @defgroup TIM_Slave_Mode TIM Slave mode
  752. * @{
  753. */
  754. #define TIM_SLAVEMODE_DISABLE ((uint32_t)0x0000)
  755. #define TIM_SLAVEMODE_RESET ((uint32_t)(TIM_SMCR_SMS_2))
  756. #define TIM_SLAVEMODE_GATED ((uint32_t)(TIM_SMCR_SMS_2 | TIM_SMCR_SMS_0))
  757. #define TIM_SLAVEMODE_TRIGGER ((uint32_t)(TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1))
  758. #define TIM_SLAVEMODE_EXTERNAL1 ((uint32_t)(TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0))
  759. #define TIM_SLAVEMODE_COMBINED_RESETTRIGGER ((uint32_t)(TIM_SMCR_SMS_3))
  760. /**
  761. * @}
  762. */
  763. /** @defgroup TIM_Output_Compare_and_PWM_modes TIM Output Compare and PWM Modes
  764. * @{
  765. */
  766. #define TIM_OCMODE_TIMING ((uint32_t)0x0000)
  767. #define TIM_OCMODE_ACTIVE ((uint32_t)TIM_CCMR1_OC1M_0)
  768. #define TIM_OCMODE_INACTIVE ((uint32_t)TIM_CCMR1_OC1M_1)
  769. #define TIM_OCMODE_TOGGLE ((uint32_t)TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0)
  770. #define TIM_OCMODE_PWM1 ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1)
  771. #define TIM_OCMODE_PWM2 ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0)
  772. #define TIM_OCMODE_FORCED_ACTIVE ((uint32_t)TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0)
  773. #define TIM_OCMODE_FORCED_INACTIVE ((uint32_t)TIM_CCMR1_OC1M_2)
  774. #define TIM_OCMODE_RETRIGERRABLE_OPM1 ((uint32_t)TIM_CCMR1_OC1M_3)
  775. #define TIM_OCMODE_RETRIGERRABLE_OPM2 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M_0)
  776. #define TIM_OCMODE_COMBINED_PWM1 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M_2)
  777. #define TIM_OCMODE_COMBINED_PWM2 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_2)
  778. #define TIM_OCMODE_ASSYMETRIC_PWM1 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2)
  779. #define TIM_OCMODE_ASSYMETRIC_PWM2 ((uint32_t)TIM_CCMR1_OC1M_3 | TIM_CCMR1_OC1M)
  780. /**
  781. * @}
  782. */
  783. /** @defgroup TIM_Trigger_Selection TIM Trigger Selection
  784. * @{
  785. */
  786. #define TIM_TS_ITR0 ((uint32_t)0x0000)
  787. #define TIM_TS_ITR1 ((uint32_t)0x0010)
  788. #define TIM_TS_ITR2 ((uint32_t)0x0020)
  789. #define TIM_TS_ITR3 ((uint32_t)0x0030)
  790. #define TIM_TS_TI1F_ED ((uint32_t)0x0040)
  791. #define TIM_TS_TI1FP1 ((uint32_t)0x0050)
  792. #define TIM_TS_TI2FP2 ((uint32_t)0x0060)
  793. #define TIM_TS_ETRF ((uint32_t)0x0070)
  794. #define TIM_TS_NONE ((uint32_t)0xFFFF)
  795. /**
  796. * @}
  797. */
  798. /** @defgroup TIM_Trigger_Polarity TIM Trigger Polarity
  799. * @{
  800. */
  801. #define TIM_TRIGGERPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx trigger sources */
  802. #define TIM_TRIGGERPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx trigger sources */
  803. #define TIM_TRIGGERPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  804. #define TIM_TRIGGERPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  805. #define TIM_TRIGGERPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  806. /**
  807. * @}
  808. */
  809. /** @defgroup TIM_Trigger_Prescaler TIM Trigger Prescaler
  810. * @{
  811. */
  812. #define TIM_TRIGGERPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  813. #define TIM_TRIGGERPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Trigger: Capture performed once every 2 events. */
  814. #define TIM_TRIGGERPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Trigger: Capture performed once every 4 events. */
  815. #define TIM_TRIGGERPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Trigger: Capture performed once every 8 events. */
  816. /**
  817. * @}
  818. */
  819. /** @defgroup TIM_TI1_Selection TIM TI1 Input Selection
  820. * @{
  821. */
  822. #define TIM_TI1SELECTION_CH1 ((uint32_t)0x0000)
  823. #define TIM_TI1SELECTION_XORCOMBINATION (TIM_CR2_TI1S)
  824. /**
  825. * @}
  826. */
  827. /** @defgroup TIM_DMA_Burst_Length TIM DMA Burst Length
  828. * @{
  829. */
  830. #define TIM_DMABURSTLENGTH_1TRANSFER (0x00000000)
  831. #define TIM_DMABURSTLENGTH_2TRANSFERS (0x00000100)
  832. #define TIM_DMABURSTLENGTH_3TRANSFERS (0x00000200)
  833. #define TIM_DMABURSTLENGTH_4TRANSFERS (0x00000300)
  834. #define TIM_DMABURSTLENGTH_5TRANSFERS (0x00000400)
  835. #define TIM_DMABURSTLENGTH_6TRANSFERS (0x00000500)
  836. #define TIM_DMABURSTLENGTH_7TRANSFERS (0x00000600)
  837. #define TIM_DMABURSTLENGTH_8TRANSFERS (0x00000700)
  838. #define TIM_DMABURSTLENGTH_9TRANSFERS (0x00000800)
  839. #define TIM_DMABURSTLENGTH_10TRANSFERS (0x00000900)
  840. #define TIM_DMABURSTLENGTH_11TRANSFERS (0x00000A00)
  841. #define TIM_DMABURSTLENGTH_12TRANSFERS (0x00000B00)
  842. #define TIM_DMABURSTLENGTH_13TRANSFERS (0x00000C00)
  843. #define TIM_DMABURSTLENGTH_14TRANSFERS (0x00000D00)
  844. #define TIM_DMABURSTLENGTH_15TRANSFERS (0x00000E00)
  845. #define TIM_DMABURSTLENGTH_16TRANSFERS (0x00000F00)
  846. #define TIM_DMABURSTLENGTH_17TRANSFERS (0x00001000)
  847. #define TIM_DMABURSTLENGTH_18TRANSFERS (0x00001100)
  848. /**
  849. * @}
  850. */
  851. /** @defgroup DMA_Handle_index TIM DMA Handle Index
  852. * @{
  853. */
  854. #define TIM_DMA_ID_UPDATE ((uint16_t) 0x0) /*!< Index of the DMA handle used for Update DMA requests */
  855. #define TIM_DMA_ID_CC1 ((uint16_t) 0x1) /*!< Index of the DMA handle used for Capture/Compare 1 DMA requests */
  856. #define TIM_DMA_ID_CC2 ((uint16_t) 0x2) /*!< Index of the DMA handle used for Capture/Compare 2 DMA requests */
  857. #define TIM_DMA_ID_CC3 ((uint16_t) 0x3) /*!< Index of the DMA handle used for Capture/Compare 3 DMA requests */
  858. #define TIM_DMA_ID_CC4 ((uint16_t) 0x4) /*!< Index of the DMA handle used for Capture/Compare 4 DMA requests */
  859. #define TIM_DMA_ID_COMMUTATION ((uint16_t) 0x5) /*!< Index of the DMA handle used for Commutation DMA requests */
  860. #define TIM_DMA_ID_TRIGGER ((uint16_t) 0x6) /*!< Index of the DMA handle used for Trigger DMA requests */
  861. /**
  862. * @}
  863. */
  864. /** @defgroup Channel_CC_State TIM Capture/Compare Channel State
  865. * @{
  866. */
  867. #define TIM_CCx_ENABLE ((uint32_t)0x0001)
  868. #define TIM_CCx_DISABLE ((uint32_t)0x0000)
  869. #define TIM_CCxN_ENABLE ((uint32_t)0x0004)
  870. #define TIM_CCxN_DISABLE ((uint32_t)0x0000)
  871. /**
  872. * @}
  873. */
  874. /** @defgroup TIM_Break_System TIM Break System
  875. * @{
  876. */
  877. #define TIM_BREAK_SYSTEM_ECC SYSCFG_CFGR2_ECCL /*!< Enables and locks the ECC error signal with Break Input of TIM1/8/15/16/17 */
  878. #define TIM_BREAK_SYSTEM_PVD SYSCFG_CFGR2_PVDL /*!< Enables and locks the PVD connection with TIM1/8/15/16/17 Break Input and also the PVDE and PLS bits of the Power Control Interface */
  879. #define TIM_BREAK_SYSTEM_SRAM2_PARITY_ERROR SYSCFG_CFGR2_SPL /*!< Enables and locks the SRAM2_PARITY error signal with Break Input of TIM1/8/15/16/17 */
  880. #define TIM_BREAK_SYSTEM_LOCKUP SYSCFG_CFGR2_CLL /*!< Enables and locks the LOCKUP output of CortexM4 with Break Input of TIM1/15/16/17 */
  881. /**
  882. * @}
  883. */
  884. /**
  885. * @}
  886. */
  887. /* End of exported constants -------------------------------------------------*/
  888. /* Exported macros -----------------------------------------------------------*/
  889. /** @defgroup TIM_Exported_Macros TIM Exported Macros
  890. * @{
  891. */
  892. /** @brief Reset TIM handle state.
  893. * @param __HANDLE__: TIM handle.
  894. * @retval None
  895. */
  896. #define __HAL_TIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_TIM_STATE_RESET)
  897. /**
  898. * @brief Enable the TIM peripheral.
  899. * @param __HANDLE__: TIM handle
  900. * @retval None
  901. */
  902. #define __HAL_TIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(TIM_CR1_CEN))
  903. /**
  904. * @brief Enable the TIM main Output.
  905. * @param __HANDLE__: TIM handle
  906. * @retval None
  907. */
  908. #define __HAL_TIM_MOE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->BDTR|=(TIM_BDTR_MOE))
  909. /**
  910. * @brief Disable the TIM peripheral.
  911. * @param __HANDLE__: TIM handle
  912. * @retval None
  913. */
  914. #define __HAL_TIM_DISABLE(__HANDLE__) \
  915. do { \
  916. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0) \
  917. { \
  918. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0) \
  919. { \
  920. (__HANDLE__)->Instance->CR1 &= ~(TIM_CR1_CEN); \
  921. } \
  922. } \
  923. } while(0)
  924. /**
  925. * @brief Disable the TIM main Output.
  926. * @param __HANDLE__: TIM handle
  927. * @retval None
  928. * @note The Main Output Enable of a timer instance is disabled only if all the CCx and CCxN channels have been disabled
  929. */
  930. #define __HAL_TIM_MOE_DISABLE(__HANDLE__) \
  931. do { \
  932. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0) \
  933. { \
  934. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0) \
  935. { \
  936. (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE); \
  937. } \
  938. } \
  939. } while(0)
  940. /**
  941. * @brief Disable the TIM main Output.
  942. * @param __HANDLE__: TIM handle
  943. * @retval None
  944. * @note The Main Output Enable of a timer instance is disabled unconditionally
  945. */
  946. #define __HAL_TIM_MOE_DISABLE_UNCONDITIONALLY(__HANDLE__) (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE)
  947. /** @brief Enable the specified TIM interrupt.
  948. * @param __HANDLE__: specifies the TIM Handle.
  949. * @param __INTERRUPT__: specifies the TIM interrupt source to enable.
  950. * This parameter can be one of the following values:
  951. * @arg TIM_IT_UPDATE: Update interrupt
  952. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  953. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  954. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  955. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  956. * @arg TIM_IT_COM: Commutation interrupt
  957. * @arg TIM_IT_TRIGGER: Trigger interrupt
  958. * @arg TIM_IT_BREAK: Break interrupt
  959. * @retval None
  960. */
  961. #define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER |= (__INTERRUPT__))
  962. /** @brief Disable the specified TIM interrupt.
  963. * @param __HANDLE__: specifies the TIM Handle.
  964. * @param __INTERRUPT__: specifies the TIM interrupt source to disable.
  965. * This parameter can be one of the following values:
  966. * @arg TIM_IT_UPDATE: Update interrupt
  967. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  968. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  969. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  970. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  971. * @arg TIM_IT_COM: Commutation interrupt
  972. * @arg TIM_IT_TRIGGER: Trigger interrupt
  973. * @arg TIM_IT_BREAK: Break interrupt
  974. * @retval None
  975. */
  976. #define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER &= ~(__INTERRUPT__))
  977. /** @brief Enable the specified DMA request.
  978. * @param __HANDLE__: specifies the TIM Handle.
  979. * @param __DMA__: specifies the TIM DMA request to enable.
  980. * This parameter can be one of the following values:
  981. * @arg TIM_DMA_UPDATE: Update DMA request
  982. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  983. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  984. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  985. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  986. * @arg TIM_DMA_COM: Commutation DMA request
  987. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  988. * @arg TIM_DMA_BREAK: Break DMA request
  989. * @retval None
  990. */
  991. #define __HAL_TIM_ENABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER |= (__DMA__))
  992. /** @brief Disable the specified DMA request.
  993. * @param __HANDLE__: specifies the TIM Handle.
  994. * @param __DMA__: specifies the TIM DMA request to disable.
  995. * This parameter can be one of the following values:
  996. * @arg TIM_DMA_UPDATE: Update DMA request
  997. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  998. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  999. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  1000. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  1001. * @arg TIM_DMA_COM: Commutation DMA request
  1002. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  1003. * @arg TIM_DMA_BREAK: Break DMA request
  1004. * @retval None
  1005. */
  1006. #define __HAL_TIM_DISABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER &= ~(__DMA__))
  1007. /** @brief Check whether the specified TIM interrupt flag is set or not.
  1008. * @param __HANDLE__: specifies the TIM Handle.
  1009. * @param __FLAG__: specifies the TIM interrupt flag to check.
  1010. * This parameter can be one of the following values:
  1011. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1012. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1013. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1014. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1015. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1016. * @arg TIM_FLAG_CC5: Compare 5 interrupt flag
  1017. * @arg TIM_FLAG_CC6: Compare 5 interrupt flag
  1018. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1019. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1020. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1021. * @arg TIM_FLAG_BREAK2: Break 2 interrupt flag
  1022. * @arg TIM_FLAG_SYSTEM_BREAK: System Break interrupt flag
  1023. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1024. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1025. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1026. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1027. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1028. */
  1029. #define __HAL_TIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR &(__FLAG__)) == (__FLAG__))
  1030. /** @brief Clear the specified TIM interrupt flag.
  1031. * @param __HANDLE__: specifies the TIM Handle.
  1032. * @param __FLAG__: specifies the TIM interrupt flag to clear.
  1033. * This parameter can be one of the following values:
  1034. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1035. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1036. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1037. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1038. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1039. * @arg TIM_FLAG_CC5: Compare 5 interrupt flag
  1040. * @arg TIM_FLAG_CC6: Compare 5 interrupt flag
  1041. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1042. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1043. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1044. * @arg TIM_FLAG_BREAK2: Break 2 interrupt flag
  1045. * @arg TIM_FLAG_SYSTEM_BREAK: System Break interrupt flag
  1046. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1047. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1048. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1049. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1050. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1051. */
  1052. #define __HAL_TIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  1053. /**
  1054. * @brief Check whether the specified TIM interrupt source is enabled or not.
  1055. * @param __HANDLE__: TIM handle
  1056. * @param __INTERRUPT__: specifies the TIM interrupt source to check.
  1057. * This parameter can be one of the following values:
  1058. * @arg TIM_IT_UPDATE: Update interrupt
  1059. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1060. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1061. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1062. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1063. * @arg TIM_IT_COM: Commutation interrupt
  1064. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1065. * @arg TIM_IT_BREAK: Break interrupt
  1066. * @retval The state of TIM_IT (SET or RESET).
  1067. */
  1068. #define __HAL_TIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->DIER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  1069. /** @brief Clear the TIM interrupt pending bits.
  1070. * @param __HANDLE__: TIM handle
  1071. * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
  1072. * This parameter can be one of the following values:
  1073. * @arg TIM_IT_UPDATE: Update interrupt
  1074. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1075. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1076. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1077. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1078. * @arg TIM_IT_COM: Commutation interrupt
  1079. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1080. * @arg TIM_IT_BREAK: Break interrupt
  1081. * @retval None
  1082. */
  1083. #define __HAL_TIM_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->SR = ~(__INTERRUPT__))
  1084. /**
  1085. * @brief Indicates whether or not the TIM Counter is used as downcounter.
  1086. * @param __HANDLE__: TIM handle.
  1087. * @retval False (Counter used as upcounter) or True (Counter used as downcounter)
  1088. * @note This macro is particularly useful to get the counting mode when the timer operates in Center-aligned mode or Encoder
  1089. mode.
  1090. */
  1091. #define __HAL_TIM_IS_TIM_COUNTING_DOWN(__HANDLE__) (((__HANDLE__)->Instance->CR1 &(TIM_CR1_DIR)) == (TIM_CR1_DIR))
  1092. /**
  1093. * @brief Set the TIM Prescaler on runtime.
  1094. * @param __HANDLE__: TIM handle.
  1095. * @param __PRESC__: specifies the Prescaler new value.
  1096. * @retval None
  1097. */
  1098. #define __HAL_TIM_SET_PRESCALER(__HANDLE__, __PRESC__) ((__HANDLE__)->Instance->PSC = (__PRESC__))
  1099. /**
  1100. * @brief Set the TIM Counter Register value on runtime.
  1101. * @param __HANDLE__: TIM handle.
  1102. * @param __COUNTER__: specifies the Counter register new value.
  1103. * @retval None
  1104. */
  1105. #define __HAL_TIM_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->CNT = (__COUNTER__))
  1106. /**
  1107. * @brief Get the TIM Counter Register value on runtime.
  1108. * @param __HANDLE__: TIM handle.
  1109. * @retval None
  1110. */
  1111. #define __HAL_TIM_GET_COUNTER(__HANDLE__) \
  1112. ((__HANDLE__)->Instance->CNT)
  1113. /**
  1114. * @brief Set the TIM Autoreload Register value on runtime without calling another time any Init function.
  1115. * @param __HANDLE__: TIM handle.
  1116. * @param __AUTORELOAD__: specifies the Counter register new value.
  1117. * @retval None
  1118. */
  1119. #define __HAL_TIM_SET_AUTORELOAD(__HANDLE__, __AUTORELOAD__) \
  1120. do{ \
  1121. (__HANDLE__)->Instance->ARR = (__AUTORELOAD__); \
  1122. (__HANDLE__)->Init.Period = (__AUTORELOAD__); \
  1123. } while(0)
  1124. /**
  1125. * @brief Get the TIM Autoreload Register value on runtime.
  1126. * @param __HANDLE__: TIM handle.
  1127. * @retval None
  1128. */
  1129. #define __HAL_TIM_GET_AUTORELOAD(__HANDLE__) \
  1130. ((__HANDLE__)->Instance->ARR)
  1131. /**
  1132. * @brief Set the TIM Clock Division value on runtime without calling another time any Init function.
  1133. * @param __HANDLE__: TIM handle.
  1134. * @param __CKD__: specifies the clock division value.
  1135. * This parameter can be one of the following value:
  1136. * @arg TIM_CLOCKDIVISION_DIV1
  1137. * @arg TIM_CLOCKDIVISION_DIV2
  1138. * @arg TIM_CLOCKDIVISION_DIV4
  1139. * @retval None
  1140. */
  1141. #define __HAL_TIM_SET_CLOCKDIVISION(__HANDLE__, __CKD__) \
  1142. do{ \
  1143. (__HANDLE__)->Instance->CR1 &= (uint16_t)(~TIM_CR1_CKD); \
  1144. (__HANDLE__)->Instance->CR1 |= (__CKD__); \
  1145. (__HANDLE__)->Init.ClockDivision = (__CKD__); \
  1146. } while(0)
  1147. /**
  1148. * @brief Get the TIM Clock Division value on runtime.
  1149. * @param __HANDLE__: TIM handle.
  1150. * @retval None
  1151. */
  1152. #define __HAL_TIM_GET_CLOCKDIVISION(__HANDLE__) \
  1153. ((__HANDLE__)->Instance->CR1 & TIM_CR1_CKD)
  1154. /**
  1155. * @brief Set the TIM Input Capture prescaler on runtime without calling another time HAL_TIM_IC_ConfigChannel() function.
  1156. * @param __HANDLE__: TIM handle.
  1157. * @param __CHANNEL__: TIM Channels to be configured.
  1158. * This parameter can be one of the following values:
  1159. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1160. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1161. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1162. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1163. * @param __ICPSC__: specifies the Input Capture4 prescaler new value.
  1164. * This parameter can be one of the following values:
  1165. * @arg TIM_ICPSC_DIV1: no prescaler
  1166. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  1167. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  1168. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  1169. * @retval None
  1170. */
  1171. #define __HAL_TIM_SET_ICPRESCALER(__HANDLE__, __CHANNEL__, __ICPSC__) \
  1172. do{ \
  1173. TIM_RESET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__)); \
  1174. TIM_SET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__), (__ICPSC__)); \
  1175. } while(0)
  1176. /**
  1177. * @brief Get the TIM Input Capture prescaler on runtime.
  1178. * @param __HANDLE__: TIM handle.
  1179. * @param __CHANNEL__: TIM Channels to be configured.
  1180. * This parameter can be one of the following values:
  1181. * @arg TIM_CHANNEL_1: get input capture 1 prescaler value
  1182. * @arg TIM_CHANNEL_2: get input capture 2 prescaler value
  1183. * @arg TIM_CHANNEL_3: get input capture 3 prescaler value
  1184. * @arg TIM_CHANNEL_4: get input capture 4 prescaler value
  1185. * @retval None
  1186. */
  1187. #define __HAL_TIM_GET_ICPRESCALER(__HANDLE__, __CHANNEL__) \
  1188. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC1PSC) :\
  1189. ((__CHANNEL__) == TIM_CHANNEL_2) ? (((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC2PSC) >> 8) :\
  1190. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC3PSC) :\
  1191. (((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC4PSC)) >> 8)
  1192. /**
  1193. * @brief Set the TIM Capture Compare Register value on runtime without calling another time ConfigChannel function.
  1194. * @param __HANDLE__: TIM handle.
  1195. * @param __CHANNEL__: TIM Channels to be configured.
  1196. * This parameter can be one of the following values:
  1197. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1198. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1199. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1200. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1201. * @arg TIM_CHANNEL_5: TIM Channel 5 selected
  1202. * @arg TIM_CHANNEL_6: TIM Channel 6 selected
  1203. * @param __COMPARE__: specifies the Capture Compare register new value.
  1204. * @retval None
  1205. */
  1206. #define __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) \
  1207. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCR1 = (__COMPARE__)) :\
  1208. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCR2 = (__COMPARE__)) :\
  1209. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCR3 = (__COMPARE__)) :\
  1210. ((__CHANNEL__) == TIM_CHANNEL_4) ? ((__HANDLE__)->Instance->CCR4 = (__COMPARE__)) :\
  1211. ((__CHANNEL__) == TIM_CHANNEL_5) ? ((__HANDLE__)->Instance->CCR5 = (__COMPARE__)) :\
  1212. ((__HANDLE__)->Instance->CCR6 = (__COMPARE__)))
  1213. /**
  1214. * @brief Get the TIM Capture Compare Register value on runtime.
  1215. * @param __HANDLE__: TIM handle.
  1216. * @param __CHANNEL__: TIM Channel associated with the capture compare register
  1217. * This parameter can be one of the following values:
  1218. * @arg TIM_CHANNEL_1: get capture/compare 1 register value
  1219. * @arg TIM_CHANNEL_2: get capture/compare 2 register value
  1220. * @arg TIM_CHANNEL_3: get capture/compare 3 register value
  1221. * @arg TIM_CHANNEL_4: get capture/compare 4 register value
  1222. * @arg TIM_CHANNEL_5: get capture/compare 5 register value
  1223. * @arg TIM_CHANNEL_6: get capture/compare 6 register value
  1224. * @retval None
  1225. */
  1226. #define __HAL_TIM_GET_COMPARE(__HANDLE__, __CHANNEL__) \
  1227. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCR1) :\
  1228. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCR2) :\
  1229. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCR3) :\
  1230. ((__CHANNEL__) == TIM_CHANNEL_4) ? ((__HANDLE__)->Instance->CCR4) :\
  1231. ((__CHANNEL__) == TIM_CHANNEL_5) ? ((__HANDLE__)->Instance->CCR5) :\
  1232. ((__HANDLE__)->Instance->CCR6))
  1233. /**
  1234. * @brief Set the Update Request Source (URS) bit of the TIMx_CR1 register.
  1235. * @param __HANDLE__: TIM handle.
  1236. * @note When the USR bit of the TIMx_CR1 register is set, only counter
  1237. * overflow/underflow generates an update interrupt or DMA request (if
  1238. * enabled)
  1239. * @retval None
  1240. */
  1241. #define __HAL_TIM_URS_ENABLE(__HANDLE__) \
  1242. ((__HANDLE__)->Instance->CR1|= (TIM_CR1_URS))
  1243. /**
  1244. * @brief Reset the Update Request Source (URS) bit of the TIMx_CR1 register.
  1245. * @param __HANDLE__: TIM handle.
  1246. * @note When the USR bit of the TIMx_CR1 register is reset, any of the
  1247. * following events generate an update interrupt or DMA request (if
  1248. * enabled):
  1249. * _ Counter overflow underflow
  1250. * _ Setting the UG bit
  1251. * _ Update generation through the slave mode controller
  1252. * @retval None
  1253. */
  1254. #define __HAL_TIM_URS_DISABLE(__HANDLE__) \
  1255. ((__HANDLE__)->Instance->CR1&=~(TIM_CR1_URS))
  1256. /**
  1257. * @brief Set the TIM Capture x input polarity on runtime.
  1258. * @param __HANDLE__: TIM handle.
  1259. * @param __CHANNEL__: TIM Channels to be configured.
  1260. * This parameter can be one of the following values:
  1261. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1262. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1263. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1264. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1265. * @param __POLARITY__: Polarity for TIx source
  1266. * @arg TIM_INPUTCHANNELPOLARITY_RISING: Rising Edge
  1267. * @arg TIM_INPUTCHANNELPOLARITY_FALLING: Falling Edge
  1268. * @arg TIM_INPUTCHANNELPOLARITY_BOTHEDGE: Rising and Falling Edge
  1269. * @retval None
  1270. */
  1271. #define __HAL_TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  1272. do{ \
  1273. TIM_RESET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__)); \
  1274. TIM_SET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__), (__POLARITY__)); \
  1275. }while(0)
  1276. /**
  1277. * @}
  1278. */
  1279. /* End of exported macros ----------------------------------------------------*/
  1280. /* Private constants ---------------------------------------------------------*/
  1281. /** @defgroup TIM_Private_Constants TIM Private Constants
  1282. * @{
  1283. */
  1284. /* The counter of a timer instance is disabled only if all the CCx and CCxN
  1285. channels have been disabled */
  1286. #define TIM_CCER_CCxE_MASK ((uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E))
  1287. #define TIM_CCER_CCxNE_MASK ((uint32_t)(TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE))
  1288. /**
  1289. * @}
  1290. */
  1291. /* End of private constants --------------------------------------------------*/
  1292. /* Private macros ------------------------------------------------------------*/
  1293. /** @defgroup TIM_Private_Macros TIM Private Macros
  1294. * @{
  1295. */
  1296. #define IS_TIM_CLEARINPUT_SOURCE(__MODE__) (((__MODE__) == TIM_CLEARINPUTSOURCE_ETR) || \
  1297. ((__MODE__) == TIM_CLEARINPUTSOURCE_OCREFCLR) || \
  1298. ((__MODE__) == TIM_CLEARINPUTSOURCE_NONE))
  1299. #define IS_TIM_DMA_BASE(__BASE__) (((__BASE__) == TIM_DMABASE_CR1) || \
  1300. ((__BASE__) == TIM_DMABASE_CR2) || \
  1301. ((__BASE__) == TIM_DMABASE_SMCR) || \
  1302. ((__BASE__) == TIM_DMABASE_DIER) || \
  1303. ((__BASE__) == TIM_DMABASE_SR) || \
  1304. ((__BASE__) == TIM_DMABASE_EGR) || \
  1305. ((__BASE__) == TIM_DMABASE_CCMR1) || \
  1306. ((__BASE__) == TIM_DMABASE_CCMR2) || \
  1307. ((__BASE__) == TIM_DMABASE_CCER) || \
  1308. ((__BASE__) == TIM_DMABASE_CNT) || \
  1309. ((__BASE__) == TIM_DMABASE_PSC) || \
  1310. ((__BASE__) == TIM_DMABASE_ARR) || \
  1311. ((__BASE__) == TIM_DMABASE_RCR) || \
  1312. ((__BASE__) == TIM_DMABASE_CCR1) || \
  1313. ((__BASE__) == TIM_DMABASE_CCR2) || \
  1314. ((__BASE__) == TIM_DMABASE_CCR3) || \
  1315. ((__BASE__) == TIM_DMABASE_CCR4) || \
  1316. ((__BASE__) == TIM_DMABASE_BDTR) || \
  1317. ((__BASE__) == TIM_DMABASE_CCMR3) || \
  1318. ((__BASE__) == TIM_DMABASE_CCR5) || \
  1319. ((__BASE__) == TIM_DMABASE_CCR6) || \
  1320. ((__BASE__) == TIM_DMABASE_OR1) || \
  1321. ((__BASE__) == TIM_DMABASE_OR2) || \
  1322. ((__BASE__) == TIM_DMABASE_OR3))
  1323. #define IS_TIM_EVENT_SOURCE(__SOURCE__) ((((__SOURCE__) & 0xFFFFFE00) == 0x00000000) && ((__SOURCE__) != 0x00000000))
  1324. #define IS_TIM_COUNTER_MODE(__MODE__) (((__MODE__) == TIM_COUNTERMODE_UP) || \
  1325. ((__MODE__) == TIM_COUNTERMODE_DOWN) || \
  1326. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED1) || \
  1327. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED2) || \
  1328. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED3))
  1329. #define IS_TIM_CLOCKDIVISION_DIV(__DIV__) (((__DIV__) == TIM_CLOCKDIVISION_DIV1) || \
  1330. ((__DIV__) == TIM_CLOCKDIVISION_DIV2) || \
  1331. ((__DIV__) == TIM_CLOCKDIVISION_DIV4))
  1332. #define IS_TIM_FAST_STATE(__STATE__) (((__STATE__) == TIM_OCFAST_DISABLE) || \
  1333. ((__STATE__) == TIM_OCFAST_ENABLE))
  1334. #define IS_TIM_OC_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_OCPOLARITY_HIGH) || \
  1335. ((__POLARITY__) == TIM_OCPOLARITY_LOW))
  1336. #define IS_TIM_OCN_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_OCNPOLARITY_HIGH) || \
  1337. ((__POLARITY__) == TIM_OCNPOLARITY_LOW))
  1338. #define IS_TIM_OCIDLE_STATE(__STATE__) (((__STATE__) == TIM_OCIDLESTATE_SET) || \
  1339. ((__STATE__) == TIM_OCIDLESTATE_RESET))
  1340. #define IS_TIM_OCNIDLE_STATE(__STATE__) (((__STATE__) == TIM_OCNIDLESTATE_SET) || \
  1341. ((__STATE__) == TIM_OCNIDLESTATE_RESET))
  1342. #define IS_TIM_IC_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_ICPOLARITY_RISING) || \
  1343. ((__POLARITY__) == TIM_ICPOLARITY_FALLING) || \
  1344. ((__POLARITY__) == TIM_ICPOLARITY_BOTHEDGE))
  1345. #define IS_TIM_IC_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_ICSELECTION_DIRECTTI) || \
  1346. ((__SELECTION__) == TIM_ICSELECTION_INDIRECTTI) || \
  1347. ((__SELECTION__) == TIM_ICSELECTION_TRC))
  1348. #define IS_TIM_IC_PRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_ICPSC_DIV1) || \
  1349. ((__PRESCALER__) == TIM_ICPSC_DIV2) || \
  1350. ((__PRESCALER__) == TIM_ICPSC_DIV4) || \
  1351. ((__PRESCALER__) == TIM_ICPSC_DIV8))
  1352. #define IS_TIM_OPM_MODE(__MODE__) (((__MODE__) == TIM_OPMODE_SINGLE) || \
  1353. ((__MODE__) == TIM_OPMODE_REPETITIVE))
  1354. #define IS_TIM_ENCODER_MODE(__MODE__) (((__MODE__) == TIM_ENCODERMODE_TI1) || \
  1355. ((__MODE__) == TIM_ENCODERMODE_TI2) || \
  1356. ((__MODE__) == TIM_ENCODERMODE_TI12))
  1357. #define IS_TIM_DMA_SOURCE(__SOURCE__) ((((__SOURCE__) & 0xFFFF80FF) == 0x00000000) && ((__SOURCE__) != 0x00000000))
  1358. #define IS_TIM_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1359. ((__CHANNEL__) == TIM_CHANNEL_2) || \
  1360. ((__CHANNEL__) == TIM_CHANNEL_3) || \
  1361. ((__CHANNEL__) == TIM_CHANNEL_4) || \
  1362. ((__CHANNEL__) == TIM_CHANNEL_5) || \
  1363. ((__CHANNEL__) == TIM_CHANNEL_6) || \
  1364. ((__CHANNEL__) == TIM_CHANNEL_ALL))
  1365. #define IS_TIM_OPM_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1366. ((__CHANNEL__) == TIM_CHANNEL_2))
  1367. #define IS_TIM_COMPLEMENTARY_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1368. ((__CHANNEL__) == TIM_CHANNEL_2) || \
  1369. ((__CHANNEL__) == TIM_CHANNEL_3))
  1370. #define IS_TIM_CLOCKSOURCE(__CLOCK__) (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL) || \
  1371. ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2) || \
  1372. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0) || \
  1373. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1) || \
  1374. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2) || \
  1375. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3) || \
  1376. ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED) || \
  1377. ((__CLOCK__) == TIM_CLOCKSOURCE_TI1) || \
  1378. ((__CLOCK__) == TIM_CLOCKSOURCE_TI2) || \
  1379. ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1))
  1380. #define IS_TIM_CLOCKPOLARITY(__POLARITY__) (((__POLARITY__) == TIM_CLOCKPOLARITY_INVERTED) || \
  1381. ((__POLARITY__) == TIM_CLOCKPOLARITY_NONINVERTED) || \
  1382. ((__POLARITY__) == TIM_CLOCKPOLARITY_RISING) || \
  1383. ((__POLARITY__) == TIM_CLOCKPOLARITY_FALLING) || \
  1384. ((__POLARITY__) == TIM_CLOCKPOLARITY_BOTHEDGE))
  1385. #define IS_TIM_CLOCKPRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV1) || \
  1386. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV2) || \
  1387. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV4) || \
  1388. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV8))
  1389. #define IS_TIM_CLOCKFILTER(ICFILTER) ((ICFILTER) <= 0xF)
  1390. #define IS_TIM_CLEARINPUT_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_CLEARINPUTPOLARITY_INVERTED) || \
  1391. ((__POLARITY__) == TIM_CLEARINPUTPOLARITY_NONINVERTED))
  1392. #define IS_TIM_CLEARINPUT_PRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV1) || \
  1393. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV2) || \
  1394. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV4) || \
  1395. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV8))
  1396. #define IS_TIM_CLEARINPUT_FILTER(__ICFILTER__) ((__ICFILTER__) <= 0xF)
  1397. #define IS_TIM_OSSR_STATE(__STATE__) (((__STATE__) == TIM_OSSR_ENABLE) || \
  1398. ((__STATE__) == TIM_OSSR_DISABLE))
  1399. #define IS_TIM_OSSI_STATE(__STATE__) (((__STATE__) == TIM_OSSI_ENABLE) || \
  1400. ((__STATE__) == TIM_OSSI_DISABLE))
  1401. #define IS_TIM_LOCK_LEVEL(__LEVEL__) (((__LEVEL__) == TIM_LOCKLEVEL_OFF) || \
  1402. ((__LEVEL__) == TIM_LOCKLEVEL_1) || \
  1403. ((__LEVEL__) == TIM_LOCKLEVEL_2) || \
  1404. ((__LEVEL__) == TIM_LOCKLEVEL_3))
  1405. #define IS_TIM_BREAK_FILTER(__BRKFILTER__) ((__BRKFILTER__) <= 0xF)
  1406. #define IS_TIM_BREAK_STATE(__STATE__) (((__STATE__) == TIM_BREAK_ENABLE) || \
  1407. ((__STATE__) == TIM_BREAK_DISABLE))
  1408. #define IS_TIM_BREAK_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_BREAKPOLARITY_LOW) || \
  1409. ((__POLARITY__) == TIM_BREAKPOLARITY_HIGH))
  1410. #define IS_TIM_BREAK2_STATE(__STATE__) (((__STATE__) == TIM_BREAK2_ENABLE) || \
  1411. ((__STATE__) == TIM_BREAK2_DISABLE))
  1412. #define IS_TIM_BREAK2_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_BREAK2POLARITY_LOW) || \
  1413. ((__POLARITY__) == TIM_BREAK2POLARITY_HIGH))
  1414. #define IS_TIM_AUTOMATIC_OUTPUT_STATE(__STATE__) (((__STATE__) == TIM_AUTOMATICOUTPUT_ENABLE) || \
  1415. ((__STATE__) == TIM_AUTOMATICOUTPUT_DISABLE))
  1416. #define IS_TIM_GROUPCH5(__OCREF__) ((((__OCREF__) & 0x1FFFFFFF) == 0x00000000))
  1417. #define IS_TIM_TRGO_SOURCE(__SOURCE__) (((__SOURCE__) == TIM_TRGO_RESET) || \
  1418. ((__SOURCE__) == TIM_TRGO_ENABLE) || \
  1419. ((__SOURCE__) == TIM_TRGO_UPDATE) || \
  1420. ((__SOURCE__) == TIM_TRGO_OC1) || \
  1421. ((__SOURCE__) == TIM_TRGO_OC1REF) || \
  1422. ((__SOURCE__) == TIM_TRGO_OC2REF) || \
  1423. ((__SOURCE__) == TIM_TRGO_OC3REF) || \
  1424. ((__SOURCE__) == TIM_TRGO_OC4REF))
  1425. #define IS_TIM_TRGO2_SOURCE(__SOURCE__) (((__SOURCE__) == TIM_TRGO2_RESET) || \
  1426. ((__SOURCE__) == TIM_TRGO2_ENABLE) || \
  1427. ((__SOURCE__) == TIM_TRGO2_UPDATE) || \
  1428. ((__SOURCE__) == TIM_TRGO2_OC1) || \
  1429. ((__SOURCE__) == TIM_TRGO2_OC1REF) || \
  1430. ((__SOURCE__) == TIM_TRGO2_OC2REF) || \
  1431. ((__SOURCE__) == TIM_TRGO2_OC3REF) || \
  1432. ((__SOURCE__) == TIM_TRGO2_OC3REF) || \
  1433. ((__SOURCE__) == TIM_TRGO2_OC4REF) || \
  1434. ((__SOURCE__) == TIM_TRGO2_OC5REF) || \
  1435. ((__SOURCE__) == TIM_TRGO2_OC6REF) || \
  1436. ((__SOURCE__) == TIM_TRGO2_OC4REF_RISINGFALLING) || \
  1437. ((__SOURCE__) == TIM_TRGO2_OC6REF_RISINGFALLING) || \
  1438. ((__SOURCE__) == TIM_TRGO2_OC4REF_RISING_OC6REF_RISING) || \
  1439. ((__SOURCE__) == TIM_TRGO2_OC4REF_RISING_OC6REF_FALLING) || \
  1440. ((__SOURCE__) == TIM_TRGO2_OC5REF_RISING_OC6REF_RISING) || \
  1441. ((__SOURCE__) == TIM_TRGO2_OC5REF_RISING_OC6REF_FALLING))
  1442. #define IS_TIM_MSM_STATE(__STATE__) (((__STATE__) == TIM_MASTERSLAVEMODE_ENABLE) || \
  1443. ((__STATE__) == TIM_MASTERSLAVEMODE_DISABLE))
  1444. #define IS_TIM_SLAVE_MODE(__MODE__) (((__MODE__) == TIM_SLAVEMODE_DISABLE) || \
  1445. ((__MODE__) == TIM_SLAVEMODE_RESET) || \
  1446. ((__MODE__) == TIM_SLAVEMODE_GATED) || \
  1447. ((__MODE__) == TIM_SLAVEMODE_TRIGGER) || \
  1448. ((__MODE__) == TIM_SLAVEMODE_EXTERNAL1) || \
  1449. ((__MODE__) == TIM_SLAVEMODE_COMBINED_RESETTRIGGER))
  1450. #define IS_TIM_PWM_MODE(__MODE__) (((__MODE__) == TIM_OCMODE_PWM1) || \
  1451. ((__MODE__) == TIM_OCMODE_PWM2) || \
  1452. ((__MODE__) == TIM_OCMODE_COMBINED_PWM1) || \
  1453. ((__MODE__) == TIM_OCMODE_COMBINED_PWM2) || \
  1454. ((__MODE__) == TIM_OCMODE_ASSYMETRIC_PWM1) || \
  1455. ((__MODE__) == TIM_OCMODE_ASSYMETRIC_PWM2))
  1456. #define IS_TIM_OC_MODE(__MODE__) (((__MODE__) == TIM_OCMODE_TIMING) || \
  1457. ((__MODE__) == TIM_OCMODE_ACTIVE) || \
  1458. ((__MODE__) == TIM_OCMODE_INACTIVE) || \
  1459. ((__MODE__) == TIM_OCMODE_TOGGLE) || \
  1460. ((__MODE__) == TIM_OCMODE_FORCED_ACTIVE) || \
  1461. ((__MODE__) == TIM_OCMODE_FORCED_INACTIVE) || \
  1462. ((__MODE__) == TIM_OCMODE_RETRIGERRABLE_OPM1) || \
  1463. ((__MODE__) == TIM_OCMODE_RETRIGERRABLE_OPM2))
  1464. #define IS_TIM_TRIGGER_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_TS_ITR0) || \
  1465. ((__SELECTION__) == TIM_TS_ITR1) || \
  1466. ((__SELECTION__) == TIM_TS_ITR2) || \
  1467. ((__SELECTION__) == TIM_TS_ITR3) || \
  1468. ((__SELECTION__) == TIM_TS_TI1F_ED) || \
  1469. ((__SELECTION__) == TIM_TS_TI1FP1) || \
  1470. ((__SELECTION__) == TIM_TS_TI2FP2) || \
  1471. ((__SELECTION__) == TIM_TS_ETRF))
  1472. #define IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_TS_ITR0) || \
  1473. ((__SELECTION__) == TIM_TS_ITR1) || \
  1474. ((__SELECTION__) == TIM_TS_ITR2) || \
  1475. ((__SELECTION__) == TIM_TS_ITR3) || \
  1476. ((__SELECTION__) == TIM_TS_NONE))
  1477. #define IS_TIM_TRIGGERPOLARITY(__POLARITY__) (((__POLARITY__) == TIM_TRIGGERPOLARITY_INVERTED ) || \
  1478. ((__POLARITY__) == TIM_TRIGGERPOLARITY_NONINVERTED) || \
  1479. ((__POLARITY__) == TIM_TRIGGERPOLARITY_RISING ) || \
  1480. ((__POLARITY__) == TIM_TRIGGERPOLARITY_FALLING ) || \
  1481. ((__POLARITY__) == TIM_TRIGGERPOLARITY_BOTHEDGE ))
  1482. #define IS_TIM_TRIGGERPRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV1) || \
  1483. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV2) || \
  1484. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV4) || \
  1485. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV8))
  1486. #define IS_TIM_TRIGGERFILTER(__ICFILTER__) ((__ICFILTER__) <= 0xF)
  1487. #define IS_TIM_TI1SELECTION(__TI1SELECTION__) (((__TI1SELECTION__) == TIM_TI1SELECTION_CH1) || \
  1488. ((__TI1SELECTION__) == TIM_TI1SELECTION_XORCOMBINATION))
  1489. #define IS_TIM_DMA_LENGTH(__LENGTH__) (((__LENGTH__) == TIM_DMABURSTLENGTH_1TRANSFER) || \
  1490. ((__LENGTH__) == TIM_DMABURSTLENGTH_2TRANSFERS) || \
  1491. ((__LENGTH__) == TIM_DMABURSTLENGTH_3TRANSFERS) || \
  1492. ((__LENGTH__) == TIM_DMABURSTLENGTH_4TRANSFERS) || \
  1493. ((__LENGTH__) == TIM_DMABURSTLENGTH_5TRANSFERS) || \
  1494. ((__LENGTH__) == TIM_DMABURSTLENGTH_6TRANSFERS) || \
  1495. ((__LENGTH__) == TIM_DMABURSTLENGTH_7TRANSFERS) || \
  1496. ((__LENGTH__) == TIM_DMABURSTLENGTH_8TRANSFERS) || \
  1497. ((__LENGTH__) == TIM_DMABURSTLENGTH_9TRANSFERS) || \
  1498. ((__LENGTH__) == TIM_DMABURSTLENGTH_10TRANSFERS) || \
  1499. ((__LENGTH__) == TIM_DMABURSTLENGTH_11TRANSFERS) || \
  1500. ((__LENGTH__) == TIM_DMABURSTLENGTH_12TRANSFERS) || \
  1501. ((__LENGTH__) == TIM_DMABURSTLENGTH_13TRANSFERS) || \
  1502. ((__LENGTH__) == TIM_DMABURSTLENGTH_14TRANSFERS) || \
  1503. ((__LENGTH__) == TIM_DMABURSTLENGTH_15TRANSFERS) || \
  1504. ((__LENGTH__) == TIM_DMABURSTLENGTH_16TRANSFERS) || \
  1505. ((__LENGTH__) == TIM_DMABURSTLENGTH_17TRANSFERS) || \
  1506. ((__LENGTH__) == TIM_DMABURSTLENGTH_18TRANSFERS))
  1507. #define IS_TIM_IC_FILTER(__ICFILTER__) ((__ICFILTER__) <= 0xF)
  1508. #define IS_TIM_DEADTIME(__DEADTIME__) ((__DEADTIME__) <= 0xFF)
  1509. #define IS_TIM_BREAK_SYSTEM(__CONFIG__) (((__CONFIG__) == TIM_BREAK_SYSTEM_ECC) || \
  1510. ((__CONFIG__) == TIM_BREAK_SYSTEM_PVD) || \
  1511. ((__CONFIG__) == TIM_BREAK_SYSTEM_SRAM2_PARITY_ERROR) || \
  1512. ((__CONFIG__) == TIM_BREAK_SYSTEM_LOCKUP))
  1513. #define TIM_SET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__, __ICPSC__) \
  1514. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= (__ICPSC__)) :\
  1515. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= ((__ICPSC__) << 8)) :\
  1516. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= (__ICPSC__)) :\
  1517. ((__HANDLE__)->Instance->CCMR2 |= ((__ICPSC__) << 8)))
  1518. #define TIM_RESET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__) \
  1519. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= (uint16_t)~TIM_CCMR1_IC1PSC) :\
  1520. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= (uint16_t)~TIM_CCMR1_IC2PSC) :\
  1521. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= (uint16_t)~TIM_CCMR2_IC3PSC) :\
  1522. ((__HANDLE__)->Instance->CCMR2 &= (uint16_t)~TIM_CCMR2_IC4PSC))
  1523. #define TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  1524. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER |= (__POLARITY__)) :\
  1525. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 4)) :\
  1526. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 8)) :\
  1527. ((__HANDLE__)->Instance->CCER |= (((__POLARITY__) << 12))))
  1528. #define TIM_RESET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__) \
  1529. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP)) :\
  1530. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC2P | TIM_CCER_CC2NP)) :\
  1531. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC3P | TIM_CCER_CC3NP)) :\
  1532. ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC4P | TIM_CCER_CC4NP)))
  1533. /**
  1534. * @}
  1535. */
  1536. /* End of private macros -----------------------------------------------------*/
  1537. /* Include TIM HAL Extended module */
  1538. #include "stm32l4xx_hal_tim_ex.h"
  1539. /* Exported functions --------------------------------------------------------*/
  1540. /** @addtogroup TIM_Exported_Functions TIM Exported Functions
  1541. * @{
  1542. */
  1543. /** @addtogroup TIM_Exported_Functions_Group1 Time Base functions
  1544. * @brief Time Base functions
  1545. * @{
  1546. */
  1547. /* Time Base functions ********************************************************/
  1548. HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim);
  1549. HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim);
  1550. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim);
  1551. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim);
  1552. /* Blocking mode: Polling */
  1553. HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim);
  1554. HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim);
  1555. /* Non-Blocking mode: Interrupt */
  1556. HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);
  1557. HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
  1558. /* Non-Blocking mode: DMA */
  1559. HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
  1560. HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim);
  1561. /**
  1562. * @}
  1563. */
  1564. /** @addtogroup TIM_Exported_Functions_Group2 Time Output Compare functions
  1565. * @brief Time Output Compare functions
  1566. * @{
  1567. */
  1568. /* Timer Output Compare functions *********************************************/
  1569. HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim);
  1570. HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim);
  1571. void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim);
  1572. void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim);
  1573. /* Blocking mode: Polling */
  1574. HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1575. HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1576. /* Non-Blocking mode: Interrupt */
  1577. HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1578. HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1579. /* Non-Blocking mode: DMA */
  1580. HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1581. HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1582. /**
  1583. * @}
  1584. */
  1585. /** @addtogroup TIM_Exported_Functions_Group3 Time PWM functions
  1586. * @brief Time PWM functions
  1587. * @{
  1588. */
  1589. /* Timer PWM functions ********************************************************/
  1590. HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim);
  1591. HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim);
  1592. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim);
  1593. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim);
  1594. /* Blocking mode: Polling */
  1595. HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1596. HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1597. /* Non-Blocking mode: Interrupt */
  1598. HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1599. HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1600. /* Non-Blocking mode: DMA */
  1601. HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1602. HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1603. /**
  1604. * @}
  1605. */
  1606. /** @addtogroup TIM_Exported_Functions_Group4 Time Input Capture functions
  1607. * @brief Time Input Capture functions
  1608. * @{
  1609. */
  1610. /* Timer Input Capture functions **********************************************/
  1611. HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim);
  1612. HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim);
  1613. void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim);
  1614. void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim);
  1615. /* Blocking mode: Polling */
  1616. HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1617. HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1618. /* Non-Blocking mode: Interrupt */
  1619. HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1620. HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1621. /* Non-Blocking mode: DMA */
  1622. HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1623. HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1624. /**
  1625. * @}
  1626. */
  1627. /** @addtogroup TIM_Exported_Functions_Group5 Time One Pulse functions
  1628. * @brief Time One Pulse functions
  1629. * @{
  1630. */
  1631. /* Timer One Pulse functions **************************************************/
  1632. HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode);
  1633. HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim);
  1634. void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim);
  1635. void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim);
  1636. /* Blocking mode: Polling */
  1637. HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1638. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1639. /* Non-Blocking mode: Interrupt */
  1640. HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1641. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1642. /**
  1643. * @}
  1644. */
  1645. /** @addtogroup TIM_Exported_Functions_Group6 Time Encoder functions
  1646. * @brief Time Encoder functions
  1647. * @{
  1648. */
  1649. /* Timer Encoder functions ****************************************************/
  1650. HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig);
  1651. HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim);
  1652. void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim);
  1653. void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim);
  1654. /* Blocking mode: Polling */
  1655. HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1656. HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1657. /* Non-Blocking mode: Interrupt */
  1658. HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1659. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1660. /* Non-Blocking mode: DMA */
  1661. HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length);
  1662. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1663. /**
  1664. * @}
  1665. */
  1666. /** @addtogroup TIM_Exported_Functions_Group7 TIM IRQ handler management
  1667. * @brief IRQ handler management
  1668. * @{
  1669. */
  1670. /* Interrupt Handler functions ***********************************************/
  1671. void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim);
  1672. /**
  1673. * @}
  1674. */
  1675. /** @defgroup TIM_Exported_Functions_Group8 Peripheral Control functions
  1676. * @brief Peripheral Control functions
  1677. * @{
  1678. */
  1679. /* Control functions *********************************************************/
  1680. HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
  1681. HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
  1682. HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel);
  1683. HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel);
  1684. HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel);
  1685. HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig);
  1686. HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection);
  1687. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig);
  1688. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig);
  1689. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1690. uint32_t *BurstBuffer, uint32_t BurstLength);
  1691. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1692. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1693. uint32_t *BurstBuffer, uint32_t BurstLength);
  1694. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1695. HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource);
  1696. uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel);
  1697. /**
  1698. * @}
  1699. */
  1700. /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
  1701. * @brief TIM Callbacks functions
  1702. * @{
  1703. */
  1704. /* Callback in non blocking modes (Interrupt and DMA) *************************/
  1705. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
  1706. void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim);
  1707. void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim);
  1708. void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim);
  1709. void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim);
  1710. void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim);
  1711. /**
  1712. * @}
  1713. */
  1714. /** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions
  1715. * @brief Peripheral State functions
  1716. * @{
  1717. */
  1718. /* Peripheral State functions ************************************************/
  1719. HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim);
  1720. HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim);
  1721. HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim);
  1722. HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim);
  1723. HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim);
  1724. HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim);
  1725. /**
  1726. * @}
  1727. */
  1728. /**
  1729. * @}
  1730. */
  1731. /* End of exported functions -------------------------------------------------*/
  1732. /* Private functions----------------------------------------------------------*/
  1733. /** @defgroup TIM_Private_Functions TIM Private Functions
  1734. * @{
  1735. */
  1736. void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure);
  1737. void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter);
  1738. void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1739. void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler,
  1740. uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter);
  1741. void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
  1742. void TIM_DMAError(DMA_HandleTypeDef *hdma);
  1743. void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma);
  1744. void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState);
  1745. /**
  1746. * @}
  1747. */
  1748. /* End of private functions --------------------------------------------------*/
  1749. /**
  1750. * @}
  1751. */
  1752. /**
  1753. * @}
  1754. */
  1755. #ifdef __cplusplus
  1756. }
  1757. #endif
  1758. #endif /* __STM32L4xx_HAL_TIM_H */
  1759. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/