1 /** 2 ****************************************************************************** 3 * @file stm32h5xx_hal_exti.h 4 * @author MCD Application Team 5 * @brief Header file of EXTI HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2022 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 STM32H5xx_HAL_EXTI_H 21 #define STM32H5xx_HAL_EXTI_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32h5xx_hal_def.h" 29 30 /** @addtogroup STM32H5xx_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 #define EXTI_LINE_17 (EXTI_DIRECT | EXTI_REG1 | 0x11U) 108 #define EXTI_LINE_18 (EXTI_DIRECT | EXTI_REG1 | 0x12U) 109 #define EXTI_LINE_19 (EXTI_DIRECT | EXTI_REG1 | 0x13U) 110 #define EXTI_LINE_20 (EXTI_DIRECT | EXTI_REG1 | 0x14U) 111 #define EXTI_LINE_21 (EXTI_DIRECT | EXTI_REG1 | 0x15U) 112 #define EXTI_LINE_22 (EXTI_DIRECT | EXTI_REG1 | 0x16U) 113 #define EXTI_LINE_23 (EXTI_DIRECT | EXTI_REG1 | 0x17U) 114 #define EXTI_LINE_24 (EXTI_DIRECT | EXTI_REG1 | 0x18U) 115 #define EXTI_LINE_25 (EXTI_DIRECT | EXTI_REG1 | 0x19U) 116 #define EXTI_LINE_26 (EXTI_DIRECT | EXTI_REG1 | 0x1AU) 117 #define EXTI_LINE_27 (EXTI_DIRECT | EXTI_REG1 | 0x1BU) 118 #define EXTI_LINE_28 (EXTI_DIRECT | EXTI_REG1 | 0x1CU) 119 #define EXTI_LINE_29 (EXTI_DIRECT | EXTI_REG1 | 0x1DU) 120 #define EXTI_LINE_30 (EXTI_DIRECT | EXTI_REG1 | 0x1EU) 121 #define EXTI_LINE_31 (EXTI_DIRECT | EXTI_REG1 | 0x1FU) 122 #define EXTI_LINE_32 (EXTI_DIRECT | EXTI_REG2 | 0x00U) 123 #define EXTI_LINE_33 (EXTI_DIRECT | EXTI_REG2 | 0x01U) 124 #define EXTI_LINE_34 (EXTI_DIRECT | EXTI_REG2 | 0x02U) 125 #define EXTI_LINE_35 (EXTI_DIRECT | EXTI_REG2 | 0x03U) 126 #define EXTI_LINE_36 (EXTI_DIRECT | EXTI_REG2 | 0x04U) 127 #define EXTI_LINE_37 (EXTI_DIRECT | EXTI_REG2 | 0x05U) 128 #define EXTI_LINE_38 (EXTI_DIRECT | EXTI_REG2 | 0x06U) 129 #define EXTI_LINE_39 (EXTI_DIRECT | EXTI_REG2 | 0x07U) 130 #define EXTI_LINE_40 (EXTI_DIRECT | EXTI_REG2 | 0x08U) 131 #define EXTI_LINE_41 (EXTI_DIRECT | EXTI_REG2 | 0x09U) 132 #define EXTI_LINE_42 (EXTI_DIRECT | EXTI_REG2 | 0x0AU) 133 #define EXTI_LINE_43 (EXTI_DIRECT | EXTI_REG2 | 0x0BU) 134 #define EXTI_LINE_44 (EXTI_DIRECT | EXTI_REG2 | 0x0CU) 135 #define EXTI_LINE_45 (EXTI_DIRECT | EXTI_REG2 | 0x0DU) 136 #if defined(ETH) 137 #define EXTI_LINE_46 (EXTI_CONFIG | EXTI_REG2 | 0x0EU) 138 #endif /* ETH */ 139 #define EXTI_LINE_47 (EXTI_DIRECT | EXTI_REG2 | 0x0FU) 140 #define EXTI_LINE_48 (EXTI_DIRECT | EXTI_REG2 | 0x10U) 141 #define EXTI_LINE_49 (EXTI_DIRECT | EXTI_REG2 | 0x11U) 142 #define EXTI_LINE_50 (EXTI_CONFIG | EXTI_REG2 | 0x12U) 143 #define EXTI_LINE_51 (EXTI_DIRECT | EXTI_REG2 | 0x13U) 144 #define EXTI_LINE_52 (EXTI_DIRECT | EXTI_REG2 | 0x14U) 145 #define EXTI_LINE_53 (EXTI_CONFIG | EXTI_REG2 | 0x15U) 146 #define EXTI_LINE_54 (EXTI_DIRECT | EXTI_REG2 | 0x16U) 147 #define EXTI_LINE_55 (EXTI_DIRECT | EXTI_REG2 | 0x17U) 148 #define EXTI_LINE_56 (EXTI_DIRECT | EXTI_REG2 | 0x18U) 149 #define EXTI_LINE_57 (EXTI_DIRECT | EXTI_REG2 | 0x19U) 150 151 /** 152 * @} 153 */ 154 155 /** @defgroup EXTI_Mode EXTI Mode 156 * @{ 157 */ 158 #define EXTI_MODE_NONE 0x00000000U 159 #define EXTI_MODE_INTERRUPT 0x00000001U 160 #define EXTI_MODE_EVENT 0x00000002U 161 /** 162 * @} 163 */ 164 165 /** @defgroup EXTI_Trigger EXTI Trigger 166 * @{ 167 */ 168 #define EXTI_TRIGGER_NONE 0x00000000U 169 #define EXTI_TRIGGER_RISING 0x00000001U 170 #define EXTI_TRIGGER_FALLING 0x00000002U 171 #define EXTI_TRIGGER_RISING_FALLING (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 172 /** 173 * @} 174 */ 175 176 /** @defgroup EXTI_GPIOSel EXTI GPIOSel 177 * @brief 178 * @{ 179 */ 180 #define EXTI_GPIOA 0x00000000U 181 #define EXTI_GPIOB 0x00000001U 182 #define EXTI_GPIOC 0x00000002U 183 #define EXTI_GPIOD 0x00000003U 184 #define EXTI_GPIOE 0x00000004U 185 #define EXTI_GPIOF 0x00000005U 186 #define EXTI_GPIOG 0x00000006U 187 #define EXTI_GPIOH 0x00000007U 188 #define EXTI_GPIOI 0x00000008U 189 /** 190 * @} 191 */ 192 193 /** @defgroup EXTI_Line_attributes EXTI line attributes 194 * @brief EXTI line secure or non-secure and privileged or non-privileged attributes 195 * @note secure and non-secure attributes are only available from secure state when the system 196 * implement the security (TZEN=1) 197 * @{ 198 */ 199 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 200 /*!< Secure line attribute */ 201 #define EXTI_LINE_SEC (EXTI_LINE_ATTR_SEC_MASK | 0x00000001U) 202 /*!< Non-secure line attribute */ 203 #define EXTI_LINE_NSEC (EXTI_LINE_ATTR_SEC_MASK | 0x00000000U) 204 #endif /* __ARM_FEATURE_CMSE */ 205 /*!< Privileged line attribute */ 206 #define EXTI_LINE_PRIV (EXTI_LINE_ATTR_PRIV_MASK | 0x00000002U) 207 /*!< Non-privileged line attribute */ 208 #define EXTI_LINE_NPRIV (EXTI_LINE_ATTR_PRIV_MASK | 0x00000000U) 209 /** 210 * @} 211 */ 212 /** @defgroup EXTI_Security_Privilege_Configuration EXTI Security Privilege Configuration 213 * @brief EXTI security and privilege configurations 214 * @{ 215 */ 216 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 217 /* Security and privilege configuration open, can be modified */ 218 #define EXTI_ATTRIBUTES_UNLOCKED 0x00000000U 219 /* Security and privilege configuration locked, can no longer be modified */ 220 #define EXTI_ATTRIBUTES_LOCKED 0x00000001U 221 #endif /* __ARM_FEATURE_CMSE */ 222 /** 223 * @} 224 */ 225 /** 226 * @} 227 */ 228 229 /* Exported macro ------------------------------------------------------------*/ 230 /** @defgroup EXTI_Exported_Macros EXTI Exported Macros 231 * @{ 232 */ 233 234 /** 235 * @} 236 */ 237 238 /* Private constants --------------------------------------------------------*/ 239 /** @defgroup EXTI_Private_Constants EXTI Private Constants 240 * @{ 241 */ 242 /** 243 * @brief EXTI Line property definition 244 */ 245 #define EXTI_PROPERTY_SHIFT 24U 246 #define EXTI_DIRECT (0x01U << EXTI_PROPERTY_SHIFT) 247 #define EXTI_CONFIG (0x02U << EXTI_PROPERTY_SHIFT) 248 #define EXTI_GPIO ((0x04U << EXTI_PROPERTY_SHIFT) | EXTI_CONFIG) 249 #define EXTI_RESERVED (0x08U << EXTI_PROPERTY_SHIFT) 250 #define EXTI_PROPERTY_MASK (EXTI_DIRECT | EXTI_CONFIG | EXTI_GPIO) 251 252 /** 253 * @brief EXTI Register and bit usage 254 */ 255 #define EXTI_REG_SHIFT 16U 256 #define EXTI_REG1 (0x00U << EXTI_REG_SHIFT) 257 #define EXTI_REG2 (0x01U << EXTI_REG_SHIFT) 258 #define EXTI_REG_MASK (EXTI_REG1 | EXTI_REG2) 259 #define EXTI_PIN_MASK 0x0000001FU 260 261 /** 262 * @brief EXTI Mask for interrupt & event mode 263 */ 264 #define EXTI_MODE_MASK (EXTI_MODE_EVENT | EXTI_MODE_INTERRUPT) 265 266 /** 267 * @brief EXTI Mask for trigger possibilities 268 */ 269 #define EXTI_TRIGGER_MASK (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 270 271 /** 272 * @brief EXTI Line number 273 */ 274 #define EXTI_LINE_NB 58U 275 276 /** 277 * @brief EXTI Mask for secure & privilege attributes 278 */ 279 #define EXTI_LINE_ATTR_SEC_MASK 0x100U 280 #define EXTI_LINE_ATTR_PRIV_MASK 0x200U 281 /** 282 * @} 283 */ 284 285 /* Private macros ------------------------------------------------------------*/ 286 /** @defgroup EXTI_Private_Macros EXTI Private Macros 287 * @{ 288 */ 289 #define IS_EXTI_LINE(__EXTI_LINE__) ((((__EXTI_LINE__) & ~(EXTI_PROPERTY_MASK | \ 290 EXTI_REG_MASK | EXTI_PIN_MASK)) == 0x00U) \ 291 &&((((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_DIRECT) || \ 292 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_CONFIG) || \ 293 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_GPIO)) && \ 294 (((__EXTI_LINE__) & (EXTI_REG_MASK | EXTI_PIN_MASK)) < \ 295 (((EXTI_LINE_NB / 32U) << EXTI_REG_SHIFT) | (EXTI_LINE_NB % 32U)))) 296 297 #define IS_EXTI_MODE(__EXTI_LINE__) ((((__EXTI_LINE__) & EXTI_MODE_MASK) != 0x00U) && \ 298 (((__EXTI_LINE__) & ~EXTI_MODE_MASK) == 0x00U)) 299 300 #define IS_EXTI_TRIGGER(__EXTI_LINE__) (((__EXTI_LINE__) & ~EXTI_TRIGGER_MASK) == 0x00U) 301 302 #define IS_EXTI_PENDING_EDGE(__EXTI_LINE__) (((__EXTI_LINE__) == EXTI_TRIGGER_RISING) || \ 303 ((__EXTI_LINE__) == EXTI_TRIGGER_FALLING)) 304 305 #define IS_EXTI_CONFIG_LINE(__EXTI_LINE__) (((__EXTI_LINE__) & EXTI_CONFIG) != 0x00U) 306 307 #define IS_EXTI_GPIO_PORT(__PORT__) (((__PORT__) == EXTI_GPIOA) || \ 308 ((__PORT__) == EXTI_GPIOB) || \ 309 ((__PORT__) == EXTI_GPIOC) || \ 310 ((__PORT__) == EXTI_GPIOD) || \ 311 ((__PORT__) == EXTI_GPIOE) || \ 312 ((__PORT__) == EXTI_GPIOF) || \ 313 ((__PORT__) == EXTI_GPIOG) || \ 314 ((__PORT__) == EXTI_GPIOH) || \ 315 ((__PORT__) == EXTI_GPIOI)) 316 317 #define IS_EXTI_GPIO_PIN(__PIN__) ((__PIN__) < 16U) 318 319 320 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 321 322 #define IS_EXTI_LINE_ATTRIBUTES(__ATTRIBUTES__) (((((__ATTRIBUTES__) & EXTI_LINE_SEC) == EXTI_LINE_SEC) || \ 323 (((__ATTRIBUTES__) & EXTI_LINE_NSEC) == EXTI_LINE_NSEC) || \ 324 (((__ATTRIBUTES__) & EXTI_LINE_PRIV) == EXTI_LINE_PRIV) || \ 325 (((__ATTRIBUTES__) & EXTI_LINE_NPRIV) == EXTI_LINE_NPRIV)) && \ 326 (((__ATTRIBUTES__) & ~(EXTI_LINE_SEC|EXTI_LINE_NSEC|EXTI_LINE_PRIV| \ 327 EXTI_LINE_NPRIV)) == 0U)) 328 329 #else 330 331 #define IS_EXTI_LINE_ATTRIBUTES(__ATTRIBUTES__) (((((__ATTRIBUTES__) & EXTI_LINE_PRIV) == EXTI_LINE_PRIV) || \ 332 (((__ATTRIBUTES__) & EXTI_LINE_NPRIV) == EXTI_LINE_NPRIV)) && \ 333 (((__ATTRIBUTES__) & ~(EXTI_LINE_PRIV|EXTI_LINE_NPRIV)) == 0U)) 334 335 #endif /* __ARM_FEATURE_CMSE */ 336 337 /** 338 * @} 339 */ 340 341 342 /* Exported functions --------------------------------------------------------*/ 343 /** @defgroup EXTI_Exported_Functions EXTI Exported Functions 344 * @brief EXTI Exported Functions 345 * @{ 346 */ 347 348 /** @defgroup EXTI_Exported_Functions_Group1 Configuration functions 349 * @brief Configuration functions 350 * @{ 351 */ 352 /* Configuration functions ****************************************************/ 353 HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 354 HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 355 HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti); 356 HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, 357 void (*pPendingCbfn)(void)); 358 HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine); 359 /** 360 * @} 361 */ 362 363 /** @defgroup EXTI_Exported_Functions_Group2 IO operation functions 364 * @brief IO operation functions 365 * @{ 366 */ 367 /* IO operation functions *****************************************************/ 368 void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti); 369 uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge); 370 void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge); 371 void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti); 372 373 /** 374 * @} 375 */ 376 377 /** @addtogroup EXTI_Exported_Functions_Group3 EXTI line attributes management functions 378 * @{ 379 */ 380 381 /* EXTI line attributes management functions **********************************/ 382 void HAL_EXTI_ConfigLineAttributes(uint32_t ExtiLine, uint32_t LineAttributes); 383 HAL_StatusTypeDef HAL_EXTI_GetConfigLineAttributes(uint32_t ExtiLine, uint32_t *pLineAttributes); 384 385 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 386 HAL_StatusTypeDef HAL_EXTI_LockConfigAttributes(void); 387 HAL_StatusTypeDef HAL_EXTI_GetLockConfigAttributes(uint32_t *const pLockState); 388 #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ 389 390 /** 391 * @} 392 */ 393 394 /** 395 * @} 396 */ 397 398 /** 399 * @} 400 */ 401 402 /** 403 * @} 404 */ 405 406 #ifdef __cplusplus 407 } 408 #endif 409 410 #endif /* STM32H5xx_HAL_EXTI_H */ 411