1 /** 2 ****************************************************************************** 3 * @file stm32c0xx_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 STM32C0xx_HAL_EXTI_H 21 #define STM32C0xx_HAL_EXTI_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32c0xx_hal_def.h" 29 30 /** @addtogroup STM32C0xx_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_RESERVED | EXTI_REG1 | 0x10U) 107 #define EXTI_LINE_17 (EXTI_RESERVED | EXTI_REG1 | 0x11U) 108 #define EXTI_LINE_18 (EXTI_RESERVED | EXTI_REG1 | 0x12U) 109 #define EXTI_LINE_19 (EXTI_DIRECT | EXTI_REG1 | 0x13U) 110 #define EXTI_LINE_20 (EXTI_RESERVED | EXTI_REG1 | 0x14U) 111 #define EXTI_LINE_21 (EXTI_RESERVED | EXTI_REG1 | 0x15U) 112 #define EXTI_LINE_22 (EXTI_RESERVED | EXTI_REG1 | 0x16U) 113 #define EXTI_LINE_23 (EXTI_DIRECT | EXTI_REG1 | 0x17U) 114 #define EXTI_LINE_24 (EXTI_RESERVED | EXTI_REG1 | 0x18U) 115 #define EXTI_LINE_25 (EXTI_DIRECT | EXTI_REG1 | 0x19U) 116 #define EXTI_LINE_26 (EXTI_RESERVED | EXTI_REG1 | 0x1AU) 117 #define EXTI_LINE_27 (EXTI_RESERVED | EXTI_REG1 | 0x1BU) 118 #define EXTI_LINE_28 (EXTI_RESERVED | EXTI_REG1 | 0x1CU) 119 #define EXTI_LINE_29 (EXTI_RESERVED | EXTI_REG1 | 0x1DU) 120 #define EXTI_LINE_30 (EXTI_RESERVED | EXTI_REG1 | 0x1EU) 121 #define EXTI_LINE_31 (EXTI_DIRECT | EXTI_REG1 | 0x1FU) 122 /** 123 * @} 124 */ 125 126 /** @defgroup EXTI_Mode EXTI Mode 127 * @{ 128 */ 129 #define EXTI_MODE_NONE 0x00000000u 130 #define EXTI_MODE_INTERRUPT 0x00000001u 131 #define EXTI_MODE_EVENT 0x00000002u 132 /** 133 * @} 134 */ 135 136 /** @defgroup EXTI_Trigger EXTI Trigger 137 * @{ 138 */ 139 #define EXTI_TRIGGER_NONE 0x00000000u 140 #define EXTI_TRIGGER_RISING 0x00000001u 141 #define EXTI_TRIGGER_FALLING 0x00000002u 142 #define EXTI_TRIGGER_RISING_FALLING (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 143 /** 144 * @} 145 */ 146 147 /** @defgroup EXTI_GPIOSel EXTI GPIOSel 148 * @brief 149 * @{ 150 */ 151 #define EXTI_GPIOA 0x00000000u 152 #define EXTI_GPIOB 0x00000001u 153 #define EXTI_GPIOC 0x00000002u 154 #if defined(STM32C031xx) 155 #define EXTI_GPIOD 0x00000003u 156 #endif /* STM32C031xx */ 157 #define EXTI_GPIOF 0x00000005u 158 /** 159 * @} 160 */ 161 162 /** 163 * @} 164 */ 165 166 /* Exported macro ------------------------------------------------------------*/ 167 /** @defgroup EXTI_Exported_Macros EXTI Exported Macros 168 * @{ 169 */ 170 171 /** 172 * @} 173 */ 174 175 /* Private constants --------------------------------------------------------*/ 176 /** @defgroup EXTI_Private_Constants EXTI Private Constants 177 * @{ 178 */ 179 /** 180 * @brief EXTI Line property definition 181 */ 182 #define EXTI_PROPERTY_SHIFT 24u 183 #define EXTI_DIRECT (0x01uL << EXTI_PROPERTY_SHIFT) 184 #define EXTI_CONFIG (0x02uL << EXTI_PROPERTY_SHIFT) 185 #define EXTI_GPIO ((0x04uL << EXTI_PROPERTY_SHIFT) | EXTI_CONFIG) 186 #define EXTI_RESERVED (0x08uL << EXTI_PROPERTY_SHIFT) 187 #define EXTI_PROPERTY_MASK (EXTI_DIRECT | EXTI_CONFIG | EXTI_GPIO) 188 189 /** 190 * @brief EXTI Register and bit usage 191 */ 192 #define EXTI_REG_SHIFT 16u 193 #define EXTI_REG1 (0x00uL << EXTI_REG_SHIFT) 194 #define EXTI_REG2 (0x01uL << EXTI_REG_SHIFT) 195 #define EXTI_REG_MASK (EXTI_REG1 | EXTI_REG2) 196 #define EXTI_PIN_MASK 0x0000001Fu 197 198 /** 199 * @brief EXTI Mask for interrupt & event mode 200 */ 201 #define EXTI_MODE_MASK (EXTI_MODE_EVENT | EXTI_MODE_INTERRUPT) 202 203 /** 204 * @brief EXTI Mask for trigger possibilities 205 */ 206 #define EXTI_TRIGGER_MASK (EXTI_TRIGGER_RISING | EXTI_TRIGGER_FALLING) 207 208 /** 209 * @brief EXTI Line number 210 */ 211 212 #define EXTI_LINE_NB 32uL 213 214 /** 215 * @} 216 */ 217 218 /* Private macros ------------------------------------------------------------*/ 219 /** @defgroup EXTI_Private_Macros EXTI Private Macros 220 * @{ 221 */ 222 #define IS_EXTI_LINE(__EXTI_LINE__) ((((__EXTI_LINE__) & ~(EXTI_PROPERTY_MASK | \ 223 EXTI_REG_MASK | EXTI_PIN_MASK)) == 0x00U) \ 224 &&((((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_DIRECT) || \ 225 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_CONFIG) || \ 226 (((__EXTI_LINE__) & EXTI_PROPERTY_MASK) == EXTI_GPIO)) && \ 227 (((__EXTI_LINE__) & (EXTI_REG_MASK | EXTI_PIN_MASK)) < \ 228 (((EXTI_LINE_NB / 32U) << EXTI_REG_SHIFT) | (EXTI_LINE_NB % 32U)))) 229 230 #define IS_EXTI_MODE(__EXTI_LINE__) ((((__EXTI_LINE__) & EXTI_MODE_MASK) != 0x00U) && \ 231 (((__EXTI_LINE__) & ~EXTI_MODE_MASK) == 0x00U)) 232 233 #define IS_EXTI_TRIGGER(__EXTI_LINE__) (((__EXTI_LINE__) & ~EXTI_TRIGGER_MASK) == 0x00U) 234 235 #define IS_EXTI_PENDING_EDGE(__EXTI_LINE__) (((__EXTI_LINE__) == EXTI_TRIGGER_RISING) || \ 236 ((__EXTI_LINE__) == EXTI_TRIGGER_FALLING)) 237 238 #define IS_EXTI_CONFIG_LINE(__EXTI_LINE__) (((__EXTI_LINE__) & EXTI_CONFIG) != 0x00U) 239 #if defined(STM32C031xx) 240 #define IS_EXTI_GPIO_PORT(__PORT__) (((__PORT__) == EXTI_GPIOA) || \ 241 ((__PORT__) == EXTI_GPIOB) || \ 242 ((__PORT__) == EXTI_GPIOC) || \ 243 ((__PORT__) == EXTI_GPIOD) || \ 244 ((__PORT__) == EXTI_GPIOF)) 245 #elif defined(STM32C011xx) 246 #define IS_EXTI_GPIO_PORT(__PORT__) (((__PORT__) == EXTI_GPIOA) || \ 247 ((__PORT__) == EXTI_GPIOB) || \ 248 ((__PORT__) == EXTI_GPIOC) || \ 249 ((__PORT__) == EXTI_GPIOF)) 250 #endif /* STM32C031xx */ 251 #define IS_EXTI_GPIO_PIN(__PIN__) ((__PIN__) < 16u) 252 253 /** 254 * @} 255 */ 256 257 258 /* Exported functions --------------------------------------------------------*/ 259 /** @defgroup EXTI_Exported_Functions EXTI Exported Functions 260 * @brief EXTI Exported Functions 261 * @{ 262 */ 263 264 /** @defgroup EXTI_Exported_Functions_Group1 Configuration functions 265 * @brief Configuration functions 266 * @{ 267 */ 268 /* Configuration functions ****************************************************/ 269 HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 270 HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig); 271 HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(const EXTI_HandleTypeDef *hexti); 272 HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, 273 void (*pPendingCbfn)(void)); 274 HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine); 275 /** 276 * @} 277 */ 278 279 /** @defgroup EXTI_Exported_Functions_Group2 IO operation functions 280 * @brief IO operation functions 281 * @{ 282 */ 283 /* IO operation functions *****************************************************/ 284 void HAL_EXTI_IRQHandler(const EXTI_HandleTypeDef *hexti); 285 uint32_t HAL_EXTI_GetPending(const EXTI_HandleTypeDef *hexti, uint32_t Edge); 286 void HAL_EXTI_ClearPending(const EXTI_HandleTypeDef *hexti, uint32_t Edge); 287 void HAL_EXTI_GenerateSWI(const EXTI_HandleTypeDef *hexti); 288 289 /** 290 * @} 291 */ 292 293 /** 294 * @} 295 */ 296 297 /** 298 * @} 299 */ 300 301 /** 302 * @} 303 */ 304 305 #ifdef __cplusplus 306 } 307 #endif 308 309 #endif /* STM32C0xx_HAL_EXTI_H */ 310