Go to the documentation of this file.00001
00022
00023 #ifndef __STM32F10x_GPIO_H
00024 #define __STM32F10x_GPIO_H
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029
00030
00031 #include <cfg/arch.h>
00032 #include <arch/cm3.h>
00033 #include <arch/cm3/stm/stm32f10x.h>
00034
00047 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
00048 ((PERIPH) == GPIOB) || \
00049 ((PERIPH) == GPIOC) || \
00050 ((PERIPH) == GPIOD) || \
00051 ((PERIPH) == GPIOE) || \
00052 ((PERIPH) == GPIOF) || \
00053 ((PERIPH) == GPIOG))
00054
00059 typedef enum
00060 {
00061 GPIO_Speed_10MHz = 1,
00062 GPIO_Speed_2MHz,
00063 GPIO_Speed_50MHz
00064 }GPIOSpeed_TypeDef;
00065 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \
00066 ((SPEED) == GPIO_Speed_50MHz))
00067
00072 typedef enum
00073 { GPIO_Mode_AIN = 0x0,
00074 GPIO_Mode_IN_FLOATING = 0x04,
00075 GPIO_Mode_IPD = 0x28,
00076 GPIO_Mode_IPU = 0x48,
00077 GPIO_Mode_Out_OD = 0x14,
00078 GPIO_Mode_Out_PP = 0x10,
00079 GPIO_Mode_AF_OD = 0x1C,
00080 GPIO_Mode_AF_PP = 0x18
00081 }GPIOMode_TypeDef;
00082
00083 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_AIN) || ((MODE) == GPIO_Mode_IN_FLOATING) || \
00084 ((MODE) == GPIO_Mode_IPD) || ((MODE) == GPIO_Mode_IPU) || \
00085 ((MODE) == GPIO_Mode_Out_OD) || ((MODE) == GPIO_Mode_Out_PP) || \
00086 ((MODE) == GPIO_Mode_AF_OD) || ((MODE) == GPIO_Mode_AF_PP))
00087 #if 0
00088
00092 typedef struct
00093 {
00094 uint16_t GPIO_Pin;
00097 GPIOSpeed_TypeDef GPIO_Speed;
00100 GPIOMode_TypeDef GPIO_Mode;
00102 }GPIO_InitTypeDef;
00103
00108 typedef enum
00109 { Bit_RESET = 0,
00110 Bit_SET
00111 }BitAction;
00112
00113 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
00114
00127 #define GPIO_Pin_0 ((uint16_t)0x0001)
00128 #define GPIO_Pin_1 ((uint16_t)0x0002)
00129 #define GPIO_Pin_2 ((uint16_t)0x0004)
00130 #define GPIO_Pin_3 ((uint16_t)0x0008)
00131 #define GPIO_Pin_4 ((uint16_t)0x0010)
00132 #define GPIO_Pin_5 ((uint16_t)0x0020)
00133 #define GPIO_Pin_6 ((uint16_t)0x0040)
00134 #define GPIO_Pin_7 ((uint16_t)0x0080)
00135 #define GPIO_Pin_8 ((uint16_t)0x0100)
00136 #define GPIO_Pin_9 ((uint16_t)0x0200)
00137 #define GPIO_Pin_10 ((uint16_t)0x0400)
00138 #define GPIO_Pin_11 ((uint16_t)0x0800)
00139 #define GPIO_Pin_12 ((uint16_t)0x1000)
00140 #define GPIO_Pin_13 ((uint16_t)0x2000)
00141 #define GPIO_Pin_14 ((uint16_t)0x4000)
00142 #define GPIO_Pin_15 ((uint16_t)0x8000)
00143 #define GPIO_Pin_All ((uint16_t)0xFFFF)
00145 #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))
00146
00147 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
00148 ((PIN) == GPIO_Pin_1) || \
00149 ((PIN) == GPIO_Pin_2) || \
00150 ((PIN) == GPIO_Pin_3) || \
00151 ((PIN) == GPIO_Pin_4) || \
00152 ((PIN) == GPIO_Pin_5) || \
00153 ((PIN) == GPIO_Pin_6) || \
00154 ((PIN) == GPIO_Pin_7) || \
00155 ((PIN) == GPIO_Pin_8) || \
00156 ((PIN) == GPIO_Pin_9) || \
00157 ((PIN) == GPIO_Pin_10) || \
00158 ((PIN) == GPIO_Pin_11) || \
00159 ((PIN) == GPIO_Pin_12) || \
00160 ((PIN) == GPIO_Pin_13) || \
00161 ((PIN) == GPIO_Pin_14) || \
00162 ((PIN) == GPIO_Pin_15))
00163
00167 #endif
00168
00173 #define GPIO_Remap_SPI1 ((uint32_t)0x00000001)
00174 #define GPIO_Remap_I2C1 ((uint32_t)0x00000002)
00175 #define GPIO_Remap_USART1 ((uint32_t)0x00000004)
00176 #define GPIO_Remap_USART2 ((uint32_t)0x00000008)
00177 #define GPIO_PartialRemap_USART3 ((uint32_t)0x00140010)
00178 #define GPIO_FullRemap_USART3 ((uint32_t)0x00140030)
00179 #define GPIO_PartialRemap_TIM1 ((uint32_t)0x00160040)
00180 #define GPIO_FullRemap_TIM1 ((uint32_t)0x001600C0)
00181 #define GPIO_PartialRemap1_TIM2 ((uint32_t)0x00180100)
00182 #define GPIO_PartialRemap2_TIM2 ((uint32_t)0x00180200)
00183 #define GPIO_FullRemap_TIM2 ((uint32_t)0x00180300)
00184 #define GPIO_PartialRemap_TIM3 ((uint32_t)0x001A0800)
00185 #define GPIO_FullRemap_TIM3 ((uint32_t)0x001A0C00)
00186 #define GPIO_Remap_TIM4 ((uint32_t)0x00001000)
00187 #define GPIO_Remap1_CAN1 ((uint32_t)0x001D4000)
00188 #define GPIO_Remap2_CAN1 ((uint32_t)0x001D6000)
00189 #define GPIO_Remap_PD01 ((uint32_t)0x00008000)
00190 #define GPIO_Remap_TIM5CH4_LSI ((uint32_t)0x00200001)
00191 #define GPIO_Remap_ADC1_ETRGINJ ((uint32_t)0x00200002)
00192 #define GPIO_Remap_ADC1_ETRGREG ((uint32_t)0x00200004)
00193 #define GPIO_Remap_ADC2_ETRGINJ ((uint32_t)0x00200008)
00194 #define GPIO_Remap_ADC2_ETRGREG ((uint32_t)0x00200010)
00195 #define GPIO_Remap_ETH ((uint32_t)0x00200020)
00196 #define GPIO_Remap_CAN2 ((uint32_t)0x00200040)
00197 #define GPIO_Remap_SWJ_NoJTRST ((uint32_t)0x00300100)
00198 #define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200)
00199 #define GPIO_Remap_SWJ_Disable ((uint32_t)0x00300400)
00200 #define GPIO_Remap_SPI3 ((uint32_t)0x00201000)
00201 #define GPIO_Remap_TIM2ITR1_PTP_SOF ((uint32_t)0x00202000)
00204 #define GPIO_Remap_PTP_PPS ((uint32_t)0x00204000)
00206 #define GPIO_Remap_TIM15 ((uint32_t)0x80000001)
00207 #define GPIO_Remap_TIM16 ((uint32_t)0x80000002)
00208 #define GPIO_Remap_TIM17 ((uint32_t)0x80000004)
00209 #define GPIO_Remap_CEC ((uint32_t)0x80000008)
00210 #define GPIO_Remap_TIM1_DMA ((uint32_t)0x80000010)
00212 #define GPIO_Remap_TIM9 ((uint32_t)0x80000020)
00213 #define GPIO_Remap_TIM10 ((uint32_t)0x80000040)
00214 #define GPIO_Remap_TIM11 ((uint32_t)0x80000080)
00215 #define GPIO_Remap_TIM13 ((uint32_t)0x80000100)
00216 #define GPIO_Remap_TIM14 ((uint32_t)0x80000200)
00217 #define GPIO_Remap_FSMC_NADV ((uint32_t)0x80000400)
00220 #define IS_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_SPI1) || ((REMAP) == GPIO_Remap_I2C1) || \
00221 ((REMAP) == GPIO_Remap_USART1) || ((REMAP) == GPIO_Remap_USART2) || \
00222 ((REMAP) == GPIO_PartialRemap_USART3) || ((REMAP) == GPIO_FullRemap_USART3) || \
00223 ((REMAP) == GPIO_PartialRemap_TIM1) || ((REMAP) == GPIO_FullRemap_TIM1) || \
00224 ((REMAP) == GPIO_PartialRemap1_TIM2) || ((REMAP) == GPIO_PartialRemap2_TIM2) || \
00225 ((REMAP) == GPIO_FullRemap_TIM2) || ((REMAP) == GPIO_PartialRemap_TIM3) || \
00226 ((REMAP) == GPIO_FullRemap_TIM3) || ((REMAP) == GPIO_Remap_TIM4) || \
00227 ((REMAP) == GPIO_Remap1_CAN1) || ((REMAP) == GPIO_Remap2_CAN1) || \
00228 ((REMAP) == GPIO_Remap_PD01) || ((REMAP) == GPIO_Remap_TIM5CH4_LSI) || \
00229 ((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \
00230 ((REMAP) == GPIO_Remap_ADC2_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC2_ETRGREG) || \
00231 ((REMAP) == GPIO_Remap_ETH) ||((REMAP) == GPIO_Remap_CAN2) || \
00232 ((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable) || \
00233 ((REMAP) == GPIO_Remap_SWJ_Disable)|| ((REMAP) == GPIO_Remap_SPI3) || \
00234 ((REMAP) == GPIO_Remap_TIM2ITR1_PTP_SOF) || ((REMAP) == GPIO_Remap_PTP_PPS) || \
00235 ((REMAP) == GPIO_Remap_TIM15) || ((REMAP) == GPIO_Remap_TIM16) || \
00236 ((REMAP) == GPIO_Remap_TIM17) || ((REMAP) == GPIO_Remap_CEC) || \
00237 ((REMAP) == GPIO_Remap_TIM1_DMA) || ((REMAP) == GPIO_Remap_TIM9) || \
00238 ((REMAP) == GPIO_Remap_TIM10) || ((REMAP) == GPIO_Remap_TIM11) || \
00239 ((REMAP) == GPIO_Remap_TIM13) || ((REMAP) == GPIO_Remap_TIM14) || \
00240 ((REMAP) == GPIO_Remap_FSMC_NADV))
00241
00245 #if 0
00246
00250 #define GPIO_PortSourceGPIOA ((uint8_t)0x00)
00251 #define GPIO_PortSourceGPIOB ((uint8_t)0x01)
00252 #define GPIO_PortSourceGPIOC ((uint8_t)0x02)
00253 #define GPIO_PortSourceGPIOD ((uint8_t)0x03)
00254 #define GPIO_PortSourceGPIOE ((uint8_t)0x04)
00255 #define GPIO_PortSourceGPIOF ((uint8_t)0x05)
00256 #define GPIO_PortSourceGPIOG ((uint8_t)0x06)
00257 #define IS_GPIO_EVENTOUT_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
00258 ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
00259 ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
00260 ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
00261 ((PORTSOURCE) == GPIO_PortSourceGPIOE))
00262
00263 #define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
00264 ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
00265 ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
00266 ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
00267 ((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
00268 ((PORTSOURCE) == GPIO_PortSourceGPIOF) || \
00269 ((PORTSOURCE) == GPIO_PortSourceGPIOG))
00270
00279 #define GPIO_PinSource0 ((uint8_t)0x00)
00280 #define GPIO_PinSource1 ((uint8_t)0x01)
00281 #define GPIO_PinSource2 ((uint8_t)0x02)
00282 #define GPIO_PinSource3 ((uint8_t)0x03)
00283 #define GPIO_PinSource4 ((uint8_t)0x04)
00284 #define GPIO_PinSource5 ((uint8_t)0x05)
00285 #define GPIO_PinSource6 ((uint8_t)0x06)
00286 #define GPIO_PinSource7 ((uint8_t)0x07)
00287 #define GPIO_PinSource8 ((uint8_t)0x08)
00288 #define GPIO_PinSource9 ((uint8_t)0x09)
00289 #define GPIO_PinSource10 ((uint8_t)0x0A)
00290 #define GPIO_PinSource11 ((uint8_t)0x0B)
00291 #define GPIO_PinSource12 ((uint8_t)0x0C)
00292 #define GPIO_PinSource13 ((uint8_t)0x0D)
00293 #define GPIO_PinSource14 ((uint8_t)0x0E)
00294 #define GPIO_PinSource15 ((uint8_t)0x0F)
00295
00296 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
00297 ((PINSOURCE) == GPIO_PinSource1) || \
00298 ((PINSOURCE) == GPIO_PinSource2) || \
00299 ((PINSOURCE) == GPIO_PinSource3) || \
00300 ((PINSOURCE) == GPIO_PinSource4) || \
00301 ((PINSOURCE) == GPIO_PinSource5) || \
00302 ((PINSOURCE) == GPIO_PinSource6) || \
00303 ((PINSOURCE) == GPIO_PinSource7) || \
00304 ((PINSOURCE) == GPIO_PinSource8) || \
00305 ((PINSOURCE) == GPIO_PinSource9) || \
00306 ((PINSOURCE) == GPIO_PinSource10) || \
00307 ((PINSOURCE) == GPIO_PinSource11) || \
00308 ((PINSOURCE) == GPIO_PinSource12) || \
00309 ((PINSOURCE) == GPIO_PinSource13) || \
00310 ((PINSOURCE) == GPIO_PinSource14) || \
00311 ((PINSOURCE) == GPIO_PinSource15))
00312
00316 #endif
00317
00320 #define GPIO_ETH_MediaInterface_MII ((u32)0x00000000)
00321 #define GPIO_ETH_MediaInterface_RMII ((u32)0x00000001)
00322
00323 #define IS_GPIO_ETH_MEDIA_INTERFACE(INTERFACE) (((INTERFACE) == GPIO_ETH_MediaInterface_MII) || \
00324 ((INTERFACE) == GPIO_ETH_MediaInterface_RMII))
00325
00332 #if 0
00333
00337 #define PIOA_ID 0
00338 #define PIOB_ID 1
00339 #define PIOC_ID 2
00340 #define PIOD_ID 3
00341 #define PIOE_ID 4
00342 #define PIOF_ID 5
00343 #define PIOG_ID 6
00344
00345
00346
00347 #define GPIO_ID2BASE(id) ((id*0x00000400)+GPIOA_BASE)
00348 #define GPIO_ID2GPIO(id) ((GPIO_TypeDef*)(GPIO_ID2BASE(id)))
00349
00350
00351 #define GPIO_BASE2ID(bs) (((bs&0x00002C00)-0x00000400)>>10)
00352
00353 #define GPIO_ID2RCC(id) _BV(GPIO_BASE2ID(id)+2)
00354
00357 #endif
00358
00361 #if 0
00362 void GPIO_DeInit(GPIO_TypeDef* GPIOx);
00363 void GPIO_AFIODeInit(void);
00364 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
00365 void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
00366 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00367 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
00368 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00369 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
00370 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00371 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00372 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
00373 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
00374 void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00375 #endif
00376 void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
00377 void GPIO_EventOutputCmd(FunctionalState NewState);
00378 void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState);
00379 void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
00380 void GPIO_ETH_MediaInterfaceConfig(uint32_t GPIO_ETH_MediaInterface);
00381
00382 #ifdef __cplusplus
00383 }
00384 #endif
00385
00386 #endif
00387
00399