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 #endif /*  TIM8 */
78 #define TIM_TIM2_ETH_PTP                       TIM_OR_ITR1_RMP_0                        /*!< TIM2 ITR1 is connected to PTP trigger output */
79 #define TIM_TIM2_USBFS_SOF                     TIM_OR_ITR1_RMP_1                        /*!< TIM2 ITR1 is connected to OTG FS SOF */
80 #define TIM_TIM2_USBHS_SOF                     (TIM_OR_ITR1_RMP_1 | TIM_OR_ITR1_RMP_0)  /*!< TIM2 ITR1 is connected to OTG HS SOF */
81 #endif /* TIM2 */
82 
83 #define TIM_TIM5_GPIO                          0x00000000U                              /*!< TIM5 TI4 is connected to GPIO */
84 #define TIM_TIM5_LSI                           TIM_OR_TI4_RMP_0                         /*!< TIM5 TI4 is connected to LSI */
85 #define TIM_TIM5_LSE                           TIM_OR_TI4_RMP_1                         /*!< TIM5 TI4 is connected to LSE */
86 #define TIM_TIM5_RTC                           (TIM_OR_TI4_RMP_1 | TIM_OR_TI4_RMP_0)    /*!< TIM5 TI4 is connected to the RTC wakeup interrupt */
87 
88 #define TIM_TIM11_GPIO                         0x00000000U                              /*!< TIM11 TI1 is connected to GPIO */
89 #define TIM_TIM11_HSE                          TIM_OR_TI1_RMP_1                         /*!< TIM11 TI1 is connected to HSE_RTC clock */
90 #if defined(SPDIFRX)
91 #define TIM_TIM11_SPDIFRX                      TIM_OR_TI1_RMP_0                         /*!< TIM11 TI1 is connected to SPDIFRX_FRAME_SYNC */
92 #endif /* SPDIFRX*/
93 
94 #if defined(LPTIM_OR_TIM1_ITR2_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP)
95 #define LPTIM_REMAP_MASK                       0x10000000U
96 
97 #define TIM_TIM9_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM9 ITR1 is connected to TIM3 TRGO */
98 #define TIM_TIM9_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM9_ITR1_RMP)  /*!< TIM9 ITR1 is connected to LPTIM1 output */
99 
100 #define TIM_TIM5_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM5 ITR1 is connected to TIM3 TRGO */
101 #define TIM_TIM5_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM5_ITR1_RMP)  /*!< TIM5 ITR1 is connected to LPTIM1 output */
102 
103 #define TIM_TIM1_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM1 ITR2 is connected to TIM3 TRGO */
104 #define TIM_TIM1_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM1_ITR2_RMP)  /*!< TIM1 ITR2 is connected to LPTIM1 output */
105 #endif /* LPTIM_OR_TIM1_ITR2_RMP &&  LPTIM_OR_TIM5_ITR1_RMP && LPTIM_OR_TIM5_ITR1_RMP */
106 /**
107   * @}
108   */
109 
110 /**
111   * @}
112   */
113 /* End of exported constants -------------------------------------------------*/
114 
115 /* Exported macro ------------------------------------------------------------*/
116 /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
117   * @{
118   */
119 
120 /**
121   * @}
122   */
123 /* End of exported macro -----------------------------------------------------*/
124 
125 /* Private macro -------------------------------------------------------------*/
126 /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
127   * @{
128   */
129 #if defined(SPDIFRX)
130 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
131   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
132                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
133                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
134    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
135                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
136                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
137                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
138    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
139                               ((TIM_REMAP) == TIM_TIM11_SPDIFRX)       || \
140                               ((TIM_REMAP) == TIM_TIM11_HSE))))
141 #elif defined(TIM2)
142 #if defined(LPTIM_OR_TIM1_ITR2_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP)
143 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
144   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
145                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
146                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
147    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
148                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
149                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
150                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
151    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
152                               ((TIM_REMAP) == TIM_TIM11_HSE)))         || \
153    (((INSTANCE) == TIM1)  && (((TIM_REMAP) == TIM_TIM1_TIM3_TRGO)      || \
154                               ((TIM_REMAP) == TIM_TIM1_LPTIM)))        || \
155    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_TIM3_TRGO)      || \
156                               ((TIM_REMAP) == TIM_TIM5_LPTIM)))        || \
157    (((INSTANCE) == TIM9)  && (((TIM_REMAP) == TIM_TIM9_TIM3_TRGO)      || \
158                               ((TIM_REMAP) == TIM_TIM9_LPTIM))))
159 #elif defined(TIM8)
160 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
161   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
162                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
163                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
164    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
165                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
166                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
167                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
168    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
169                               ((TIM_REMAP) == TIM_TIM11_HSE))))
170 #else
171 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
172   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_ETH_PTP)        || \
173                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
174                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
175    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
176                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
177                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
178                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
179    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
180                               ((TIM_REMAP) == TIM_TIM11_HSE))))
181 #endif /* LPTIM_OR_TIM1_ITR2_RMP &&  LPTIM_OR_TIM5_ITR1_RMP && LPTIM_OR_TIM5_ITR1_RMP */
182 #else
183 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
184   ((((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
185                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
186                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
187                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
188    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
189                               ((TIM_REMAP) == TIM_TIM11_HSE))))
190 #endif /* SPDIFRX */
191 
192 /**
193   * @}
194   */
195 /* End of private macro ------------------------------------------------------*/
196 
197 /* Exported functions --------------------------------------------------------*/
198 /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
199   * @{
200   */
201 
202 /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
203   *  @brief    Timer Hall Sensor functions
204   * @{
205   */
206 /*  Timer Hall Sensor functions  **********************************************/
207 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, const TIM_HallSensor_InitTypeDef *sConfig);
208 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
209 
210 void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
211 void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
212 
213 /* Blocking mode: Polling */
214 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
215 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
216 /* Non-Blocking mode: Interrupt */
217 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
218 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
219 /* Non-Blocking mode: DMA */
220 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
221 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
222 /**
223   * @}
224   */
225 
226 /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
227   *  @brief   Timer Complementary Output Compare functions
228   * @{
229   */
230 /*  Timer Complementary Output Compare functions  *****************************/
231 /* Blocking mode: Polling */
232 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
233 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
234 
235 /* Non-Blocking mode: Interrupt */
236 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
237 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
238 
239 /* Non-Blocking mode: DMA */
240 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
241                                           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, const uint32_t *pData,
261                                            uint16_t Length);
262 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
263 /**
264   * @}
265   */
266 
267 /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
268   *  @brief    Timer Complementary One Pulse functions
269   * @{
270   */
271 /*  Timer Complementary One Pulse functions  **********************************/
272 /* Blocking mode: Polling */
273 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
274 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
275 
276 /* Non-Blocking mode: Interrupt */
277 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
278 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
279 /**
280   * @}
281   */
282 
283 /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
284   *  @brief    Peripheral Control functions
285   * @{
286   */
287 /* Extended Control functions  ************************************************/
288 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
289                                               uint32_t  CommutationSource);
290 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
291                                                  uint32_t  CommutationSource);
292 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
293                                                   uint32_t  CommutationSource);
294 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
295                                                         const TIM_MasterConfigTypeDef *sMasterConfig);
296 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
297                                                 const TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
298 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
299 /**
300   * @}
301   */
302 
303 /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
304   * @brief    Extended Callbacks functions
305   * @{
306   */
307 /* Extended Callback **********************************************************/
308 void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
309 void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
310 void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
311 /**
312   * @}
313   */
314 
315 /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
316   * @brief    Extended Peripheral State functions
317   * @{
318   */
319 /* Extended Peripheral State functions  ***************************************/
320 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(const TIM_HandleTypeDef *htim);
321 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(const TIM_HandleTypeDef *htim,  uint32_t ChannelN);
322 /**
323   * @}
324   */
325 
326 /**
327   * @}
328   */
329 /* End of exported functions -------------------------------------------------*/
330 
331 /* Private functions----------------------------------------------------------*/
332 /** @addtogroup TIMEx_Private_Functions TIM Extended Private Functions
333   * @{
334   */
335 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
336 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
337 /**
338   * @}
339   */
340 /* End of private functions --------------------------------------------------*/
341 
342 /**
343   * @}
344   */
345 
346 /**
347   * @}
348   */
349 
350 #ifdef __cplusplus
351 }
352 #endif
353 
354 
355 #endif /* STM32F4xx_HAL_TIM_EX_H */
356