Statistics
| Branch: | Tag: | Revision:

amiro-blt / Target / Demo / ARMCM4_STM32F405_Power_Management_GCC / Boot / lib / stdperiphlib / STM32F4xx_StdPeriph_Driver / inc / stm32f4xx_gpio.h @ 69661903

History | View | Annotate | Download (18.101 KB)

1
/**
2
  ******************************************************************************
3
  * @file    stm32f4xx_gpio.h
4
  * @author  MCD Application Team
5
  * @version V1.1.0
6
  * @date    11-January-2013
7
  * @brief   This file contains all the functions prototypes for the GPIO firmware
8
  *          library.  
9
  ******************************************************************************
10
  * @attention
11
  *
12
  * <h2><center>&copy; COPYRIGHT 2013 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

    
60
                                                                                                
61
/** 
62
  * @brief  GPIO Configuration Mode enumeration 
63
  */   
64
typedef enum
65
{ 
66
  GPIO_Mode_IN   = 0x00, /*!< GPIO Input Mode */
67
  GPIO_Mode_OUT  = 0x01, /*!< GPIO Output Mode */
68
  GPIO_Mode_AF   = 0x02, /*!< GPIO Alternate function Mode */
69
  GPIO_Mode_AN   = 0x03  /*!< GPIO Analog Mode */
70
}GPIOMode_TypeDef;
71
#define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)  || ((MODE) == GPIO_Mode_OUT) || \
72
                            ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
73

    
74
/** 
75
  * @brief  GPIO Output type enumeration 
76
  */  
77
typedef enum
78
{ 
79
  GPIO_OType_PP = 0x00,
80
  GPIO_OType_OD = 0x01
81
}GPIOOType_TypeDef;
82
#define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
83

    
84

    
85
/** 
86
  * @brief  GPIO Output Maximum frequency enumeration 
87
  */  
88
typedef enum
89
{ 
90
  GPIO_Speed_2MHz   = 0x00, /*!< Low speed */
91
  GPIO_Speed_25MHz  = 0x01, /*!< Medium speed */
92
  GPIO_Speed_50MHz  = 0x02, /*!< Fast speed */
93
  GPIO_Speed_100MHz = 0x03  /*!< High speed on 30 pF (80 MHz Output max speed on 15 pF) */
94
}GPIOSpeed_TypeDef;
95
#define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_2MHz) || ((SPEED) == GPIO_Speed_25MHz) || \
96
                              ((SPEED) == GPIO_Speed_50MHz)||  ((SPEED) == GPIO_Speed_100MHz)) 
97

    
98
/** 
99
  * @brief  GPIO Configuration PullUp PullDown enumeration 
100
  */ 
101
typedef enum
102
{ 
103
  GPIO_PuPd_NOPULL = 0x00,
104
  GPIO_PuPd_UP     = 0x01,
105
  GPIO_PuPd_DOWN   = 0x02
106
}GPIOPuPd_TypeDef;
107
#define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
108
                            ((PUPD) == GPIO_PuPd_DOWN))
109

    
110
/** 
111
  * @brief  GPIO Bit SET and Bit RESET enumeration 
112
  */ 
113
typedef enum
114
{ 
115
  Bit_RESET = 0,
116
  Bit_SET
117
}BitAction;
118
#define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
119

    
120

    
121
/** 
122
  * @brief   GPIO Init structure definition  
123
  */ 
124
typedef struct
125
{
126
  uint32_t GPIO_Pin;              /*!< Specifies the GPIO pins to be configured.
127
                                       This parameter can be any value of @ref GPIO_pins_define */
128

    
129
  GPIOMode_TypeDef GPIO_Mode;     /*!< Specifies the operating mode for the selected pins.
130
                                       This parameter can be a value of @ref GPIOMode_TypeDef */
131

    
132
  GPIOSpeed_TypeDef GPIO_Speed;   /*!< Specifies the speed for the selected pins.
133
                                       This parameter can be a value of @ref GPIOSpeed_TypeDef */
134

    
135
  GPIOOType_TypeDef GPIO_OType;   /*!< Specifies the operating output type for the selected pins.
136
                                       This parameter can be a value of @ref GPIOOType_TypeDef */
137

    
138
  GPIOPuPd_TypeDef GPIO_PuPd;     /*!< Specifies the operating Pull-up/Pull down for the selected pins.
139
                                       This parameter can be a value of @ref GPIOPuPd_TypeDef */
140
}GPIO_InitTypeDef;
141

    
142
/* Exported constants --------------------------------------------------------*/
143

    
144
/** @defgroup GPIO_Exported_Constants
145
  * @{
146
  */ 
