11 #ifndef __MG32F157_GPIO_H 12 #define __MG32F157_GPIO_H 31 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \ 32 ((PERIPH) == GPIOB) || \ 33 ((PERIPH) == GPIOC) || \ 34 ((PERIPH) == GPIOD) || \ 46 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \ 47 ((SPEED) == GPIO_Speed_50MHz)) 55 GPIO_Mode_IN_FLOATING = 0x04,
58 GPIO_Mode_Out_OD = 0x14,
59 GPIO_Mode_Out_PP = 0x10,
60 GPIO_Mode_AF_OD = 0x1C,
61 GPIO_Mode_AF_PP = 0x18
64 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_AIN) || ((MODE) == GPIO_Mode_IN_FLOATING) || \ 65 ((MODE) == GPIO_Mode_IPD) || ((MODE) == GPIO_Mode_IPU) || \ 66 ((MODE) == GPIO_Mode_Out_OD) || ((MODE) == GPIO_Mode_Out_PP) || \ 67 ((MODE) == GPIO_Mode_AF_OD) || ((MODE) == GPIO_Mode_AF_PP)) 94 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET)) 105 #define GPIO_Pin_0 ((uint16_t)0x0001) 106 #define GPIO_Pin_1 ((uint16_t)0x0002) 107 #define GPIO_Pin_2 ((uint16_t)0x0004) 108 #define GPIO_Pin_3 ((uint16_t)0x0008) 109 #define GPIO_Pin_4 ((uint16_t)0x0010) 110 #define GPIO_Pin_5 ((uint16_t)0x0020) 111 #define GPIO_Pin_6 ((uint16_t)0x0040) 112 #define GPIO_Pin_7 ((uint16_t)0x0080) 113 #define GPIO_Pin_8 ((uint16_t)0x0100) 114 #define GPIO_Pin_9 ((uint16_t)0x0200) 115 #define GPIO_Pin_10 ((uint16_t)0x0400) 116 #define GPIO_Pin_11 ((uint16_t)0x0800) 117 #define GPIO_Pin_12 ((uint16_t)0x1000) 118 #define GPIO_Pin_13 ((uint16_t)0x2000) 119 #define GPIO_Pin_14 ((uint16_t)0x4000) 120 #define GPIO_Pin_15 ((uint16_t)0x8000) 121 #define GPIO_Pin_All ((uint16_t)0xFFFF) 123 #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00)) 125 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \ 126 ((PIN) == GPIO_Pin_1) || \ 127 ((PIN) == GPIO_Pin_2) || \ 128 ((PIN) == GPIO_Pin_3) || \ 129 ((PIN) == GPIO_Pin_4) || \ 130 ((PIN) == GPIO_Pin_5) || \ 131 ((PIN) == GPIO_Pin_6) || \ 132 ((PIN) == GPIO_Pin_7) || \ 133 ((PIN) == GPIO_Pin_8) || \ 134 ((PIN) == GPIO_Pin_9) || \ 135 ((PIN) == GPIO_Pin_10) || \ 136 ((PIN) == GPIO_Pin_11) || \ 137 ((PIN) == GPIO_Pin_12) || \ 138 ((PIN) == GPIO_Pin_13) || \ 139 ((PIN) == GPIO_Pin_14) || \ 140 ((PIN) == GPIO_Pin_15)) 149 #define GPIO_Remap_SPI1 ((uint32_t)0x00000001) 150 #define GPIO_Remap_I2C1 ((uint32_t)0x00000002) 151 #define GPIO_Remap_USART1 ((uint32_t)0x00000004) 152 #define GPIO_Remap_USART2 ((uint32_t)0x00000008) 153 #define GPIO_PartialRemap_USART3 ((uint32_t)0x00140010) 154 #define GPIO_FullRemap_USART3 ((uint32_t)0x00140030) 155 #define GPIO_PartialRemap_TIM1 ((uint32_t)0x00160040) 156 #define GPIO_FullRemap_TIM1 ((uint32_t)0x001600C0) 157 #define GPIO_PartialRemap1_TIM2 ((uint32_t)0x00180100) 158 #define GPIO_PartialRemap2_TIM2 ((uint32_t)0x00180200) 159 #define GPIO_FullRemap_TIM2 ((uint32_t)0x00180300) 160 #define GPIO_PartialRemap_TIM3 ((uint32_t)0x001A0800) 161 #define GPIO_FullRemap_TIM3 ((uint32_t)0x001A0C00) 162 #define GPIO_Remap_TIM4 ((uint32_t)0x00001000) 163 #define GPIO_Remap1_CAN1 ((uint32_t)0x001D4000) 164 #define GPIO_Remap2_CAN1 ((uint32_t)0x001D6000) 165 #define GPIO_Remap_PD01 ((uint32_t)0x00008000) 166 #define GPIO_Remap_TIM5CH4_LSI ((uint32_t)0x00200001) 167 #define GPIO_Remap_ADC1_ETRGINJ ((uint32_t)0x00200002) 168 #define GPIO_Remap_ADC1_ETRGREG ((uint32_t)0x00200004) 169 #define GPIO_Remap_ADC2_ETRGINJ ((uint32_t)0x00200008) 170 #define GPIO_Remap_ADC2_ETRGREG ((uint32_t)0x00200010) 171 #define GPIO_Remap_SWJ_NoJTRST ((uint32_t)0x00300100) 172 #define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200) 173 #define GPIO_Remap_SWJ_Disable ((uint32_t)0x00300400) 174 #define GPIO_Remap_OPA1 ((uint32_t)0x00202000) 175 #define GPIO_Remap_OPA2 ((uint32_t)0x00204000) 176 #define GPIO_Remap_OPA3 ((uint32_t)0x00208000) 178 #define IS_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_SPI1) || ((REMAP) == GPIO_Remap_I2C1) || \ 179 ((REMAP) == GPIO_Remap_USART1) || ((REMAP) == GPIO_Remap_USART2) || \ 180 ((REMAP) == GPIO_PartialRemap_USART3) || ((REMAP) == GPIO_FullRemap_USART3) || \ 181 ((REMAP) == GPIO_PartialRemap_TIM1) || ((REMAP) == GPIO_FullRemap_TIM1) || \ 182 ((REMAP) == GPIO_PartialRemap1_TIM2) || ((REMAP) == GPIO_PartialRemap2_TIM2) || \ 183 ((REMAP) == GPIO_FullRemap_TIM2) || ((REMAP) == GPIO_PartialRemap_TIM3) || \ 184 ((REMAP) == GPIO_FullRemap_TIM3) || ((REMAP) == GPIO_Remap_TIM4) || \ 185 ((REMAP) == GPIO_Remap1_CAN1) || ((REMAP) == GPIO_Remap2_CAN1) || \ 186 ((REMAP) == GPIO_Remap_PD01) || ((REMAP) == GPIO_Remap_TIM5CH4_LSI) || \ 187 ((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \ 188 ((REMAP) == GPIO_Remap_ADC2_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC2_ETRGREG) || \ 189 ((REMAP) == GPIO_Remap_ETH) ||((REMAP) == GPIO_Remap_CAN2) || \ 190 ((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable) || \ 191 ((REMAP) == GPIO_Remap_SWJ_Disable)|| ((REMAP) == GPIO_Remap_OPA1) || \ 192 ((REMAP) == GPIO_Remap_OPA2) || ((REMAP) == GPIO_Remap_OPA3)) 201 #define GPIO_PortSourceGPIOA ((uint8_t)0x00) 202 #define GPIO_PortSourceGPIOB ((uint8_t)0x01) 203 #define GPIO_PortSourceGPIOC ((uint8_t)0x02) 204 #define GPIO_PortSourceGPIOD ((uint8_t)0x03) 205 #define GPIO_PortSourceGPIOE ((uint8_t)0x04) 206 #define IS_GPIO_EVENTOUT_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \ 207 ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \ 208 ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \ 209 ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \ 210 ((PORTSOURCE) == GPIO_PortSourceGPIOE)) 212 #define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \ 213 ((PORTSOURCE) == GPIO_PortSourceGPIOB) || \ 214 ((PORTSOURCE) == GPIO_PortSourceGPIOC) || \ 215 ((PORTSOURCE) == GPIO_PortSourceGPIOD) || \ 216 ((PORTSOURCE) == GPIO_PortSourceGPIOE)) 225 #define GPIO_PinSource0 ((uint8_t)0x00) 226 #define GPIO_PinSource1 ((uint8_t)0x01) 227 #define GPIO_PinSource2 ((uint8_t)0x02) 228 #define GPIO_PinSource3 ((uint8_t)0x03) 229 #define GPIO_PinSource4 ((uint8_t)0x04) 230 #define GPIO_PinSource5 ((uint8_t)0x05) 231 #define GPIO_PinSource6 ((uint8_t)0x06) 232 #define GPIO_PinSource7 ((uint8_t)0x07) 233 #define GPIO_PinSource8 ((uint8_t)0x08) 234 #define GPIO_PinSource9 ((uint8_t)0x09) 235 #define GPIO_PinSource10 ((uint8_t)0x0A) 236 #define GPIO_PinSource11 ((uint8_t)0x0B) 237 #define GPIO_PinSource12 ((uint8_t)0x0C) 238 #define GPIO_PinSource13 ((uint8_t)0x0D) 239 #define GPIO_PinSource14 ((uint8_t)0x0E) 240 #define GPIO_PinSource15 ((uint8_t)0x0F) 242 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \ 243 ((PINSOURCE) == GPIO_PinSource1) || \ 244 ((PINSOURCE) == GPIO_PinSource2) || \ 245 ((PINSOURCE) == GPIO_PinSource3) || \ 246 ((PINSOURCE) == GPIO_PinSource4) || \ 247 ((PINSOURCE) == GPIO_PinSource5) || \ 248 ((PINSOURCE) == GPIO_PinSource6) || \ 249 ((PINSOURCE) == GPIO_PinSource7) || \ 250 ((PINSOURCE) == GPIO_PinSource8) || \ 251 ((PINSOURCE) == GPIO_PinSource9) || \ 252 ((PINSOURCE) == GPIO_PinSource10) || \ 253 ((PINSOURCE) == GPIO_PinSource11) || \ 254 ((PINSOURCE) == GPIO_PinSource12) || \ 255 ((PINSOURCE) == GPIO_PinSource13) || \ 256 ((PINSOURCE) == GPIO_PinSource14) || \ 257 ((PINSOURCE) == GPIO_PinSource15)) 266 #define GPIO_ETH_MediaInterface_MII ((u32)0x00000000) 267 #define GPIO_ETH_MediaInterface_RMII ((u32)0x00000001) 269 #define IS_GPIO_ETH_MEDIA_INTERFACE(INTERFACE) (((INTERFACE) == GPIO_ETH_MediaInterface_MII) || \ 270 ((INTERFACE) == GPIO_ETH_MediaInterface_RMII)) void GPIO_AFIODeInit(void)
Deinitializes the Alternate Functions (remap, event control and EXTI configuration) registers to thei...
Definition: mg32f157_gpio.c:109
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Reads the specified input port pin.
Definition: mg32f157_gpio.c:231
GPIOSpeed_TypeDef
Output Maximum frequency selection.
Definition: mg32f157_gpio.h:40
void GPIO_ToggleBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Toggle data value for several pin of specified port.
Definition: mg32f157_gpio.c:368
GPIOSpeed_TypeDef GPIO_Speed
Definition: mg32f157_gpio.h:77
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Reads the specified output data port bit.
Definition: mg32f157_gpio.c:270
uint16_t GPIO_ReadOutputData(GPIO_TypeDef *GPIOx)
Reads the specified GPIO output data port.
Definition: mg32f157_gpio.c:293
GPIOMode_TypeDef
Configuration Mode enumeration.
Definition: mg32f157_gpio.h:52
uint16_t GPIO_Pin
Definition: mg32f157_gpio.h:74
Definition: mg32f157.h:634
void GPIO_PinLockConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Locks GPIO Pins configuration registers.
Definition: mg32f157_gpio.c:397
void GPIO_StructInit(GPIO_InitTypeDef *GPIO_InitStruct)
Fills each GPIO_InitStruct member with its default value.
Definition: mg32f157_gpio.c:216
void GPIO_WriteBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
Sets or clears the selected data port bit.
Definition: mg32f157_gpio.c:344
void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
Selects the GPIO pin used as EXTI Line.
Definition: mg32f157_gpio.c:552
void GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_InitStruct)
Initializes the GPIOx peripheral according to the specified parameters in the GPIO_InitStruct.
Definition: mg32f157_gpio.c:123
void GPIO_SetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Sets the selected data port bits.
Definition: mg32f157_gpio.c:308
void GPIO_EventOutputCmd(FunctionalState NewState)
Enables or disables the Event Output.
Definition: mg32f157_gpio.c:448
GPIOMode_TypeDef GPIO_Mode
Definition: mg32f157_gpio.h:80
void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState)
Changes the mapping of the specified pin.
Definition: mg32f157_gpio.c:492
GPIO Init structure definition.
Definition: mg32f157_gpio.h:72
void GPIO_Write(GPIO_TypeDef *GPIOx, uint16_t PortVal)
Writes data to the specified GPIO data port.
Definition: mg32f157_gpio.c:382
void GPIO_ResetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Clears the selected data port bits.
Definition: mg32f157_gpio.c:324
BitAction
Bit_SET and Bit_RESET enumeration.
Definition: mg32f157_gpio.h:88
uint16_t GPIO_ReadInputData(GPIO_TypeDef *GPIOx)
Reads the specified GPIO input data port.
Definition: mg32f157_gpio.c:255
void GPIO_DeInit(GPIO_TypeDef *GPIOx)
Deinitializes the GPIOx peripheral registers to their default reset values.
Definition: mg32f157_gpio.c:71
void GPIO_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
Selects the GPIO pin used as Event output.
Definition: mg32f157_gpio.c:427