1 /** 2 ****************************************************************************** 3 * @file stm32g4xx_hal_exti.h 4 * @author MCD Application Team 5 * @brief Header file of EXTI HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2019 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 STM32G4xx_HAL_EXTI_H 21 #define STM32G4xx_HAL_EXTI_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32g4xx_hal_def.h" 29 30 /** @addtogroup STM32G4xx_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 = 0x00UL 47 } EXTI_CallbackIDTypeDef; 48 49 50 /** 51 * @brief EXTI Handle structure definition 52 */ 53 typedef struct 54 { 55 uint32_t Line; /*!< Exti line number */ 56 void (* PendingCallback)(void); /*!< Exti pending callback */ 57 } EXTI_HandleTypeDef; 58 59 /** 60 * @brief EXTI Configuration structure definition 61 */ 62 typedef struct 63 { 64 uint32_t Line; /*!< The Exti line to be configured. This parameter 65 can be a value of @ref EXTI_Line */ 66 uint32_t Mode; /*!< The Exit Mode to be configured for a core. 67 This parameter can be a combination of @ref EXTI_Mode */ 68 uint32_t Trigger; /*!< The Exti Trigger to be configured. This parameter 69 can be a value of @ref EXTI_Trigger */ 70 uint32_t GPIOSel; /*!< The Exti GPIO multiplexer selection to be configured. 71 This parameter is only possible for line 0 to 15. It 72 can be a value of @ref EXTI_GPIOSel */ 73 } EXTI_ConfigTypeDef; 74 75 /** 76 * @} 77 */ 78 79 /* Exported constants --------------------------------------------------------*/ 80 /** @defgroup EXTI_Exported_Constants EXTI Exported Constants 81 * @{ 82 */ 83 84 /** @defgroup EXTI_Line EXTI Line 85 * @{ 86 */ 87 #define EXTI_LINE_0 (EXTI_GPIO | EXTI_REG1 | 0x00u) 88 #define EXTI_LINE_1 (EXTI_GPIO | EXTI_REG1 | 0x01u) 89 #define EXTI_LINE_2 (EXTI_GPIO | EXTI_REG1 | 0x02u) 90 #define EXTI_LINE_3 (EXTI_GPIO | EXTI_REG1 | 0x03u) 91 #define EXTI_LINE_4 (EXTI_GPIO | EXTI_REG1 | 0x04u) 92 #define EXTI_LINE_5 (EXTI_GPIO | EXTI_REG1 | 0x05u) 93 #define EXTI_LINE_6 (EXTI_GPIO | EXTI_REG1 | 0x06u) 94 #define EXTI_LINE_7 (EXTI_GPIO | EXTI_REG1 | 0x07u) 95 #define EXTI_LINE_8 (EXTI_GPIO | EXTI_REG1 | 0x08u) 96 #define EXTI_LINE_9 (EXTI_GPIO | EXTI_REG1 | 0x09u) 97 #define EXTI_LINE_10 (EXTI_GPIO | EXTI_REG1 | 0x0Au) 98 #define EXTI_LINE_11 (EXTI_GPIO | EXTI_REG1 | 0x0Bu) 99 #define EXTI_LINE_12 (EXTI_GPIO | EXTI_REG1 | 0x0Cu) 100 #define EXTI_LINE_13 (EXTI_GPIO | EXTI_REG1 | 0x0Du) 101 #define EXTI_LINE_14 (EXTI_GPIO | EXTI_REG1 | 0x0Eu) 102 #define EXTI_LINE_15 (EXTI_GPIO | EXTI_REG1 | 0x0Fu) 103 #define EXTI_LINE_16 (EXTI_CONFIG | EXTI_REG1 | 0x10u) 104 #define EXTI_LINE_17 (EXTI_CONFIG | EXTI_REG1 | 0x11u) 105 #define EXTI_LINE_18 (EXTI_DIRECT | EXTI_REG1 | 0x12u) 106 #define EXTI_LINE_19 (EXTI_CONFIG | EXTI_REG1 | 0x13u) 107 #define EXTI_LINE_20 (EXTI_CONFIG | EXTI_REG1 | 0x14u) 108 #define EXTI_LINE_21 (EXTI_CONFIG | EXTI_REG1 | 0x15u) 109 #define EXTI_LINE_22 (EXTI_CONFIG | EXTI_REG1 | 0x16u) 110 #define EXTI_LINE_23 (EXTI_DIRECT | EXTI_REG1 | 0x17u) 111 #define EXTI_LINE_24 (EXTI_DIRECT | EXTI_REG1 | 0x18u) 112 #define EXTI_LINE_25 (EXTI_DIRECT | EXTI_REG1 | 0x19u) 113 #define EXTI_LINE_26 (EXTI_DIRECT | EXTI_REG1 | 0x1Au) 114 #define EXTI_LINE_27 (EXTI_DIRECT | EXTI_REG1 | 0x1Bu) 115 #define EXTI_LINE_28 (EXTI_DIRECT | EXTI_REG1 | 0x1Cu) 116 #define EXTI_LINE_29 (EXTI_CONFIG | EXTI_REG1 | 0x1Du) 117 #define EXTI_LINE_30 (EXTI_CONFIG | EXTI_REG1 | 0x1Eu) 118 #define EXTI_LINE_31 (EXTI_CONFIG | EXTI_REG1 | 0x1Fu) 119 #define EXTI_LINE_32 (EXTI_CONFIG | EXTI_REG2 | 0x00u) 120 #define EXTI_LINE_33 (EXTI_CONFIG | EXTI_REG2 | 0x01u) 121 #define EXTI_LINE_34 (EXTI_DIRECT | EXTI_REG2 | 0x02u) 122 #define EXTI_LINE_35 (EXTI_DIRECT | EXTI_REG2 | 0x03u) 123 #define EXTI_LINE_36 (EXTI_DIRECT | EXTI_REG2 | 0x04u) 124 #define EXTI_LINE_37 (EXTI_DIRECT | EXTI_REG2 | 0x05u) 125 #define EXTI_LINE_38 (EXTI_CONFIG | EXTI_REG2 | 0x06u) 126 #define EXTI_LINE_39 (EXTI_CONFIG | EXTI_REG2 | 0x07u) 127 #define EXTI_LINE_40 (EXTI_CONFIG | EXTI_REG2 | 0x08u) 128 #define EXTI_LINE_41 (EXTI_CONFIG | EXTI_REG2 | 0x09u) 129 #define EXTI_LINE_42 (EXTI_DIRECT | EXTI_REG2 | 0x0Au) 130 #define EXTI_LINE_43 (EXTI_DIRECT | EXTI_REG2 | 0x0Bu) 131 /** 132 * @} 133 */ 134 135 /** @defgroup EXTI_Mode EXTI Mode 136 * @{ 137 */ 138 #define EXTI_MODE_NONE 0x00000000U 139 #define EXTI_MODE_INTERRUPT 0x00000001U 140 #define EXTI_MODE_EVENT 0x00000002U 141 /** 142 * @} 143 */ 144 145 /** @defgroup EXTI_Trigger EXTI Trigger 146 * @{ 147 */ 148 #define EXTI_TRIGGER_NONE 0x00000000U 149 #define EXTI_TRIGGER_RISING 0x00000001U 150 #define EXTI_TRIGGER_FALLING 0x00000002U 151 #define EXTI_TRIGGER_RISING_FALLING (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 152 /** 153 * @} 154 */ 155 156 /** @defgroup EXTI_GPIOSel EXTI GPIOSel 157 * @brief 158 * @{ 159 */ 160 #define EXTI_GPIOA 0x00000000U 161 #define EXTI_GPIOB 0x00000001U 162 #define EXTI_GPIOC 0x00000002U 163 #define EXTI_GPIOD 0x00000003U 164 #define EXTI_GPIOE 0x00000004U 165 #define EXTI_GPIOF 0x00000005U 166 #define EXTI_GPIOG 0x00000006U 167 /** 168 * @} 169 */ 170 171 /** 172 * @} 173 */ 174 175 /* Exported macro ------------------------------------------------------------*/ 176 /** @defgroup EXTI_Exported_Macros EXTI Exported Macros 177 * @{ 178 */ 179 180 /** 181 * @} 182 */ 183 184 /* Private constants --------------------------------------------------------*/ 185 /** @defgroup EXTI_Private_Constants EXTI Private Constants 186 * @{ 187 */ 188 /** 189 * @brief EXTI Line property definition 190 */ 191 #define EXTI_PROPERTY_SHIFT 24U 192 #define EXTI_DIRECT (0x01uL << EXTI_PROPERTY_SHIFT) 193 #define EXTI_CONFIG (0x02uL << EXTI_PROPERTY_SHIFT) 194 #define EXTI_GPIO ((0x04uL << EXTI_PROPERTY_SHIFT) | EXTI_CONFIG) 195 #define EXTI_RESERVED (0x08uL << EXTI_PROPERTY_SHIFT) 196 #define EXTI_PROPERTY_MASK (EXTI_DIRECT | EXTI_CONFIG | EXTI_GPIO) 197 198 /** 199 * @brief EXTI Register and bit usage 200 */ 201 #define EXTI_REG_SHIFT 16U 202 #define EXTI_REG1 (0x00uL << EXTI_REG_SHIFT) 203 #define EXTI_REG2 (0x01uL << EXTI_REG_SHIFT) 204 #define EXTI_REG_MASK (EXTI_REG1 | EXTI_REG2) 205 #define EXTI_PIN_MASK 0x0000001FU 206 207 /** 208 * @brief EXTI Mask for interrupt & event mode 209 */ 210 #define EXTI_MODE_MASK (EXTI_MODE_EVENT | EXTI_MODE_INTERRUPT) 211 212 /** 213 * @brief EXTI Mask for trigger possibilities 214 */ 215 #define EXTI_TRIGGER_MASK (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 216 217 /** 218 * @brief EXTI Line number 219 */ 220 #define EXTI_LINE_NB 44UL 221 222 /** 223 * @} 224 */ 225 226 /* Private macros ------------------------------------------------------------*/ 227 /** @defgroup EXTI_Private_Macros EXTI Private Macros 228 * @{ 229 */ 230 #define IS_EXTI_LINE(__EXTI_LINE__) ((((__EXTI_LINE__) & ~(EXTI_PROPERTY_MASK | EXTI_REG_MASK | EXTI_PIN_MASK)) == 0x00U) && \ 231 ((((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_DIRECT) || \ 232 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_CONFIG) || \ 233 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_GPIO)) && \ 234 (((__EXTI_LINE__) & (EXTI_REG_MASK | EXTI_PIN_MASK)) < \ 235 (((EXTI_LINE_NB / 32u) << EXTI_REG_SHIFT) | (EXTI_LINE_NB % 32u)))) 236 237 #define IS_EXTI_MODE(__EXTI_LINE__) ((((__EXTI_LINE__) & EXTI_MODE_MASK) != 0x00U) && \ 238 (((__EXTI_LINE__) & ~EXTI_MODE_MASK) == 0x00U)) 239 240 #define IS_EXTI_TRIGGER(__EXTI_LINE__) (((__EXTI_LINE__) & ~EXTI_TRIGGER_MASK) == 0x00U) 241 242 #define IS_EXTI_CONFIG_LINE(__EXTI_LINE__) (((__EXTI_LINE__) & EXTI_CONFIG) != 0x00U) 243 244 #define IS_EXTI_GPIO_PORT(__PORT__) (((__PORT__) == EXTI_GPIOA) || \ 245 ((__PORT__) == EXTI_GPIOB) || \ 246 ((__PORT__) == EXTI_GPIOC) || \ 247 ((__PORT__) == EXTI_GPIOD) || \ 248 ((__PORT__) == EXTI_GPIOE) || \ 249 ((__PORT__) == EXTI_GPIOF) || \ 250 ((__PORT__) == EXTI_GPIOG)) 251 252 #define IS_EXTI_GPIO_PIN(__PIN__) ((__PIN__) < 16u) 253 254 #define IS_EXTI_PENDING_EDGE(__EDGE__) (((__EDGE__) == EXTI_TRIGGER_RISING) || \ 255 ((__EDGE__) == EXTI_TRIGGER_FALLING)|| \ 256 ((__EDGE__) == EXTI_TRIGGER_RISING_FALLING)) 257 258 #define IS_EXTI_CB(__CB__) ((__CB__) == HAL_EXTI_COMMON_CB_ID) 259 /** 260 * @} 261 */ 262 263 264 /* Exported functions --------------------------------------------------------*/ 265 /** @defgroup EXTI_Exported_Functions EXTI Exported Functions 266 * @brief EXTI Exported Functions 267 * @{ 268 */ 269 270 /** @defgroup EXTI_Exported_Functions_Group1 Configuration functions 271 * @brief Configuration functions 272 * @{ 273 */ 274 /* Configuration functions ****************************************************/ 275 HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 276 HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 277 HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti); 278 HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void)); 279 HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine); 280 /** 281 * @} 282 */ 283 284 /** @defgroup EXTI_Exported_Functions_Group2 IO operation functions 285 * @brief IO operation functions 286 * @{ 287 */ 288 /* IO operation functions *****************************************************/ 289 void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti); 290 uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge); 291 void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge); 292 void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti); 293 294 /** 295 * @} 296 */ 297 298 /** 299 * @} 300 */ 301 302 /** 303 * @} 304 */ 305 306 /** 307 * @} 308 */ 309 310 #ifdef __cplusplus 311 } 312 #endif 313 314 #endif /* STM32G4xx_HAL_EXTI_H */ 315 316