MG32F10x Standard Peripherals Firmware Library
mg32f10x_gpio.h
Go to the documentation of this file.
1 
10 /* Define to prevent recursive inclusion -------------------------------------*/
11 #ifndef __MG32F10x_GPIO_H
12 #define __MG32F10x_GPIO_H
13 
14 #ifdef __cplusplus
15  extern "C" {
16 #endif
17 
18 /* Includes ------------------------------------------------------------------*/
19 #include "mg32f10x.h"
20 
29 /* Exported types ------------------------------------------------------------*/
30 /* Exported constants --------------------------------------------------------*/
31 
36 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
37  ((PERIPH) == GPIOB) || \
38  ((PERIPH) == GPIOC) || \
39  ((PERIPH) == GPIOD))
40 
44 typedef enum
45 {
46  Bit_RESET = 0,
47  Bit_SET
48 } BitAction;
49 #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
50 
51 
55 #define GPIO_Pin_0 ((uint16_t)0x0001)
56 #define GPIO_Pin_1 ((uint16_t)0x0002)
57 #define GPIO_Pin_2 ((uint16_t)0x0004)
58 #define GPIO_Pin_3 ((uint16_t)0x0008)
59 #define GPIO_Pin_4 ((uint16_t)0x0010)
60 #define GPIO_Pin_5 ((uint16_t)0x0020)
61 #define GPIO_Pin_6 ((uint16_t)0x0040)
62 #define GPIO_Pin_7 ((uint16_t)0x0080)
63 #define GPIO_Pin_8 ((uint16_t)0x0100)
64 #define GPIO_Pin_9 ((uint16_t)0x0200)
65 #define GPIO_Pin_10 ((uint16_t)0x0400)
66 #define GPIO_Pin_11 ((uint16_t)0x0800)
67 #define GPIO_Pin_12 ((uint16_t)0x1000)
68 #define GPIO_Pin_13 ((uint16_t)0x2000)
69 #define GPIO_Pin_14 ((uint16_t)0x4000)
70 #define GPIO_Pin_15 ((uint16_t)0x8000)
71 #define GPIO_Pin_All ((uint16_t)0xFFFF)
73 #define IS_GPIO_PIN(PIN) (((PIN) & 0x0000FFFF) != (uint32_t)0x00)
74 #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
75  ((PIN) == GPIO_Pin_1) || \
76  ((PIN) == GPIO_Pin_2) || \
77  ((PIN) == GPIO_Pin_3) || \
78  ((PIN) == GPIO_Pin_4) || \
79  ((PIN) == GPIO_Pin_5) || \
80  ((PIN) == GPIO_Pin_6) || \
81  ((PIN) == GPIO_Pin_7) || \
82  ((PIN) == GPIO_Pin_8) || \
83  ((PIN) == GPIO_Pin_9) || \
84  ((PIN) == GPIO_Pin_10) || \
85  ((PIN) == GPIO_Pin_11) || \
86  ((PIN) == GPIO_Pin_12) || \
87  ((PIN) == GPIO_Pin_13) || \
88  ((PIN) == GPIO_Pin_14) || \
89  ((PIN) == GPIO_Pin_15))
90 
97 #define GPIO_PortSourceGPIOA ((uint8_t)0x00)
98 #define GPIO_PortSourceGPIOB ((uint8_t)0x01)
99 #define GPIO_PortSourceGPIOC ((uint8_t)0x02)
100 #define GPIO_PortSourceGPIOD ((uint8_t)0x03)
101 
108 #define GPIO_PinSource0 ((uint8_t)0x00)
109 #define GPIO_PinSource1 ((uint8_t)0x01)
110 #define GPIO_PinSource2 ((uint8_t)0x02)
111 #define GPIO_PinSource3 ((uint8_t)0x03)
112 #define GPIO_PinSource4 ((uint8_t)0x04)
113 #define GPIO_PinSource5 ((uint8_t)0x05)
114 #define GPIO_PinSource6 ((uint8_t)0x06)
115 #define GPIO_PinSource7 ((uint8_t)0x07)
116 #define GPIO_PinSource8 ((uint8_t)0x08)
117 #define GPIO_PinSource9 ((uint8_t)0x09)
118 #define GPIO_PinSource10 ((uint8_t)0x0A)
119 #define GPIO_PinSource11 ((uint8_t)0x0B)
120 #define GPIO_PinSource12 ((uint8_t)0x0C)
121 #define GPIO_PinSource13 ((uint8_t)0x0D)
122 #define GPIO_PinSource14 ((uint8_t)0x0E)
123 #define GPIO_PinSource15 ((uint8_t)0x0F)
124 
125 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
126  ((PINSOURCE) == GPIO_PinSource1) || \
127  ((PINSOURCE) == GPIO_PinSource2) || \
128  ((PINSOURCE) == GPIO_PinSource3) || \
129  ((PINSOURCE) == GPIO_PinSource4) || \
130  ((PINSOURCE) == GPIO_PinSource5) || \
131  ((PINSOURCE) == GPIO_PinSource6) || \
132  ((PINSOURCE) == GPIO_PinSource7) || \
133  ((PINSOURCE) == GPIO_PinSource8) || \
134  ((PINSOURCE) == GPIO_PinSource9) || \
135  ((PINSOURCE) == GPIO_PinSource10) || \
136  ((PINSOURCE) == GPIO_PinSource11) || \
137  ((PINSOURCE) == GPIO_PinSource12) || \
138  ((PINSOURCE) == GPIO_PinSource13) || \
139  ((PINSOURCE) == GPIO_PinSource14) || \
140  ((PINSOURCE) == GPIO_PinSource15))
141 
148 #define GPIO_MODE_IN 0x00000000U
149 #define GPIO_MODE_OUT 0x10000000U
150 #define GPIO_MODE_AF 0x20000000U
151 #define GPIO_MODE_ANA 0x30000000U
159 #define GPIO_OTYPE_PP 0x00000000U
160 #define GPIO_OTYPE_OD 0x01000000U
168 #define GPIO_SPEED_LOW 0x00100000U
169 #define GPIO_SPEED_HIGH 0x00000000U
177 #define GPIO_PUPD_NOPULL 0x00000000U
178 #define GPIO_PUPD_UP 0x00010000U
179 #define GPIO_PUPD_DOWN 0x00020000U
187 #define GPIO_AF0 0
188 #define GPIO_AF1 1
189 #define GPIO_AF2 2
190 #define GPIO_AF3 3
191 #define GPIO_AF4 4
192 #define GPIO_AF5 5
193 #define GPIO_AF6 6
194 #define GPIO_AF7 7
195 #define GPIO_AF8 8
196 #define GPIO_AF9 9
197 #define GPIO_AF10 10
198 #define GPIO_AF11 11
199 #define GPIO_AF12 12
200 #define GPIO_AF13 13
201 #define GPIO_AF14 14
202 #define GPIO_AF15 15
203 
211 /* Exported macro ------------------------------------------------------------*/
212 /* Exported functions --------------------------------------------------------*/
213 
214 void GPIO_DeInit(GPIO_TypeDef* GPIOx);
215 void GPIO_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t PinConfig);
216 void GPIO_SetAFPin_0_7(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Alternate);
217 void GPIO_SetAFPin_8_15(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Alternate);
218 void GPIO_SetAFPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Alternate);
219 uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
220 uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
221 uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
222 uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
223 void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
224 void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
225 void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
226 void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
227 void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
228 void GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
229 uint32_t GPIO_IsPinLocked(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
230 void GPIO_SchmittTriggerCmd(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, FunctionalState NewState);
231 void GPIO_DriveCurrentConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, uint32_t Current);
232 void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
233 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif /* __MG32F10x_GPIO_H */
void GPIO_DriveCurrentConfig(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t Current)
Configure the drive current of several pins for a specified port.
Definition: mg32f10x_gpio.c:380
void GPIO_SetAFPin_8_15(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t Alternate)
Configure gpio alternate function of a dedicated pin from 8 to 15 for a dedicated port.
Definition: mg32f10x_gpio.c:119
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Reads the specified input port pin.
Definition: mg32f10x_gpio.c:150
void GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Lock configuration of several pins for a specified port.
Definition: mg32f10x_gpio.c:320
void GPIO_ToggleBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Toggle data value for several pin of specified port.
Definition: mg32f10x_gpio.c:302
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Reads the specified output data port bit.
Definition: mg32f10x_gpio.c:189
uint16_t GPIO_ReadOutputData(GPIO_TypeDef *GPIOx)
Reads the specified GPIO output data port.
Definition: mg32f10x_gpio.c:213
Definition: mg32f10x.h:203
uint32_t GPIO_IsPinLocked(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Return 1 if all pins passed as parameter, of a specified port, are locked. else Return 0.
Definition: mg32f10x_gpio.c:346
void GPIO_WriteBit(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
Sets or clears the selected data port bit.
Definition: mg32f10x_gpio.c:264
void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
Selects the GPIO pin used as EXTI Line.
Definition: mg32f10x_gpio.c:394
void GPIO_SetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Sets the selected data port bits.
Definition: mg32f10x_gpio.c:228
void GPIO_SetAFPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t Alternate)
Configure gpio alternate function of any pins for a dedicated port.
Definition: mg32f10x_gpio.c:135
void GPIO_SchmittTriggerCmd(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, FunctionalState NewState)
Enables or disables the schmitt trigger of several pins for a specified port.
Definition: mg32f10x_gpio.c:360
void GPIO_Write(GPIO_TypeDef *GPIOx, uint16_t PortVal)
Writes data to the specified GPIO data port.
Definition: mg32f10x_gpio.c:287
void GPIO_ResetBits(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Clears the selected data port bits.
Definition: mg32f10x_gpio.c:244
void GPIO_Init(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t PinConfig)
Initializes the GPIOx peripheral according to the PinConfig.
Definition: mg32f10x_gpio.c:75
uint16_t GPIO_ReadInputData(GPIO_TypeDef *GPIOx)
Reads the specified GPIO input data port.
Definition: mg32f10x_gpio.c:174
void GPIO_DeInit(GPIO_TypeDef *GPIOx)
De-initializes the GPIOx peripheral registers to their default reset values.
Definition: mg32f10x_gpio.c:38
BitAction
GPIO Bit SET and Bit RESET enumeration.
Definition: mg32f10x_gpio.h:44
void GPIO_SetAFPin_0_7(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, uint32_t Alternate)
Configure gpio alternate function of a dedicated pin from 0 to 7 for a dedicated port.
Definition: mg32f10x_gpio.c:103