1 /** 2 ****************************************************************************** 3 * @file stm32c0xx_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) 2022 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 STM32C0xx_HAL_TIM_EX_H 21 #define STM32C0xx_HAL_TIM_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32c0xx_hal_def.h" 29 30 /** @addtogroup STM32C0xx_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 connected to GPIO */ 89 #define TIM_TIM1_ETR_ADC1_AWD1 (TIM_AF1_ETRSEL_1 | TIM_AF1_ETRSEL_0) /*!< TIM1_ETR is connected to ADC1 AWD1 */ 90 #define TIM_TIM1_ETR_ADC1_AWD2 TIM_AF1_ETRSEL_2 /*!< TIM1_ETR is connected to ADC1 AWD2 */ 91 #define TIM_TIM1_ETR_ADC1_AWD3 (TIM_AF1_ETRSEL_2 | TIM_AF1_ETRSEL_0) /*!< TIM1_ETR is connected to ADC1 AWD3 */ 92 93 #if defined(TIM2) 94 #define TIM_TIM2_ETR_GPIO 0x00000000U /*!< TIM2_ETR is connected to GPIO */ 95 #define TIM_TIM2_ETR_LSE (TIM_AF1_ETRSEL_1 | TIM_AF1_ETRSEL_0) /*!< TIM2_ETR is connected to LSE */ 96 #define TIM_TIM2_ETR_MCO TIM_AF1_ETRSEL_2 /*!< TIM2_ETR is connected to MCO */ 97 #define TIM_TIM2_ETR_MCO2 (TIM_AF1_ETRSEL_2 | TIM_AF1_ETRSEL_0) /*!< TIM2_ETR is connected to MCO2 */ 98 #endif /* TIM2 */ 99 100 #define TIM_TIM3_ETR_GPIO 0x00000000U /*!< TIM3_ETR is connected to GPIO */ 101 /** 102 * @} 103 */ 104 105 /** @defgroup TIMEx_Break_Input TIM Extended Break input 106 * @{ 107 */ 108 #define TIM_BREAKINPUT_BRK 0x00000001U /*!< Timer break input */ 109 #define TIM_BREAKINPUT_BRK2 0x00000002U /*!< Timer break2 input */ 110 /** 111 * @} 112 */ 113 114 /** @defgroup TIMEx_Break_Input_Source TIM Extended Break input source 115 * @{ 116 */ 117 #define TIM_BREAKINPUTSOURCE_BKIN 0x00000001U /*!< An external source (GPIO) is connected to the BKIN pin */ 118 119 /** 120 * @} 121 */ 122 123 /** @defgroup TIMEx_Break_Input_Source_Enable TIM Extended Break input source enabling 124 * @{ 125 */ 126 #define TIM_BREAKINPUTSOURCE_DISABLE 0x00000000U /*!< Break input source is disabled */ 127 #define TIM_BREAKINPUTSOURCE_ENABLE 0x00000001U /*!< Break input source is enabled */ 128 /** 129 * @} 130 */ 131 132 /** @defgroup TIMEx_Break_Input_Source_Polarity TIM Extended Break input polarity 133 * @{ 134 */ 135 #define TIM_BREAKINPUTSOURCE_POLARITY_LOW 0x00000001U /*!< Break input source is active low */ 136 #define TIM_BREAKINPUTSOURCE_POLARITY_HIGH 0x00000000U /*!< Break input source is active_high */ 137 /** 138 * @} 139 */ 140 141 /** @defgroup TIMEx_Timer_Input_Selection TIM Extended Timer input selection 142 * @{ 143 */ 144 #define TIM_TIM14_TI1_GPIO 0x00000000U /*!< TIM14_TI1 is connected to GPIO */ 145 #define TIM_TIM14_TI1_RTC 0x00000001U /*!< TIM14_TI1 is connected to RTC clock */ 146 #define TIM_TIM14_TI1_HSE_32 0x00000002U /*!< TIM14_TI1 is connected to HSE div 32 */ 147 #define TIM_TIM14_TI1_MCO 0x00000003U /*!< TIM14_TI1 is connected to MCO */ 148 #define TIM_TIM14_TI1_MCO2 0x00000004U /*!< TIM14_TI1 is connected to MCO2 */ 149 150 #define TIM_TIM16_TI1_GPIO 0x00000000U /*!< TIM16_TI1 is connected to GPIO */ 151 #define TIM_TIM16_TI1_LSI 0x00000001U /*!< TIM16_TI1 is connected to LSI */ 152 #define TIM_TIM16_TI1_LSE 0x00000002U /*!< TIM16_TI1 is connected to LSE */ 153 #define TIM_TIM16_TI1_MCO2 0x00000004U /*!< TIM16_TI1 is connected to MCO2 */ 154 155 #define TIM_TIM17_TI1_GPIO 0x00000000U /*!< TIM17_TI1 is connected to GPIO */ 156 #define TIM_TIM17_TI1_HSE_32 0x00000002U /*!< TIM17_TI1 is connected to HSE div 32 */ 157 #define TIM_TIM17_TI1_MCO 0x00000003U /*!< TIM17_TI1 is connected to MCO */ 158 #define TIM_TIM17_TI1_MCO2 0x00000004U /*!< TIM17_TI1 is connected to MCO2 */ 159 /** 160 * @} 161 */ 162 163 /** 164 * @} 165 */ 166 /* End of exported constants -------------------------------------------------*/ 167 168 /* Exported macro ------------------------------------------------------------*/ 169 /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros 170 * @{ 171 */ 172 173 /** 174 * @} 175 */ 176 /* End of exported macro -----------------------------------------------------*/ 177 178 /* Private macro -------------------------------------------------------------*/ 179 /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros 180 * @{ 181 */ 182 #define IS_TIM_REMAP(__REMAP__) ((((__REMAP__) & 0xFFFC3FFFU) == 0x00000000U)) 183 184 #define IS_TIM_BREAKINPUT(__BREAKINPUT__) (((__BREAKINPUT__) == TIM_BREAKINPUT_BRK) || \ 185 ((__BREAKINPUT__) == TIM_BREAKINPUT_BRK2)) 186 187 #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__) ((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN) 188 189 #define IS_TIM_BREAKINPUTSOURCE_STATE(__STATE__) (((__STATE__) == TIM_BREAKINPUTSOURCE_DISABLE) || \ 190 ((__STATE__) == TIM_BREAKINPUTSOURCE_ENABLE)) 191 192 #define IS_TIM_BREAKINPUTSOURCE_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_LOW) || \ 193 ((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_HIGH)) 194 195 #define IS_TIM_TISEL(__TISEL__) ((((__TISEL__) & 0xF0F0F0F0U) == 0x00000000U)) 196 197 /** 198 * @} 199 */ 200 /* End of private macro ------------------------------------------------------*/ 201 202 /* Exported functions --------------------------------------------------------*/ 203 /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions 204 * @{ 205 */ 206 207 /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions 208 * @brief Timer Hall Sensor functions 209 * @{ 210 */ 211 /* Timer Hall Sensor functions **********************************************/ 212 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, const TIM_HallSensor_InitTypeDef *sConfig); 213 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim); 214 215 void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim); 216 void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim); 217 218 /* Blocking mode: Polling */ 219 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim); 220 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim); 221 /* Non-Blocking mode: Interrupt */ 222 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim); 223 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim); 224 /* Non-Blocking mode: DMA */ 225 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length); 226 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim); 227 /** 228 * @} 229 */ 230 231 /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions 232 * @brief Timer Complementary Output Compare functions 233 * @{ 234 */ 235 /* Timer Complementary Output Compare functions *****************************/ 236 /* Blocking mode: Polling */ 237 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel); 238 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel); 239 240 /* Non-Blocking mode: Interrupt */ 241 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 242 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 243 244 /* Non-Blocking mode: DMA */ 245 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, 246 uint16_t Length); 247 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel); 248 /** 249 * @} 250 */ 251 252 /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions 253 * @brief Timer Complementary PWM functions 254 * @{ 255 */ 256 /* Timer Complementary PWM functions ****************************************/ 257 /* Blocking mode: Polling */ 258 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel); 259 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel); 260 261 /* Non-Blocking mode: Interrupt */ 262 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 263 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 264 /* Non-Blocking mode: DMA */ 265 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, 266 uint16_t Length); 267 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel); 268 /** 269 * @} 270 */ 271 272 /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions 273 * @brief Timer Complementary One Pulse functions 274 * @{ 275 */ 276 /* Timer Complementary One Pulse functions **********************************/ 277 /* Blocking mode: Polling */ 278 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 279 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 280 281 /* Non-Blocking mode: Interrupt */ 282 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 283 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 284 /** 285 * @} 286 */ 287 288 /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions 289 * @brief Peripheral Control functions 290 * @{ 291 */ 292 /* Extended Control functions ************************************************/ 293 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 294 uint32_t CommutationSource); 295 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 296 uint32_t CommutationSource); 297 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 298 uint32_t CommutationSource); 299 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, 300 const TIM_MasterConfigTypeDef *sMasterConfig); 301 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, 302 const TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig); 303 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput, 304 const TIMEx_BreakInputConfigTypeDef *sBreakInputConfig); 305 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels); 306 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap); 307 HAL_StatusTypeDef HAL_TIMEx_TISelection(TIM_HandleTypeDef *htim, uint32_t TISelection, uint32_t Channel); 308 309 HAL_StatusTypeDef HAL_TIMEx_DisarmBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput); 310 HAL_StatusTypeDef HAL_TIMEx_ReArmBreakInput(const TIM_HandleTypeDef *htim, uint32_t BreakInput); 311 /** 312 * @} 313 */ 314 315 /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions 316 * @brief Extended Callbacks functions 317 * @{ 318 */ 319 /* Extended Callback **********************************************************/ 320 void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim); 321 void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim); 322 void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim); 323 void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim); 324 /** 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(const TIM_HandleTypeDef *htim); 334 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(const TIM_HandleTypeDef *htim, uint32_t ChannelN); 335 /** 336 * @} 337 */ 338 339 /** 340 * @} 341 */ 342 /* End of exported functions -------------------------------------------------*/ 343 344 /* Private functions----------------------------------------------------------*/ 345 /** @addtogroup TIMEx_Private_Functions TIM Extended Private Functions 346 * @{ 347 */ 348 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma); 349 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma); 350 /** 351 * @} 352 */ 353 /* End of private functions --------------------------------------------------*/ 354 355 /** 356 * @} 357 */ 358 359 /** 360 * @} 361 */ 362 363 #ifdef __cplusplus 364 } 365 #endif 366 367 368 #endif /* STM32C0xx_HAL_TIM_EX_H */ 369