1 |
582 |
jeremybenn |
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
|
2 |
|
|
* File Name : stm32f10x_gpio.h
|
3 |
|
|
* Author : MCD Application Team
|
4 |
|
|
* Date First Issued : 09/29/2006
|
5 |
|
|
* Description : This file contains all the functions prototypes for the
|
6 |
|
|
* GPIO firmware library.
|
7 |
|
|
********************************************************************************
|
8 |
|
|
* History:
|
9 |
|
|
* 04/02/2007: V0.2
|
10 |
|
|
* 02/05/2007: V0.1
|
11 |
|
|
* 09/29/2006: V0.01
|
12 |
|
|
********************************************************************************
|
13 |
|
|
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
14 |
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
|
15 |
|
|
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
|
16 |
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
|
17 |
|
|
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
|
18 |
|
|
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
19 |
|
|
*******************************************************************************/
|
20 |
|
|
|
21 |
|
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
22 |
|
|
#ifndef __STM32F10x_GPIO_H
|
23 |
|
|
#define __STM32F10x_GPIO_H
|
24 |
|
|
|
25 |
|
|
/* Includes ------------------------------------------------------------------*/
|
26 |
|
|
#include "stm32f10x_map.h"
|
27 |
|
|
|
28 |
|
|
/* Exported types ------------------------------------------------------------*/
|
29 |
|
|
/* Output Maximum frequency selection ----------------------------------------*/
|
30 |
|
|
typedef enum
|
31 |
|
|
{
|
32 |
|
|
GPIO_Speed_10MHz = 1,
|
33 |
|
|
GPIO_Speed_2MHz,
|
34 |
|
|
GPIO_Speed_50MHz
|
35 |
|
|
}GPIOSpeed_TypeDef;
|
36 |
|
|
|
37 |
|
|
#define IS_GPIO_SPEED(SPEED) ((SPEED == GPIO_Speed_10MHz) || (SPEED == GPIO_Speed_2MHz) || \
|
38 |
|
|
(SPEED == GPIO_Speed_50MHz))
|
39 |
|
|
|
40 |
|
|
/* Configuration Mode enumeration --------------------------------------------*/
|
41 |
|
|
typedef enum
|
42 |
|
|
{ GPIO_Mode_AIN = 0x0,
|
43 |
|
|
GPIO_Mode_IN_FLOATING = 0x04,
|
44 |
|
|
GPIO_Mode_IPD = 0x28,
|
45 |
|
|
GPIO_Mode_IPU = 0x48,
|
46 |
|
|
GPIO_Mode_Out_OD = 0x14,
|
47 |
|
|
GPIO_Mode_Out_PP = 0x10,
|
48 |
|
|
GPIO_Mode_AF_OD = 0x1C,
|
49 |
|
|
GPIO_Mode_AF_PP = 0x18
|
50 |
|
|
}GPIOMode_TypeDef;
|
51 |
|
|
|
52 |
|
|
#define IS_GPIO_MODE(MODE) ((MODE == GPIO_Mode_AIN) || (MODE == GPIO_Mode_IN_FLOATING) || \
|
53 |
|
|
(MODE == GPIO_Mode_IPD) || (MODE == GPIO_Mode_IPU) || \
|
54 |
|
|
(MODE == GPIO_Mode_Out_OD) || (MODE == GPIO_Mode_Out_PP) || \
|
55 |
|
|
(MODE == GPIO_Mode_AF_OD) || (MODE == GPIO_Mode_AF_PP))
|
56 |
|
|
|
57 |
|
|
/* GPIO Init structure definition */
|
58 |
|
|
typedef struct
|
59 |
|
|
{
|
60 |
|
|
u16 GPIO_Pin;
|
61 |
|
|
GPIOSpeed_TypeDef GPIO_Speed;
|
62 |
|
|
GPIOMode_TypeDef GPIO_Mode;
|
63 |
|
|
}GPIO_InitTypeDef;
|
64 |
|
|
|
65 |
|
|
/* Bit_SET and Bit_RESET enumeration -----------------------------------------*/
|
66 |
|
|
typedef enum
|
67 |
|
|
{ Bit_RESET = 0,
|
68 |
|
|
Bit_SET
|
69 |
|
|
}BitAction;
|
70 |
|
|
#define IS_GPIO_BIT_ACTION(ACTION) ((ACTION == Bit_RESET) || (ACTION == Bit_SET))
|
71 |
|
|
|
72 |
|
|
/* Exported constants --------------------------------------------------------*/
|
73 |
|
|
/* GPIO pins define ----------------------------------------------------------*/
|
74 |
|
|
#define GPIO_Pin_0 ((u16)0x0001) /* Pin 0 selected */
|
75 |
|
|
#define GPIO_Pin_1 ((u16)0x0002) /* Pin 1 selected */
|
76 |
|
|
#define GPIO_Pin_2 ((u16)0x0004) /* Pin 2 selected */
|
77 |
|
|
#define GPIO_Pin_3 ((u16)0x0008) /* Pin 3 selected */
|
78 |
|
|
#define GPIO_Pin_4 ((u16)0x0010) /* Pin 4 selected */
|
79 |
|
|
#define GPIO_Pin_5 ((u16)0x0020) /* Pin 5 selected */
|
80 |
|
|
#define GPIO_Pin_6 ((u16)0x0040) /* Pin 6 selected */
|
81 |
|
|
#define GPIO_Pin_7 ((u16)0x0080) /* Pin 7 selected */
|
82 |
|
|
#define GPIO_Pin_8 ((u16)0x0100) /* Pin 8 selected */
|
83 |
|
|
#define GPIO_Pin_9 ((u16)0x0200) /* Pin 9 selected */
|
84 |
|
|
#define GPIO_Pin_10 ((u16)0x0400) /* Pin 10 selected */
|
85 |
|
|
#define GPIO_Pin_11 ((u16)0x0800) /* Pin 11 selected */
|
86 |
|
|
#define GPIO_Pin_12 ((u16)0x1000) /* Pin 12 selected */
|
87 |
|
|
#define GPIO_Pin_13 ((u16)0x2000) /* Pin 13 selected */
|
88 |
|
|
#define GPIO_Pin_14 ((u16)0x4000) /* Pin 14 selected */
|
89 |
|
|
#define GPIO_Pin_15 ((u16)0x8000) /* Pin 15 selected */
|
90 |
|
|
#define GPIO_Pin_All ((u16)0xFFFF) /* All pins selected */
|
91 |
|
|
|
92 |
|
|
#define IS_GPIO_PIN(PIN) (((PIN & (u16)0x00) == 0x00) && (PIN != (u16)0x00))
|
93 |
|
|
|
94 |
|
|
/* GPIO Remap define ---------------------------------------------------------*/
|
95 |
|
|
#define GPIO_Remap_SPI1 ((u32)0x00000001) /* SPI1 Alternate Function mapping */
|
96 |
|
|
#define GPIO_Remap_I2C1 ((u32)0x00000002) /* I2C1 Alternate Function mapping */
|
97 |
|
|
#define GPIO_Remap_USART1 ((u32)0x00000004) /* USART1 Alternate Function mapping */
|
98 |
|
|
#define GPIO_Remap_USART2 ((u32)0x00000008) /* USART2 Alternate Function mapping */
|
99 |
|
|
#define GPIO_PartialRemap_USART3 ((u32)0x00140010) /* USART3 Partial Alternate Function mapping */
|
100 |
|
|
#define GPIO_FullRemap_USART3 ((u32)0x00140030) /* USART3 Full Alternate Function mapping */
|
101 |
|
|
#define GPIO_PartialRemap_TIM1 ((u32)0x00160040) /* TIM1 Partial Alternate Function mapping */
|
102 |
|
|
#define GPIO_FullRemap_TIM1 ((u32)0x001600C0) /* TIM1 Full Alternate Function mapping */
|
103 |
|
|
#define GPIO_PartialRemap1_TIM2 ((u32)0x00180100) /* TIM2 Partial1 Alternate Function mapping */
|
104 |
|
|
#define GPIO_PartialRemap2_TIM2 ((u32)0x00180200) /* TIM2 Partial2 Alternate Function mapping */
|
105 |
|
|
#define GPIO_FullRemap_TIM2 ((u32)0x00180300) /* TIM2 Full Alternate Function mapping */
|
106 |
|
|
#define GPIO_PartialRemap_TIM3 ((u32)0x001A0800) /* TIM3 Partial Alternate Function mapping */
|
107 |
|
|
#define GPIO_FullRemap_TIM3 ((u32)0x001A0C00) /* TIM3 Full Alternate Function mapping */
|
108 |
|
|
#define GPIO_Remap_TIM4 ((u32)0x00001000) /* TIM4 Alternate Function mapping */
|
109 |
|
|
#define GPIO_Remap1_CAN ((u32)0x001D2000) /* CAN Alternate Function mapping */
|
110 |
|
|
#define GPIO_Remap2_CAN ((u32)0x001D6000) /* CAN Alternate Function mapping */
|
111 |
|
|
#define GPIO_Remap_PD01 ((u32)0x00008000) /* PD01 Alternate Function mapping */
|
112 |
|
|
#define GPIO_Remap_SWJ_NoJTRST ((u32)0x00300100) /* Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST */
|
113 |
|
|
#define GPIO_Remap_SWJ_JTAGDisable ((u32)0x00300200) /* JTAG-DP Disabled and SW-DP Enabled */
|
114 |
|
|
#define GPIO_Remap_SWJ_Disable ((u32)0x00300400) /* Full SWJ Disabled (JTAG-DP + SW-DP) */
|
115 |
|
|
|
116 |
|
|
#define IS_GPIO_REMAP(REMAP) ((REMAP == GPIO_Remap_SPI1) || (REMAP == GPIO_Remap_I2C1) || \
|
117 |
|
|
(REMAP == GPIO_Remap_USART1) || (REMAP == GPIO_Remap_USART2) || \
|
118 |
|
|
(REMAP == GPIO_PartialRemap_USART3) || (REMAP == GPIO_FullRemap_USART3) || \
|
119 |
|
|
(REMAP == GPIO_PartialRemap_TIM1) || (REMAP == GPIO_FullRemap_TIM1) || \
|
120 |
|
|
(REMAP == GPIO_PartialRemap1_TIM2) || (REMAP == GPIO_PartialRemap2_TIM2) || \
|
121 |
|
|
(REMAP == GPIO_FullRemap_TIM2) || (REMAP == GPIO_PartialRemap_TIM3) || \
|
122 |
|
|
(REMAP == GPIO_FullRemap_TIM3) || (REMAP == GPIO_Remap_TIM4) || \
|
123 |
|
|
(REMAP == GPIO_Remap1_CAN) || (REMAP == GPIO_Remap2_CAN) || \
|
124 |
|
|
(REMAP == GPIO_Remap_PD01) || (REMAP == GPIO_Remap_SWJ_NoJTRST) || \
|
125 |
|
|
(REMAP == GPIO_Remap_SWJ_JTAGDisable) || (REMAP == GPIO_Remap_SWJ_Disable))
|
126 |
|
|
|
127 |
|
|
/* GPIO Port Sources ---------------------------------------------------------*/
|
128 |
|
|
#define GPIO_PortSourceGPIOA ((u8)0x00)
|
129 |
|
|
#define GPIO_PortSourceGPIOB ((u8)0x01)
|
130 |
|
|
#define GPIO_PortSourceGPIOC ((u8)0x02)
|
131 |
|
|
#define GPIO_PortSourceGPIOD ((u8)0x03)
|
132 |
|
|
#define GPIO_PortSourceGPIOE ((u8)0x04)
|
133 |
|
|
|
134 |
|
|
#define IS_GPIO_PORT_SOURCE(PORTSOURCE) ((PORTSOURCE == GPIO_PortSourceGPIOA) || \
|
135 |
|
|
(PORTSOURCE == GPIO_PortSourceGPIOB) || \
|
136 |
|
|
(PORTSOURCE == GPIO_PortSourceGPIOC) || \
|
137 |
|
|
(PORTSOURCE == GPIO_PortSourceGPIOD) || \
|
138 |
|
|
(PORTSOURCE == GPIO_PortSourceGPIOE))
|
139 |
|
|
|
140 |
|
|
/* GPIO Pin sources ----------------------------------------------------------*/
|
141 |
|
|
#define GPIO_PinSource0 ((u8)0x00)
|
142 |
|
|
#define GPIO_PinSource1 ((u8)0x01)
|
143 |
|
|
#define GPIO_PinSource2 ((u8)0x02)
|
144 |
|
|
#define GPIO_PinSource3 ((u8)0x03)
|
145 |
|
|
#define GPIO_PinSource4 ((u8)0x04)
|
146 |
|
|
#define GPIO_PinSource5 ((u8)0x05)
|
147 |
|
|
#define GPIO_PinSource6 ((u8)0x06)
|
148 |
|
|
#define GPIO_PinSource7 ((u8)0x07)
|
149 |
|
|
#define GPIO_PinSource8 ((u8)0x08)
|
150 |
|
|
#define GPIO_PinSource9 ((u8)0x09)
|
151 |
|
|
#define GPIO_PinSource10 ((u8)0x0A)
|
152 |
|
|
#define GPIO_PinSource11 ((u8)0x0B)
|
153 |
|
|
#define GPIO_PinSource12 ((u8)0x0C)
|
154 |
|
|
#define GPIO_PinSource13 ((u8)0x0D)
|
155 |
|
|
#define GPIO_PinSource14 ((u8)0x0E)
|
156 |
|
|
#define GPIO_PinSource15 ((u8)0x0F)
|
157 |
|
|
|
158 |
|
|
#define IS_GPIO_PIN_SOURCE(PINSOURCE) ((PINSOURCE == GPIO_PinSource0) || \
|
159 |
|
|
(PINSOURCE == GPIO_PinSource1) || \
|
160 |
|
|
(PINSOURCE == GPIO_PinSource2) || \
|
161 |
|
|
(PINSOURCE == GPIO_PinSource3) || \
|
162 |
|
|
(PINSOURCE == GPIO_PinSource4) || \
|
163 |
|
|
(PINSOURCE == GPIO_PinSource5) || \
|
164 |
|
|
(PINSOURCE == GPIO_PinSource6) || \
|
165 |
|
|
(PINSOURCE == GPIO_PinSource7) || \
|
166 |
|
|
(PINSOURCE == GPIO_PinSource8) || \
|
167 |
|
|
(PINSOURCE == GPIO_PinSource9) || \
|
168 |
|
|
(PINSOURCE == GPIO_PinSource10) || \
|
169 |
|
|
(PINSOURCE == GPIO_PinSource11) || \
|
170 |
|
|
(PINSOURCE == GPIO_PinSource12) || \
|
171 |
|
|
(PINSOURCE == GPIO_PinSource13) || \
|
172 |
|
|
(PINSOURCE == GPIO_PinSource14) || \
|
173 |
|
|
(PINSOURCE == GPIO_PinSource15))
|
174 |
|
|
|
175 |
|
|
/* Exported macro ------------------------------------------------------------*/
|
176 |
|
|
/* Exported functions ------------------------------------------------------- */
|
177 |
|
|
void GPIO_DeInit(GPIO_TypeDef* GPIOx);
|
178 |
|
|
void GPIO_AFIODeInit(void);
|
179 |
|
|
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
|
180 |
|
|
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
|
181 |
|
|
u8 GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
|
182 |
|
|
u16 GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
|
183 |
|
|
u8 GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
|
184 |
|
|
u16 GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
|
185 |
|
|
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin, BitAction BitVal);
|
186 |
|
|
void GPIO_Write(GPIO_TypeDef* GPIOx, u16 PortVal);
|
187 |
|
|
void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, u16 GPIO_Pin);
|
188 |
|
|
void GPIO_EventOutputConfig(u8 GPIO_PortSource, u8 GPIO_PinSource);
|
189 |
|
|
void GPIO_EventOutputCmd(FunctionalState NewState);
|
190 |
|
|
void GPIO_PinRemapConfig(u32 GPIO_Remap, FunctionalState NewState);
|
191 |
|
|
void GPIO_EXTILineConfig(u8 GPIO_PortSource, u8 GPIO_PinSource);
|
192 |
|
|
|
193 |
|
|
#endif /* __STM32F10x_GPIO_H */
|
194 |
|
|
|
195 |
|
|
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
|