Rev Author Line No. Line
3328 povik 1 /**
2 ******************************************************************************
3 * @file stm32f10x_gpio.h
4 * @author MCD Application Team
5 * @version V3.1.0
6 * @date 06/19/2009
7 * @brief This file contains all the functions prototypes for the GPIO
8 * firmware library.
9 ******************************************************************************
10 * @copy
11 *
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 *
19 * <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
20 */
21  
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  
33 /** @addtogroup STM32F10x_StdPeriph_Driver
34 * @{
35 */
36  
37 /** @addtogroup GPIO
38 * @{
39 */
40  
41 /** @defgroup GPIO_Exported_Types
42 * @{
43 */
44  
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  
53 /**
54 * @brief Output Maximum frequency selection
55 */
56  
57 typedef enum
58 {
59 GPIO_Speed_10MHz = 1,
60 GPIO_Speed_2MHz,
61 GPIO_Speed_50MHz
62 }GPIOSpeed_TypeDef;
63 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \
64 ((SPEED) == GPIO_Speed_50MHz))
65  
66 /**
67 * @brief Configuration Mode enumeration
68 */
69  
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
79 }GPIOMode_TypeDef;
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  
86 /**
87 * @brief GPIO Init structure definition
88 */
89  
90 typedef struct
91 {
92 uint16_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
93 This parameter can be any value of @ref GPIO_pins_define */
94  
95 GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
96 This parameter can be a value of @ref GPIOSpeed_TypeDef */
97  
98 GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
99 This parameter can be a value of @ref GPIOMode_TypeDef */
100 }GPIO_InitTypeDef;
101  
102  
103 /**
104 * @brief Bit_SET and Bit_RESET enumeration
105 */
106  
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  
114 /**
115 * @}
116 */
117  
118 /** @defgroup GPIO_Exported_Constants
119 * @{
120 */
121  
122 /** @defgroup GPIO_pins_define
123 * @{
124 */
125  
126 #define GPIO_Pin_0 ((uint16_t)0x0001) /*!< Pin 0 selected */
127 #define GPIO_Pin_1 ((uint16_t)0x0002) /*!< Pin 1 selected */
128 #define GPIO_Pin_2 ((uint16_t)0x0004) /*!< Pin 2 selected */
129 #define GPIO_Pin_3 ((uint16_t)0x0008) /*!< Pin 3 selected */
130 #define GPIO_Pin_4 ((uint16_t)0x0010) /*!< Pin 4 selected */
131 #define GPIO_Pin_5 ((uint16_t)0x0020) /*!< Pin 5 selected */
132 #define GPIO_Pin_6 ((uint16_t)0x0040) /*!< Pin 6 selected */
133 #define GPIO_Pin_7 ((uint16_t)0x0080) /*!< Pin 7 selected */
134 #define GPIO_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */
135 #define GPIO_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */
136 #define GPIO_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */
137 #define GPIO_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */
138 #define GPIO_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */
139 #define GPIO_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */
140 #define GPIO_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */
141 #define GPIO_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */
142 #define GPIO_Pin_All ((uint16_t)0xFFFF) /*!< All pins selected */
143  
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  
163 /**
164 * @}
165 */
166  
167 /** @defgroup GPIO_Remap_define
168 * @{
169 */
170  
171 #define GPIO_Remap_SPI1 ((uint32_t)0x00000001) /*!< SPI1 Alternate Function mapping */
172 #define GPIO_Remap_I2C1 ((uint32_t)0x00000002) /*!< I2C1 Alternate Function mapping */
173 #define GPIO_Remap_USART1 ((uint32_t)0x00000004) /*!< USART1 Alternate Function mapping */
174 #define GPIO_Remap_USART2 ((uint32_t)0x00000008) /*!< USART2 Alternate Function mapping */
175 #define GPIO_PartialRemap_USART3 ((uint32_t)0x00140010) /*!< USART3 Partial Alternate Function mapping */
176 #define GPIO_FullRemap_USART3 ((uint32_t)0x00140030) /*!< USART3 Full Alternate Function mapping */
177 #define GPIO_PartialRemap_TIM1 ((uint32_t)0x00160040) /*!< TIM1 Partial Alternate Function mapping */
178 #define GPIO_FullRemap_TIM1 ((uint32_t)0x001600C0) /*!< TIM1 Full Alternate Function mapping */
179 #define GPIO_PartialRemap1_TIM2 ((uint32_t)0x00180100) /*!< TIM2 Partial1 Alternate Function mapping */
180 #define GPIO_PartialRemap2_TIM2 ((uint32_t)0x00180200) /*!< TIM2 Partial2 Alternate Function mapping */
181 #define GPIO_FullRemap_TIM2 ((uint32_t)0x00180300) /*!< TIM2 Full Alternate Function mapping */
182 #define GPIO_PartialRemap_TIM3 ((uint32_t)0x001A0800) /*!< TIM3 Partial Alternate Function mapping */
183 #define GPIO_FullRemap_TIM3 ((uint32_t)0x001A0C00) /*!< TIM3 Full Alternate Function mapping */
184 #define GPIO_Remap_TIM4 ((uint32_t)0x00001000) /*!< TIM4 Alternate Function mapping */
185 #define GPIO_Remap1_CAN1 ((uint32_t)0x001D4000) /*!< CAN1 Alternate Function mapping */
186 #define GPIO_Remap2_CAN1 ((uint32_t)0x001D6000) /*!< CAN1 Alternate Function mapping */
187 #define GPIO_Remap_PD01 ((uint32_t)0x00008000) /*!< PD01 Alternate Function mapping */
188 #define GPIO_Remap_TIM5CH4_LSI ((uint32_t)0x00200001) /*!< LSI connected to TIM5 Channel4 input capture for calibration */
189 #define GPIO_Remap_ADC1_ETRGINJ ((uint32_t)0x00200002) /*!< ADC1 External Trigger Injected Conversion remapping */
190 #define GPIO_Remap_ADC1_ETRGREG ((uint32_t)0x00200004) /*!< ADC1 External Trigger Regular Conversion remapping */
191 #define GPIO_Remap_ADC2_ETRGINJ ((uint32_t)0x00200008) /*!< ADC2 External Trigger Injected Conversion remapping */
192 #define GPIO_Remap_ADC2_ETRGREG ((uint32_t)0x00200010) /*!< ADC2 External Trigger Regular Conversion remapping */
193 #define GPIO_Remap_ETH ((uint32_t)0x00200020) /*!< Ethernet remapping (only for Connectivity line devices) */
194 #define GPIO_Remap_CAN2 ((uint32_t)0x00200040) /*!< CAN2 remapping (only for Connectivity line devices) */
195 #define GPIO_Remap_SWJ_NoJTRST ((uint32_t)0x00300100) /*!< Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST */
196 #define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200) /*!< JTAG-DP Disabled and SW-DP Enabled */
197 #define GPIO_Remap_SWJ_Disable ((uint32_t)0x00300400) /*!< Full SWJ Disabled (JTAG-DP + SW-DP) */
198 #define GPIO_Remap_SPI3 ((uint32_t)0x00201000) /*!< SPI3 Alternate Function mapping (only for Connectivity line devices) */
199 #define GPIO_Remap_TIM2ITR1_PTP_SOF ((uint32_t)0x00202000) /*!< Ethernet PTP output or USB OTG SOF (Start of Frame) connected
200 to TIM2 Internal Trigger 1 for calibration
201 (only for Connectivity line devices) */
202 #define GPIO_Remap_PTP_PPS ((uint32_t)0x00204000) /*!< Ethernet MAC PPS_PTS output on PB05 (only for Connectivity line devices) */
203  
204 #define IS_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_SPI1) || ((REMAP) == GPIO_Remap_I2C1) || \
205 ((REMAP) == GPIO_Remap_USART1) || ((REMAP) == GPIO_Remap_USART2) || \
206 ((REMAP) == GPIO_PartialRemap_USART3) || ((REMAP) == GPIO_FullRemap_USART3) || \
207 ((REMAP) == GPIO_PartialRemap_TIM1) || ((REMAP) == GPIO_FullRemap_TIM1) || \
208 ((REMAP) == GPIO_PartialRemap1_TIM2) || ((REMAP) == GPIO_PartialRemap2_TIM2) || \
209 ((REMAP) == GPIO_FullRemap_TIM2) || ((REMAP) == GPIO_PartialRemap_TIM3) || \
210 ((REMAP) == GPIO_FullRemap_TIM3) || ((REMAP) == GPIO_Remap_TIM4) || \
211 ((REMAP) == GPIO_Remap1_CAN1) || ((REMAP) == GPIO_Remap2_CAN1) || \
212 ((REMAP) == GPIO_Remap_PD01) || ((REMAP) == GPIO_Remap_TIM5CH4_LSI) || \
213 ((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \
214 ((REMAP) == GPIO_Remap_ADC2_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC2_ETRGREG) || \
215 ((REMAP) == GPIO_Remap_ETH) ||((REMAP) == GPIO_Remap_CAN2) || \
216 ((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable) || \
217 ((REMAP) == GPIO_Remap_SWJ_Disable)|| ((REMAP) == GPIO_Remap_SPI3) || \
218 ((REMAP) == GPIO_Remap_TIM2ITR1_PTP_SOF) || ((REMAP) == GPIO_Remap_PTP_PPS))
219  
220 /**
221 * @}
222 */
223  
224 /** @defgroup GPIO_Port_Sources
225 * @{
226 */
227  
228 #define GPIO_PortSourceGPIOA ((uint8_t)0x00)
229 #define GPIO_PortSourceGPIOB ((uint8_t)0x01)
230 #define GPIO_PortSourceGPIOC ((uint8_t)0x02)
231 #define GPIO_PortSourceGPIOD ((uint8_t)0x03)
232 #define GPIO_PortSourceGPIOE ((uint8_t)0x04)
233 #define GPIO_PortSourceGPIOF ((uint8_t)0x05)
234 #define GPIO_PortSourceGPIOG ((uint8_t)0x06)
235 #define IS_GPIO_EVENTOUT_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
236 ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
237 ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
238 ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
239 ((PORTSOURCE) == GPIO_PortSourceGPIOE))
240  
241 #define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
242 ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
243 ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
244 ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
245 ((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
246 ((PORTSOURCE) == GPIO_PortSourceGPIOF) || \
247 ((PORTSOURCE) == GPIO_PortSourceGPIOG))
248  
249 /**
250 * @}
251 */
252  
253 /** @defgroup GPIO_Pin_sources
254 * @{
255 */
256  
257 #define GPIO_PinSource0 ((uint8_t)0x00)
258 #define GPIO_PinSource1 ((uint8_t)0x01)
259 #define GPIO_PinSource2 ((uint8_t)0x02)
260 #define GPIO_PinSource3 ((uint8_t)0x03)
261 #define GPIO_PinSource4 ((uint8_t)0x04)
262 #define GPIO_PinSource5 ((uint8_t)0x05)
263 #define GPIO_PinSource6 ((uint8_t)0x06)
264 #define GPIO_PinSource7 ((uint8_t)0x07)
265 #define GPIO_PinSource8 ((uint8_t)0x08)
266 #define GPIO_PinSource9 ((uint8_t)0x09)
267 #define GPIO_PinSource10 ((uint8_t)0x0A)
268 #define GPIO_PinSource11 ((uint8_t)0x0B)
269 #define GPIO_PinSource12 ((uint8_t)0x0C)
270 #define GPIO_PinSource13 ((uint8_t)0x0D)
271 #define GPIO_PinSource14 ((uint8_t)0x0E)
272 #define GPIO_PinSource15 ((uint8_t)0x0F)
273  
274 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
275 ((PINSOURCE) == GPIO_PinSource1) || \
276 ((PINSOURCE) == GPIO_PinSource2) || \
277 ((PINSOURCE) == GPIO_PinSource3) || \
278 ((PINSOURCE) == GPIO_PinSource4) || \
279 ((PINSOURCE) == GPIO_PinSource5) || \
280 ((PINSOURCE) == GPIO_PinSource6) || \
281 ((PINSOURCE) == GPIO_PinSource7) || \
282 ((PINSOURCE) == GPIO_PinSource8) || \
283 ((PINSOURCE) == GPIO_PinSource9) || \
284 ((PINSOURCE) == GPIO_PinSource10) || \
285 ((PINSOURCE) == GPIO_PinSource11) || \
286 ((PINSOURCE) == GPIO_PinSource12) || \
287 ((PINSOURCE) == GPIO_PinSource13) || \
288 ((PINSOURCE) == GPIO_PinSource14) || \
289 ((PINSOURCE) == GPIO_PinSource15))
290  
291 /**
292 * @}
293 */
294  
295 /** @defgroup Ethernet_Media_Interface
296 * @{
297 */
298 #define GPIO_ETH_MediaInterface_MII ((u32)0x00000000)
299 #define GPIO_ETH_MediaInterface_RMII ((u32)0x00000001)
300  
301 #define IS_GPIO_ETH_MEDIA_INTERFACE(INTERFACE) (((INTERFACE) == GPIO_ETH_MediaInterface_MII) || \
302 ((INTERFACE) == GPIO_ETH_MediaInterface_RMII))
303  
304 /**
305 * @}
306 */
307 /**
308 * @}
309 */
310  
311 /** @defgroup GPIO_Exported_Macros
312 * @{
313 */
314  
315 /**
316 * @}
317 */
318  
319 /** @defgroup GPIO_Exported_Functions
320 * @{
321 */
322  
323 void GPIO_DeInit(GPIO_TypeDef* GPIOx);
324 void GPIO_AFIODeInit(void);
325 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
326 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
327 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
328 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
329 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
330 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
331 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
332 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
333 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
334 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
335 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
336 void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
337 void GPIO_EventOutputCmd(FunctionalState NewState);
338 void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState);
339 void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
340 void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface);
341  
342 #ifdef __cplusplus
343 }
344 #endif
345  
346 #endif /* __STM32F10x_GPIO_H */
347 /**
348 * @}
349 */
350  
351 /**
352 * @}
353 */
354  
355 /**
356 * @}
357 */
358  
359 /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/