1 /** 2 ****************************************************************************** 3 * @file stm32l5xx_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 STM32L5xx_HAL_EXTI_H 21 #define STM32L5xx_HAL_EXTI_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32l5xx_hal_def.h" 29 30 /** @addtogroup STM32L5xx_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_CONFIG | EXTI_REG1 | 0x15U) 112 #define EXTI_LINE_22 (EXTI_CONFIG | 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_CONFIG | EXTI_REG2 | 0x03U) 126 #define EXTI_LINE_36 (EXTI_CONFIG | EXTI_REG2 | 0x04U) 127 #define EXTI_LINE_37 (EXTI_CONFIG | EXTI_REG2 | 0x05U) 128 #define EXTI_LINE_38 (EXTI_CONFIG | EXTI_REG2 | 0x06U) 129 #define EXTI_LINE_39 (EXTI_RESERVED | 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 /** 134 * @} 135 */ 136 137 /** @defgroup EXTI_Mode EXTI Mode 138 * @{ 139 */ 140 #define EXTI_MODE_NONE 0x00000000U 141 #define EXTI_MODE_INTERRUPT 0x00000001U 142 #define EXTI_MODE_EVENT 0x00000002U 143 /** 144 * @} 145 */ 146 147 /** @defgroup EXTI_Trigger EXTI Trigger 148 * @{ 149 */ 150 #define EXTI_TRIGGER_NONE 0x00000000U 151 #define EXTI_TRIGGER_RISING 0x00000001U 152 #define EXTI_TRIGGER_FALLING 0x00000002U 153 #define EXTI_TRIGGER_RISING_FALLING (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 154 /** 155 * @} 156 */ 157 158 /** @defgroup EXTI_GPIOSel EXTI GPIOSel 159 * @brief 160 * @{ 161 */ 162 #define EXTI_GPIOA 0x00000000U 163 #define EXTI_GPIOB 0x00000001U 164 #define EXTI_GPIOC 0x00000002U 165 #define EXTI_GPIOD 0x00000003U 166 #define EXTI_GPIOE 0x00000004U 167 #define EXTI_GPIOF 0x00000005U 168 #define EXTI_GPIOG 0x00000006U 169 #define EXTI_GPIOH 0x00000007U 170 /** 171 * @} 172 */ 173 174 /** @defgroup EXTI_Line_attributes EXTI line attributes 175 * @brief EXTI line secure or non-secure and privileged or non-privileged attributes 176 * @note secure and non-secure attributes are only available from secure state when the system 177 * implement the security (TZEN=1) 178 * @{ 179 */ 180 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 181 #define EXTI_LINE_SEC (EXTI_LINE_ATTR_SEC_MASK | 0x00000001U) /*!< Secure line attribute */ 182 #define EXTI_LINE_NSEC (EXTI_LINE_ATTR_SEC_MASK | 0x00000000U) /*!< Non-secure line attribute */ 183 #endif /* __ARM_FEATURE_CMSE */ 184 #define EXTI_LINE_PRIV (EXTI_LINE_ATTR_PRIV_MASK | 0x00000002U) /*!< Privileged line attribute */ 185 #define EXTI_LINE_NPRIV (EXTI_LINE_ATTR_PRIV_MASK | 0x00000000U) /*!< Non-privileged line attribute */ 186 /** 187 * @} 188 */ 189 190 /** 191 * @} 192 */ 193 194 /* Exported macro ------------------------------------------------------------*/ 195 /** @defgroup EXTI_Exported_Macros EXTI Exported Macros 196 * @{ 197 */ 198 199 /** 200 * @} 201 */ 202 203 /* Private constants --------------------------------------------------------*/ 204 /** @defgroup EXTI_Private_Constants EXTI Private Constants 205 * @{ 206 */ 207 /** 208 * @brief EXTI Line property definition 209 */ 210 #define EXTI_PROPERTY_SHIFT 24U 211 #define EXTI_DIRECT (0x01UL << EXTI_PROPERTY_SHIFT) 212 #define EXTI_CONFIG (0x02UL << EXTI_PROPERTY_SHIFT) 213 #define EXTI_GPIO ((0x04UL << EXTI_PROPERTY_SHIFT) | EXTI_CONFIG) 214 #define EXTI_RESERVED (0x08UL << EXTI_PROPERTY_SHIFT) 215 #define EXTI_PROPERTY_MASK (EXTI_DIRECT | EXTI_CONFIG | EXTI_GPIO) 216 217 /** 218 * @brief EXTI Register and bit usage 219 */ 220 #define EXTI_REG_SHIFT 16U 221 #define EXTI_REG1 (0x00UL << EXTI_REG_SHIFT) 222 #define EXTI_REG2 (0x01UL << EXTI_REG_SHIFT) 223 #define EXTI_REG_MASK (EXTI_REG1 | EXTI_REG2) 224 #define EXTI_PIN_MASK 0x0000001FU 225 226 /** 227 * @brief EXTI Mask for interrupt & event mode 228 */ 229 #define EXTI_MODE_MASK (EXTI_MODE_EVENT | EXTI_MODE_INTERRUPT) 230 231 /** 232 * @brief EXTI Mask for trigger possibilities 233 */ 234 #define EXTI_TRIGGER_MASK (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 235 236 /** 237 * @brief EXTI Line number 238 */ 239 #define EXTI_LINE_NB 43UL 240 241 /** 242 * @brief EXTI Mask for secure & privilege attributes 243 */ 244 #define EXTI_LINE_ATTR_SEC_MASK 0x100U 245 #define EXTI_LINE_ATTR_PRIV_MASK 0x200U 246 /** 247 * @} 248 */ 249 250 /* Private macros ------------------------------------------------------------*/ 251 /** @defgroup EXTI_Private_Macros EXTI Private Macros 252 * @{ 253 */ 254 #define IS_EXTI_LINE(__EXTI_LINE__) ((((__EXTI_LINE__) & ~(EXTI_PROPERTY_MASK | EXTI_REG_MASK | EXTI_PIN_MASK)) == 0x00U) && \ 255 ((((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_DIRECT) || \ 256 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_CONFIG) || \ 257 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_GPIO)) && \ 258 (((__EXTI_LINE__) & (EXTI_REG_MASK | EXTI_PIN_MASK)) < \ 259 (((EXTI_LINE_NB / 32U) << EXTI_REG_SHIFT) | (EXTI_LINE_NB % 32U)))) 260 261 #define IS_EXTI_MODE(__EXTI_LINE__) ((((__EXTI_LINE__) & EXTI_MODE_MASK) != 0x00U) && \ 262 (((__EXTI_LINE__) & ~EXTI_MODE_MASK) == 0x00U)) 263 264 #define IS_EXTI_TRIGGER(__EXTI_LINE__) (((__EXTI_LINE__) & ~EXTI_TRIGGER_MASK) == 0x00U) 265 266 #define IS_EXTI_PENDING_EDGE(__EXTI_LINE__) (((__EXTI_LINE__) == EXTI_TRIGGER_RISING) || \ 267 ((__EXTI_LINE__) == EXTI_TRIGGER_FALLING)) 268 269 #define IS_EXTI_CONFIG_LINE(__EXTI_LINE__) (((__EXTI_LINE__) & EXTI_CONFIG) != 0x00U) 270 271 #define IS_EXTI_GPIO_PORT(__PORT__) (((__PORT__) == EXTI_GPIOA) || \ 272 ((__PORT__) == EXTI_GPIOB) || \ 273 ((__PORT__) == EXTI_GPIOC) || \ 274 ((__PORT__) == EXTI_GPIOD) || \ 275 ((__PORT__) == EXTI_GPIOE) || \ 276 ((__PORT__) == EXTI_GPIOF) || \ 277 ((__PORT__) == EXTI_GPIOG) || \ 278 ((__PORT__) == EXTI_GPIOH)) 279 280 #define IS_EXTI_GPIO_PIN(__PIN__) ((__PIN__) < 16U) 281 282 283 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) 284 285 #define IS_EXTI_LINE_ATTRIBUTES(__ATTRIBUTES__) (((((__ATTRIBUTES__) & EXTI_LINE_SEC) == EXTI_LINE_SEC) || \ 286 (((__ATTRIBUTES__) & EXTI_LINE_NSEC) == EXTI_LINE_NSEC) || \ 287 (((__ATTRIBUTES__) & EXTI_LINE_PRIV) == EXTI_LINE_PRIV) || \ 288 (((__ATTRIBUTES__) & EXTI_LINE_NPRIV) == EXTI_LINE_NPRIV)) && \ 289 (((__ATTRIBUTES__) & ~(EXTI_LINE_SEC|EXTI_LINE_NSEC|EXTI_LINE_PRIV|EXTI_LINE_NPRIV)) == 0U)) 290 291 #else 292 293 #define IS_EXTI_LINE_ATTRIBUTES(__ATTRIBUTES__) (((((__ATTRIBUTES__) & EXTI_LINE_PRIV) == EXTI_LINE_PRIV) || \ 294 (((__ATTRIBUTES__) & EXTI_LINE_NPRIV) == EXTI_LINE_NPRIV)) && \ 295 (((__ATTRIBUTES__) & ~(EXTI_LINE_PRIV|EXTI_LINE_NPRIV)) == 0U)) 296 297 #endif /* __ARM_FEATURE_CMSE */ 298 299 /** 300 * @} 301 */ 302 303 304 /* Exported functions --------------------------------------------------------*/ 305 /** @defgroup EXTI_Exported_Functions EXTI Exported Functions 306 * @brief EXTI Exported Functions 307 * @{ 308 */ 309 310 /** @defgroup EXTI_Exported_Functions_Group1 Configuration functions 311 * @brief Configuration functions 312 * @{ 313 */ 314 /* Configuration functions ****************************************************/ 315 HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 316 HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 317 HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti); 318 HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void (*pPendingCbfn)(void)); 319 HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine); 320 /** 321 * @} 322 */ 323 324 /** @defgroup EXTI_Exported_Functions_Group2 IO operation functions 325 * @brief IO operation functions 326 * @{ 327 */ 328 /* IO operation functions *****************************************************/ 329 void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti); 330 uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge); 331 void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge); 332 void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti); 333 334 /** 335 * @} 336 */ 337 338 /** @addtogroup EXTI_Exported_Functions_Group3 EXTI line attributes management functions 339 * @{ 340 */ 341 342 /* EXTI line attributes management functions **********************************/ 343 void HAL_EXTI_ConfigLineAttributes(uint32_t ExtiLine, uint32_t LineAttributes); 344 HAL_StatusTypeDef HAL_EXTI_GetConfigLineAttributes(uint32_t ExtiLine, uint32_t *pLineAttributes); 345 346 /** 347 * @} 348 */ 349 350 /** 351 * @} 352 */ 353 354 /** 355 * @} 356 */ 357 358 /** 359 * @} 360 */ 361 362 #ifdef __cplusplus 363 } 364 #endif 365 366 #endif /* STM32L5xx_HAL_EXTI_H */ 367 368