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