STM32F1 Standard Peripheral bibliotheek  1.0
ST Microelectronics bibliotheek documentatie voor de STM32F1 Standard Peripheral Library
 All Data Structures Files Functions Variables Enumerations Groups
stm32f10x_gpio.h
Go to the documentation of this file.
1 
22 /* Define to prevent recursive inclusion -------------------------------------*/
23 #ifndef __STM32F10x_GPIO_H
24 #define __STM32F10x_GPIO_H
25 
26 #ifdef __cplusplus
27  extern "C" {
28 #endif
29 
30 /* Includes ------------------------------------------------------------------*/
31 #include "stm32f10x.h"
32 
45 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
46  ((PERIPH) == GPIOB) || \
47  ((PERIPH) == GPIOC) || \
48  ((PERIPH) == GPIOD) || \
49  ((PERIPH) == GPIOE) || \
50  ((PERIPH) == GPIOF) || \
51  ((PERIPH) == GPIOG))
52 
57 typedef enum
58 {
59  GPIO_Speed_10MHz = 1,
60  GPIO_Speed_2MHz,
61  GPIO_Speed_50MHz
63 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \
64  ((SPEED) == GPIO_Speed_50MHz))
65 
70 typedef enum
71 { GPIO_Mode_AIN = 0x0,
72  GPIO_Mode_IN_FLOATING = 0x04,
73  GPIO_Mode_IPD = 0x28,
74  GPIO_Mode_IPU = 0x48,
75  GPIO_Mode_Out_OD = 0x14,
76  GPIO_Mode_Out_PP = 0x10,
77  GPIO_Mode_AF_OD = 0x1C,
78  GPIO_Mode_AF_PP = 0x18
80 
81 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_AIN) || ((MODE) == GPIO_Mode_IN_FLOATING) || \
82  ((MODE) == GPIO_Mode_IPD) || ((MODE) == GPIO_Mode_IPU) || \
83  ((MODE) == GPIO_Mode_Out_OD) || ((MODE) == GPIO_Mode_Out_PP) || \
84  ((MODE) == GPIO_Mode_AF_OD) || ((MODE) == GPIO_Mode_AF_PP))
85 
90 typedef struct
91 {
92  uint16_t GPIO_Pin;
95  GPIOSpeed_TypeDef GPIO_Speed;
98  GPIOMode_TypeDef GPIO_Mode;
101 
102 
107 typedef enum
108 { Bit_RESET = 0,
109  Bit_SET
110 }BitAction;
111 
112 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
113 
126 #define GPIO_Pin_0 ((uint16_t)0x0001)
127 #define GPIO_Pin_1 ((uint16_t)0x0002)
128 #define GPIO_Pin_2 ((uint16_t)0x0004)
129 #define GPIO_Pin_3 ((uint16_t)0x0008)
130 #define GPIO_Pin_4 ((uint16_t)0x0010)
131 #define GPIO_Pin_5 ((uint16_t)0x0020)
132 #define GPIO_Pin_6 ((uint16_t)0x0040)
133 #define GPIO_Pin_7 ((uint16_t)0x0080)
134 #define GPIO_Pin_8 ((uint16_t)0x0100)
135 #define GPIO_Pin_9 ((uint16_t)0x0200)
136 #define GPIO_Pin_10 ((uint16_t)0x0400)
137 #define GPIO_Pin_11 ((uint16_t)0x0800)
138 #define GPIO_Pin_12 ((uint16_t)0x1000)
139 #define GPIO_Pin_13 ((uint16_t)0x2000)
140 #define GPIO_Pin_14 ((uint16_t)0x4000)
141 #define GPIO_Pin_15 ((uint16_t)0x8000)
142 #define GPIO_Pin_All ((uint16_t)0xFFFF)
144 #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))
145 
146 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
147  ((PIN) == GPIO_Pin_1) || \
148  ((PIN) == GPIO_Pin_2) || \
149  ((PIN) == GPIO_Pin_3) || \
150  ((PIN) == GPIO_Pin_4) || \
151  ((PIN) == GPIO_Pin_5) || \
152  ((PIN) == GPIO_Pin_6) || \
153  ((PIN) == GPIO_Pin_7) || \
154  ((PIN) == GPIO_Pin_8) || \
155  ((PIN) == GPIO_Pin_9) || \
156  ((PIN) == GPIO_Pin_10) || \
157  ((PIN) == GPIO_Pin_11) || \
158  ((PIN) == GPIO_Pin_12) || \
159  ((PIN) == GPIO_Pin_13) || \
160  ((PIN) == GPIO_Pin_14) || \
161  ((PIN) == GPIO_Pin_15))
162 
171 #define GPIO_Remap_SPI1 ((uint32_t)0x00000001)
172 #define GPIO_Remap_I2C1 ((uint32_t)0x00000002)
173 #define GPIO_Remap_USART1 ((uint32_t)0x00000004)
174 #define GPIO_Remap_USART2 ((uint32_t)0x00000008)
175 #define GPIO_PartialRemap_USART3 ((uint32_t)0x00140010)
176 #define GPIO_FullRemap_USART3 ((uint32_t)0x00140030)
177 #define GPIO_PartialRemap_TIM1 ((uint32_t)0x00160040)
178 #define GPIO_FullRemap_TIM1 ((uint32_t)0x001600C0)
179 #define GPIO_PartialRemap1_TIM2 ((uint32_t)0x00180100)
180 #define GPIO_PartialRemap2_TIM2 ((uint32_t)0x00180200)
181 #define GPIO_FullRemap_TIM2 ((uint32_t)0x00180300)
182 #define GPIO_PartialRemap_TIM3 ((uint32_t)0x001A0800)
183 #define GPIO_FullRemap_TIM3 ((uint32_t)0x001A0C00)
184 #define GPIO_Remap_TIM4 ((uint32_t)0x00001000)
185 #define GPIO_Remap1_CAN1 ((uint32_t)0x001D4000)
186 #define GPIO_Remap2_CAN1 ((uint32_t)0x001D6000)
187 #define GPIO_Remap_PD01 ((uint32_t)0x00008000)
188 #define GPIO_Remap_TIM5CH4_LSI ((uint32_t)0x00200001)
189 #define GPIO_Remap_ADC1_ETRGINJ ((uint32_t)0x00200002)
190 #define GPIO_Remap_ADC1_ETRGREG ((uint32_t)0x00200004)
191 #define GPIO_Remap_ADC2_ETRGINJ ((uint32_t)0x00200008)
192 #define GPIO_Remap_ADC2_ETRGREG ((uint32_t)0x00200010)
193 #define GPIO_Remap_ETH ((uint32_t)0x00200020)
194 #define GPIO_Remap_CAN2 ((uint32_t)0x00200040)
195 #define GPIO_Remap_SWJ_NoJTRST ((uint32_t)0x00300100)
196 #define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200)
197 #define GPIO_Remap_SWJ_Disable ((uint32_t)0x00300400)
198 #define GPIO_Remap_SPI3 ((uint32_t)0x00201000)
199 #define GPIO_Remap_TIM2ITR1_PTP_SOF ((uint32_t)0x00202000)
202 #define GPIO_Remap_PTP_PPS ((uint32_t)0x00204000)
204 #define GPIO_Remap_TIM15 ((uint32_t)0x80000001)
205 #define GPIO_Remap_TIM16 ((uint32_t)0x80000002)
206 #define GPIO_Remap_TIM17 ((uint32_t)0x80000004)
207 #define GPIO_Remap_CEC ((uint32_t)0x80000008)
208 #define GPIO_Remap_TIM1_DMA ((uint32_t)0x80000010)
210 #define GPIO_Remap_TIM9 ((uint32_t)0x80000020)
211 #define GPIO_Remap_TIM10 ((uint32_t)0x80000040)
212 #define GPIO_Remap_TIM11 ((uint32_t)0x80000080)
213 #define GPIO_Remap_TIM13 ((uint32_t)0x80000100)
214 #define GPIO_Remap_TIM14 ((uint32_t)0x80000200)
215 #define GPIO_Remap_FSMC_NADV ((uint32_t)0x80000400)
218 #define IS_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_SPI1) || ((REMAP) == GPIO_Remap_I2C1) || \
219  ((REMAP) == GPIO_Remap_USART1) || ((REMAP) == GPIO_Remap_USART2) || \
220  ((REMAP) == GPIO_PartialRemap_USART3) || ((REMAP) == GPIO_FullRemap_USART3) || \
221  ((REMAP) == GPIO_PartialRemap_TIM1) || ((REMAP) == GPIO_FullRemap_TIM1) || \
222  ((REMAP) == GPIO_PartialRemap1_TIM2) || ((REMAP) == GPIO_PartialRemap2_TIM2) || \
223  ((REMAP) == GPIO_FullRemap_TIM2) || ((REMAP) == GPIO_PartialRemap_TIM3) || \
224  ((REMAP) == GPIO_FullRemap_TIM3) || ((REMAP) == GPIO_Remap_TIM4) || \
225  ((REMAP) == GPIO_Remap1_CAN1) || ((REMAP) == GPIO_Remap2_CAN1) || \
226  ((REMAP) == GPIO_Remap_PD01) || ((REMAP) == GPIO_Remap_TIM5CH4_LSI) || \
227  ((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \
228  ((REMAP) == GPIO_Remap_ADC2_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC2_ETRGREG) || \
229  ((REMAP) == GPIO_Remap_ETH) ||((REMAP) == GPIO_Remap_CAN2) || \
230  ((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable) || \
231  ((REMAP) == GPIO_Remap_SWJ_Disable)|| ((REMAP) == GPIO_Remap_SPI3) || \
232  ((REMAP) == GPIO_Remap_TIM2ITR1_PTP_SOF) || ((REMAP) == GPIO_Remap_PTP_PPS) || \
233  ((REMAP) == GPIO_Remap_TIM15) || ((REMAP) == GPIO_Remap_TIM16) || \
234  ((REMAP) == GPIO_Remap_TIM17) || ((REMAP) == GPIO_Remap_CEC) || \
235  ((REMAP) == GPIO_Remap_TIM1_DMA) || ((REMAP) == GPIO_Remap_TIM9) || \
236  ((REMAP) == GPIO_Remap_TIM10) || ((REMAP) == GPIO_Remap_TIM11) || \
237  ((REMAP) == GPIO_Remap_TIM13) || ((REMAP) == GPIO_Remap_TIM14) || \
238  ((REMAP) == GPIO_Remap_FSMC_NADV))
239 
248 #define GPIO_PortSourceGPIOA ((uint8_t)0x00)
249 #define GPIO_PortSourceGPIOB ((uint8_t)0x01)
250 #define GPIO_PortSourceGPIOC ((uint8_t)0x02)
251 #define GPIO_PortSourceGPIOD ((uint8_t)0x03)
252 #define GPIO_PortSourceGPIOE ((uint8_t)0x04)
253 #define GPIO_PortSourceGPIOF ((uint8_t)0x05)
254 #define GPIO_PortSourceGPIOG ((uint8_t)0x06)
255 #define IS_GPIO_EVENTOUT_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
256  ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
257  ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
258  ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
259  ((PORTSOURCE) == GPIO_PortSourceGPIOE))
260 
261 #define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
262  ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
263  ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
264  ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
265  ((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
266  ((PORTSOURCE) == GPIO_PortSourceGPIOF) || \
267  ((PORTSOURCE) == GPIO_PortSourceGPIOG))
268 
277 #define GPIO_PinSource0 ((uint8_t)0x00)
278 #define GPIO_PinSource1 ((uint8_t)0x01)
279 #define GPIO_PinSource2 ((uint8_t)0x02)
280 #define GPIO_PinSource3 ((uint8_t)0x03)
281 #define GPIO_PinSource4 ((uint8_t)0x04)
282 #define GPIO_PinSource5 ((uint8_t)0x05)
283 #define GPIO_PinSource6 ((uint8_t)0x06)
284 #define GPIO_PinSource7 ((uint8_t)0x07)
285 #define GPIO_PinSource8 ((uint8_t)0x08)
286 #define GPIO_PinSource9 ((uint8_t)0x09)
287 #define GPIO_PinSource10 ((uint8_t)0x0A)
288 #define GPIO_PinSource11 ((uint8_t)0x0B)
289 #define GPIO_PinSource12 ((uint8_t)0x0C)
290 #define GPIO_PinSource13 ((uint8_t)0x0D)
291 #define GPIO_PinSource14 ((uint8_t)0x0E)
292 #define GPIO_PinSource15 ((uint8_t)0x0F)
293 
294 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
295  ((PINSOURCE) == GPIO_PinSource1) || \
296  ((PINSOURCE) == GPIO_PinSource2) || \
297  ((PINSOURCE) == GPIO_PinSource3) || \
298  ((PINSOURCE) == GPIO_PinSource4) || \
299  ((PINSOURCE) == GPIO_PinSource5) || \
300  ((PINSOURCE) == GPIO_PinSource6) || \
301  ((PINSOURCE) == GPIO_PinSource7) || \
302  ((PINSOURCE) == GPIO_PinSource8) || \
303  ((PINSOURCE) == GPIO_PinSource9) || \
304  ((PINSOURCE) == GPIO_PinSource10) || \
305  ((PINSOURCE) == GPIO_PinSource11) || \
306  ((PINSOURCE) == GPIO_PinSource12) || \
307  ((PINSOURCE) == GPIO_PinSource13) || \
308  ((PINSOURCE) == GPIO_PinSource14) || \
309  ((PINSOURCE) == GPIO_PinSource15))
310 
318 #define GPIO_ETH_MediaInterface_MII ((u32)0x00000000)
319 #define GPIO_ETH_MediaInterface_RMII ((u32)0x00000001)
320 
321 #define IS_GPIO_ETH_MEDIA_INTERFACE(INTERFACE) (((INTERFACE) == GPIO_ETH_MediaInterface_MII) || \
322  ((INTERFACE) == GPIO_ETH_MediaInterface_RMII))
323 
343 void GPIO_DeInit(GPIO_TypeDef* GPIOx);
344 void GPIO_AFIODeInit(void);
345 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
346 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
347 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
348 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
349 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
350 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
351 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
352 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
353 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
354 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
355 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
356 void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
357 void GPIO_EventOutputCmd(FunctionalState NewState);
358 void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState);
359 void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
360 void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface);
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 
366 #endif /* __STM32F10x_GPIO_H */
367 
379 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/