1 /** 2 ****************************************************************************** 3 * @file stm32mp1xx_hal_gpio.h 4 * @author MCD Application Team 5 * @brief Header file of GPIO HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2019 STMicroelectronics. 10 * All rights reserved.</center></h2> 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 __STM32MP1XX_HAL_GPIO_H__ 22 #define __STM32MP1XX_HAL_GPIO_H__ 23 #include <stdint.h> 24 #ifdef __cplusplus 25 extern "C" { 26 #endif /* __cplusplus */ 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32mp1xx_hal_def.h" 30 31 /** @addtogroup STM32MP1xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup GPIO 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup GPIO_Exported_Types GPIO Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief GPIO Init structure definition 46 */ 47 typedef struct 48 { 49 uint32_t Pin; /*!< Specifies the GPIO pins to be configured. 50 This parameter can be any value of @ref GPIO_pins_define */ 51 52 uint32_t Mode; /*!< Specifies the operating mode for the selected pins. 53 This parameter can be a value of @ref GPIO_mode_define */ 54 55 uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins. 56 This parameter can be a value of @ref GPIO_pull_define */ 57 58 uint32_t Speed; /*!< Specifies the speed for the selected pins. 59 This parameter can be a value of @ref GPIO_speed_define */ 60 61 uint32_t Alternate; /*!< Peripheral to be connected to the selected pins. 62 This parameter can be a value of @ref GPIO_Alternate_function_selection */ 63 }GPIO_InitTypeDef; 64 65 /** 66 * @brief GPIO Bit SET and Bit RESET enumeration 67 */ 68 typedef enum 69 { 70 GPIO_PIN_RESET = 0, 71 GPIO_PIN_SET 72 }GPIO_PinState; 73 74 typedef enum 75 { 76 GPIO_DIR_OUTPUT = 0, 77 GPIO_DIR_INPUT 78 }GPIO_DirState; 79 80 /** 81 * @} 82 */ 83 84 /* Exported constants --------------------------------------------------------*/ 85 86 /** @defgroup GPIO_Exported_Constants GPIO Exported Constants 87 * @{ 88 */ 89 90 /** @defgroup GPIO_pins_define GPIO pins define 91 * @{ 92 */ 93 #define GPIO_PIN_0 ((uint16_t)0x0001U) /* Pin 0 selected */ 94 #define GPIO_PIN_1 ((uint16_t)0x0002U) /* Pin 1 selected */ 95 #define GPIO_PIN_2 ((uint16_t)0x0004U) /* Pin 2 selected */ 96 #define GPIO_PIN_3 ((uint16_t)0x0008U) /* Pin 3 selected */ 97 #define GPIO_PIN_4 ((uint16_t)0x0010U) /* Pin 4 selected */ 98 #define GPIO_PIN_5 ((uint16_t)0x0020U) /* Pin 5 selected */ 99 #define GPIO_PIN_6 ((uint16_t)0x0040U) /* Pin 6 selected */ 100 #define GPIO_PIN_7 ((uint16_t)0x0080U) /* Pin 7 selected */ 101 #define GPIO_PIN_8 ((uint16_t)0x0100U) /* Pin 8 selected */ 102 #define GPIO_PIN_9 ((uint16_t)0x0200U) /* Pin 9 selected */ 103 #define GPIO_PIN_10 ((uint16_t)0x0400U) /* Pin 10 selected */ 104 #define GPIO_PIN_11 ((uint16_t)0x0800U) /* Pin 11 selected */ 105 #define GPIO_PIN_12 ((uint16_t)0x1000U) /* Pin 12 selected */ 106 #define GPIO_PIN_13 ((uint16_t)0x2000U) /* Pin 13 selected */ 107 #define GPIO_PIN_14 ((uint16_t)0x4000U) /* Pin 14 selected */ 108 #define GPIO_PIN_15 ((uint16_t)0x8000U) /* Pin 15 selected */ 109 #define GPIO_PIN_All ((uint16_t)0xFFFFU) /* All pins selected */ 110 111 #define GPIO_PIN_MASK ((uint32_t)0x0000FFFFU) /* PIN mask for assert test */ 112 /** 113 * @} 114 */ 115 116 /** @defgroup GPIO_mode_define GPIO mode define 117 * @brief GPIO Configuration Mode 118 * Elements values convention: 0xX0yz00YZ 119 * - X : GPIO mode or EXTI Mode 120 * - y : External IT or Event trigger detection 121 * - z : IO configuration on External IT or Event 122 * - Y : Output type (Push Pull or Open Drain) 123 * - Z : IO Direction mode (Input, Output, Alternate or Analog) 124 * @{ 125 */ 126 #define GPIO_MODE_INPUT ((uint32_t)0x00000000U) /*!< Input Floating Mode */ 127 #define GPIO_MODE_OUTPUT_PP ((uint32_t)0x00000001U) /*!< Output Push Pull Mode */ 128 #define GPIO_MODE_OUTPUT_OD ((uint32_t)0x00000011U) /*!< Output Open Drain Mode */ 129 #define GPIO_MODE_AF_PP ((uint32_t)0x00000002U) /*!< Alternate Function Push Pull Mode */ 130 #define GPIO_MODE_AF_OD ((uint32_t)0x00000012U) /*!< Alternate Function Open Drain Mode */ 131 132 #define GPIO_MODE_AF GPIO_MODE_AF_PP /*!< Alternate Function for Input PIN */ 133 134 #define GPIO_MODE_ANALOG ((uint32_t)0x00000003U) /*!< Analog Mode */ 135 136 #define GPIO_MODE_IT_RISING ((uint32_t)0x10110000U) /*!< External Interrupt Mode with Rising edge trigger detection */ 137 #define GPIO_MODE_IT_FALLING ((uint32_t)0x10210000U) /*!< External Interrupt Mode with Falling edge trigger detection */ 138 #define GPIO_MODE_IT_RISING_FALLING ((uint32_t)0x10310000U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ 139 140 #define GPIO_MODE_EVT_RISING ((uint32_t)0x10120000U) /*!< External Event Mode with Rising edge trigger detection */ 141 #define GPIO_MODE_EVT_FALLING ((uint32_t)0x10220000U) /*!< External Event Mode with Falling edge trigger detection */ 142 #define GPIO_MODE_EVT_RISING_FALLING ((uint32_t)0x10320000U) /*!< External Event Mode with Rising/Falling edge trigger detection */ 143 /** 144 * @} 145 */ 146 147 /** @defgroup GPIO_speed_define GPIO speed define 148 * @brief GPIO Output Maximum frequency 149 * @{ 150 */ 151 #define GPIO_SPEED_FREQ_LOW ((uint32_t)0x00000000U) /*!< Low speed */ 152 #define GPIO_SPEED_FREQ_MEDIUM ((uint32_t)0x00000001U) /*!< Medium speed */ 153 #define GPIO_SPEED_FREQ_HIGH ((uint32_t)0x00000002U) /*!< Fast speed */ 154 #define GPIO_SPEED_FREQ_VERY_HIGH ((uint32_t)0x00000003U) /*!< High speed */ 155 /** 156 * @} 157 */ 158 159 /** @defgroup GPIO_pull_define GPIO pull define 160 * @brief GPIO Pull-Up or Pull-Down Activation 161 * @{ 162 */ 163 #define GPIO_NOPULL ((uint32_t)0x00000000U) /*!< No Pull-up or Pull-down activation */ 164 #define GPIO_PULLUP ((uint32_t)0x00000001U) /*!< Pull-up activation */ 165 #define GPIO_PULLDOWN ((uint32_t)0x00000002U) /*!< Pull-down activation */ 166 /** 167 * @} 168 */ 169 170 /** 171 * @} 172 */ 173 /* Exported macro ------------------------------------------------------------*/ 174 /** @defgroup GPIO_Exported_Macros GPIO Exported Macros 175 * @{ 176 */ 177 178 /** 179 * @brief Checks whether the specified EXTI line is asserted or not. 180 181 * @param __EXTI_LINE__: specifies the EXTI line to check. 182 * This parameter can be GPIO_PIN_x where x can be(0..15) 183 * @retval The new state of __EXTI_LINE__ (SET or RESET). 184 */ 185 #define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__,EXTI) ((EXTI->RPR1 & (__EXTI_LINE__)) | (EXTI->FPR1 & (__EXTI_LINE__))) 186 187 /** 188 * @brief Clears the EXTI's line pending bits. 189 * @param __EXTI_LINE__: specifies the EXTI lines to clear. 190 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 191 192 * @retval None 193 */ 194 #define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__,EXTI) do { \ 195 EXTI->RPR1 = (__EXTI_LINE__); \ 196 EXTI->FPR1 = (__EXTI_LINE__); \ 197 } while (0); 198 199 /** 200 * @brief Checks whether the specified EXTI line is asserted or not for Rising edge. 201 202 * @param __EXTI_LINE__: specifies the EXTI line to check. 203 * This parameter can be GPIO_PIN_x where x can be(0..15) 204 * @retval The new state of __EXTI_LINE__ (SET or RESET). 205 */ 206 #define __HAL_GPIO_EXTI_GET_RISING_IT(__EXTI_LINE__,EXTI) (EXTI->RPR1 & (__EXTI_LINE__)) 207 208 /** 209 * @brief Checks whether the specified EXTI line is asserted or not for Falling edge. 210 211 * @param __EXTI_LINE__: specifies the EXTI line to check. 212 * This parameter can be GPIO_PIN_x where x can be(0..15) 213 * @retval The new state of __EXTI_LINE__ (SET or RESET). 214 */ 215 #define __HAL_GPIO_EXTI_GET_FALLING_IT(__EXTI_LINE__,EXTI) (EXTI->FPR1 & (__EXTI_LINE__)) 216 217 /** 218 * @brief Clears the EXTI's line pending bits for Risng edge. 219 * @param __EXTI_LINE__: specifies the EXTI lines to clear. 220 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 221 * @retval None 222 */ 223 #define __HAL_GPIO_EXTI_CLEAR_RISING_IT(__EXTI_LINE__,EXTI) do { \ 224 EXTI->RPR1 = (__EXTI_LINE__); \ 225 } while (0); 226 227 /** 228 * @brief Clears the EXTI's line pending bits for Falling edge. 229 * @param __EXTI_LINE__: specifies the EXTI lines to clear. 230 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 231 * @retval None 232 */ 233 #define __HAL_GPIO_EXTI_CLEAR_FALLING_IT(__EXTI_LINE__,EXTI) do { \ 234 EXTI->FPR1 = (__EXTI_LINE__); \ 235 } while (0); 236 237 /** 238 * @brief Generates a Software interrupt on selected EXTI line. 239 * @param __EXTI_LINE__: specifies the EXTI line to check. 240 * This parameter can be GPIO_PIN_x where x can be(0..15) 241 * @retval None 242 243 */ 244 #define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__,EXTI) (EXTI->SWIER1 |= (__EXTI_LINE__)) 245 246 /** 247 * @brief Check whether the specified EXTI line flag is set or not. 248 * @param __EXTI_LINE__ specifies the EXTI line flag to check. 249 * This parameter can be GPIO_PIN_x where x can be(0..15) 250 * @retval The new state of __EXTI_LINE__ (SET or RESET). 251 */ 252 #define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) 253 254 /** 255 * @brief Clear the EXTI line pending flags. 256 * @param __EXTI_LINE__ specifies the EXTI lines flags to clear. 257 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 258 * @retval None 259 */ 260 #define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) 261 262 /** 263 * @} 264 */ 265 266 /* Include GPIO HAL Extension module */ 267 #include "stm32mp1xx_hal_gpio_ex.h" 268 269 /* Exported functions --------------------------------------------------------*/ 270 /** @addtogroup GPIO_Exported_Functions 271 * @{ 272 */ 273 274 /** @addtogroup GPIO_Exported_Functions_Group1 275 * @{ 276 */ 277 /* Initialization and de-initialization functions *****************************/ 278 void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init); 279 void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); 280 /** 281 * @} 282 */ 283 284 /** @addtogroup GPIO_Exported_Functions_Group2 285 * @{ 286 */ 287 /* IO operation functions *****************************************************/ 288 GPIO_DirState HAL_GPIO_ReadDir(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 289 GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 290 void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState); 291 void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 292 293 /** 294 * @} 295 */ 296 297 /** 298 * @} 299 */ 300 /* Private types -------------------------------------------------------------*/ 301 /* Private variables ---------------------------------------------------------*/ 302 /* Private constants ---------------------------------------------------------*/ 303 /** @defgroup GPIO_Private_Constants GPIO Private Constants 304 * @{ 305 */ 306 307 /** 308 * @} 309 */ 310 311 /* Private macros ------------------------------------------------------------*/ 312 /** @defgroup GPIO_Private_Macros GPIO Private Macros 313 * @{ 314 */ 315 #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET)) 316 317 #define IS_GPIO_PIN(__PIN__) ((((uint32_t)(__PIN__) & GPIO_PIN_MASK ) != 0x00u) &&\ 318 (((uint32_t)(__PIN__) & ~GPIO_PIN_MASK) == 0x00u)) 319 320 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT) ||\ 321 ((MODE) == GPIO_MODE_OUTPUT_PP) ||\ 322 ((MODE) == GPIO_MODE_OUTPUT_OD) ||\ 323 ((MODE) == GPIO_MODE_AF_PP) ||\ 324 ((MODE) == GPIO_MODE_AF_OD) ||\ 325 ((MODE) == GPIO_MODE_IT_RISING) ||\ 326 ((MODE) == GPIO_MODE_IT_FALLING) ||\ 327 ((MODE) == GPIO_MODE_IT_RISING_FALLING) ||\ 328 ((MODE) == GPIO_MODE_EVT_RISING) ||\ 329 ((MODE) == GPIO_MODE_EVT_FALLING) ||\ 330 ((MODE) == GPIO_MODE_EVT_RISING_FALLING) ||\ 331 ((MODE) == GPIO_MODE_ANALOG)) 332 333 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_SPEED_FREQ_LOW) || ((SPEED) == GPIO_SPEED_FREQ_MEDIUM) || \ 334 ((SPEED) == GPIO_SPEED_FREQ_HIGH) || ((SPEED) == GPIO_SPEED_FREQ_VERY_HIGH)) 335 336 #define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \ 337 ((PULL) == GPIO_PULLDOWN)) 338 /** 339 * @} 340 */ 341 342 /* Private functions ---------------------------------------------------------*/ 343 /** @defgroup GPIO_Private_Functions GPIO Private Functions 344 * @{ 345 */ 346 347 /** 348 * @} 349 */ 350 351 /** 352 * @} 353 */ 354 355 /** 356 * @} 357 */ 358 359 #ifdef __cplusplus 360 } 361 #endif /* __cplusplus */ 362 363 #endif 364