1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_gpio.h
4   * @author  MCD Application Team
5   * @version V1.5.1
6   * @date    22-May-2015
7   * @brief   This file contains all the functions prototypes for the GPIO firmware
8   *          library.
9   ******************************************************************************
10   * @attention
11   *
12   * <h2><center>&copy; 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 __STM32F4xx_GPIO_H
31 #define __STM32F4xx_GPIO_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx.h"
39 
40 /** @addtogroup STM32F4xx_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                                     ((PERIPH) == GPIOI) || \
59                                     ((PERIPH) == GPIOJ) || \
60                                     ((PERIPH) == GPIOK))
61 
62 /**
63   * @brief  GPIO Configuration Mode enumeration
64   */
65 typedef enum
66 {
67   GPIO_Mode_IN   = 0x00, /*!< GPIO Input Mode */
68   GPIO_Mode_OUT  = 0x01, /*!< GPIO Output Mode */
69   GPIO_Mode_AF   = 0x02, /*!< GPIO Alternate function Mode */
70   GPIO_Mode_AN   = 0x03  /*!< GPIO Analog Mode */
71 }GPIOMode_TypeDef;
72 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)  || ((MODE) == GPIO_Mode_OUT) || \
73                             ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
74 
75 /**
76   * @brief  GPIO Output type enumeration
77   */
78 typedef enum
79 {
80   GPIO_OType_PP = 0x00,
81   GPIO_OType_OD = 0x01
82 }GPIOOType_TypeDef;
83 #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
84 
85 
86 /**
87   * @brief  GPIO Output Maximum frequency enumeration
88   */
89 typedef enum
90 {
91   GPIO_Low_Speed     = 0x00, /*!< Low speed    */
92   GPIO_Medium_Speed  = 0x01, /*!< Medium speed */
93   GPIO_Fast_Speed    = 0x02, /*!< Fast speed   */
94   GPIO_High_Speed    = 0x03  /*!< High speed   */
95 }GPIOSpeed_TypeDef;
96 
97 /* Add legacy definition */
98 #define  GPIO_Speed_2MHz    GPIO_Low_Speed
99 #define  GPIO_Speed_25MHz   GPIO_Medium_Speed
100 #define  GPIO_Speed_50MHz   GPIO_Fast_Speed
101 #define  GPIO_Speed_100MHz  GPIO_High_Speed
102 
103 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Low_Speed) || ((SPEED) == GPIO_Medium_Speed) || \
104                               ((SPEED) == GPIO_Fast_Speed)||  ((SPEED) == GPIO_High_Speed))
105 
106 /**
107   * @brief  GPIO Configuration PullUp PullDown enumeration
108   */
109 typedef enum
110 {
111   GPIO_PuPd_NOPULL = 0x00,
112   GPIO_PuPd_UP     = 0x01,
113   GPIO_PuPd_DOWN   = 0x02
114 }GPIOPuPd_TypeDef;
115 #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
116                             ((PUPD) == GPIO_PuPd_DOWN))
117 
118 /**
119   * @brief  GPIO Bit SET and Bit RESET enumeration
120   */
121 typedef enum
122 {
123   Bit_RESET = 0,
124   Bit_SET
125 }BitAction;
126 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
127 
128 
129 /**
130   * @brief   GPIO Init structure definition
131   */
132 typedef struct
133 {
134   uint32_t GPIO_Pin;              /*!< Specifies the GPIO pins to be configured.
135                                        This parameter can be any value of @ref GPIO_pins_define */
136 
137   GPIOMode_TypeDef GPIO_Mode;     /*!< Specifies the operating mode for the selected pins.
138                                        This parameter can be a value of @ref GPIOMode_TypeDef */
139 
140   GPIOSpeed_TypeDef GPIO_Speed;   /*!< Specifies the speed for the selected pins.
141                                        This parameter can be a value of @ref GPIOSpeed_TypeDef */
142 
143   GPIOOType_TypeDef GPIO_OType;   /*!< Specifies the operating output type for the selected pins.
144                                        This parameter can be a value of @ref GPIOOType_TypeDef */
145 
146   GPIOPuPd_TypeDef GPIO_PuPd;     /*!< Specifies the operating Pull-up/Pull down for the selected pins.
147                                        This parameter can be a value of @ref GPIOPuPd_TypeDef */
148 }GPIO_InitTypeDef;
149 
150 /* Exported constants --------------------------------------------------------*/
151 
152 /** @defgroup GPIO_Exported_Constants
153   * @{
154   */
155 
156 /** @defgroup GPIO_pins_define
157   * @{
158   */
159 #define GPIO_Pin_0                 ((uint16_t)0x0001)  /* Pin 0 selected */
160 #define GPIO_Pin_1                 ((uint16_t)0x0002)  /* Pin 1 selected */
161 #define GPIO_Pin_2                 ((uint16_t)0x0004)  /* Pin 2 selected */
162 #define GPIO_Pin_3                 ((uint16_t)0x0008)  /* Pin 3 selected */
163 #define GPIO_Pin_4                 ((uint16_t)0x0010)  /* Pin 4 selected */
164 #define GPIO_Pin_5                 ((uint16_t)0x0020)  /* Pin 5 selected */
165 #define GPIO_Pin_6                 ((uint16_t)0x0040)  /* Pin 6 selected */
166 #define GPIO_Pin_7                 ((uint16_t)0x0080)  /* Pin 7 selected */
167 #define GPIO_Pin_8                 ((uint16_t)0x0100)  /* Pin 8 selected */
168 #define GPIO_Pin_9                 ((uint16_t)0x0200)  /* Pin 9 selected */
169 #define GPIO_Pin_10                ((uint16_t)0x0400)  /* Pin 10 selected */
170 #define GPIO_Pin_11                ((uint16_t)0x0800)  /* Pin 11 selected */
171 #define GPIO_Pin_12                ((uint16_t)0x1000)  /* Pin 12 selected */
172 #define GPIO_Pin_13                ((uint16_t)0x2000)  /* Pin 13 selected */
173 #define GPIO_Pin_14                ((uint16_t)0x4000)  /* Pin 14 selected */
174 #define GPIO_Pin_15                ((uint16_t)0x8000)  /* Pin 15 selected */
175 #define GPIO_Pin_All               ((uint16_t)0xFFFF)  /* All pins selected */
176 
177 #define GPIO_PIN_MASK              ((uint32_t)0x0000FFFF) /* PIN mask for assert test */
178 #define IS_GPIO_PIN(PIN)           (((PIN) & GPIO_PIN_MASK ) != (uint32_t)0x00)
179 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
180                               ((PIN) == GPIO_Pin_1) || \
181                               ((PIN) == GPIO_Pin_2) || \
182                               ((PIN) == GPIO_Pin_3) || \
183                               ((PIN) == GPIO_Pin_4) || \
184                               ((PIN) == GPIO_Pin_5) || \
185                               ((PIN) == GPIO_Pin_6) || \
186                               ((PIN) == GPIO_Pin_7) || \
187                               ((PIN) == GPIO_Pin_8) || \
188                               ((PIN) == GPIO_Pin_9) || \
189                               ((PIN) == GPIO_Pin_10) || \
190                               ((PIN) == GPIO_Pin_11) || \
191                               ((PIN) == GPIO_Pin_12) || \
192                               ((PIN) == GPIO_Pin_13) || \
193                               ((PIN) == GPIO_Pin_14) || \
194                               ((PIN) == GPIO_Pin_15))
195 /**
196   * @}
197   */
198 
199 
200 /** @defgroup GPIO_Pin_sources
201   * @{
202   */
203 #define GPIO_PinSource0            ((uint8_t)0x00)
204 #define GPIO_PinSource1            ((uint8_t)0x01)
205 #define GPIO_PinSource2            ((uint8_t)0x02)
206 #define GPIO_PinSource3            ((uint8_t)0x03)
207 #define GPIO_PinSource4            ((uint8_t)0x04)
208 #define GPIO_PinSource5            ((uint8_t)0x05)
209 #define GPIO_PinSource6            ((uint8_t)0x06)
210 #define GPIO_PinSource7            ((uint8_t)0x07)
211 #define GPIO_PinSource8            ((uint8_t)0x08)
212 #define GPIO_PinSource9            ((uint8_t)0x09)
213 #define GPIO_PinSource10           ((uint8_t)0x0A)
214 #define GPIO_PinSource11           ((uint8_t)0x0B)
215 #define GPIO_PinSource12           ((uint8_t)0x0C)
216 #define GPIO_PinSource13           ((uint8_t)0x0D)
217 #define GPIO_PinSource14           ((uint8_t)0x0E)
218 #define GPIO_PinSource15           ((uint8_t)0x0F)
219 
220 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
221                                        ((PINSOURCE) == GPIO_PinSource1) || \
222                                        ((PINSOURCE) == GPIO_PinSource2) || \
223                                        ((PINSOURCE) == GPIO_PinSource3) || \
224                                        ((PINSOURCE) == GPIO_PinSource4) || \
225                                        ((PINSOURCE) == GPIO_PinSource5) || \
226                                        ((PINSOURCE) == GPIO_PinSource6) || \
227                                        ((PINSOURCE) == GPIO_PinSource7) || \
228                                        ((PINSOURCE) == GPIO_PinSource8) || \
229                                        ((PINSOURCE) == GPIO_PinSource9) || \
230                                        ((PINSOURCE) == GPIO_PinSource10) || \
231                                        ((PINSOURCE) == GPIO_PinSource11) || \
232                                        ((PINSOURCE) == GPIO_PinSource12) || \
233                                        ((PINSOURCE) == GPIO_PinSource13) || \
234                                        ((PINSOURCE) == GPIO_PinSource14) || \
235                                        ((PINSOURCE) == GPIO_PinSource15))
236 /**
237   * @}
238   */
239 
240 /** @defgroup GPIO_Alternat_function_selection_define
241   * @{
242   */
243 /**
244   * @brief   AF 0 selection
245   */
246 #define GPIO_AF_RTC_50Hz      ((uint8_t)0x00)  /* RTC_50Hz Alternate Function mapping */
247 #define GPIO_AF_MCO           ((uint8_t)0x00)  /* MCO (MCO1 and MCO2) Alternate Function mapping */
248 #define GPIO_AF_TAMPER        ((uint8_t)0x00)  /* TAMPER (TAMPER_1 and TAMPER_2) Alternate Function mapping */
249 #define GPIO_AF_SWJ           ((uint8_t)0x00)  /* SWJ (SWD and JTAG) Alternate Function mapping */
250 #define GPIO_AF_TRACE         ((uint8_t)0x00)  /* TRACE Alternate Function mapping */
251 #if defined (STM32F446xx)
252 #define GPIO_AF0_TIM2         ((uint8_t)0x00)  /* TIM2 Alternate Function mapping */
253 #endif /* STM32F446xx */
254 
255 /**
256   * @brief   AF 1 selection
257   */
258 #define GPIO_AF_TIM1          ((uint8_t)0x01)  /* TIM1 Alternate Function mapping */
259 #define GPIO_AF_TIM2          ((uint8_t)0x01)  /* TIM2 Alternate Function mapping */
260 
261 /**
262   * @brief   AF 2 selection
263   */
264 #define GPIO_AF_TIM3          ((uint8_t)0x02)  /* TIM3 Alternate Function mapping */
265 #define GPIO_AF_TIM4          ((uint8_t)0x02)  /* TIM4 Alternate Function mapping */
266 #define GPIO_AF_TIM5          ((uint8_t)0x02)  /* TIM5 Alternate Function mapping */
267 
268 /**
269   * @brief   AF 3 selection
270   */
271 #define GPIO_AF_TIM8          ((uint8_t)0x03)  /* TIM8 Alternate Function mapping */
272 #define GPIO_AF_TIM9          ((uint8_t)0x03)  /* TIM9 Alternate Function mapping */
273 #define GPIO_AF_TIM10         ((uint8_t)0x03)  /* TIM10 Alternate Function mapping */
274 #define GPIO_AF_TIM11         ((uint8_t)0x03)  /* TIM11 Alternate Function mapping */
275 #if defined (STM32F446xx)
276 #define GPIO_AF3_CEC          ((uint8_t)0x03)  /* CEC Alternate Function mapping */
277 #endif /* STM32F446xx */
278 /**
279   * @brief   AF 4 selection
280   */
281 #define GPIO_AF_I2C1          ((uint8_t)0x04)  /* I2C1 Alternate Function mapping */
282 #define GPIO_AF_I2C2          ((uint8_t)0x04)  /* I2C2 Alternate Function mapping */
283 #define GPIO_AF_I2C3          ((uint8_t)0x04)  /* I2C3 Alternate Function mapping */
284 #if defined (STM32F446xx)
285 #define GPIO_AF4_CEC          ((uint8_t)0x04)  /* CEC Alternate Function mapping */
286 #define GPIO_AF_FMPI2C        ((uint8_t)0x04)  /* FMPI2C Alternate Function mapping */
287 #endif /* STM32F446xx */
288 
289 /**
290   * @brief   AF 5 selection
291   */
292 #define GPIO_AF_SPI1          ((uint8_t)0x05)  /* SPI1/I2S1 Alternate Function mapping */
293 #define GPIO_AF_SPI2          ((uint8_t)0x05)  /* SPI2/I2S2 Alternate Function mapping */
294 #define GPIO_AF5_SPI3         ((uint8_t)0x05)  /* SPI3/I2S3 Alternate Function mapping (Only for STM32F411xE Devices) */
295 #define GPIO_AF_SPI4          ((uint8_t)0x05)  /* SPI4/I2S4 Alternate Function mapping */
296 #define GPIO_AF_SPI5          ((uint8_t)0x05)  /* SPI5 Alternate Function mapping      */
297 #define GPIO_AF_SPI6          ((uint8_t)0x05)  /* SPI6 Alternate Function mapping      */
298 
299 /**
300   * @brief   AF 6 selection
301   */
302 #define GPIO_AF_SPI3          ((uint8_t)0x06)  /* SPI3/I2S3 Alternate Function mapping */
303 #define GPIO_AF6_SPI2         ((uint8_t)0x06)  /* SPI2 Alternate Function mapping (Only for STM32F411xE Devices) */
304 #define GPIO_AF6_SPI4         ((uint8_t)0x06)  /* SPI4 Alternate Function mapping (Only for STM32F411xE Devices) */
305 #define GPIO_AF6_SPI5         ((uint8_t)0x06)  /* SPI5 Alternate Function mapping (Only for STM32F411xE Devices) */
306 #define GPIO_AF_SAI1          ((uint8_t)0x06)  /* SAI1 Alternate Function mapping      */
307 
308 /**
309   * @brief   AF 7 selection
310   */
311 #define GPIO_AF_USART1         ((uint8_t)0x07)  /* USART1 Alternate Function mapping  */
312 #define GPIO_AF_USART2         ((uint8_t)0x07)  /* USART2 Alternate Function mapping  */
313 #define GPIO_AF_USART3         ((uint8_t)0x07)  /* USART3 Alternate Function mapping  */
314 #define GPIO_AF7_SPI3          ((uint8_t)0x07)  /* SPI3/I2S3ext Alternate Function mapping */
315 
316 /**
317   * @brief   AF 7 selection Legacy
318   */
319 #define GPIO_AF_I2S3ext   GPIO_AF7_SPI3
320 
321 /**
322   * @brief   AF 8 selection
323   */
324 #define GPIO_AF_UART4         ((uint8_t)0x08)  /* UART4 Alternate Function mapping  */
325 #define GPIO_AF_UART5         ((uint8_t)0x08)  /* UART5 Alternate Function mapping  */
326 #define GPIO_AF_USART6        ((uint8_t)0x08)  /* USART6 Alternate Function mapping */
327 #define GPIO_AF_UART7         ((uint8_t)0x08)  /* UART7 Alternate Function mapping  */
328 #define GPIO_AF_UART8         ((uint8_t)0x08)  /* UART8 Alternate Function mapping  */
329 #if defined (STM32F446xx)
330 #define GPIO_AF8_SAI2          ((uint8_t)0x08)  /* SAI2 Alternate Function mapping */
331 #define GPIO_AF_SPDIF         ((uint8_t)0x08)   /* SPDIF Alternate Function mapping */
332 #endif /* STM32F446xx */
333 
334 /**
335   * @brief   AF 9 selection
336   */
337 #define GPIO_AF_CAN1          ((uint8_t)0x09)  /* CAN1 Alternate Function mapping  */
338 #define GPIO_AF_CAN2          ((uint8_t)0x09)  /* CAN2 Alternate Function mapping  */
339 #define GPIO_AF_TIM12         ((uint8_t)0x09)  /* TIM12 Alternate Function mapping */
340 #define GPIO_AF_TIM13         ((uint8_t)0x09)  /* TIM13 Alternate Function mapping */
341 #define GPIO_AF_TIM14         ((uint8_t)0x09)  /* TIM14 Alternate Function mapping */
342 
343 #define GPIO_AF9_I2C2         ((uint8_t)0x09)  /* I2C2 Alternate Function mapping (Only for STM32F401xx/STM32F411xE Devices) */
344 #define GPIO_AF9_I2C3         ((uint8_t)0x09)  /* I2C3 Alternate Function mapping (Only for STM32F401xx/STM32F411xE Devices) */
345 #if defined (STM32F446xx)
346 #define GPIO_AF9_SAI2         ((uint8_t)0x09)  /* SAI2 Alternate Function mapping */
347 #endif /* STM32F446xx */
348 #define GPIO_AF9_LTDC         ((uint8_t)0x09)  /* LTDC Alternate Function mapping */
349 #if defined (STM32F446xx)
350 #define GPIO_AF9_QUADSPI      ((uint8_t)0x09)  /* QuadSPI Alternate Function mapping */
351 #endif /* STM32F446xx */
352 /**
353   * @brief   AF 10 selection
354   */
355 #define GPIO_AF_OTG_FS         ((uint8_t)0xA)  /* OTG_FS Alternate Function mapping */
356 #define GPIO_AF_OTG_HS         ((uint8_t)0xA)  /* OTG_HS Alternate Function mapping */
357 #if defined (STM32F446xx)
358 #define GPIO_AF10_SAI2         ((uint8_t)0x0A)  /* SAI2 Alternate Function mapping */
359 #endif /* STM32F446xx */
360 #if defined (STM32F446xx)
361 #define GPIO_AF10_QUADSPI      ((uint8_t)0x0A)  /* QuadSPI Alternate Function mapping */
362 #endif /* STM32F446xx */
363 /**
364   * @brief   AF 11 selection
365   */
366 #define GPIO_AF_ETH             ((uint8_t)0x0B)  /* ETHERNET Alternate Function mapping */
367 
368 /**
369   * @brief   AF 12 selection
370   */
371 #if defined (STM32F40_41xxx)
372 #define GPIO_AF_FSMC             ((uint8_t)0xC)  /* FSMC Alternate Function mapping                     */
373 #endif /* STM32F40_41xxx */
374 
375 #if defined (STM32F427_437xx) || defined (STM32F429_439xx) || defined (STM32F446xx)
376 #define GPIO_AF_FMC              ((uint8_t)0xC)  /* FMC Alternate Function mapping                      */
377 #endif /* STM32F427_437xx || STM32F429_439xx || STM32F446xx */
378 
379 #define GPIO_AF_OTG_HS_FS        ((uint8_t)0xC)  /* OTG HS configured in FS, Alternate Function mapping */
380 #define GPIO_AF_SDIO             ((uint8_t)0xC)  /* SDIO Alternate Function mapping                     */
381 
382 /**
383   * @brief   AF 13 selection
384   */
385 #define GPIO_AF_DCMI          ((uint8_t)0x0D)  /* DCMI Alternate Function mapping */
386 
387 /**
388   * @brief   AF 14 selection
389   */
390 #define GPIO_AF_LTDC          ((uint8_t)0x0E)  /* LCD-TFT Alternate Function mapping */
391 
392 /**
393   * @brief   AF 15 selection
394   */
395 #define GPIO_AF_EVENTOUT      ((uint8_t)0x0F)  /* EVENTOUT Alternate Function mapping */
396 
397 #if defined (STM32F40_41xxx)
398 #define IS_GPIO_AF(AF)   (((AF) == GPIO_AF_RTC_50Hz)  || ((AF) == GPIO_AF_TIM14)     || \
399                           ((AF) == GPIO_AF_MCO)       || ((AF) == GPIO_AF_TAMPER)    || \
400                           ((AF) == GPIO_AF_SWJ)       || ((AF) == GPIO_AF_TRACE)     || \
401                           ((AF) == GPIO_AF_TIM1)      || ((AF) == GPIO_AF_TIM2)      || \
402                           ((AF) == GPIO_AF_TIM3)      || ((AF) == GPIO_AF_TIM4)      || \
403                           ((AF) == GPIO_AF_TIM5)      || ((AF) == GPIO_AF_TIM8)      || \
404                           ((AF) == GPIO_AF_I2C1)      || ((AF) == GPIO_AF_I2C2)      || \
405                           ((AF) == GPIO_AF_I2C3)      || ((AF) == GPIO_AF_SPI1)      || \
406                           ((AF) == GPIO_AF_SPI2)      || ((AF) == GPIO_AF_TIM13)     || \
407                           ((AF) == GPIO_AF_SPI3)      || ((AF) == GPIO_AF_TIM14)     || \
408                           ((AF) == GPIO_AF_USART1)    || ((AF) == GPIO_AF_USART2)    || \
409                           ((AF) == GPIO_AF_USART3)    || ((AF) == GPIO_AF_UART4)     || \
410                           ((AF) == GPIO_AF_UART5)     || ((AF) == GPIO_AF_USART6)    || \
411                           ((AF) == GPIO_AF_CAN1)      || ((AF) == GPIO_AF_CAN2)      || \
412                           ((AF) == GPIO_AF_OTG_FS)    || ((AF) == GPIO_AF_OTG_HS)    || \
413                           ((AF) == GPIO_AF_ETH)       || ((AF) == GPIO_AF_OTG_HS_FS) || \
414                           ((AF) == GPIO_AF_SDIO)      || ((AF) == GPIO_AF_DCMI)      || \
415                           ((AF) == GPIO_AF_EVENTOUT)  || ((AF) == GPIO_AF_FSMC))
416 #endif /* STM32F40_41xxx */
417 
418 #if defined (STM32F401xx)
419 #define IS_GPIO_AF(AF)   (((AF) == GPIO_AF_RTC_50Hz)  || ((AF) == GPIO_AF_TIM14)     || \
420                           ((AF) == GPIO_AF_MCO)       || ((AF) == GPIO_AF_TAMPER)    || \
421                           ((AF) == GPIO_AF_SWJ)       || ((AF) == GPIO_AF_TRACE)     || \
422                           ((AF) == GPIO_AF_TIM1)      || ((AF) == GPIO_AF_TIM2)      || \
423                           ((AF) == GPIO_AF_TIM3)      || ((AF) == GPIO_AF_TIM4)      || \
424                           ((AF) == GPIO_AF_TIM5)      || ((AF) == GPIO_AF_TIM8)      || \
425                           ((AF) == GPIO_AF_I2C1)      || ((AF) == GPIO_AF_I2C2)      || \
426                           ((AF) == GPIO_AF_I2C3)      || ((AF) == GPIO_AF_SPI1)      || \
427                           ((AF) == GPIO_AF_SPI2)      || ((AF) == GPIO_AF_TIM13)     || \
428                           ((AF) == GPIO_AF_SPI3)      || ((AF) == GPIO_AF_TIM14)     || \
429                           ((AF) == GPIO_AF_USART1)    || ((AF) == GPIO_AF_USART2)    || \
430                           ((AF) == GPIO_AF_SDIO)      || ((AF) == GPIO_AF_USART6)    || \
431                           ((AF) == GPIO_AF_OTG_FS)    || ((AF) == GPIO_AF_OTG_HS)    || \
432                           ((AF) == GPIO_AF_EVENTOUT)  || ((AF) == GPIO_AF_SPI4))
433 #endif /* STM32F401xx */
434 
435 #if defined (STM32F411xE)
436 #define IS_GPIO_AF(AF)   (((AF) < 16) && ((AF) != 11) && ((AF) != 13) && ((AF) != 14))
437 #endif /* STM32F411xE */
438 
439 #if defined (STM32F427_437xx) || defined (STM32F429_439xx)
440 #define IS_GPIO_AF(AF)   (((AF) == GPIO_AF_RTC_50Hz)  || ((AF) == GPIO_AF_TIM14)     || \
441                           ((AF) == GPIO_AF_MCO)       || ((AF) == GPIO_AF_TAMPER)    || \
442                           ((AF) == GPIO_AF_SWJ)       || ((AF) == GPIO_AF_TRACE)     || \
443                           ((AF) == GPIO_AF_TIM1)      || ((AF) == GPIO_AF_TIM2)      || \
444                           ((AF) == GPIO_AF_TIM3)      || ((AF) == GPIO_AF_TIM4)      || \
445                           ((AF) == GPIO_AF_TIM5)      || ((AF) == GPIO_AF_TIM8)      || \
446                           ((AF) == GPIO_AF_I2C1)      || ((AF) == GPIO_AF_I2C2)      || \
447                           ((AF) == GPIO_AF_I2C3)      || ((AF) == GPIO_AF_SPI1)      || \
448                           ((AF) == GPIO_AF_SPI2)      || ((AF) == GPIO_AF_TIM13)     || \
449                           ((AF) == GPIO_AF_SPI3)      || ((AF) == GPIO_AF_TIM14)     || \
450                           ((AF) == GPIO_AF_USART1)    || ((AF) == GPIO_AF_USART2)    || \
451                           ((AF) == GPIO_AF_USART3)    || ((AF) == GPIO_AF_UART4)     || \
452                           ((AF) == GPIO_AF_UART5)     || ((AF) == GPIO_AF_USART6)    || \
453                           ((AF) == GPIO_AF_CAN1)      || ((AF) == GPIO_AF_CAN2)      || \
454                           ((AF) == GPIO_AF_OTG_FS)    || ((AF) == GPIO_AF_OTG_HS)    || \
455                           ((AF) == GPIO_AF_ETH)       || ((AF) == GPIO_AF_OTG_HS_FS) || \
456                           ((AF) == GPIO_AF_SDIO)      || ((AF) == GPIO_AF_DCMI)      || \
457                           ((AF) == GPIO_AF_EVENTOUT)  || ((AF) == GPIO_AF_SPI4)      || \
458                           ((AF) == GPIO_AF_SPI5)      || ((AF) == GPIO_AF_SPI6)      || \
459                           ((AF) == GPIO_AF_UART7)     || ((AF) == GPIO_AF_UART8)     || \
460                           ((AF) == GPIO_AF_FMC)       ||  ((AF) == GPIO_AF_SAI1)     || \
461                           ((AF) == GPIO_AF_LTDC))
462 #endif /* STM32F427_437xx ||  STM32F429_439xx */
463 
464 #if defined (STM32F446xx)
465 #define IS_GPIO_AF(AF)   (((AF) < 16) && ((AF) != 11) && ((AF) != 14))
466 #endif /* STM32F446xx */
467 
468 /**
469   * @}
470   */
471 
472 /** @defgroup GPIO_Legacy
473   * @{
474   */
475 
476 #define GPIO_Mode_AIN           GPIO_Mode_AN
477 
478 #define GPIO_AF_OTG1_FS         GPIO_AF_OTG_FS
479 #define GPIO_AF_OTG2_HS         GPIO_AF_OTG_HS
480 #define GPIO_AF_OTG2_FS         GPIO_AF_OTG_HS_FS
481 
482 /**
483   * @}
484   */
485 
486 /**
487   * @}
488   */
489 
490 /* Exported macro ------------------------------------------------------------*/
491 /* Exported functions --------------------------------------------------------*/
492 
493 /*  Function used to set the GPIO configuration to the default reset state ****/
494 void GPIO_DeInit(GPIO_TypeDef* GPIOx);
495 
496 /* Initialization and Configuration functions *********************************/
497 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
498 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
499 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
500 
501 /* GPIO Read and Write functions **********************************************/
502 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
503 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
504 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
505 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
506 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
507 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
508 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
509 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
510 void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
511 
512 /* GPIO Alternate functions configuration function ****************************/
513 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
514 
515 #ifdef __cplusplus
516 }
517 #endif
518 
519 #endif /*__STM32F4xx_GPIO_H */
520 
521 /**
522   * @}
523   */
524 
525 /**
526   * @}
527   */
528 
529 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
530