147

    
148
/** @defgroup GPIO_pins_define 
149
  * @{
150
  */ 
151
#define GPIO_Pin_0                 ((uint16_t)0x0001)  /* Pin 0 selected */
152
#define GPIO_Pin_1                 ((uint16_t)0x0002)  /* Pin 1 selected */
153
#define GPIO_Pin_2                 ((uint16_t)0x0004)  /* Pin 2 selected */
154
#define GPIO_Pin_3                 ((uint16_t)0x0008)  /* Pin 3 selected */
155
#define GPIO_Pin_4                 ((uint16_t)0x0010)  /* Pin 4 selected */
156
#define GPIO_Pin_5                 ((uint16_t)0x0020)  /* Pin 5 selected */
157
#define GPIO_Pin_6                 ((uint16_t)0x0040)  /* Pin 6 selected */
158
#define GPIO_Pin_7                 ((uint16_t)0x0080)  /* Pin 7 selected */
159
#define GPIO_Pin_8                 ((uint16_t)0x0100)  /* Pin 8 selected */
160
#define GPIO_Pin_9                 ((uint16_t)0x0200)  /* Pin 9 selected */
161
#define GPIO_Pin_10                ((uint16_t)0x0400)  /* Pin 10 selected */
162
#define GPIO_Pin_11                ((uint16_t)0x0800)  /* Pin 11 selected */
163
#define GPIO_Pin_12                ((uint16_t)0x1000)  /* Pin 12 selected */
164
#define GPIO_Pin_13                ((uint16_t)0x2000)  /* Pin 13 selected */
165
#define GPIO_Pin_14                ((uint16_t)0x4000)  /* Pin 14 selected */
166
#define GPIO_Pin_15                ((uint16_t)0x8000)  /* Pin 15 selected */
167
#define GPIO_Pin_All               ((uint16_t)0xFFFF)  /* All pins selected */
168

    
169
#define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))
170
#define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
171
                              ((PIN) == GPIO_Pin_1) || \
172
                              ((PIN) == GPIO_Pin_2) || \
173
                              ((PIN) == GPIO_Pin_3) || \
174
                              ((PIN) == GPIO_Pin_4) || \
175
                              ((PIN) == GPIO_Pin_5) || \
176
                              ((PIN) == GPIO_Pin_6) || \
177
                              ((PIN) == GPIO_Pin_7) || \
178
                              ((PIN) == GPIO_Pin_8) || \
179
                              ((PIN) == GPIO_Pin_9) || \
180
                              ((PIN) == GPIO_Pin_10) || \
181
                              ((PIN) == GPIO_Pin_11) || \
182
                              ((PIN) == GPIO_Pin_12) || \
183
                              ((PIN) == GPIO_Pin_13) || \
184
                              ((PIN) == GPIO_Pin_14) || \
185
                              ((PIN) == GPIO_Pin_15))
186
/**
187
  * @}
188
  */ 
189

    
190

    
191
/** @defgroup GPIO_Pin_sources 
192
  * @{
193
  */ 
194
#define GPIO_PinSource0            ((uint8_t)0x00)
195
#define GPIO_PinSource1            ((uint8_t)0x01)
196
#define GPIO_PinSource2            ((uint8_t)0x02)
197
#define GPIO_PinSource3            ((uint8_t)0x03)
198
#define GPIO_PinSource4            ((uint8_t)0x04)
199
#define GPIO_PinSource5            ((uint8_t)0x05)
200
#define GPIO_PinSource6            ((uint8_t)0x06)
201
#define GPIO_PinSource7            ((uint8_t)0x07)
202
#define GPIO_PinSource8            ((uint8_t)0x08)
203
#define GPIO_PinSource9            ((uint8_t)0x09)
204
#define GPIO_PinSource10           ((uint8_t)0x0A)
205
#define GPIO_PinSource11           ((uint8_t)0x0B)
206
#define GPIO_PinSource12           ((uint8_t)0x0C)
207
#define GPIO_PinSource13           ((uint8_t)0x0D)
208
#define GPIO_PinSource14           ((uint8_t)0x0E)
209
#define GPIO_PinSource15           ((uint8_t)0x0F)
210

    
211
#define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
212
                                       ((PINSOURCE) == GPIO_PinSource1) || \
