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