1 /**
2   ******************************************************************************
3   * @file    stm32g0xx_hal_exti.h
4   * @author  MCD Application Team
5   * @brief   Header file of EXTI HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2018 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 STM32G0xx_HAL_EXTI_H
21 #define STM32G0xx_HAL_EXTI_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g0xx_hal_def.h"
29 
30 /** @addtogroup STM32G0xx_HAL_Driver
31   * @{
32   */
33 
34 /** @defgroup EXTI EXTI
35   * @brief EXTI HAL module driver
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 
41 /** @defgroup EXTI_Exported_Types EXTI Exported Types
42   * @{
43   */
44 typedef enum
45 {
46   HAL_EXTI_COMMON_CB_ID          = 0x00U,
47   HAL_EXTI_RISING_CB_ID          = 0x01U,
48   HAL_EXTI_FALLING_CB_ID         = 0x02U,
49 } EXTI_CallbackIDTypeDef;
50 
51 
52 /**
53   * @brief  EXTI Handle structure definition
54   */
55 typedef struct
56 {
57   uint32_t Line;                    /*!<  Exti line number */
58   void (* RisingCallback)(void);    /*!<  Exti rising callback */
59   void (* FallingCallback)(void);   /*!<  Exti falling callback */
60 } EXTI_HandleTypeDef;
61 
62 /**
63   * @brief  EXTI Configuration structure definition
64   */
65 typedef struct
66 {
67   uint32_t Line;      /*!< The Exti line to be configured. This parameter
68                            can be a value of @ref EXTI_Line */
69   uint32_t Mode;      /*!< The Exit Mode to be configured for a core.
70                            This parameter can be a combination of @ref EXTI_Mode */
71   uint32_t Trigger;   /*!< The Exti Trigger to be configured. This parameter
72                            can be a value of @ref EXTI_Trigger */
73   uint32_t GPIOSel;   /*!< The Exti GPIO multiplexer selection to be configured.
74                            This parameter is only possible for line 0 to 15. It
75                            can be a value of @ref EXTI_GPIOSel */
76 } EXTI_ConfigTypeDef;
77 
78 /**
79   * @}
80   */
81 
82 /* Exported constants --------------------------------------------------------*/
83 /** @defgroup EXTI_Exported_Constants EXTI Exported Constants
84   * @{
85   */
86 
87 /** @defgroup EXTI_Line  EXTI Line
88   * @{
89   */
90 #define EXTI_LINE_0                         (EXTI_GPIO     | EXTI_REG1 | 0x00u)
91 #define EXTI_LINE_1                         (EXTI_GPIO     | EXTI_REG1 | 0x01u)
92 #define EXTI_LINE_2                         (EXTI_GPIO     | EXTI_REG1 | 0x02u)
93 #define EXTI_LINE_3                         (EXTI_GPIO     | EXTI_REG1 | 0x03u)
94 #define EXTI_LINE_4                         (EXTI_GPIO     | EXTI_REG1 | 0x04u)
95 #define EXTI_LINE_5                         (EXTI_GPIO     | EXTI_REG1 | 0x05u)
96 #define EXTI_LINE_6                         (EXTI_GPIO     | EXTI_REG1 | 0x06u)
97 #define EXTI_LINE_7                         (EXTI_GPIO     | EXTI_REG1 | 0x07u)
98 #define EXTI_LINE_8                         (EXTI_GPIO     | EXTI_REG1 | 0x08u)
99 #define EXTI_LINE_9                         (EXTI_GPIO     | EXTI_REG1 | 0x09u)
100 #define EXTI_LINE_10                        (EXTI_GPIO     | EXTI_REG1 | 0x0Au)
101 #define EXTI_LINE_11                        (EXTI_GPIO     | EXTI_REG1 | 0x0Bu)
102 #define EXTI_LINE_12                        (EXTI_GPIO     | EXTI_REG1 | 0x0Cu)
103 #define EXTI_LINE_13                        (EXTI_GPIO     | EXTI_REG1 | 0x0Du)
104 #define EXTI_LINE_14                        (EXTI_GPIO     | EXTI_REG1 | 0x0Eu)
105 #define EXTI_LINE_15                        (EXTI_GPIO     | EXTI_REG1 | 0x0Fu)
106 #define EXTI_LINE_16                        (EXTI_CONFIG   | EXTI_REG1 | 0x10u)
107 #if defined(COMP1)
108 #define EXTI_LINE_17                        (EXTI_CONFIG   | EXTI_REG1 | 0x11u)
109 #else
110 #define EXTI_LINE_17                        (EXTI_RESERVED | EXTI_REG1 | 0x11u)
111 #endif /* COMP1 */
112 #if defined(COMP2)
113 #define EXTI_LINE_18                        (EXTI_CONFIG   | EXTI_REG1 | 0x12u)
114 #else
115 #define EXTI_LINE_18                        (EXTI_RESERVED | EXTI_REG1 | 0x12u)
116 #endif /* COMP2 */
117 #define EXTI_LINE_19                        (EXTI_DIRECT   | EXTI_REG1 | 0x13u)
118 #if defined(COMP3)
119 #define EXTI_LINE_20                        (EXTI_CONFIG   | EXTI_REG1 | 0x14u)
120 #else
121 #define EXTI_LINE_20                        (EXTI_RESERVED | EXTI_REG1 | 0x14u)
122 #endif /* COMP3 */
123 #define EXTI_LINE_21                        (EXTI_DIRECT   | EXTI_REG1 | 0x15u)
124 #if defined(RCC_CCIPR_I2C2SEL)
125 #define EXTI_LINE_22                        (EXTI_DIRECT   | EXTI_REG1 | 0x16u)
126 #else
127 #define EXTI_LINE_22                        (EXTI_RESERVED | EXTI_REG1 | 0x16u)
128 #endif /* RCC_CCIPR_I2C2SEL */
129 #define EXTI_LINE_23                        (EXTI_DIRECT   | EXTI_REG1 | 0x17u)
130 #if defined(RCC_CCIPR_USART3SEL)
131 #define EXTI_LINE_24                        (EXTI_DIRECT   | EXTI_REG1 | 0x18u)
132 #else
133 #define EXTI_LINE_24                        (EXTI_RESERVED | EXTI_REG1 | 0x18u)
134 #endif /* RCC_CCIPR_USART3SEL */
135 #define EXTI_LINE_25                        (EXTI_DIRECT   | EXTI_REG1 | 0x19u)
136 #if defined(RCC_CCIPR_USART2SEL)
137 #define EXTI_LINE_26                        (EXTI_DIRECT   | EXTI_REG1 | 0x1Au)
138 #else
139 #define EXTI_LINE_26                        (EXTI_RESERVED | EXTI_REG1 | 0x1Au)
140 #endif /* RCC_CCIPR_USART2SEL */
141 #if defined(CEC)
142 #define EXTI_LINE_27                        (EXTI_DIRECT   | EXTI_REG1 | 0x1Bu)
143 #else
144 #define EXTI_LINE_27                        (EXTI_RESERVED | EXTI_REG1 | 0x1Bu)
145 #endif /* CEC */
146 #if defined(LPUART1)
147 #define EXTI_LINE_28                        (EXTI_DIRECT   | EXTI_REG1 | 0x1Cu)
148 #else
149 #define EXTI_LINE_28                        (EXTI_RESERVED | EXTI_REG1 | 0x1Cu)
150 #endif /* LPUART1 */
151 #if defined(LPTIM1)
152 #define EXTI_LINE_29                        (EXTI_DIRECT   | EXTI_REG1 | 0x1Du)
153 #else
154 #define EXTI_LINE_29                        (EXTI_RESERVED | EXTI_REG1 | 0x1Du)
155 #endif /* LPTIM1 */
156 #if defined(LPTIM2)
157 #define EXTI_LINE_30                        (EXTI_DIRECT   | EXTI_REG1 | 0x1Eu)
158 #else
159 #define EXTI_LINE_30                        (EXTI_RESERVED | EXTI_REG1 | 0x1Eu)
160 #endif /* LPTIM2 */
161 #define EXTI_LINE_31                        (EXTI_DIRECT   | EXTI_REG1 | 0x1Fu)
162 #if defined(UCPD1)
163 #define EXTI_LINE_32                        (EXTI_DIRECT   | EXTI_REG2 | 0x00u)
164 #else
165 #define EXTI_LINE_32                        (EXTI_RESERVED | EXTI_REG2 | 0x00u)
166 #endif /* UCPD1 */
167 #if defined(UCPD2)
168 #define EXTI_LINE_33                        (EXTI_DIRECT   | EXTI_REG2 | 0x01u)
169 #else
170 #define EXTI_LINE_33                        (EXTI_RESERVED | EXTI_REG2 | 0x01u)
171 #endif /* UCPD2 */
172 #if defined(STM32G0C1xx) || defined(STM32G0B1xx)
173 #define EXTI_LINE_34                        (EXTI_CONFIG   | EXTI_REG2 | 0x02u)
174 #else
175 #define EXTI_LINE_34                        (EXTI_RESERVED | EXTI_REG2 | 0x02u)
176 #endif /* STM32G0C1xx || STM32G0B1xx */
177 #if defined(LPUART2)
178 #define EXTI_LINE_35                        (EXTI_DIRECT   | EXTI_REG2 | 0x03u)
179 #else
180 #define EXTI_LINE_35                        (EXTI_RESERVED | EXTI_REG2 | 0x03u)
181 #endif /* LPUART2 */
182 #if defined(STM32G0C1xx) || defined(STM32G0B1xx) || defined(STM32G0B0xx)
183 #define EXTI_LINE_36                        (EXTI_DIRECT | EXTI_REG2 | 0x04u)
184 #endif /* STM32G0C1xx || STM32G0B1xx || STM32G0B0xx */
185 /**
186   * @}
187   */
188 
189 /** @defgroup EXTI_Mode  EXTI Mode
190   * @{
191   */
192 #define EXTI_MODE_NONE                      0x00000000u
193 #define EXTI_MODE_INTERRUPT                 0x00000001u
194 #define EXTI_MODE_EVENT                     0x00000002u
195 /**
196   * @}
197   */
198 
199 /** @defgroup EXTI_Trigger  EXTI Trigger
200   * @{
201   */
202 #define EXTI_TRIGGER_NONE                   0x00000000u
203 #define EXTI_TRIGGER_RISING                 0x00000001u
204 #define EXTI_TRIGGER_FALLING                0x00000002u
205 #define EXTI_TRIGGER_RISING_FALLING         (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING)
206 /**
207   * @}
208   */
209 
210 /** @defgroup EXTI_GPIOSel  EXTI GPIOSel
211   * @brief
212   * @{
213   */
214 #define EXTI_GPIOA                          0x00000000u
215 #define EXTI_GPIOB                          0x00000001u
216 #define EXTI_GPIOC                          0x00000002u
217 #define EXTI_GPIOD                          0x00000003u
218 #if defined(GPIOE)
219 #define EXTI_GPIOE                          0x00000004u
220 #endif /* GPIOE */
221 #define EXTI_GPIOF                          0x00000005u
222 /**
223   * @}
224   */
225 
226 /**
227   * @}
228   */
229 
230 /* Exported macro ------------------------------------------------------------*/
231 /** @defgroup EXTI_Exported_Macros EXTI Exported Macros
232   * @{
233   */
234 
235 /**
236   * @}
237   */
238 
239 /* Private constants --------------------------------------------------------*/
240 /** @defgroup EXTI_Private_Constants EXTI Private Constants
241   * @{
242   */
243 /**
244   * @brief  EXTI Line property definition
245   */
246 #define EXTI_PROPERTY_SHIFT                  24u
247 #define EXTI_DIRECT                         (0x01uL << EXTI_PROPERTY_SHIFT)
248 #define EXTI_CONFIG                         (0x02uL << EXTI_PROPERTY_SHIFT)
249 #define EXTI_GPIO                           ((0x04uL << EXTI_PROPERTY_SHIFT) | EXTI_CONFIG)
250 #define EXTI_RESERVED                       (0x08uL << EXTI_PROPERTY_SHIFT)
251 #define EXTI_PROPERTY_MASK                  (EXTI_DIRECT | EXTI_CONFIG | EXTI_GPIO)
252 
253 /**
254   * @brief  EXTI Register and bit usage
255   */
256 #define EXTI_REG_SHIFT                      16u
257 #define EXTI_REG1                           (0x00uL << EXTI_REG_SHIFT)
258 #define EXTI_REG2                           (0x01uL << EXTI_REG_SHIFT)
259 #define EXTI_REG_MASK                       (EXTI_REG1 | EXTI_REG2)
260 #define EXTI_PIN_MASK                       0x0000001Fu
261 
262 /**
263   * @brief  EXTI Mask for interrupt & event mode
264   */
265 #define EXTI_MODE_MASK                      (EXTI_MODE_EVENT | EXTI_MODE_INTERRUPT)
266 
267 /**
268   * @brief  EXTI Mask for trigger possibilities
269   */
270 #define EXTI_TRIGGER_MASK                   (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING)
271 
272 /**
273   * @brief  EXTI Line number
274   */
275 #if defined(STM32G0C1xx) || defined(STM32G0B1xx)
276 #define EXTI_LINE_NB                        37uL
277 #elif defined(STM32G0B0xx)
278 #define EXTI_LINE_NB                        37uL
279 #elif defined(STM32G081xx) || defined(STM32G071xx)
280 #define EXTI_LINE_NB                        34uL
281 #elif defined(STM32G070xx)
282 #define EXTI_LINE_NB                        34uL
283 #elif defined(STM32G041xx) || defined(STM32G031xx)
284 #define EXTI_LINE_NB                        32uL
285 #else
286 #define EXTI_LINE_NB                        32uL
287 #endif /* STM32G0C1xx || STM32G0B1xx */
288 
289 /**
290   * @}
291   */
292 
293 /* Private macros ------------------------------------------------------------*/
294 /** @defgroup EXTI_Private_Macros EXTI Private Macros
295   * @{
296   */
297 #define IS_EXTI_LINE(__EXTI_LINE__)     ((((__EXTI_LINE__) & ~(EXTI_PROPERTY_MASK | EXTI_REG_MASK | EXTI_PIN_MASK)) == 0x00u) && \
298                                         ((((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_DIRECT)   || \
299                                          (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_CONFIG)   || \
300                                          (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_GPIO))    && \
301                                          (((__EXTI_LINE__) & (EXTI_REG_MASK | EXTI_PIN_MASK))      < \
302                                          (((EXTI_LINE_NB / 32u) << EXTI_REG_SHIFT) | (EXTI_LINE_NB % 32u))))
303 
304 #define IS_EXTI_MODE(__MODE__)          ((((__MODE__) & EXTI_MODE_MASK) != 0x00u) && \
305                                          (((__MODE__) & ~EXTI_MODE_MASK) == 0x00u))
306 
307 #define IS_EXTI_TRIGGER(__EXTI_LINE__)  (((__EXTI_LINE__) & ~EXTI_TRIGGER_MASK) == 0x00u)
308 
309 #define IS_EXTI_PENDING_EDGE(__EXTI_LINE__)  (((__EXTI_LINE__) == EXTI_TRIGGER_RISING) || \
310                                               ((__EXTI_LINE__) == EXTI_TRIGGER_FALLING))
311 
312 #define IS_EXTI_CONFIG_LINE(__EXTI_LINE__)   (((__EXTI_LINE__) & EXTI_CONFIG) != 0x00u)
313 
314 #if defined(GPIOE)
315 #define IS_EXTI_GPIO_PORT(__PORT__)     (((__PORT__) == EXTI_GPIOA) || \
316                                          ((__PORT__) == EXTI_GPIOB) || \
317                                          ((__PORT__) == EXTI_GPIOC) || \
318                                          ((__PORT__) == EXTI_GPIOD) || \
319                                          ((__PORT__) == EXTI_GPIOE) || \
320                                          ((__PORT__) == EXTI_GPIOF))
321 #else
322 #define IS_EXTI_GPIO_PORT(__PORT__)     (((__PORT__) == EXTI_GPIOA) || \
323                                          ((__PORT__) == EXTI_GPIOB) || \
324                                          ((__PORT__) == EXTI_GPIOC) || \
325                                          ((__PORT__) == EXTI_GPIOD) || \
326                                          ((__PORT__) == EXTI_GPIOF))
327 #endif /* GPIOE */
328 
329 #define IS_EXTI_GPIO_PIN(__PIN__)       ((__PIN__) < 16u)
330 
331 /**
332   * @}
333   */
334 
335 
336 /* Exported functions --------------------------------------------------------*/
337 /** @defgroup EXTI_Exported_Functions EXTI Exported Functions
338   * @brief    EXTI Exported Functions
339   * @{
340   */
341 
342 /** @defgroup EXTI_Exported_Functions_Group1 Configuration functions
343   * @brief    Configuration functions
344   * @{
345   */
346 /* Configuration functions ****************************************************/
347 HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig);
348 HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig);
349 HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti);
350 HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void));
351 HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine);
352 /**
353   * @}
354   */
355 
356 /** @defgroup EXTI_Exported_Functions_Group2 IO operation functions
357   * @brief    IO operation functions
358   * @{
359   */
360 /* IO operation functions *****************************************************/
361 void              HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti);
362 uint32_t          HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge);
363 void              HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge);
364 void              HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti);
365 
366 /**
367   * @}
368   */
369 
370 /**
371   * @}
372   */
373 
374 /**
375   * @}
376   */
377 
378 /**
379   * @}
380   */
381 
382 #ifdef __cplusplus
383 }
384 #endif
385 
386 #endif /* STM32G0xx_HAL_EXTI_H */
387 
388