213
                                       ((PINSOURCE) == GPIO_PinSource2) || \
214
                                       ((PINSOURCE) == GPIO_PinSource3) || \
215
                                       ((PINSOURCE) == GPIO_PinSource4) || \
216
                                       ((PINSOURCE) == GPIO_PinSource5) || \
217
                                       ((PINSOURCE) == GPIO_PinSource6) || \
218
                                       ((PINSOURCE) == GPIO_PinSource7) || \
219
                                       ((PINSOURCE) == GPIO_PinSource8) || \
220
                                       ((PINSOURCE) == GPIO_PinSource9) || \
221
                                       ((PINSOURCE) == GPIO_PinSource10) || \
222
                                       ((PINSOURCE) == GPIO_PinSource11) || \
223
                                       ((PINSOURCE) == GPIO_PinSource12) || \
224
                                       ((PINSOURCE) == GPIO_PinSource13) || \
225
                                       ((PINSOURCE) == GPIO_PinSource14) || \
226
                                       ((PINSOURCE) == GPIO_PinSource15))
227
/**
228
  * @}
229
  */ 
230

    
231
/** @defgroup GPIO_Alternat_function_selection_define 
232
  * @{
233
  */ 
234
/** 
235
  * @brief   AF 0 selection  
236
  */ 
237
#define GPIO_AF_RTC_50Hz      ((uint8_t)0x00)  /* RTC_50Hz Alternate Function mapping */
238
#define GPIO_AF_MCO           ((uint8_t)0x00)  /* MCO (MCO1 and MCO2) Alternate Function mapping */
239
#define GPIO_AF_TAMPER        ((uint8_t)0x00)  /* TAMPER (TAMPER_1 and TAMPER_2) Alternate Function mapping */
240
#define GPIO_AF_SWJ           ((uint8_t)0x00)  /* SWJ (SWD and JTAG) Alternate Function mapping */
241
#define GPIO_AF_TRACE         ((uint8_t)0x00)  /* TRACE Alternate Function mapping */
242

    
243
/** 
244
  * @brief   AF 1 selection  
245
  */ 
246
#define GPIO_AF_TIM1          ((uint8_t)0x01)  /* TIM1 Alternate Function mapping */
247
#define GPIO_AF_TIM2          ((uint8_t)0x01)  /* TIM2 Alternate Function mapping */
248

    
249
/** 
250
  * @brief   AF 2 selection  
251
  */ 
252
#define GPIO_AF_TIM3          ((uint8_t)0x02)  /* TIM3 Alternate Function mapping */
253
#define GPIO_AF_TIM4          ((uint8_t)0x02)  /* TIM4 Alternate Function mapping */
254
#define GPIO_AF_TIM5          ((uint8_t)0x02)  /* TIM5 Alternate Function mapping */
255

    
256
/** 
257
  * @brief   AF 3 selection  
258
  */ 
259
#define GPIO_AF_TIM8          ((uint8_t)0x03)  /* TIM8 Alternate Function mapping */
260
#define GPIO_AF_TIM9          ((uint8_t)0x03)  /* TIM9 Alternate Function mapping */
261
#define GPIO_AF_TIM10         ((uint8_t)0x03)  /* TIM10 Alternate Function mapping */
262
#define GPIO_AF_TIM11         ((uint8_t)0x03)  /* TIM11 Alternate Function mapping */
263

    
264
/** 
265
  * @brief   AF 4 selection  
266
  */ 
267
#define GPIO_AF_I2C1          ((uint8_t)0x04)  /* I2C1 Alternate Function mapping */
268
#define GPIO_AF_I2C2          ((uint8_t)0x04)  /* I2C2 Alternate Function mapping */
269
#define GPIO_AF_I2C3          ((uint8_t)0x04)  /* I2C3 Alternate Function mapping */
270

    
271
/** 
272
  * @brief   AF 5 selection  
273
  */ 
