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