1 /** 2 ****************************************************************************** 3 * @file stm32f30x_gpio.h 4 * @author MCD Application Team 5 * @version V1.2.3 6 * @date 10-July-2015 7 * @brief This file contains all the functions prototypes for the GPIO 8 * firmware library. 9 ****************************************************************************** 10 * @attention 11 * 12 * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> 13 * 14 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 * You may not use this file except in compliance with the License. 16 * You may obtain a copy of the License at: 17 * 18 * http://www.st.com/software_license_agreement_liberty_v2 19 * 20 * Unless required by applicable law or agreed to in writing, software 21 * distributed under the License is distributed on an "AS IS" BASIS, 22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 * See the License for the specific language governing permissions and 24 * limitations under the License. 25 * 26 ****************************************************************************** 27 */ 28 29 /* Define to prevent recursive inclusion -------------------------------------*/ 30 #ifndef __STM32F30x_GPIO_H 31 #define __STM32F30x_GPIO_H 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 /* Includes ------------------------------------------------------------------*/ 38 #include "stm32f30x.h" 39 40 /** @addtogroup STM32F30x_StdPeriph_Driver 41 * @{ 42 */ 43 44 /** @addtogroup GPIO 45 * @{ 46 */ 47 48 /* Exported types ------------------------------------------------------------*/ 49 50 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \ 51 ((PERIPH) == GPIOB) || \ 52 ((PERIPH) == GPIOC) || \ 53 ((PERIPH) == GPIOD) || \ 54 ((PERIPH) == GPIOE) || \ 55 ((PERIPH) == GPIOF) || \ 56 ((PERIPH) == GPIOG) || \ 57 ((PERIPH) == GPIOH)) 58 59 #define IS_GPIO_LIST_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \ 60 ((PERIPH) == GPIOB) || \ 61 ((PERIPH) == GPIOC)|| \ 62 ((PERIPH) == GPIOD) || \ 63 ((PERIPH) == GPIOF)) 64 /** @defgroup Configuration_Mode_enumeration 65 * @{ 66 */ 67 typedef enum 68 { 69 GPIO_Mode_IN = 0x00, /*!< GPIO Input Mode */ 70 GPIO_Mode_OUT = 0x01, /*!< GPIO Output Mode */ 71 GPIO_Mode_AF = 0x02, /*!< GPIO Alternate function Mode */ 72 GPIO_Mode_AN = 0x03 /*!< GPIO Analog In/Out Mode */ 73 }GPIOMode_TypeDef; 74 75 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)|| ((MODE) == GPIO_Mode_OUT) || \ 76 ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN)) 77 /** 78 * @} 79 */ 80 81 /** @defgroup Output_type_enumeration 82 * @{ 83 */ 84 typedef enum 85 { 86 GPIO_OType_PP = 0x00, 87 GPIO_OType_OD = 0x01 88 }GPIOOType_TypeDef; 89 90 #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD)) 91 92 /** 93 * @} 94 */ 95 96 /** @defgroup Output_Maximum_frequency_enumeration 97 * @{ 98 */ 99 typedef enum 100 { 101 GPIO_Speed_Level_1 = 0x01, /*!< Fast Speed */ 102 GPIO_Speed_Level_2 = 0x02, /*!< Meduim Speed */ 103 GPIO_Speed_Level_3 = 0x03 /*!< High Speed */ 104 }GPIOSpeed_TypeDef; 105 106 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_Level_1) || ((SPEED) == GPIO_Speed_Level_2) || \ 107 ((SPEED) == GPIO_Speed_Level_3)) 108 /** 109 * @} 110 */ 111 112 /** @defgroup Configuration_Pull-Up_Pull-Down_enumeration 113 * @{ 114 */ 115 typedef enum 116 { 117 GPIO_PuPd_NOPULL = 0x00, 118 GPIO_PuPd_UP = 0x01, 119 GPIO_PuPd_DOWN = 0x02 120 }GPIOPuPd_TypeDef; 121 122 #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \ 123 ((PUPD) == GPIO_PuPd_DOWN)) 124 /** 125 * @} 126 */ 127 128 /** @defgroup Bit_SET_and_Bit_RESET_enumeration 129 * @{ 130 */ 131 typedef enum 132 { 133 Bit_RESET = 0, 134 Bit_SET 135 }BitAction; 136 137 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET)) 138 /** 139 * @} 140 */ 141 142 /** 143 * @brief GPIO Init structure definition 144 */ 145 typedef struct 146 { 147 uint32_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured. 148 This parameter can be any value of @ref GPIO_pins_define */ 149 150 GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins. 151 This parameter can be a value of @ref GPIOMode_TypeDef */ 152 153 GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins. 154 This parameter can be a value of @ref GPIOSpeed_TypeDef */ 155 156 GPIOOType_TypeDef GPIO_OType; /*!< Specifies the operating output type for the selected pins. 157 This parameter can be a value of @ref GPIOOType_TypeDef */ 158 159 GPIOPuPd_TypeDef GPIO_PuPd; /*!< Specifies the operating Pull-up/Pull down for the selected pins. 160 This parameter can be a value of @ref GPIOPuPd_TypeDef */ 161 }GPIO_InitTypeDef; 162 163 /* Exported constants --------------------------------------------------------*/ 164 165 /** @defgroup GPIO_Exported_Constants 166 * @{ 167 */ 168 169 /** @defgroup GPIO_pins_define 170 * @{ 171 */ 172 #define GPIO_Pin_0 ((uint16_t)0x0001) /*!< Pin 0 selected */ 173 #define GPIO_Pin_1 ((uint16_t)0x0002) /*!< Pin 1 selected */ 174 #define GPIO_Pin_2 ((uint16_t)0x0004) /*!< Pin 2 selected */ 175 #define GPIO_Pin_3 ((uint16_t)0x0008) /*!< Pin 3 selected */ 176 #define GPIO_Pin_4 ((uint16_t)0x0010) /*!< Pin 4 selected */ 177 #define GPIO_Pin_5 ((uint16_t)0x0020) /*!< Pin 5 selected */ 178 #define GPIO_Pin_6 ((uint16_t)0x0040) /*!< Pin 6 selected */ 179 #define GPIO_Pin_7 ((uint16_t)0x0080) /*!< Pin 7 selected */ 180 #define GPIO_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */ 181 #define GPIO_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */ 182 #define GPIO_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */ 183 #define GPIO_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */ 184 #define GPIO_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */ 185 #define GPIO_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */ 186 #define GPIO_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */ 187 #define GPIO_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */ 188 #define GPIO_Pin_All ((uint16_t)0xFFFF) /*!< All pins selected */ 189 190 #define IS_GPIO_PIN(PIN) ((PIN) != (uint16_t)0x00) 191 192 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \ 193 ((PIN) == GPIO_Pin_1) || \ 194 ((PIN) == GPIO_Pin_2) || \ 195 ((PIN) == GPIO_Pin_3) || \ 196 ((PIN) == GPIO_Pin_4) || \ 197 ((PIN) == GPIO_Pin_5) || \ 198 ((PIN) == GPIO_Pin_6) || \ 199 ((PIN) == GPIO_Pin_7) || \ 200 ((PIN) == GPIO_Pin_8) || \ 201 ((PIN) == GPIO_Pin_9) || \ 202 ((PIN) == GPIO_Pin_10) || \ 203 ((PIN) == GPIO_Pin_11) || \ 204 ((PIN) == GPIO_Pin_12) || \ 205 ((PIN) == GPIO_Pin_13) || \ 206 ((PIN) == GPIO_Pin_14) || \ 207 ((PIN) == GPIO_Pin_15)) 208 209 /** 210 * @} 211 */ 212 213 /** @defgroup GPIO_Pin_sources 214 * @{ 215 */ 216 #define GPIO_PinSource0 ((uint8_t)0x00) 217 #define GPIO_PinSource1 ((uint8_t)0x01) 218 #define GPIO_PinSource2 ((uint8_t)0x02) 219 #define GPIO_PinSource3 ((uint8_t)0x03) 220 #define GPIO_PinSource4 ((uint8_t)0x04) 221 #define GPIO_PinSource5 ((uint8_t)0x05) 222 #define GPIO_PinSource6 ((uint8_t)0x06) 223 #define GPIO_PinSource7 ((uint8_t)0x07) 224 #define GPIO_PinSource8 ((uint8_t)0x08) 225 #define GPIO_PinSource9 ((uint8_t)0x09) 226 #define GPIO_PinSource10 ((uint8_t)0x0A) 227 #define GPIO_PinSource11 ((uint8_t)0x0B) 228 #define GPIO_PinSource12 ((uint8_t)0x0C) 229 #define GPIO_PinSource13 ((uint8_t)0x0D) 230 #define GPIO_PinSource14 ((uint8_t)0x0E) 231 #define GPIO_PinSource15 ((uint8_t)0x0F) 232 233 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \ 234 ((PINSOURCE) == GPIO_PinSource1) || \ 235 ((PINSOURCE) == GPIO_PinSource2) || \ 236 ((PINSOURCE) == GPIO_PinSource3) || \ 237 ((PINSOURCE) == GPIO_PinSource4) || \ 238 ((PINSOURCE) == GPIO_PinSource5) || \ 239 ((PINSOURCE) == GPIO_PinSource6) || \ 240 ((PINSOURCE) == GPIO_PinSource7) || \ 241 ((PINSOURCE) == GPIO_PinSource8) || \ 242 ((PINSOURCE) == GPIO_PinSource9) || \ 243 ((PINSOURCE) == GPIO_PinSource10) || \ 244 ((PINSOURCE) == GPIO_PinSource11) || \ 245 ((PINSOURCE) == GPIO_PinSource12) || \ 246 ((PINSOURCE) == GPIO_PinSource13) || \ 247 ((PINSOURCE) == GPIO_PinSource14) || \ 248 ((PINSOURCE) == GPIO_PinSource15)) 249 /** 250 * @} 251 */ 252 253 /** @defgroup GPIO_Alternate_function_selection_define 254 * @{ 255 */ 256 257 /** 258 * @brief AF 0 selection 259 */ 260 #define GPIO_AF_0 ((uint8_t)0x00) /* JTCK-SWCLK, JTDI, JTDO/TRACESW0, JTMS-SWDAT, 261 MCO, NJTRST, TRACED, TRACECK */ 262 /** 263 * @brief AF 1 selection 264 */ 265 #define GPIO_AF_1 ((uint8_t)0x01) /* OUT, TIM2, TIM15, TIM16, TIM17 */ 266 267 /** 268 * @brief AF 2 selection 269 */ 270 #define GPIO_AF_2 ((uint8_t)0x02) /* COMP1_OUT, TIM1, TIM2, TIM3, TIM4, TIM8, TIM15, TIM16 */ 271 272 /** 273 * @brief AF 3 selection 274 */ 275 #define GPIO_AF_3 ((uint8_t)0x03) /* COMP7_OUT, TIM8, TIM15, Touch, HRTIM1 */ 276 277 /** 278 * @brief AF 4 selection 279 */ 280 #define GPIO_AF_4 ((uint8_t)0x04) /* I2C1, I2C2, TIM1, TIM8, TIM16, TIM17 */ 281 282 /** 283 * @brief AF 5 selection 284 */ 285 #define GPIO_AF_5 ((uint8_t)0x05) /* IR_OUT, I2S2, I2S3, SPI1, SPI2, TIM8, USART4, USART5 */ 286 287 /** 288 * @brief AF 6 selection 289 */ 290 #define GPIO_AF_6 ((uint8_t)0x06) /* IR_OUT, I2S2, I2S3, SPI2, SPI3, TIM1, TIM8 */ 291 292 /** 293 * @brief AF 7 selection 294 */ 295 #define GPIO_AF_7 ((uint8_t)0x07) /* AOP2_OUT, CAN, COMP3_OUT, COMP5_OUT, COMP6_OUT, 296 USART1, USART2, USART3 */ 297 298 /** 299 * @brief AF 8 selection 300 */ 301 #define GPIO_AF_8 ((uint8_t)0x08) /* COMP1_OUT, COMP2_OUT, COMP3_OUT, COMP4_OUT, 302 COMP5_OUT, COMP6_OUT */ 303 304 /** 305 * @brief AF 9 selection 306 */ 307 #define GPIO_AF_9 ((uint8_t)0x09) /* AOP4_OUT, CAN, TIM1, TIM8, TIM15 */ 308 309 /** 310 * @brief AF 10 selection 311 */ 312 #define GPIO_AF_10 ((uint8_t)0x0A) /* AOP1_OUT, AOP3_OUT, TIM2, TIM3, TIM4, TIM8, TIM17 */ 313 314 /** 315 * @brief AF 11 selection 316 */ 317 #define GPIO_AF_11 ((uint8_t)0x0B) /* TIM1, TIM8 */ 318 319 /** 320 * @brief AF 12 selection 321 */ 322 #define GPIO_AF_12 ((uint8_t)0x0C) /* TIM1, HRTIM1 */ 323 324 /** 325 * @brief AF 13 selection 326 */ 327 #define GPIO_AF_13 ((uint8_t)0x0D) /* HRTIM1, AOP2_OUT */ 328 329 /** 330 * @brief AF 14 selection 331 */ 332 #define GPIO_AF_14 ((uint8_t)0x0E) /* USBDM, USBDP */ 333 334 /** 335 * @brief AF 15 selection 336 */ 337 #define GPIO_AF_15 ((uint8_t)0x0F) /* OUT */ 338 339 #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_0)||((AF) == GPIO_AF_1)||\ 340 ((AF) == GPIO_AF_2)||((AF) == GPIO_AF_3)||\ 341 ((AF) == GPIO_AF_4)||((AF) == GPIO_AF_5)||\ 342 ((AF) == GPIO_AF_6)||((AF) == GPIO_AF_7)||\ 343 ((AF) == GPIO_AF_8)||((AF) == GPIO_AF_9)||\ 344 ((AF) == GPIO_AF_10)||((AF) == GPIO_AF_11)||\ 345 ((AF) == GPIO_AF_12)||((AF) == GPIO_AF_13)||\ 346 ((AF) == GPIO_AF_14)||((AF) == GPIO_AF_15)) 347 348 /** 349 * @} 350 */ 351 352 /** @defgroup GPIO_Speed_Legacy 353 * @{ 354 */ 355 356 #define GPIO_Speed_10MHz GPIO_Speed_Level_1 /*!< Fast Speed:10MHz */ 357 #define GPIO_Speed_2MHz GPIO_Speed_Level_2 /*!< Medium Speed:2MHz */ 358 #define GPIO_Speed_50MHz GPIO_Speed_Level_3 /*!< High Speed:50MHz */ 359 360 /** 361 * @} 362 */ 363 364 /** 365 * @} 366 */ 367 368 /* Exported macro ------------------------------------------------------------*/ 369 /* Exported functions ------------------------------------------------------- */ 370 /* Function used to set the GPIO configuration to the default reset state *****/ 371 void GPIO_DeInit(GPIO_TypeDef* GPIOx); 372 373 /* Initialization and Configuration functions *********************************/ 374 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct); 375 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct); 376 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 377 378 /* GPIO Read and Write functions **********************************************/ 379 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 380 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx); 381 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 382 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx); 383 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 384 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 385 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal); 386 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal); 387 388 /* GPIO Alternate functions configuration functions ***************************/ 389 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF); 390 391 #ifdef __cplusplus 392 } 393 #endif 394 395 #endif /* __STM32F30x_GPIO_H */ 396 /** 397 * @} 398 */ 399 400 /** 401 * @} 402 */ 403 404 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 405