274
#define GPIO_AF_SPI1          ((uint8_t)0x05)  /* SPI1 Alternate Function mapping      */
275
#define GPIO_AF_SPI2          ((uint8_t)0x05)  /* SPI2/I2S2 Alternate Function mapping */
276
#define GPIO_AF_SPI4          ((uint8_t)0x05)  /* SPI4 Alternate Function mapping      */
277
#define GPIO_AF_SPI5          ((uint8_t)0x05)  /* SPI5 Alternate Function mapping      */
278
#define GPIO_AF_SPI6          ((uint8_t)0x05)  /* SPI6 Alternate Function mapping      */
279

    
280
/** 
281
  * @brief   AF 6 selection  
282
  */ 
283
#define GPIO_AF_SPI3          ((uint8_t)0x06)  /* SPI3/I2S3 Alternate Function mapping */
284

    
285
/** 
286
  * @brief   AF 7 selection  
287
  */ 
288
#define GPIO_AF_USART1        ((uint8_t)0x07)  /* USART1 Alternate Function mapping  */
289
#define GPIO_AF_USART2        ((uint8_t)0x07)  /* USART2 Alternate Function mapping  */
290
#define GPIO_AF_USART3        ((uint8_t)0x07)  /* USART3 Alternate Function mapping  */
291
#define GPIO_AF_I2S3ext       ((uint8_t)0x07)  /* I2S3ext Alternate Function mapping */
292

    
293
/** 
294
  * @brief   AF 8 selection  
295
  */ 
296
#define GPIO_AF_UART4         ((uint8_t)0x08)  /* UART4 Alternate Function mapping  */
297
#define GPIO_AF_UART5         ((uint8_t)0x08)  /* UART5 Alternate Function mapping  */
298
#define GPIO_AF_USART6        ((uint8_t)0x08)  /* USART6 Alternate Function mapping */
299
#define GPIO_AF_UART7         ((uint8_t)0x08)  /* UART7 Alternate Function mapping  */
300
#define GPIO_AF_UART8         ((uint8_t)0x08)  /* UART8 Alternate Function mapping  */
301

    
302
/** 
303
  * @brief   AF 9 selection 
304
  */ 
305
#define GPIO_AF_CAN1          ((uint8_t)0x09)  /* CAN1 Alternate Function mapping  */
306
#define GPIO_AF_CAN2          ((uint8_t)0x09)  /* CAN2 Alternate Function mapping  */
307
#define GPIO_AF_TIM12         ((uint8_t)0x09)  /* TIM12 Alternate Function mapping */
308
#define GPIO_AF_TIM13         ((uint8_t)0x09)  /* TIM13 Alternate Function mapping */
309
#define GPIO_AF_TIM14         ((uint8_t)0x09)  /* TIM14 Alternate Function mapping */
310

    
311
/** 
312
  * @brief   AF 10 selection  
313
  */ 
314
#define GPIO_AF_OTG_FS         ((uint8_t)0xA)  /* OTG_FS Alternate Function mapping */
315
#define GPIO_AF_OTG_HS         ((uint8_t)0xA)  /* OTG_HS Alternate Function mapping */
316

    
317
/** 
318
  * @brief   AF 11 selection  
319
  */ 
320
#define GPIO_AF_ETH             ((uint8_t)0x0B)  /* ETHERNET Alternate Function mapping */
321

    
322
/** 
323
  * @brief   AF 12 selection  
324
  */ 
325
#define GPIO_AF_FSMC             ((uint8_t)0xC)  /* FSMC Alternate Function mapping                     */
326

    
327
#define GPIO_AF_OTG_HS_FS        ((uint8_t)0xC)  /* OTG HS configured in FS, Alternate Function mapping */
328
#define GPIO_AF_SDIO             ((uint8_t)0xC)  /* SDIO Alternate Function mapping                     */
329

    
330
/** 
331
  * @brief   AF 13 selection  
332
  */ 
333
#define GPIO_AF_DCMI          ((uint8_t)0x0D)  /* DCMI Alternate Function mapping */
334

    
335
/** 
336
  * @brief   AF 15 selection  
337
  */ 
