2 ******************************************************************************
3 * @file stm32f30x_gpio.h
4 * @author MCD Application Team
7 * @brief This file contains all the functions prototypes for the GPIO
9 ******************************************************************************
12 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
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:
18 * http://www.st.com/software_license_agreement_liberty_v2
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.
26 ******************************************************************************
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F30x_GPIO_H
31 #define __STM32F30x_GPIO_H
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f30x.h"
40 /** @addtogroup STM32F30x_StdPeriph_Driver
48 /* Exported types ------------------------------------------------------------*/
50 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
51 ((PERIPH) == GPIOB) || \
52 ((PERIPH) == GPIOC) || \
53 ((PERIPH) == GPIOD) || \
54 ((PERIPH) == GPIOE) || \
57 #define IS_GPIO_LIST_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
58 ((PERIPH) == GPIOB) || \
60 /** @defgroup Configuration_Mode_enumeration
65 GPIO_Mode_IN
= 0x00, /*!< GPIO Input Mode */
66 GPIO_Mode_OUT
= 0x01, /*!< GPIO Output Mode */
67 GPIO_Mode_AF
= 0x02, /*!< GPIO Alternate function Mode */
68 GPIO_Mode_AN
= 0x03 /*!< GPIO Analog In/Out Mode */
71 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)|| ((MODE) == GPIO_Mode_OUT) || \
72 ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
77 /** @defgroup Output_type_enumeration
86 #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
92 /** @defgroup Output_Maximum_frequency_enumeration
97 GPIO_Speed_Level_1
= 0x01, /*!< Fast Speed */
98 GPIO_Speed_Level_2
= 0x02, /*!< Meduim Speed */
99 GPIO_Speed_Level_3
= 0x03 /*!< High Speed */
102 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_Level_1) || ((SPEED) == GPIO_Speed_Level_2) || \
103 ((SPEED) == GPIO_Speed_Level_3))
108 /** @defgroup Configuration_Pull-Up_Pull-Down_enumeration
113 GPIO_PuPd_NOPULL
= 0x00,
115 GPIO_PuPd_DOWN
= 0x02
118 #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
119 ((PUPD) == GPIO_PuPd_DOWN))
124 /** @defgroup Bit_SET_and_Bit_RESET_enumeration
133 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
139 * @brief GPIO Init structure definition
143 uint32_t GPIO_Pin
; /*!< Specifies the GPIO pins to be configured.
144 This parameter can be any value of @ref GPIO_pins_define */
146 GPIOMode_TypeDef GPIO_Mode
; /*!< Specifies the operating mode for the selected pins.
147 This parameter can be a value of @ref GPIOMode_TypeDef */
149 GPIOSpeed_TypeDef GPIO_Speed
; /*!< Specifies the speed for the selected pins.
150 This parameter can be a value of @ref GPIOSpeed_TypeDef */
152 GPIOOType_TypeDef GPIO_OType
; /*!< Specifies the operating output type for the selected pins.
153 This parameter can be a value of @ref GPIOOType_TypeDef */
155 GPIOPuPd_TypeDef GPIO_PuPd
; /*!< Specifies the operating Pull-up/Pull down for the selected pins.
156 This parameter can be a value of @ref GPIOPuPd_TypeDef */
159 /* Exported constants --------------------------------------------------------*/
161 /** @defgroup GPIO_Exported_Constants
165 /** @defgroup GPIO_pins_define
168 #define GPIO_Pin_0 ((uint16_t)0x0001) /*!< Pin 0 selected */
169 #define GPIO_Pin_1 ((uint16_t)0x0002) /*!< Pin 1 selected */
170 #define GPIO_Pin_2 ((uint16_t)0x0004) /*!< Pin 2 selected */
171 #define GPIO_Pin_3 ((uint16_t)0x0008) /*!< Pin 3 selected */
172 #define GPIO_Pin_4 ((uint16_t)0x0010) /*!< Pin 4 selected */
173 #define GPIO_Pin_5 ((uint16_t)0x0020) /*!< Pin 5 selected */
174 #define GPIO_Pin_6 ((uint16_t)0x0040) /*!< Pin 6 selected */
175 #define GPIO_Pin_7 ((uint16_t)0x0080) /*!< Pin 7 selected */
176 #define GPIO_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */
177 #define GPIO_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */
178 #define GPIO_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */
179 #define GPIO_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */
180 #define GPIO_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */
181 #define GPIO_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */
182 #define GPIO_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */
183 #define GPIO_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */
184 #define GPIO_Pin_All ((uint16_t)0xFFFF) /*!< All pins selected */
186 #define IS_GPIO_PIN(PIN) ((PIN) != (uint16_t)0x00)
188 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
189 ((PIN) == GPIO_Pin_1) || \
190 ((PIN) == GPIO_Pin_2) || \
191 ((PIN) == GPIO_Pin_3) || \
192 ((PIN) == GPIO_Pin_4) || \
193 ((PIN) == GPIO_Pin_5) || \
194 ((PIN) == GPIO_Pin_6) || \
195 ((PIN) == GPIO_Pin_7) || \
196 ((PIN) == GPIO_Pin_8) || \
197 ((PIN) == GPIO_Pin_9) || \
198 ((PIN) == GPIO_Pin_10) || \
199 ((PIN) == GPIO_Pin_11) || \
200 ((PIN) == GPIO_Pin_12) || \
201 ((PIN) == GPIO_Pin_13) || \
202 ((PIN) == GPIO_Pin_14) || \
203 ((PIN) == GPIO_Pin_15))
209 /** @defgroup GPIO_Pin_sources
212 #define GPIO_PinSource0 ((uint8_t)0x00)
213 #define GPIO_PinSource1 ((uint8_t)0x01)
214 #define GPIO_PinSource2 ((uint8_t)0x02)
215 #define GPIO_PinSource3 ((uint8_t)0x03)
216 #define GPIO_PinSource4 ((uint8_t)0x04)
217 #define GPIO_PinSource5 ((uint8_t)0x05)
218 #define GPIO_PinSource6 ((uint8_t)0x06)
219 #define GPIO_PinSource7 ((uint8_t)0x07)
220 #define GPIO_PinSource8 ((uint8_t)0x08)
221 #define GPIO_PinSource9 ((uint8_t)0x09)
222 #define GPIO_PinSource10 ((uint8_t)0x0A)
223 #define GPIO_PinSource11 ((uint8_t)0x0B)
224 #define GPIO_PinSource12 ((uint8_t)0x0C)
225 #define GPIO_PinSource13 ((uint8_t)0x0D)
226 #define GPIO_PinSource14 ((uint8_t)0x0E)
227 #define GPIO_PinSource15 ((uint8_t)0x0F)
229 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
230 ((PINSOURCE) == GPIO_PinSource1) || \
231 ((PINSOURCE) == GPIO_PinSource2) || \
232 ((PINSOURCE) == GPIO_PinSource3) || \
233 ((PINSOURCE) == GPIO_PinSource4) || \
234 ((PINSOURCE) == GPIO_PinSource5) || \
235 ((PINSOURCE) == GPIO_PinSource6) || \
236 ((PINSOURCE) == GPIO_PinSource7) || \
237 ((PINSOURCE) == GPIO_PinSource8) || \
238 ((PINSOURCE) == GPIO_PinSource9) || \
239 ((PINSOURCE) == GPIO_PinSource10) || \
240 ((PINSOURCE) == GPIO_PinSource11) || \
241 ((PINSOURCE) == GPIO_PinSource12) || \
242 ((PINSOURCE) == GPIO_PinSource13) || \
243 ((PINSOURCE) == GPIO_PinSource14) || \
244 ((PINSOURCE) == GPIO_PinSource15))
249 /** @defgroup GPIO_Alternate_function_selection_define
254 * @brief AF 0 selection
256 #define GPIO_AF_0 ((uint8_t)0x00) /* JTCK-SWCLK, JTDI, JTDO/TRACESW0, JTMS-SWDAT,
257 MCO, NJTRST, TRACED, TRACECK */
259 * @brief AF 1 selection
261 #define GPIO_AF_1 ((uint8_t)0x01) /* OUT, TIM2, TIM15, TIM16, TIM17 */
264 * @brief AF 2 selection
266 #define GPIO_AF_2 ((uint8_t)0x02) /* COMP1_OUT, TIM1, TIM2, TIM3, TIM4, TIM8, TIM15, TIM16 */
269 * @brief AF 3 selection
271 #define GPIO_AF_3 ((uint8_t)0x03) /* COMP7_OUT, TIM8, TIM15, Touch, HRTIM1 */
274 * @brief AF 4 selection
276 #define GPIO_AF_4 ((uint8_t)0x04) /* I2C1, I2C2, TIM1, TIM8, TIM16, TIM17 */
279 * @brief AF 5 selection
281 #define GPIO_AF_5 ((uint8_t)0x05) /* IR_OUT, I2S2, I2S3, SPI1, SPI2, TIM8, USART4, USART5 */
284 * @brief AF 6 selection
286 #define GPIO_AF_6 ((uint8_t)0x06) /* IR_OUT, I2S2, I2S3, SPI2, SPI3, TIM1, TIM8 */
289 * @brief AF 7 selection
291 #define GPIO_AF_7 ((uint8_t)0x07) /* AOP2_OUT, CAN, COMP3_OUT, COMP5_OUT, COMP6_OUT,
292 USART1, USART2, USART3 */
295 * @brief AF 8 selection
297 #define GPIO_AF_8 ((uint8_t)0x08) /* COMP1_OUT, COMP2_OUT, COMP3_OUT, COMP4_OUT,
298 COMP5_OUT, COMP6_OUT */
301 * @brief AF 9 selection
303 #define GPIO_AF_9 ((uint8_t)0x09) /* AOP4_OUT, CAN, TIM1, TIM8, TIM15 */
306 * @brief AF 10 selection
308 #define GPIO_AF_10 ((uint8_t)0x0A) /* AOP1_OUT, AOP3_OUT, TIM2, TIM3, TIM4, TIM8, TIM17 */
311 * @brief AF 11 selection
313 #define GPIO_AF_11 ((uint8_t)0x0B) /* TIM1, TIM8 */
316 * @brief AF 12 selection
318 #define GPIO_AF_12 ((uint8_t)0x0C) /* TIM1, HRTIM1 */
321 * @brief AF 13 selection
323 #define GPIO_AF_13 ((uint8_t)0x0D) /* HRTIM1, AOP2_OUT */
326 * @brief AF 14 selection
328 #define GPIO_AF_14 ((uint8_t)0x0E) /* USBDM, USBDP */
331 * @brief AF 15 selection
333 #define GPIO_AF_15 ((uint8_t)0x0F) /* OUT */
335 #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_0)||((AF) == GPIO_AF_1)||\
336 ((AF) == GPIO_AF_2)||((AF) == GPIO_AF_3)||\
337 ((AF) == GPIO_AF_4)||((AF) == GPIO_AF_5)||\
338 ((AF) == GPIO_AF_6)||((AF) == GPIO_AF_7)||\
339 ((AF) == GPIO_AF_8)||((AF) == GPIO_AF_9)||\
340 ((AF) == GPIO_AF_10)||((AF) == GPIO_AF_11)||\
341 ((AF) == GPIO_AF_12)||((AF) == GPIO_AF_13)||\
342 ((AF) == GPIO_AF_14)||((AF) == GPIO_AF_15))
348 /** @defgroup GPIO_Speed_Legacy
352 #define GPIO_Speed_10MHz GPIO_Speed_Level_1 /*!< Fast Speed:10MHz */
353 #define GPIO_Speed_2MHz GPIO_Speed_Level_2 /*!< Medium Speed:2MHz */
354 #define GPIO_Speed_50MHz GPIO_Speed_Level_3 /*!< High Speed:50MHz */
364 /* Exported macro ------------------------------------------------------------*/
365 /* Exported functions ------------------------------------------------------- */
366 /* Function used to set the GPIO configuration to the default reset state *****/
367 void GPIO_DeInit(GPIO_TypeDef
* GPIOx
);
369 /* Initialization and Configuration functions *********************************/
370 void GPIO_Init(GPIO_TypeDef
* GPIOx
, GPIO_InitTypeDef
* GPIO_InitStruct
);
371 void GPIO_StructInit(GPIO_InitTypeDef
* GPIO_InitStruct
);
372 void GPIO_PinLockConfig(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
374 /* GPIO Read and Write functions **********************************************/
375 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
376 uint16_t GPIO_ReadInputData(GPIO_TypeDef
* GPIOx
);
377 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
378 uint16_t GPIO_ReadOutputData(GPIO_TypeDef
* GPIOx
);
379 void GPIO_SetBits(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
380 void GPIO_ResetBits(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
);
381 void GPIO_WriteBit(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_Pin
, BitAction BitVal
);
382 void GPIO_Write(GPIO_TypeDef
* GPIOx
, uint16_t PortVal
);
384 /* GPIO Alternate functions configuration functions ***************************/
385 void GPIO_PinAFConfig(GPIO_TypeDef
* GPIOx
, uint16_t GPIO_PinSource
, uint8_t GPIO_AF
);
391 #endif /* __STM32F30x_GPIO_H */
400 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/