1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_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) 2016 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 STM32F4xx_HAL_TIM_EX_H
21 #define STM32F4xx_HAL_TIM_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f4xx_hal_def.h"
29 
30 /** @addtogroup STM32F4xx_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   */
64 /* End of exported types -----------------------------------------------------*/
65 
66 /* Exported constants --------------------------------------------------------*/
67 /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants
68   * @{
69   */
70 
71 /** @defgroup TIMEx_Remap TIM Extended Remapping
72   * @{
73   */
74 #if defined (TIM2)
75 #if defined(TIM8)
76 #define TIM_TIM2_TIM8_TRGO                     0x00000000U                              /*!< TIM2 ITR1 is connected to TIM8 TRGO */
77 #else
78 #define TIM_TIM2_ETH_PTP                       TIM_OR_ITR1_RMP_0                        /*!< TIM2 ITR1 is connected to PTP trigger output */
79 #endif /*  TIM8 */
80 #define TIM_TIM2_USBFS_SOF                     TIM_OR_ITR1_RMP_1                        /*!< TIM2 ITR1 is connected to OTG FS SOF */
81 #define TIM_TIM2_USBHS_SOF                     (TIM_OR_ITR1_RMP_1 | TIM_OR_ITR1_RMP_0)  /*!< TIM2 ITR1 is connected to OTG HS SOF */
82 #endif /* TIM2 */
83 
84 #define TIM_TIM5_GPIO                          0x00000000U                              /*!< TIM5 TI4 is connected to GPIO */
85 #define TIM_TIM5_LSI                           TIM_OR_TI4_RMP_0                         /*!< TIM5 TI4 is connected to LSI */
86 #define TIM_TIM5_LSE                           TIM_OR_TI4_RMP_1                         /*!< TIM5 TI4 is connected to LSE */
87 #define TIM_TIM5_RTC                           (TIM_OR_TI4_RMP_1 | TIM_OR_TI4_RMP_0)    /*!< TIM5 TI4 is connected to the RTC wakeup interrupt */
88 
89 #define TIM_TIM11_GPIO                         0x00000000U                              /*!< TIM11 TI1 is connected to GPIO */
90 #define TIM_TIM11_HSE                          TIM_OR_TI1_RMP_1                         /*!< TIM11 TI1 is connected to HSE_RTC clock */
91 #if defined(SPDIFRX)
92 #define TIM_TIM11_SPDIFRX                      TIM_OR_TI1_RMP_0                         /*!< TIM11 TI1 is connected to SPDIFRX_FRAME_SYNC */
93 #endif /* SPDIFRX*/
94 
95 #if defined(LPTIM_OR_TIM1_ITR2_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP)
96 #define LPTIM_REMAP_MASK                       0x10000000U
97 
98 #define TIM_TIM9_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM9 ITR1 is connected to TIM3 TRGO */
99 #define TIM_TIM9_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM9_ITR1_RMP)  /*!< TIM9 ITR1 is connected to LPTIM1 output */
100 
101 #define TIM_TIM5_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM5 ITR1 is connected to TIM3 TRGO */
102 #define TIM_TIM5_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM5_ITR1_RMP)  /*!< TIM5 ITR1 is connected to LPTIM1 output */
103 
104 #define TIM_TIM1_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM1 ITR2 is connected to TIM3 TRGO */
105 #define TIM_TIM1_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM1_ITR2_RMP)  /*!< TIM1 ITR2 is connected to LPTIM1 output */
106 #endif /* LPTIM_OR_TIM1_ITR2_RMP &&  LPTIM_OR_TIM5_ITR1_RMP && LPTIM_OR_TIM5_ITR1_RMP */
107 /**
108   * @}
109   */
110 
111 /**
112   * @}
113   */
114 /* End of exported constants -------------------------------------------------*/
115 
116 /* Exported macro ------------------------------------------------------------*/
117 /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
118   * @{
119   */
120 
121 /**
122   * @}
123   */
124 /* End of exported macro -----------------------------------------------------*/
125 
126 /* Private macro -------------------------------------------------------------*/
127 /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
128   * @{
129   */
130 #if defined(SPDIFRX)
131 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
132   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
133                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
134                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
135    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
136                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
137                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
138                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
139    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
140                               ((TIM_REMAP) == TIM_TIM11_SPDIFRX)       || \
141                               ((TIM_REMAP) == TIM_TIM11_HSE))))
142 #elif defined(TIM2)
143 #if defined(LPTIM_OR_TIM1_ITR2_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP)
144 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
145   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
146                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
147                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
148    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
149                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
150                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
151                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
152    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
153                               ((TIM_REMAP) == TIM_TIM11_HSE)))         || \
154    (((INSTANCE) == TIM1)  && (((TIM_REMAP) == TIM_TIM1_TIM3_TRGO)      || \
155                               ((TIM_REMAP) == TIM_TIM1_LPTIM)))        || \
156    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_TIM3_TRGO)      || \
157                               ((TIM_REMAP) == TIM_TIM5_LPTIM)))        || \
158    (((INSTANCE) == TIM9)  && (((TIM_REMAP) == TIM_TIM9_TIM3_TRGO)      || \
159                               ((TIM_REMAP) == TIM_TIM9_LPTIM))))
160 #elif defined(TIM8)
161 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
162   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
163                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
164                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
165    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
166                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
167                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
168                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
169    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
170                               ((TIM_REMAP) == TIM_TIM11_HSE))))
171 #else
172 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
173   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_ETH_PTP)        || \
174                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
175                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
176    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
177                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
178                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
179                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
180    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
181                               ((TIM_REMAP) == TIM_TIM11_HSE))))
182 #endif /* LPTIM_OR_TIM1_ITR2_RMP &&  LPTIM_OR_TIM5_ITR1_RMP && LPTIM_OR_TIM5_ITR1_RMP */
183 #else
184 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
185   ((((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
186                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
187                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
188                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
189    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
190                               ((TIM_REMAP) == TIM_TIM11_HSE))))
191 #endif /* SPDIFRX */
192 
193 /**
194   * @}
195   */
196 /* End of private macro ------------------------------------------------------*/
197 
198 /* Exported functions --------------------------------------------------------*/
199 /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
200   * @{
201   */
202 
203 /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
204   *  @brief    Timer Hall Sensor functions
205   * @{
206   */
207 /*  Timer Hall Sensor functions  **********************************************/
208 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig);
209 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
210 
211 void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
212 void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
213 
214 /* Blocking mode: Polling */
215 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
216 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
217 /* Non-Blocking mode: Interrupt */
218 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
219 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
220 /* Non-Blocking mode: DMA */
221 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
222 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
223 /**
224   * @}
225   */
226 
227 /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
228   *  @brief   Timer Complementary Output Compare functions
229   * @{
230   */
231 /*  Timer Complementary Output Compare functions  *****************************/
232 /* Blocking mode: Polling */
233 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
234 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
235 
236 /* Non-Blocking mode: Interrupt */
237 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
238 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
239 
240 /* Non-Blocking mode: DMA */
241 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
242 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
243 /**
244   * @}
245   */
246 
247 /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
248   *  @brief    Timer Complementary PWM functions
249   * @{
250   */
251 /*  Timer Complementary PWM functions  ****************************************/
252 /* Blocking mode: Polling */
253 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
254 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
255 
256 /* Non-Blocking mode: Interrupt */
257 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
258 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
259 /* Non-Blocking mode: DMA */
260 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, 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                                                         TIM_MasterConfigTypeDef *sMasterConfig);
295 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
296                                                 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
297 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
298 /**
299   * @}
300   */
301 
302 /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
303   * @brief    Extended Callbacks functions
304   * @{
305   */
306 /* Extended Callback **********************************************************/
307 void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
308 void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
309 void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
310 /**
311   * @}
312   */
313 
314 /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
315   * @brief    Extended Peripheral State functions
316   * @{
317   */
318 /* Extended Peripheral State functions  ***************************************/
319 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim);
320 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(TIM_HandleTypeDef *htim,  uint32_t ChannelN);
321 /**
322   * @}
323   */
324 
325 /**
326   * @}
327   */
328 /* End of exported functions -------------------------------------------------*/
329 
330 /* Private functions----------------------------------------------------------*/
331 /** @addtogroup TIMEx_Private_Functions TIM Extended Private Functions
332   * @{
333   */
334 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
335 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
336 /**
337   * @}
338   */
339 /* End of private functions --------------------------------------------------*/
340 
341 /**
342   * @}
343   */
344 
345 /**
346   * @}
347   */
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 
353 
354 #endif /* STM32F4xx_HAL_TIM_EX_H */
355