338
#define GPIO_AF_EVENTOUT      ((uint8_t)0x0F)  /* EVENTOUT Alternate Function mapping */
339

    
340
#define IS_GPIO_AF(AF)   (((AF) == GPIO_AF_RTC_50Hz)  || ((AF) == GPIO_AF_TIM14)     || \
341
                          ((AF) == GPIO_AF_MCO)       || ((AF) == GPIO_AF_TAMPER)    || \
342
                          ((AF) == GPIO_AF_SWJ)       || ((AF) == GPIO_AF_TRACE)     || \
343
                          ((AF) == GPIO_AF_TIM1)      || ((AF) == GPIO_AF_TIM2)      || \
344
                          ((AF) == GPIO_AF_TIM3)      || ((AF) == GPIO_AF_TIM4)      || \
345
                          ((AF) == GPIO_AF_TIM5)      || ((AF) == GPIO_AF_TIM8)      || \
346
                          ((AF) == GPIO_AF_I2C1)      || ((AF) == GPIO_AF_I2C2)      || \
347
                          ((AF) == GPIO_AF_I2C3)      || ((AF) == GPIO_AF_SPI1)      || \
348
                          ((AF) == GPIO_AF_SPI2)      || ((AF) == GPIO_AF_TIM13)     || \
349
                          ((AF) == GPIO_AF_SPI3)      || ((AF) == GPIO_AF_TIM14)     || \
350
                          ((AF) == GPIO_AF_USART1)    || ((AF) == GPIO_AF_USART2)    || \
351
                          ((AF) == GPIO_AF_USART3)    || ((AF) == GPIO_AF_UART4)     || \
352
                          ((AF) == GPIO_AF_UART5)     || ((AF) == GPIO_AF_USART6)    || \
353
                          ((AF) == GPIO_AF_CAN1)      || ((AF) == GPIO_AF_CAN2)      || \
354
                          ((AF) == GPIO_AF_OTG_FS)    || ((AF) == GPIO_AF_OTG_HS)    || \
355
                          ((AF) == GPIO_AF_ETH)       || ((AF) == GPIO_AF_OTG_HS_FS) || \
356
                          ((AF) == GPIO_AF_SDIO)      || ((AF) == GPIO_AF_DCMI)      || \
357
                          ((AF) == GPIO_AF_EVENTOUT)  || ((AF) == GPIO_AF_SPI4)      || \
358
                          ((AF) == GPIO_AF_SPI5)      || ((AF) == GPIO_AF_SPI6)      || \
359
                          ((AF) == GPIO_AF_UART7)     || ((AF) == GPIO_AF_UART8)     || \
360
                          ((AF) == GPIO_AF_FSMC))
361

    
362
/**
363
  * @}
364
  */ 
365

    
366
/** @defgroup GPIO_Legacy 
367
  * @{
368
  */
369
    
370
#define GPIO_Mode_AIN           GPIO_Mode_AN
371

    
372
#define GPIO_AF_OTG1_FS         GPIO_AF_OTG_FS
373
#define GPIO_AF_OTG2_HS         GPIO_AF_OTG_HS
374
#define GPIO_AF_OTG2_FS         GPIO_AF_OTG_HS_FS
375

    
376
/**
377
  * @}
378
  */
379

    
380
/**
381
  * @}
382
  */
383

    
384
/* Exported macro ------------------------------------------------------------*/
385
/* Exported functions --------------------------------------------------------*/ 
386

    
387
/*  Function used to set the GPIO configuration to the default reset state ****/
388
void GPIO_DeInit(GPIO_TypeDef* GPIOx);
389

    
390
/* Initialization and Configuration functions *********************************/
391
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
392
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
393
void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
394

    
395
/* GPIO Read and Write functions **********************************************/
396
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
397
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
398
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
399
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
400
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
401
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
402
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
403
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
404
void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
405

    
406
/* GPIO Alternate functions configuration function ****************************/
407
void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
408

    
409
#ifdef __cplusplus
410
}
411
#endif
412

    
413
#endif /*__STM32F4xx_GPIO_H */
414

    
415
/**
416
  * @}
417
  */ 
418

    
419
/**
420
  * @}
421
  */ 
422

    
423
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/