STM32F2 Standard Peripheral bibliotheek  1.0
ST Microelectronics bibliotheek documentatie voor de STM32F2 Standard Peripheral Library
 All Data Structures Files Functions Variables Enumerations Enumerator Groups
stm32f2xx_gpio.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F2xx_GPIO_H
31 #define __STM32F2xx_GPIO_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f2xx.h"
39 
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 
63 typedef enum
64 {
65  GPIO_Mode_IN = 0x00,
66  GPIO_Mode_OUT = 0x01,
67  GPIO_Mode_AF = 0x02,
68  GPIO_Mode_AN = 0x03
70 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN) || ((MODE) == GPIO_Mode_OUT) || \
71  ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
72 
76 typedef enum
77 {
78  GPIO_OType_PP = 0x00,
79  GPIO_OType_OD = 0x01
81 #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
82 
83 
87 typedef enum
88 {
89  GPIO_Speed_2MHz = 0x00,
94 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_2MHz) || ((SPEED) == GPIO_Speed_25MHz) || \
95  ((SPEED) == GPIO_Speed_50MHz)|| ((SPEED) == GPIO_Speed_100MHz))
96 
100 typedef enum
101 {
102  GPIO_PuPd_NOPULL = 0x00,
103  GPIO_PuPd_UP = 0x01,
104  GPIO_PuPd_DOWN = 0x02
106 #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
107  ((PUPD) == GPIO_PuPd_DOWN))
108 
112 typedef enum
113 {
114  Bit_RESET = 0,
115  Bit_SET
116 }BitAction;
117 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
118 
119 
123 typedef struct
124 {
125  uint32_t GPIO_Pin;
128  GPIOMode_TypeDef GPIO_Mode;
131  GPIOSpeed_TypeDef GPIO_Speed;
134  GPIOOType_TypeDef GPIO_OType;
137  GPIOPuPd_TypeDef GPIO_PuPd;
140 
141 /* Exported constants --------------------------------------------------------*/
142 
150 #define GPIO_Pin_0 ((uint16_t)0x0001) /* Pin 0 selected */
151 #define GPIO_Pin_1 ((uint16_t)0x0002) /* Pin 1 selected */
152 #define GPIO_Pin_2 ((uint16_t)0x0004) /* Pin 2 selected */
153 #define GPIO_Pin_3 ((uint16_t)0x0008) /* Pin 3 selected */
154 #define GPIO_Pin_4 ((uint16_t)0x0010) /* Pin 4 selected */
155 #define GPIO_Pin_5 ((uint16_t)0x0020) /* Pin 5 selected */
156 #define GPIO_Pin_6 ((uint16_t)0x0040) /* Pin 6 selected */
157 #define GPIO_Pin_7 ((uint16_t)0x0080) /* Pin 7 selected */
158 #define GPIO_Pin_8 ((uint16_t)0x0100) /* Pin 8 selected */
159 #define GPIO_Pin_9 ((uint16_t)0x0200) /* Pin 9 selected */
160 #define GPIO_Pin_10 ((uint16_t)0x0400) /* Pin 10 selected */
161 #define GPIO_Pin_11 ((uint16_t)0x0800) /* Pin 11 selected */
162 #define GPIO_Pin_12 ((uint16_t)0x1000) /* Pin 12 selected */
163 #define GPIO_Pin_13 ((uint16_t)0x2000) /* Pin 13 selected */
164 #define GPIO_Pin_14 ((uint16_t)0x4000) /* Pin 14 selected */
165 #define GPIO_Pin_15 ((uint16_t)0x8000) /* Pin 15 selected */
166 #define GPIO_Pin_All ((uint16_t)0xFFFF) /* All pins selected */
167 
168 #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))
169 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
170  ((PIN) == GPIO_Pin_1) || \
171  ((PIN) == GPIO_Pin_2) || \
172  ((PIN) == GPIO_Pin_3) || \
173  ((PIN) == GPIO_Pin_4) || \
174  ((PIN) == GPIO_Pin_5) || \
175  ((PIN) == GPIO_Pin_6) || \
176  ((PIN) == GPIO_Pin_7) || \
177  ((PIN) == GPIO_Pin_8) || \
178  ((PIN) == GPIO_Pin_9) || \
179  ((PIN) == GPIO_Pin_10) || \
180  ((PIN) == GPIO_Pin_11) || \
181  ((PIN) == GPIO_Pin_12) || \
182  ((PIN) == GPIO_Pin_13) || \
183  ((PIN) == GPIO_Pin_14) || \
184  ((PIN) == GPIO_Pin_15))
185 
193 #define GPIO_PinSource0 ((uint8_t)0x00)
194 #define GPIO_PinSource1 ((uint8_t)0x01)
195 #define GPIO_PinSource2 ((uint8_t)0x02)
196 #define GPIO_PinSource3 ((uint8_t)0x03)
197 #define GPIO_PinSource4 ((uint8_t)0x04)
198 #define GPIO_PinSource5 ((uint8_t)0x05)
199 #define GPIO_PinSource6 ((uint8_t)0x06)
200 #define GPIO_PinSource7 ((uint8_t)0x07)
201 #define GPIO_PinSource8 ((uint8_t)0x08)
202 #define GPIO_PinSource9 ((uint8_t)0x09)
203 #define GPIO_PinSource10 ((uint8_t)0x0A)
204 #define GPIO_PinSource11 ((uint8_t)0x0B)
205 #define GPIO_PinSource12 ((uint8_t)0x0C)
206 #define GPIO_PinSource13 ((uint8_t)0x0D)
207 #define GPIO_PinSource14 ((uint8_t)0x0E)
208 #define GPIO_PinSource15 ((uint8_t)0x0F)
209 
210 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
211  ((PINSOURCE) == GPIO_PinSource1) || \
212  ((PINSOURCE) == GPIO_PinSource2) || \
213  ((PINSOURCE) == GPIO_PinSource3) || \
214  ((PINSOURCE) == GPIO_PinSource4) || \
215  ((PINSOURCE) == GPIO_PinSource5) || \
216  ((PINSOURCE) == GPIO_PinSource6) || \
217  ((PINSOURCE) == GPIO_PinSource7) || \
218  ((PINSOURCE) == GPIO_PinSource8) || \
219  ((PINSOURCE) == GPIO_PinSource9) || \
220  ((PINSOURCE) == GPIO_PinSource10) || \
221  ((PINSOURCE) == GPIO_PinSource11) || \
222  ((PINSOURCE) == GPIO_PinSource12) || \
223  ((PINSOURCE) == GPIO_PinSource13) || \
224  ((PINSOURCE) == GPIO_PinSource14) || \
225  ((PINSOURCE) == GPIO_PinSource15))
226 
236 #define GPIO_AF_RTC_50Hz ((uint8_t)0x00) /* RTC_50Hz Alternate Function mapping */
237 #define GPIO_AF_MCO ((uint8_t)0x00) /* MCO (MCO1 and MCO2) Alternate Function mapping */
238 #define GPIO_AF_TAMPER ((uint8_t)0x00) /* TAMPER (TAMPER_1 and TAMPER_2) Alternate Function mapping */
239 #define GPIO_AF_SWJ ((uint8_t)0x00) /* SWJ (SWD and JTAG) Alternate Function mapping */
240 #define GPIO_AF_TRACE ((uint8_t)0x00) /* TRACE Alternate Function mapping */
241 
245 #define GPIO_AF_TIM1 ((uint8_t)0x01) /* TIM1 Alternate Function mapping */
246 #define GPIO_AF_TIM2 ((uint8_t)0x01) /* TIM2 Alternate Function mapping */
247 
251 #define GPIO_AF_TIM3 ((uint8_t)0x02) /* TIM3 Alternate Function mapping */
252 #define GPIO_AF_TIM4 ((uint8_t)0x02) /* TIM4 Alternate Function mapping */
253 #define GPIO_AF_TIM5 ((uint8_t)0x02) /* TIM5 Alternate Function mapping */
254 
258 #define GPIO_AF_TIM8 ((uint8_t)0x03) /* TIM8 Alternate Function mapping */
259 #define GPIO_AF_TIM9 ((uint8_t)0x03) /* TIM9 Alternate Function mapping */
260 #define GPIO_AF_TIM10 ((uint8_t)0x03) /* TIM10 Alternate Function mapping */
261 #define GPIO_AF_TIM11 ((uint8_t)0x03) /* TIM11 Alternate Function mapping */
262 
266 #define GPIO_AF_I2C1 ((uint8_t)0x04) /* I2C1 Alternate Function mapping */
267 #define GPIO_AF_I2C2 ((uint8_t)0x04) /* I2C2 Alternate Function mapping */
268 #define GPIO_AF_I2C3 ((uint8_t)0x04) /* I2C3 Alternate Function mapping */
269 
273 #define GPIO_AF_SPI1 ((uint8_t)0x05) /* SPI1 Alternate Function mapping */
274 #define GPIO_AF_SPI2 ((uint8_t)0x05) /* SPI2/I2S2 Alternate Function mapping */
275 
279 #define GPIO_AF_SPI3 ((uint8_t)0x06) /* SPI3/I2S3 Alternate Function mapping */
280 
284 #define GPIO_AF_USART1 ((uint8_t)0x07) /* USART1 Alternate Function mapping */
285 #define GPIO_AF_USART2 ((uint8_t)0x07) /* USART2 Alternate Function mapping */
286 #define GPIO_AF_USART3 ((uint8_t)0x07) /* USART3 Alternate Function mapping */
287 
291 #define GPIO_AF_UART4 ((uint8_t)0x08) /* UART4 Alternate Function mapping */
292 #define GPIO_AF_UART5 ((uint8_t)0x08) /* UART5 Alternate Function mapping */
293 #define GPIO_AF_USART6 ((uint8_t)0x08) /* USART6 Alternate Function mapping */
294 
298 #define GPIO_AF_CAN1 ((uint8_t)0x09) /* CAN1 Alternate Function mapping */
299 #define GPIO_AF_CAN2 ((uint8_t)0x09) /* CAN2 Alternate Function mapping */
300 #define GPIO_AF_TIM12 ((uint8_t)0x09) /* TIM12 Alternate Function mapping */
301 #define GPIO_AF_TIM13 ((uint8_t)0x09) /* TIM13 Alternate Function mapping */
302 #define GPIO_AF_TIM14 ((uint8_t)0x09) /* TIM14 Alternate Function mapping */
303 
307 #define GPIO_AF_OTG_FS ((uint8_t)0xA) /* OTG_FS Alternate Function mapping */
308 #define GPIO_AF_OTG_HS ((uint8_t)0xA) /* OTG_HS Alternate Function mapping */
309 
313 #define GPIO_AF_ETH ((uint8_t)0x0B) /* ETHERNET Alternate Function mapping */
314 
318 #define GPIO_AF_FSMC ((uint8_t)0xC) /* FSMC Alternate Function mapping */
319 #define GPIO_AF_OTG_HS_FS ((uint8_t)0xC) /* OTG HS configured in FS, Alternate Function mapping */
320 #define GPIO_AF_SDIO ((uint8_t)0xC) /* SDIO Alternate Function mapping */
321 
325 #define GPIO_AF_DCMI ((uint8_t)0x0D) /* DCMI Alternate Function mapping */
326 
330 #define GPIO_AF_EVENTOUT ((uint8_t)0x0F) /* EVENTOUT Alternate Function mapping */
331 
332 #define IS_GPIO_AF(AF) (((AF) == GPIO_AF_RTC_50Hz) || ((AF) == GPIO_AF_TIM14) || \
333  ((AF) == GPIO_AF_MCO) || ((AF) == GPIO_AF_TAMPER) || \
334  ((AF) == GPIO_AF_SWJ) || ((AF) == GPIO_AF_TRACE) || \
335  ((AF) == GPIO_AF_TIM1) || ((AF) == GPIO_AF_TIM2) || \
336  ((AF) == GPIO_AF_TIM3) || ((AF) == GPIO_AF_TIM4) || \
337  ((AF) == GPIO_AF_TIM5) || ((AF) == GPIO_AF_TIM8) || \
338  ((AF) == GPIO_AF_I2C1) || ((AF) == GPIO_AF_I2C2) || \
339  ((AF) == GPIO_AF_I2C3) || ((AF) == GPIO_AF_SPI1) || \
340  ((AF) == GPIO_AF_SPI2) || ((AF) == GPIO_AF_TIM13) || \
341  ((AF) == GPIO_AF_SPI3) || ((AF) == GPIO_AF_TIM14) || \
342  ((AF) == GPIO_AF_USART1) || ((AF) == GPIO_AF_USART2) || \
343  ((AF) == GPIO_AF_USART3) || ((AF) == GPIO_AF_UART4) || \
344  ((AF) == GPIO_AF_UART5) || ((AF) == GPIO_AF_USART6) || \
345  ((AF) == GPIO_AF_CAN1) || ((AF) == GPIO_AF_CAN2) || \
346  ((AF) == GPIO_AF_OTG_FS) || ((AF) == GPIO_AF_OTG_HS) || \
347  ((AF) == GPIO_AF_ETH) || ((AF) == GPIO_AF_FSMC) || \
348  ((AF) == GPIO_AF_OTG_HS_FS) || ((AF) == GPIO_AF_SDIO) || \
349  ((AF) == GPIO_AF_DCMI) || ((AF) == GPIO_AF_EVENTOUT))
350 
358 #define GPIO_Mode_AIN GPIO_Mode_AN
359 
360 #define GPIO_AF_OTG1_FS GPIO_AF_OTG_FS
361 #define GPIO_AF_OTG2_HS GPIO_AF_OTG_HS
362 #define GPIO_AF_OTG2_FS GPIO_AF_OTG_HS_FS
363 
372 /* Exported macro ------------------------------------------------------------*/
373 /* Exported functions --------------------------------------------------------*/
374 
375 /* Function used to set the GPIO configuration to the default reset state ****/
376 void GPIO_DeInit(GPIO_TypeDef* GPIOx);
377 
378 /* Initialization and Configuration functions *********************************/
379 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
380 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
381 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
382 
383 /* GPIO Read and Write functions **********************************************/
384 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
385 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
386 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
387 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
388 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
389 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
390 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
391 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
392 void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
393 
394 /* GPIO Alternate functions configuration function ****************************/
395 void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
396 
397 #ifdef __cplusplus
398 }
399 #endif
400 
401 #endif /*__STM32F2xx_GPIO_H */
402 
411 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/