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) 2023 STMicroelectronics. 10 * All rights reserved. 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 STM32H5xx_HAL_EXTI_H 22 #define STM32H5xx_HAL_EXTI_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32h5xx_hal_def.h" 30 31 /** @addtogroup STM32H5xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @defgroup EXTI EXTI 36 * @brief EXTI HAL module driver 37 * @{ 38 */ 39 40 /* Exported types ------------------------------------------------------------*/ 41 42 /** @defgroup EXTI_Exported_Types EXTI Exported Types 43 * @{ 44 */ 45 typedef enum 46 { 47 HAL_EXTI_COMMON_CB_ID = 0x00U, 48 HAL_EXTI_RISING_CB_ID = 0x01U, 49 HAL_EXTI_FALLING_CB_ID = 0x02U, 50 } EXTI_CallbackIDTypeDef; 51 52 53 /** 54 * @brief EXTI Handle structure definition 55 */ 56 typedef struct 57 { 58 uint32_t Line; /*!< Exti line number */ 59 void (* RisingCallback)(void); /*!< Exti rising callback */ 60 void (* FallingCallback)(void); /*!< Exti falling callback */ 61 } EXTI_HandleTypeDef; 62 63 /** 64 * @brief EXTI Configuration structure definition 65 */ 66 typedef struct 67 { 68 uint32_t Line; /*!< The Exti line to be configured. This parameter 69 can be a value of @ref EXTI_Line */ 70 uint32_t Mode; /*!< The Exit Mode to be configured for a core. 71 This parameter can be a combination of @ref EXTI_Mode */ 72 uint32_t Trigger; /*!< The Exti Trigger to be configured. This parameter 73 can be a value of @ref EXTI_Trigger */ 74 uint32_t GPIOSel; /*!< The Exti GPIO multiplexer selection to be configured. 75 This parameter is only possible for line 0 to 15. It 76 can be a value of @ref EXTI_GPIOSel */ 77 } EXTI_ConfigTypeDef; 78 79 /** 80 * @} 81 */ 82 83 /* Exported constants --------------------------------------------------------*/ 84 /** @defgroup EXTI_Exported_Constants EXTI Exported Constants 85 * @{ 86 */ 87 88 /** @defgroup EXTI_Line EXTI Line 89 * @{ 90 */ 91 #define EXTI_LINE_0 (EXTI_GPIO | EXTI_REG1 | 0x00U) 92 #define EXTI_LINE_1 (EXTI_GPIO | EXTI_REG1 | 0x01U) 93 #define EXTI_LINE_2 (EXTI_GPIO | EXTI_REG1 | 0x02U) 94 #define EXTI_LINE_3 (EXTI_GPIO | EXTI_REG1 | 0x03U) 95 #define EXTI_LINE_4 (EXTI_GPIO | EXTI_REG1 | 0x04U) 96 #define EXTI_LINE_5 (EXTI_GPIO | EXTI_REG1 | 0x05U) 97 #define EXTI_LINE_6 (EXTI_GPIO | EXTI_REG1 | 0x06U) 98 #define EXTI_LINE_7 (EXTI_GPIO | EXTI_REG1 | 0x07U) 99 #define EXTI_LINE_8 (EXTI_GPIO | EXTI_REG1 | 0x08U) 100 #define EXTI_LINE_9 (EXTI_GPIO | EXTI_REG1 | 0x09U) 101 #define EXTI_LINE_10 (EXTI_GPIO | EXTI_REG1 | 0x0AU) 102 #define EXTI_LINE_11 (EXTI_GPIO | EXTI_REG1 | 0x0BU) 103 #define EXTI_LINE_12 (EXTI_GPIO | EXTI_REG1 | 0x0CU) 104 #define EXTI_LINE_13 (EXTI_GPIO | EXTI_REG1 | 0x0DU) 105 #define EXTI_LINE_14 (EXTI_GPIO | EXTI_REG1 | 0x0EU) 106 #define EXTI_LINE_15 (EXTI_GPIO | EXTI_REG1 | 0x0FU) 107 #define EXTI_LINE_16 (EXTI_CONFIG | EXTI_REG1 | 0x10U) 108 #define EXTI_LINE_17 (EXTI_DIRECT | EXTI_REG1 | 0x11U) 109 #define EXTI_LINE_18 (EXTI_DIRECT | EXTI_REG1 | 0x12U) 110 #define EXTI_LINE_19 (EXTI_DIRECT | EXTI_REG1 | 0x13U) 111 #define EXTI_LINE_20 (EXTI_DIRECT | EXTI_REG1 | 0x14U) 112 #define EXTI_LINE_21 (EXTI_DIRECT | EXTI_REG1 | 0x15U) 113 #define EXTI_LINE_22 (EXTI_DIRECT | EXTI_REG1 | 0x16U) 114 #define EXTI_LINE_23 (EXTI_DIRECT | EXTI_REG1 | 0x17U) 115 #define EXTI_LINE_24 (EXTI_DIRECT | EXTI_REG1 | 0x18U) 116 #define EXTI_LINE_25 (EXTI_DIRECT | EXTI_REG1 | 0x19U) 117 #define EXTI_LINE_26 (EXTI_DIRECT | EXTI_REG1 | 0x1AU) 118 #define EXTI_LINE_27 (EXTI_DIRECT | EXTI_REG1 | 0x1BU) 119 #define EXTI_LINE_28 (EXTI_DIRECT | EXTI_REG1 | 0x1CU) 120 #define EXTI_LINE_29 (EXTI_DIRECT | EXTI_REG1 | 0x1DU) 121 #define EXTI_LINE_30 (EXTI_DIRECT | EXTI_REG1 | 0x1EU) 122 #define EXTI_LINE_31 (EXTI_DIRECT | EXTI_REG1 | 0x1FU) 123 #define EXTI_LINE_32 (EXTI_DIRECT | EXTI_REG2 | 0x00U) 124 #define EXTI_LINE_33 (EXTI_DIRECT | EXTI_REG2 | 0x01U) 125 #define EXTI_LINE_34 (EXTI_DIRECT | EXTI_REG2 | 0x02U) 126 #define EXTI_LINE_35 (EXTI_DIRECT | EXTI_REG2 | 0x03U) 127 #define EXTI_LINE_36 (EXTI_DIRECT | EXTI_REG2 | 0x04U) 128 #define EXTI_LINE_37 (EXTI_DIRECT | EXTI_REG2 | 0x05U) 129 #define EXTI_LINE_38 (EXTI_DIRECT | EXTI_REG2 | 0x06U) 130 #define EXTI_LINE_39 (EXTI_DIRECT | EXTI_REG2 | 0x07U) 131 #define EXTI_LINE_40 (EXTI_DIRECT | EXTI_REG2 | 0x08U) 132 #define EXTI_LINE_41 (EXTI_DIRECT | EXTI_REG2 | 0x09U) 133 #define EXTI_LINE_42 (EXTI_DIRECT | EXTI_REG2 | 0x0AU) 134 #define EXTI_LINE_43 (EXTI_DIRECT | EXTI_REG2 | 0x0BU) 135 #define EXTI_LINE_44 (EXTI_DIRECT | EXTI_REG2 | 0x0CU) 136 #define EXTI_LINE_45 (EXTI_DIRECT | EXTI_REG2 | 0x0DU) 137 #if defined(ETH) 138 #define EXTI_LINE_46 (EXTI_CONFIG | EXTI_REG2 | 0x0EU) 139 #endif /* ETH */ 140 #define EXTI_LINE_47 (EXTI_DIRECT | EXTI_REG2 | 0x0FU) 141 #define EXTI_LINE_48 (EXTI_DIRECT | EXTI_REG2 | 0x10U) 142 #define EXTI_LINE_49 (EXTI_DIRECT | EXTI_REG2 | 0x11U) 143 #define EXTI_LINE_50 (EXTI_CONFIG | EXTI_REG2 | 0x12U) 144 #define EXTI_LINE_51 (EXTI_DIRECT | EXTI_REG2 | 0x13U) 145 #define EXTI_LINE_52 (EXTI_DIRECT | EXTI_REG2 | 0x14U) 146 #define EXTI_LINE_53 (EXTI_CONFIG | EXTI_REG2 | 0x15U) 147 #define EXTI_LINE_54 (EXTI_DIRECT | EXTI_REG2 | 0x16U) 148 #define EXTI_LINE_55 (EXTI_DIRECT | EXTI_REG2 | 0x17U) 149 #define EXTI_LINE_56 (EXTI_DIRECT | EXTI_REG2 | 0x18U) 150 #define EXTI_LINE_57 (EXTI_DIRECT | EXTI_REG2 | 0x19U) 151 152 /** 153 * @} 154 */ 155 156 /** @defgroup EXTI_Mode EXTI Mode 157 * @{ 158 */ 159 #define EXTI_MODE_NONE 0x00000000U 160 #define EXTI_MODE_INTERRUPT 0x00000001U 161 #define EXTI_MODE_EVENT 0x00000002U 162 /** 163 * @} 164 */ 165 166 /** @defgroup EXTI_Trigger EXTI Trigger 167 * @{ 168 */ 169 #define EXTI_TRIGGER_NONE 0x00000000U 170 #define EXTI_TRIGGER_RISING 0x00000001U 171 #define EXTI_TRIGGER_FALLING 0x00000002U 172 #define EXTI_TRIGGER_RISING_FALLING (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 173 /** 174 * @} 175 */ 176 177 /** @defgroup EXTI_GPIOSel EXTI GPIOSel 178 * @brief 179 * @{ 180 */ 181 #define EXTI_GPIOA 0x00000000U 182 #define EXTI_GPIOB 0x00000001U 183 #define EXTI_GPIOC 0x00000002U 184 #define EXTI_GPIOD 0x00000003U 185 #define EXTI_GPIOE 0x00000004U 186 #define EXTI_GPIOF 0x00000005U 187 #define EXTI_GPIOG 0x00000006U 188 #define EXTI_GPIOH 0x00000007U 189 #define EXTI_GPIOI 0x00000008U 190 /** 191 * @} 192 */ 193 194 /** @defgroup EXTI_Line_attributes EXTI line attributes 195 * @brief EXTI line secure or non-secure and privileged or non-privileged attributes 196 * @note secure and non-secure attributes are only available from secure state when the system 197 * implement the security (TZEN=1) 198 * @{ 199 */ 200 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 201 /*!< Secure line attribute */ 202 #define EXTI_LINE_SEC (EXTI_LINE_ATTR_SEC_MASK | 0x00000001U) 203 /*!< Non-secure line attribute */ 204 #define EXTI_LINE_NSEC (EXTI_LINE_ATTR_SEC_MASK | 0x00000000U) 205 #endif /* __ARM_FEATURE_CMSE */ 206 /*!< Privileged line attribute */ 207 #define EXTI_LINE_PRIV (EXTI_LINE_ATTR_PRIV_MASK | 0x00000002U) 208 /*!< Non-privileged line attribute */ 209 #define EXTI_LINE_NPRIV (EXTI_LINE_ATTR_PRIV_MASK | 0x00000000U) 210 /** 211 * @} 212 */ 213 /** @defgroup EXTI_Security_Privilege_Configuration EXTI Security Privilege Configuration 214 * @brief EXTI security and privilege configurations 215 * @{ 216 */ 217 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 218 /* Security and privilege configuration open, can be modified */ 219 #define EXTI_ATTRIBUTES_UNLOCKED 0x00000000U 220 /* Security and privilege configuration locked, can no longer be modified */ 221 #define EXTI_ATTRIBUTES_LOCKED 0x00000001U 222 #endif /* __ARM_FEATURE_CMSE */ 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 (0x01U << EXTI_PROPERTY_SHIFT) 248 #define EXTI_CONFIG (0x02U << EXTI_PROPERTY_SHIFT) 249 #define EXTI_GPIO ((0x04U << EXTI_PROPERTY_SHIFT) | EXTI_CONFIG) 250 #define EXTI_RESERVED (0x08U << 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 (0x00U << EXTI_REG_SHIFT) 258 #define EXTI_REG2 (0x01U << 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 #define EXTI_LINE_NB 58U 276 277 /** 278 * @brief EXTI Mask for secure & privilege attributes 279 */ 280 #define EXTI_LINE_ATTR_SEC_MASK 0x100U 281 #define EXTI_LINE_ATTR_PRIV_MASK 0x200U 282 /** 283 * @} 284 */ 285 286 /* Private macros ------------------------------------------------------------*/ 287 /** @defgroup EXTI_Private_Macros EXTI Private Macros 288 * @{ 289 */ 290 #define IS_EXTI_LINE(__EXTI_LINE__) ((((__EXTI_LINE__) & ~(EXTI_PROPERTY_MASK | \ 291 EXTI_REG_MASK | EXTI_PIN_MASK)) == 0x00U) \ 292 &&((((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_DIRECT) || \ 293 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_CONFIG) || \ 294 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_GPIO)) && \ 295 (((__EXTI_LINE__) & (EXTI_REG_MASK | EXTI_PIN_MASK)) < \ 296 (((EXTI_LINE_NB / 32U) << EXTI_REG_SHIFT) | (EXTI_LINE_NB % 32U)))) 297 298 #define IS_EXTI_MODE(__EXTI_LINE__) ((((__EXTI_LINE__) & EXTI_MODE_MASK) != 0x00U) && \ 299 (((__EXTI_LINE__) & ~EXTI_MODE_MASK) == 0x00U)) 300 301 #define IS_EXTI_TRIGGER(__EXTI_LINE__) (((__EXTI_LINE__) & ~EXTI_TRIGGER_MASK) == 0x00U) 302 303 #define IS_EXTI_PENDING_EDGE(__EXTI_LINE__) (((__EXTI_LINE__) == EXTI_TRIGGER_RISING) || \ 304 ((__EXTI_LINE__) == EXTI_TRIGGER_FALLING)) 305 306 #define IS_EXTI_CONFIG_LINE(__EXTI_LINE__) (((__EXTI_LINE__) & EXTI_CONFIG) != 0x00U) 307 308 #define IS_EXTI_GPIO_PORT(__PORT__) (((__PORT__) == EXTI_GPIOA) || \ 309 ((__PORT__) == EXTI_GPIOB) || \ 310 ((__PORT__) == EXTI_GPIOC) || \ 311 ((__PORT__) == EXTI_GPIOD) || \ 312 ((__PORT__) == EXTI_GPIOE) || \ 313 ((__PORT__) == EXTI_GPIOF) || \ 314 ((__PORT__) == EXTI_GPIOG) || \ 315 ((__PORT__) == EXTI_GPIOH) || \ 316 ((__PORT__) == EXTI_GPIOI)) 317 318 #define IS_EXTI_GPIO_PIN(__PIN__) ((__PIN__) < 16U) 319 320 321 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 322 323 #define IS_EXTI_LINE_ATTRIBUTES(__ATTRIBUTES__) (((((__ATTRIBUTES__) & EXTI_LINE_SEC) == EXTI_LINE_SEC) || \ 324 (((__ATTRIBUTES__) & EXTI_LINE_NSEC) == EXTI_LINE_NSEC) || \ 325 (((__ATTRIBUTES__) & EXTI_LINE_PRIV) == EXTI_LINE_PRIV) || \ 326 (((__ATTRIBUTES__) & EXTI_LINE_NPRIV) == EXTI_LINE_NPRIV)) && \ 327 (((__ATTRIBUTES__) & ~(EXTI_LINE_SEC|EXTI_LINE_NSEC|EXTI_LINE_PRIV| \ 328 EXTI_LINE_NPRIV)) == 0U)) 329 330 #else 331 332 #define IS_EXTI_LINE_ATTRIBUTES(__ATTRIBUTES__) (((((__ATTRIBUTES__) & EXTI_LINE_PRIV) == EXTI_LINE_PRIV) || \ 333 (((__ATTRIBUTES__) & EXTI_LINE_NPRIV) == EXTI_LINE_NPRIV)) && \ 334 (((__ATTRIBUTES__) & ~(EXTI_LINE_PRIV|EXTI_LINE_NPRIV)) == 0U)) 335 336 #endif /* __ARM_FEATURE_CMSE */ 337 338 /** 339 * @} 340 */ 341 342 343 /* Exported functions --------------------------------------------------------*/ 344 /** @defgroup EXTI_Exported_Functions EXTI Exported Functions 345 * @brief EXTI Exported Functions 346 * @{ 347 */ 348 349 /** @defgroup EXTI_Exported_Functions_Group1 Configuration functions 350 * @brief Configuration functions 351 * @{ 352 */ 353 /* Configuration functions ****************************************************/ 354 HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 355 HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 356 HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti); 357 HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, 358 void (*pPendingCbfn)(void)); 359 HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine); 360 /** 361 * @} 362 */ 363 364 /** @defgroup EXTI_Exported_Functions_Group2 IO operation functions 365 * @brief IO operation functions 366 * @{ 367 */ 368 /* IO operation functions *****************************************************/ 369 void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti); 370 uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge); 371 void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge); 372 void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti); 373 374 /** 375 * @} 376 */ 377 378 /** @addtogroup EXTI_Exported_Functions_Group3 EXTI line attributes management functions 379 * @{ 380 */ 381 382 /* EXTI line attributes management functions **********************************/ 383 void HAL_EXTI_ConfigLineAttributes(uint32_t ExtiLine, uint32_t LineAttributes); 384 HAL_StatusTypeDef HAL_EXTI_GetConfigLineAttributes(uint32_t ExtiLine, uint32_t *pLineAttributes); 385 386 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 387 HAL_StatusTypeDef HAL_EXTI_LockConfigAttributes(void); 388 HAL_StatusTypeDef HAL_EXTI_GetLockConfigAttributes(uint32_t *const pLockState); 389 #endif /* defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) */ 390 391 /** 392 * @} 393 */ 394 395 /** 396 * @} 397 */ 398 399 /** 400 * @} 401 */ 402 403 /** 404 * @} 405 */ 406 407 #ifdef __cplusplus 408 } 409 #endif 410 411 #endif /* STM32H5xx_HAL_EXTI_H */ 412