1 /**
2   ******************************************************************************
3   * @file    stm32f7xx_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) 2017 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 STM32F7xx_HAL_TIM_EX_H
21 #define STM32F7xx_HAL_TIM_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f7xx_hal_def.h"
29 
30 /** @addtogroup STM32F7xx_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 #if defined(TIM_BREAK_INPUT_SUPPORT)
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                                 Not relevant when analog watchdog output of the DFSDM1 used as break input source */
75 } TIMEx_BreakInputConfigTypeDef;
76 
77 #endif /* TIM_BREAK_INPUT_SUPPORT */
78 /**
79   * @}
80   */
81 /* End of exported types -----------------------------------------------------*/
82 
83 /* Exported constants --------------------------------------------------------*/
84 /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants
85   * @{
86   */
87 
88 /** @defgroup TIMEx_Remap TIM Extended Remapping
89   * @{
90   */
91 #define TIM_TIM2_TIM8_TRGO                     (0x00000000U)
92 #define TIM_TIM2_ETH_PTP                       (0x00000400U)
93 #define TIM_TIM2_USBFS_SOF                     (0x00000800U)
94 #define TIM_TIM2_USBHS_SOF                     (0x00000C00U)
95 #define TIM_TIM5_GPIO                          (0x00000000U)
96 #define TIM_TIM5_LSI                           (0x00000040U)
97 #define TIM_TIM5_LSE                           (0x00000080U)
98 #define TIM_TIM5_RTC                           (0x000000C0U)
99 #define TIM_TIM11_GPIO                         (0x00000000U)
100 #define TIM_TIM11_SPDIFRX                      (0x00000001U)
101 #define TIM_TIM11_HSE                          (0x00000002U)
102 #define TIM_TIM11_MCO1                         (0x00000003U)
103 /**
104   * @}
105   */
106 #if defined(TIM_BREAK_INPUT_SUPPORT)
107 
108 /** @defgroup TIMEx_Break_Input TIM Extended Break input
109   * @{
110   */
111 #define TIM_BREAKINPUT_BRK     0x00000001U                                      /*!< Timer break input  */
112 #define TIM_BREAKINPUT_BRK2    0x00000002U                                      /*!< Timer break2 input */
113 /**
114   * @}
115   */
116 
117 /** @defgroup TIMEx_Break_Input_Source TIM Extended Break input source
118   * @{
119   */
120 #define TIM_BREAKINPUTSOURCE_BKIN     (0x00000001U)                  /* !< An external source (GPIO) is connected to the BKIN pin  */
121 #define TIM_BREAKINPUTSOURCE_DFSDM1   (0x00000008U)                  /* !< The analog watchdog output of the DFSDM1 peripheral is connected to the break input */
122 /**
123   * @}
124   */
125 
126 /** @defgroup TIMEx_Break_Input_Source_Enable TIM Extended Break input source enabling
127   * @{
128   */
129 #define TIM_BREAKINPUTSOURCE_DISABLE     0x00000000U                            /*!< Break input source is disabled */
130 #define TIM_BREAKINPUTSOURCE_ENABLE      0x00000001U                            /*!< Break input source is enabled */
131 /**
132   * @}
133   */
134 
135 /** @defgroup TIMEx_Break_Input_Source_Polarity TIM Extended Break input polarity
136   * @{
137   */
138 #define TIM_BREAKINPUTSOURCE_POLARITY_LOW     0x00000001U                       /*!< Break input source is active low */
139 #define TIM_BREAKINPUTSOURCE_POLARITY_HIGH    0x00000000U                       /*!< Break input source is active_high */
140 /**
141   * @}
142   */
143 #endif /* TIM_BREAK_INPUT_SUPPORT */
144 
145 /**
146   * @}
147   */
148 /* End of exported constants -------------------------------------------------*/
149 
150 /* Exported macro ------------------------------------------------------------*/
151 /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
152   * @{
153   */
154 
155 /**
156   * @}
157   */
158 /* End of exported macro -----------------------------------------------------*/
159 
160 /* Private macro -------------------------------------------------------------*/
161 /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
162   * @{
163   */
164 #define IS_TIM_REMAP(__TIM_REMAP__)  (((__TIM_REMAP__) == TIM_TIM2_TIM8_TRGO)||\
165                                       ((__TIM_REMAP__) == TIM_TIM2_ETH_PTP)  ||\
166                                       ((__TIM_REMAP__) == TIM_TIM2_USBFS_SOF)||\
167                                       ((__TIM_REMAP__) == TIM_TIM2_USBHS_SOF)||\
168                                       ((__TIM_REMAP__) == TIM_TIM5_GPIO)     ||\
169                                       ((__TIM_REMAP__) == TIM_TIM5_LSI)      ||\
170                                       ((__TIM_REMAP__) == TIM_TIM5_LSE)      ||\
171                                       ((__TIM_REMAP__) == TIM_TIM5_RTC)      ||\
172                                       ((__TIM_REMAP__) == TIM_TIM11_GPIO)    ||\
173                                       ((__TIM_REMAP__) == TIM_TIM11_SPDIFRX) ||\
174                                       ((__TIM_REMAP__) == TIM_TIM11_HSE)     ||\
175                                       ((__TIM_REMAP__) == TIM_TIM11_MCO1))
176 #if defined(TIM_BREAK_INPUT_SUPPORT)
177 
178 #define IS_TIM_BREAKINPUT(__BREAKINPUT__)  (((__BREAKINPUT__) == TIM_BREAKINPUT_BRK)  || \
179                                             ((__BREAKINPUT__) == TIM_BREAKINPUT_BRK2))
180 
181 #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__)  (((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN)  || \
182                                               ((__SOURCE__) == TIM_BREAKINPUTSOURCE_DFSDM))
183 
184 #define IS_TIM_BREAKINPUTSOURCE_STATE(__STATE__)  (((__STATE__) == TIM_BREAKINPUTSOURCE_DISABLE)  || \
185                                                    ((__STATE__) == TIM_BREAKINPUTSOURCE_ENABLE))
186 
187 #define IS_TIM_BREAKINPUTSOURCE_POLARITY(__POLARITY__)  (((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_LOW)  || \
188                                                          ((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_HIGH))
189 #endif /* TIM_BREAK_INPUT_SUPPORT */
190 
191 /**
192   * @}
193   */
194 /* End of private macro ------------------------------------------------------*/
195 
196 /* Exported functions --------------------------------------------------------*/
197 /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
198   * @{
199   */
200 
201 /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
202   *  @brief    Timer Hall Sensor functions
203   * @{
204   */
205 /*  Timer Hall Sensor functions  **********************************************/
206 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, const TIM_HallSensor_InitTypeDef *sConfig);
207 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
208 
209 void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
210 void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
211 
212 /* Blocking mode: Polling */
213 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
214 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
215 /* Non-Blocking mode: Interrupt */
216 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
217 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
218 /* Non-Blocking mode: DMA */
219 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
220 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
221 /**
222   * @}
223   */
224 
225 /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
226   *  @brief   Timer Complementary Output Compare functions
227   * @{
228   */
229 /*  Timer Complementary Output Compare functions  *****************************/
230 /* Blocking mode: Polling */
231 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
232 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
233 
234 /* Non-Blocking mode: Interrupt */
235 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
236 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
237 
238 /* Non-Blocking mode: DMA */
239 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
240                                           uint16_t Length);
241 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
242 /**
243   * @}
244   */
245 
246 /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
247   *  @brief    Timer Complementary PWM functions
248   * @{
249   */
250 /*  Timer Complementary PWM functions  ****************************************/
251 /* Blocking mode: Polling */
252 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
253 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
254 
255 /* Non-Blocking mode: Interrupt */
256 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
257 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
258 /* Non-Blocking mode: DMA */
259 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
260                                            uint16_t Length);
261 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
262 /**
263   * @}
264   */
265 
266 /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
267   *  @brief    Timer Complementary One Pulse functions
268   * @{
269   */
270 /*  Timer Complementary One Pulse functions  **********************************/
271 /* Blocking mode: Polling */
272 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
273 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
274 
275 /* Non-Blocking mode: Interrupt */
276 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
277 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
278 /**
279   * @}
280   */
281 
282 /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
283   *  @brief    Peripheral Control functions
284   * @{
285   */
286 /* Extended Control functions  ************************************************/
287 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
288                                               uint32_t  CommutationSource);
289 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
290                                                  uint32_t  CommutationSource);
291 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
292                                                   uint32_t  CommutationSource);
293 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
294                                                         const TIM_MasterConfigTypeDef *sMasterConfig);
295 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
296                                                 const TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
297 #if defined(TIM_BREAK_INPUT_SUPPORT)
298 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput,
299                                              const TIMEx_BreakInputConfigTypeDef *sBreakInputConfig);
300 #endif /* TIM_BREAK_INPUT_SUPPORT */
301 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels);
302 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
303 /**
304   * @}
305   */
306 
307 /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
308   * @brief    Extended Callbacks functions
309   * @{
310   */
311 /* Extended Callback **********************************************************/
312 void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
313 void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
314 void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
315 void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim);
316 /**
317   * @}
318   */
319 
320 /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
321   * @brief    Extended Peripheral State functions
322   * @{
323   */
324 /* Extended Peripheral State functions  ***************************************/
325 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(const TIM_HandleTypeDef *htim);
326 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(const TIM_HandleTypeDef *htim,  uint32_t ChannelN);
327 /**
328   * @}
329   */
330 
331 /**
332   * @}
333   */
334 /* End of exported functions -------------------------------------------------*/
335 
336 /* Private functions----------------------------------------------------------*/
337 /** @addtogroup TIMEx_Private_Functions TIM Extended Private Functions
338   * @{
339   */
340 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
341 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
342 /**
343   * @}
344   */
345 /* End of private functions --------------------------------------------------*/
346 
347 /**
348   * @}
349   */
350 
351 /**
352   * @}
353   */
354 
355 #ifdef __cplusplus
356 }
357 #endif
358 
359 
360 #endif /* STM32F7xx_HAL_TIM_EX_H */
361