1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_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) 2016 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 STM32F3xx_HAL_TIM_EX_H
22 #define STM32F3xx_HAL_TIM_EX_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32f3xx_hal_def.h"
30 
31 /** @addtogroup STM32F3xx_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   */
65 /* End of exported types -----------------------------------------------------*/
66 
67 /* Exported constants --------------------------------------------------------*/
68 /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants
69   * @{
70   */
71 
72 /** @defgroup TIMEx_Remap TIM Extended Remapping
73   * @{
74   */
75 #if defined(TIM1)
76 #define TIM_TIM1_ADC1_NONE                     (0x00000000U) /*!< TIM1_ETR is not connected to any AWD (analog watchdog)*/
77 #define TIM_TIM1_ADC1_AWD1                     (0x00000001U) /*!< TIM1_ETR is connected to ADC1 AWD1 */
78 #define TIM_TIM1_ADC1_AWD2                     (0x00000002U) /*!< TIM1_ETR is connected to ADC1 AWD2 */
79 #define TIM_TIM1_ADC1_AWD3                     (0x00000003U) /*!< TIM1_ETR is connected to ADC1 AWD3 */
80 
81 #if defined(ADC4)
82 #define TIM_TIM1_ADC4_NONE                     (0x00000000U) /*!< TIM1_ETR is not connected to any AWD (analog watchdog)*/
83 #define TIM_TIM1_ADC4_AWD1                     (0x00000004U) /*!< TIM1_ETR is connected to ADC4 AWD1 */
84 #define TIM_TIM1_ADC4_AWD2                     (0x00000008U) /*!< TIM1_ETR is connected to ADC4 AWD2 */
85 #define TIM_TIM1_ADC4_AWD3                     (0x0000000CU) /*!< TIM1_ETR is connected to ADC4 AWD3 */
86 #elif defined(ADC2)
87 #define TIM_TIM1_ADC2_NONE                     (0x00000000U) /*!< TIM1_ETR is not connected to any AWD (analog watchdog)*/
88 #define TIM_TIM1_ADC2_AWD1                     (0x00000004U) /*!< TIM1_ETR is connected to ADC2 AWD1 */
89 #define TIM_TIM1_ADC2_AWD2                     (0x00000008U) /*!< TIM1_ETR is connected to ADC2 AWD2 */
90 #define TIM_TIM1_ADC2_AWD3                     (0x0000000CU) /*!< TIM1_ETR is connected to ADC2 AWD3 */
91 #endif /* ADC4 */
92 #endif /* TIM1 */
93 
94 #if defined(TIM8)
95 #define TIM_TIM8_ADC2_NONE                     (0x00000000U) /*!< TIM8_ETR is not connected to any AWD (analog watchdog) */
96 #define TIM_TIM8_ADC2_AWD1                     (0x00000001U) /*!< TIM8_ETR is connected to ADC2 AWD1 */
97 #define TIM_TIM8_ADC2_AWD2                     (0x00000002U) /*!< TIM8_ETR is connected to ADC2 AWD2 */
98 #define TIM_TIM8_ADC2_AWD3                     (0x00000003U) /*!< TIM8_ETR is connected to ADC2 AWD3 */
99 
100 #define TIM_TIM8_ADC3_NONE                     (0x00000000U) /*!< TIM8_ETR is not connected to any AWD (analog watchdog) */
101 #define TIM_TIM8_ADC3_AWD1                     (0x00000004U) /*!< TIM8_ETR is connected to ADC3 AWD1 */
102 #define TIM_TIM8_ADC3_AWD2                     (0x00000008U) /*!< TIM8_ETR is connected to ADC3 AWD2 */
103 #define TIM_TIM8_ADC3_AWD3                     (0x0000000CU) /*!< TIM8_ETR is connected to ADC3 AWD3 */
104 #endif /* TIM8 */
105 
106 #if defined(TIM14)
107 #define TIM_TIM14_GPIO                         (0x00000000U) /*!< TIM14 TI1 is connected to GPIO */
108 #define TIM_TIM14_RTC                          (0x00000001U) /*!< TIM14 TI1 is connected to RTC_clock */
109 #define TIM_TIM14_HSE                          (0x00000002U) /*!< TIM14 TI1 is connected to HSE/32U */
110 #define TIM_TIM14_MCO                          (0x00000003U) /*!< TIM14 TI1 is connected to MCO */
111 #endif /* TIM14 */
112 
113 #if defined(TIM16)
114 #define TIM_TIM16_GPIO                         (0x00000000U) /*!< TIM16 TI1 is connected to GPIO */
115 #define TIM_TIM16_RTC                          (0x00000001U) /*!< TIM16 TI1 is connected to RTC_clock */
116 #define TIM_TIM16_HSE                          (0x00000002U) /*!< TIM16 TI1 is connected to HSE/32 */
117 #define TIM_TIM16_MCO                          (0x00000003U) /*!< TIM16 TI1 is connected to MCO */
118 #endif /* TIM16 */
119 
120 #if defined(TIM20)
121 #define TIM_TIM20_ADC3_NONE                    (0x00000000U) /*!< TIM20_ETR is not connected to any AWD (analog watchdog) */
122 #define TIM_TIM20_ADC3_AWD1                    (0x00000001U) /*!< TIM20_ETR is connected to ADC3 AWD1 */
123 #define TIM_TIM20_ADC3_AWD2                    (0x00000002U) /*!< TIM20_ETR is connected to ADC3 AWD2 */
124 #define TIM_TIM20_ADC3_AWD3                    (0x00000003U) /*!< TIM20_ETR is connected to ADC3 AWD3 */
125 
126 #define TIM_TIM20_ADC4_NONE                    (0x00000000U) /*!< TIM20_ETR is not connected to any AWD (analog watchdog) */
127 #define TIM_TIM20_ADC4_AWD1                    (0x00000004U) /*!< TIM20_ETR is connected to ADC4 AWD1 */
128 #define TIM_TIM20_ADC4_AWD2                    (0x00000008U) /*!< TIM20_ETR is connected to ADC4 AWD2 */
129 #define TIM_TIM20_ADC4_AWD3                    (0x0000000CU) /*!< TIM20_ETR is connected to ADC4 AWD3 */
130 #endif /* TIM20 */
131 /**
132   * @}
133   */
134 
135 /**
136   * @}
137   */
138 /* End of exported constants -------------------------------------------------*/
139 
140 /* Exported macro ------------------------------------------------------------*/
141 /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
142   * @{
143   */
144 
145 /**
146   * @}
147   */
148 /* End of exported macro -----------------------------------------------------*/
149 
150 /* Private macro -------------------------------------------------------------*/
151 /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
152   * @{
153   */
154 #if defined(TIM1) && defined(TIM8) && defined(TIM20) && defined(TIM16)
155 #define IS_TIM_REMAP(__INSTANCE__, __REMAP__)                                        \
156   ((((__INSTANCE__) == TIM1)  && ((((__REMAP__) & 0xFFFFFFF0U) == 0x00000000U)))     \
157    || (((__INSTANCE__) == TIM8)  && ((((__REMAP__) & 0xFFFFFFF0U) == 0x00000000U)))  \
158    || (((__INSTANCE__) == TIM20) && ((((__REMAP__) & 0xFFFFFFF0U) == 0x00000000U)))  \
159    || (((__INSTANCE__) == TIM16) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))))
160 #elif defined(TIM1) && defined(TIM8) && defined(TIM16)
161 #define IS_TIM_REMAP(__INSTANCE__, __REMAP__)                                        \
162   ((((__INSTANCE__) == TIM1)  && ((((__REMAP__) & 0xFFFFFFF0U) == 0x00000000U)))     \
163    || (((__INSTANCE__) == TIM8)  && ((((__REMAP__) & 0xFFFFFFF0U) == 0x00000000U)))  \
164    || (((__INSTANCE__) == TIM16) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))))
165 #elif defined(TIM1) && defined(TIM16)
166 #define IS_TIM_REMAP(__INSTANCE__, __REMAP__)                                        \
167   ((((__INSTANCE__) == TIM1)  && ((((__REMAP__) & 0xFFFFFFF0U) == 0x00000000U)))     \
168    || (((__INSTANCE__) == TIM16) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))))
169 #elif defined(TIM14)
170 #define IS_TIM_REMAP(__INSTANCE__, __REMAP__)                                        \
171   (((__INSTANCE__) == TIM14)  && (((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))
172 #endif /* TIM1 && TIM8 && TIM20 && TIM16 */
173 
174 /**
175   * @}
176   */
177 /* End of private macro ------------------------------------------------------*/
178 
179 /* Exported functions --------------------------------------------------------*/
180 /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
181   * @{
182   */
183 
184 /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
185   *  @brief    Timer Hall Sensor functions
186   * @{
187   */
188 /*  Timer Hall Sensor functions  **********************************************/
189 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig);
190 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
191 
192 void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
193 void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
194 
195 /* Blocking mode: Polling */
196 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
197 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
198 /* Non-Blocking mode: Interrupt */
199 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
200 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
201 /* Non-Blocking mode: DMA */
202 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
203 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
204 /**
205   * @}
206   */
207 
208 /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
209   *  @brief   Timer Complementary Output Compare functions
210   * @{
211   */
212 /*  Timer Complementary Output Compare functions  *****************************/
213 /* Blocking mode: Polling */
214 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
215 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
216 
217 /* Non-Blocking mode: Interrupt */
218 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
219 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
220 
221 /* Non-Blocking mode: DMA */
222 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
223 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
224 /**
225   * @}
226   */
227 
228 /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
229   *  @brief    Timer Complementary PWM functions
230   * @{
231   */
232 /*  Timer Complementary PWM functions  ****************************************/
233 /* Blocking mode: Polling */
234 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
235 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
236 
237 /* Non-Blocking mode: Interrupt */
238 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
239 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
240 /* Non-Blocking mode: DMA */
241 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
242 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
243 /**
244   * @}
245   */
246 
247 /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
248   *  @brief    Timer Complementary One Pulse functions
249   * @{
250   */
251 /*  Timer Complementary One Pulse functions  **********************************/
252 /* Blocking mode: Polling */
253 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
254 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
255 
256 /* Non-Blocking mode: Interrupt */
257 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
258 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
259 /**
260   * @}
261   */
262 
263 /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
264   *  @brief    Peripheral Control functions
265   * @{
266   */
267 /* Extended Control functions  ************************************************/
268 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
269                                               uint32_t  CommutationSource);
270 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
271                                                  uint32_t  CommutationSource);
272 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
273                                                   uint32_t  CommutationSource);
274 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
275                                                         TIM_MasterConfigTypeDef *sMasterConfig);
276 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
277                                                 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
278 #if defined(TIM_CCR5_CCR5)
279 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels);
280 #endif /* TIM_CCR5_CCR5 */
281 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
282 /**
283   * @}
284   */
285 
286 /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
287   * @brief    Extended Callbacks functions
288   * @{
289   */
290 /* Extended Callback **********************************************************/
291 void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
292 void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
293 void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
294 #if defined(TIM_BDTR_BK2E)
295 void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim);
296 #endif /* TIM_BDTR_BK2E */
297 /**
298   * @}
299   */
300 
301 /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
302   * @brief    Extended Peripheral State functions
303   * @{
304   */
305 /* Extended Peripheral State functions  ***************************************/
306 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim);
307 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(TIM_HandleTypeDef *htim,  uint32_t ChannelN);
308 /**
309   * @}
310   */
311 
312 /**
313   * @}
314   */
315 /* End of exported functions -------------------------------------------------*/
316 
317 /* Private functions----------------------------------------------------------*/
318 /** @addtogroup TIMEx_Private_Functions TIMEx Private Functions
319   * @{
320   */
321 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
322 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
323 /**
324   * @}
325   */
326 /* End of private functions --------------------------------------------------*/
327 
328 /**
329   * @}
330   */
331 
332 /**
333   * @}
334   */
335 
336 #ifdef __cplusplus
337 }
338 #endif
339 
340 
341 #endif /* STM32F3xx_HAL_TIM_EX_H */
342 
343 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
344