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.
 
 
 

420 lines
18 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_hal_tim_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of TIM HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 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 STM32WBxx_HAL_TIM_EX_H
  21. #define STM32WBxx_HAL_TIM_EX_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32wbxx_hal_def.h"
  27. /** @addtogroup STM32WBxx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup TIMEx
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup TIMEx_Exported_Types TIM Extended Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief TIM Hall sensor Configuration Structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal.
  43. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  44. uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler.
  45. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  46. uint32_t IC1Filter; /*!< Specifies the input capture filter.
  47. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  48. uint32_t Commutation_Delay; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  49. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  50. } TIM_HallSensor_InitTypeDef;
  51. /**
  52. * @brief TIM Break/Break2 input configuration
  53. */
  54. typedef struct
  55. {
  56. uint32_t Source; /*!< Specifies the source of the timer break input.
  57. This parameter can be a value of @ref TIMEx_Break_Input_Source */
  58. uint32_t Enable; /*!< Specifies whether or not the break input source is enabled.
  59. This parameter can be a value of @ref TIMEx_Break_Input_Source_Enable */
  60. uint32_t Polarity; /*!< Specifies the break input source polarity.
  61. This parameter can be a value of @ref TIMEx_Break_Input_Source_Polarity */
  62. }
  63. TIMEx_BreakInputConfigTypeDef;
  64. /**
  65. * @}
  66. */
  67. /* End of exported types -----------------------------------------------------*/
  68. /* Exported constants --------------------------------------------------------*/
  69. /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants
  70. * @{
  71. */
  72. /** @defgroup TIMEx_Remap TIM Extended Remapping
  73. * @{
  74. */
  75. #define TIM_TIM1_ETR_GPIO 0x00000000U /* !< TIM1_ETR is not connected to I/O */
  76. #define TIM_TIM1_ETR_ADC1_AWD1 TIM1_OR_ETR_ADC1_RMP_0 /* !< TIM1_ETR is connected to ADC1 AWD1 */
  77. #if defined(ADC_SUPPORT_5_MSPS)
  78. #define TIM_TIM1_ETR_ADC1_AWD2 TIM1_OR_ETR_ADC1_RMP_1 /* !< TIM1_ETR is connected to ADC1 AWD2 */
  79. #define TIM_TIM1_ETR_ADC1_AWD3 (TIM1_OR_ETR_ADC1_RMP_0 | TIM1_OR_ETR_ADC1_RMP_1) /* !< TIM1_ETR is connected to ADC1 AWD3 */
  80. #endif
  81. #if defined(COMP1)
  82. #define TIM_TIM1_ETR_COMP1 TIM1_AF1_ETRSEL_0 /* !< TIM1_ETR is connected to COMP1 output */
  83. #endif /* COMP1 */
  84. #if defined(COMP2)
  85. #define TIM_TIM1_ETR_COMP2 TIM1_AF1_ETRSEL_1 /* !< TIM1_ETR is connected to COMP2 output */
  86. #endif /* COMP2 */
  87. #define TIM_TIM1_TI1_GPIO 0x00000000U /* !< TIM1 Input capture 1 is connected to I/0 */
  88. #define TIM_TIM1_TI1_COMP1 TIM1_OR_TI1_RMP /* !< TIM1 Input capture 1is connected to COMP1 OUT */
  89. #define TIM_TIM2_ITR_NC 0x00000000U /* !< TIM2 Internal trigger ITR is not connected */
  90. #if defined(USB)
  91. #define TIM_TIM2_ITR_USB TIM2_OR_ITR1_RMP /* !< TIM2 Internal trigger ITR is connected to USBFS SOF */
  92. #endif /* USB */
  93. #define TIM_TIM2_ETR_GPIO 0x00000000U /* !< TIM2 External trigger ETR is connected to I/O */
  94. #define TIM_TIM2_ETR_LSE TIM2_OR_ETR_RMP /* !< TIM2 External trigger ETR is connected to LSE */
  95. #if defined(COMP1)
  96. #define TIM_TIM2_ETR_COMP1 TIM2_AF1_ETRSEL_0 /* !< TIM2_ETR is connected to COMP1 output */
  97. #endif /* COMP1 */
  98. #if defined(COMP2)
  99. #define TIM_TIM2_ETR_COMP2 TIM2_AF1_ETRSEL_1 /* !< TIM2_ETR is connected to COMP2 output */
  100. #endif /* COMP2 */
  101. #define TIM_TIM2_TI4_GPIO 0x00000000U /* !< TIM2_TI4 is connected to I/O */
  102. #if defined(COMP1)
  103. #define TIM_TIM2_TI4_COMP1 TIM2_OR_TI4_RMP_0 /* !< TIM2_TI4 is connected to COMP1 OUT */
  104. #endif /* COMP1 */
  105. #if defined(COMP2)
  106. #define TIM_TIM2_TI4_COMP2 TIM2_OR_TI4_RMP_1 /* !< TIM2_TI4 is connected to COMP1 OUT */
  107. #endif /* COMP2 */
  108. #if defined(COMP1) && defined(COMP2)
  109. #define TIM_TIM2_TI4_COMP1_COMP2 (TIM2_OR_TI4_RMP_0 | TIM2_OR_TI4_RMP_1) /* !< TIM2_TI4 is connected to COMP1 and COMP2 OUT */
  110. #endif /* COMP1 && COMP2 */
  111. #if defined(TIM16)
  112. #define TIM_TIM16_TI1_GPIO 0x00000000U /* !< TIM16_TI1 is connected to I/O */
  113. #define TIM_TIM16_TI1_LSI TIM16_OR_TI1_RMP_0 /* !< TIM16_TI1 is connected to LSI Clock */
  114. #define TIM_TIM16_TI1_LSE TIM16_OR_TI1_RMP_1 /* !< TIM16_TI1 is connected to LSE Clock */
  115. #define TIM_TIM16_TI1_RTC (TIM16_OR_TI1_RMP_0 | TIM16_OR_TI1_RMP_1) /* !< TIM16_TI1 is connected to RTC */
  116. #endif /* TIM16 */
  117. #if defined(TIM17)
  118. #define TIM_TIM17_TI1_GPIO 0x00000000U /* !< TIM17_TI1 is connected to I/O */
  119. #define TIM_TIM17_TI1_MSI TIM17_OR_TI1_RMP_0 /* !< TIM17_TI1 is connected to MSI */
  120. #define TIM_TIM17_TI1_HSE TIM17_OR_TI1_RMP_1 /* !< TIM17_TI1 is connected to HSE/32 */
  121. #define TIM_TIM17_TI1_MCO (TIM17_OR_TI1_RMP_0 | TIM17_OR_TI1_RMP_1) /* !< TIM17_TI1 is connected to MCO */
  122. #endif /* TIM17 */
  123. /**
  124. * @}
  125. */
  126. /** @defgroup TIMEx_Break_Input TIM Extended Break input
  127. * @{
  128. */
  129. #define TIM_BREAKINPUT_BRK 0x00000001U /* !< Timer break input */
  130. #define TIM_BREAKINPUT_BRK2 0x00000002U /* !< Timer break2 input */
  131. /**
  132. * @}
  133. */
  134. /** @defgroup TIMEx_Break_Input_Source TIM Extended Break input source
  135. * @{
  136. */
  137. #define TIM_BREAKINPUTSOURCE_BKIN 0x00000001U /* !< An external source (GPIO) is connected to the BKIN pin */
  138. #if defined(COMP1)
  139. #define TIM_BREAKINPUTSOURCE_COMP1 0x00000002U /* !< The COMP1 output is connected to the break input */
  140. #endif /* COMP1 */
  141. #if defined(COMP2)
  142. #define TIM_BREAKINPUTSOURCE_COMP2 0x00000004U /* !< The COMP2 output is connected to the break input */
  143. #endif /* COMP2 */
  144. /**
  145. * @}
  146. */
  147. /** @defgroup TIMEx_Break_Input_Source_Enable TIM Extended Break input source enabling
  148. * @{
  149. */
  150. #define TIM_BREAKINPUTSOURCE_DISABLE 0x00000000U /* !< Break input source is disabled */
  151. #define TIM_BREAKINPUTSOURCE_ENABLE 0x00000001U /* !< Break input source is enabled */
  152. /**
  153. * @}
  154. */
  155. /** @defgroup TIMEx_Break_Input_Source_Polarity TIM Extended Break input polarity
  156. * @{
  157. */
  158. #define TIM_BREAKINPUTSOURCE_POLARITY_LOW 0x00000001U /* !< Break input source is active low */
  159. #define TIM_BREAKINPUTSOURCE_POLARITY_HIGH 0x00000000U /* !< Break input source is active_high */
  160. /**
  161. * @}
  162. */
  163. /**
  164. * @}
  165. */
  166. /* End of exported constants -------------------------------------------------*/
  167. /* Exported macro ------------------------------------------------------------*/
  168. /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
  169. * @{
  170. */
  171. /**
  172. * @}
  173. */
  174. /* End of exported macro -----------------------------------------------------*/
  175. /* Private macro -------------------------------------------------------------*/
  176. /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
  177. * @{
  178. */
  179. #if defined(STM32WB55xx) || defined(STM32WB5Mxx) || defined(STM32WB35xx)
  180. #define IS_TIM_REMAP(__INSTANCE__, __REMAP__) \
  181. ((((__INSTANCE__) == TIM1) && ((((__REMAP__) & 0xFFFE3FECU) == 0x00000000U))) \
  182. || (((__INSTANCE__) == TIM2) && ((((__REMAP__) & 0xFFFE3FF0U) == 0x00000000U))) \
  183. || (((__INSTANCE__) == TIM16) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))) \
  184. || (((__INSTANCE__) == TIM17) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))))
  185. #else
  186. #define IS_TIM_REMAP(__INSTANCE__, __REMAP__) \
  187. ((((__INSTANCE__) == TIM1) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))) \
  188. || (((__INSTANCE__) == TIM2) && ((((__REMAP__) & 0xFFFFFFF0U) == 0x00000000U))) \
  189. || (((__INSTANCE__) == TIM16) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))) \
  190. || (((__INSTANCE__) == TIM17) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))))
  191. #endif
  192. #define IS_TIM_BREAKINPUT(__BREAKINPUT__) \
  193. (((__BREAKINPUT__) == TIM_BREAKINPUT_BRK) || \
  194. ((__BREAKINPUT__) == TIM_BREAKINPUT_BRK2))
  195. #if defined(COMP1)
  196. #if defined(COMP2)
  197. #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__) \
  198. (((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN) || \
  199. ((__SOURCE__) == TIM_BREAKINPUTSOURCE_COMP1) || \
  200. ((__SOURCE__) == TIM_BREAKINPUTSOURCE_COMP2))
  201. #else
  202. #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__) \
  203. (((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN))
  204. #endif
  205. #else
  206. #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__) \
  207. (((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN))
  208. #endif
  209. #define IS_TIM_BREAKINPUTSOURCE_STATE(__STATE__) \
  210. (((__STATE__) == TIM_BREAKINPUTSOURCE_DISABLE) || \
  211. ((__STATE__) == TIM_BREAKINPUTSOURCE_ENABLE))
  212. #define IS_TIM_BREAKINPUTSOURCE_POLARITY(__POLARITY__) \
  213. (((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_LOW) || \
  214. ((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_HIGH))
  215. /**
  216. * @}
  217. */
  218. /* End of private macro ------------------------------------------------------*/
  219. /* Exported functions --------------------------------------------------------*/
  220. /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
  221. * @{
  222. */
  223. /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
  224. * @brief Timer Hall Sensor functions
  225. * @{
  226. */
  227. /* Timer Hall Sensor functions **********************************************/
  228. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig);
  229. HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
  230. void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
  231. void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
  232. /* Blocking mode: Polling */
  233. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
  234. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
  235. /* Non-Blocking mode: Interrupt */
  236. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
  237. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
  238. /* Non-Blocking mode: DMA */
  239. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
  240. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
  241. /**
  242. * @}
  243. */
  244. /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
  245. * @brief Timer Complementary Output Compare functions
  246. * @{
  247. */
  248. /* Timer Complementary Output Compare functions *****************************/
  249. /* Blocking mode: Polling */
  250. HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  251. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  252. /* Non-Blocking mode: Interrupt */
  253. HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  254. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  255. /* Non-Blocking mode: DMA */
  256. HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  257. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  258. /**
  259. * @}
  260. */
  261. /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
  262. * @brief Timer Complementary PWM functions
  263. * @{
  264. */
  265. /* Timer Complementary PWM functions ****************************************/
  266. /* Blocking mode: Polling */
  267. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  268. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  269. /* Non-Blocking mode: Interrupt */
  270. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  271. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  272. /* Non-Blocking mode: DMA */
  273. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  274. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  275. /**
  276. * @}
  277. */
  278. /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
  279. * @brief Timer Complementary One Pulse functions
  280. * @{
  281. */
  282. /* Timer Complementary One Pulse functions **********************************/
  283. /* Blocking mode: Polling */
  284. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  285. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  286. /* Non-Blocking mode: Interrupt */
  287. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  288. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  289. /**
  290. * @}
  291. */
  292. /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
  293. * @brief Peripheral Control functions
  294. * @{
  295. */
  296. /* Extended Control functions ************************************************/
  297. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
  298. uint32_t CommutationSource);
  299. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
  300. uint32_t CommutationSource);
  301. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger,
  302. uint32_t CommutationSource);
  303. HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
  304. TIM_MasterConfigTypeDef *sMasterConfig);
  305. HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
  306. TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
  307. HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput,
  308. TIMEx_BreakInputConfigTypeDef *sBreakInputConfig);
  309. HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels);
  310. HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
  311. HAL_StatusTypeDef HAL_TIMEx_DisarmBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput);
  312. HAL_StatusTypeDef HAL_TIMEx_ReArmBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput);
  313. /**
  314. * @}
  315. */
  316. /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
  317. * @brief Extended Callbacks functions
  318. * @{
  319. */
  320. /* Extended Callback **********************************************************/
  321. void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
  322. void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
  323. void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
  324. void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim);
  325. /**
  326. * @}
  327. */
  328. /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
  329. * @brief Extended Peripheral State functions
  330. * @{
  331. */
  332. /* Extended Peripheral State functions ***************************************/
  333. HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim);
  334. HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(TIM_HandleTypeDef *htim, uint32_t ChannelN);
  335. /**
  336. * @}
  337. */
  338. /**
  339. * @}
  340. */
  341. /* End of exported functions -------------------------------------------------*/
  342. /* Private functions----------------------------------------------------------*/
  343. /** @addtogroup TIMEx_Private_Functions TIMEx Private Functions
  344. * @{
  345. */
  346. void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
  347. void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
  348. /**
  349. * @}
  350. */
  351. /* End of private functions --------------------------------------------------*/
  352. /**
  353. * @}
  354. */
  355. /**
  356. * @}
  357. */
  358. #ifdef __cplusplus
  359. }
  360. #endif
  361. #endif /* STM32WBxx_HAL_TIM_EX_H */
  362. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/