M480 BSP  V3.05.001
The Board Support Package for M480 Series
gpio.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef __GPIO_H__
10 #define __GPIO_H__
11 
12 
13 #ifdef __cplusplus
14 extern "C"
15 {
16 #endif
17 
31 #define GPIO_PIN_MAX 16UL
34 /*---------------------------------------------------------------------------------------------------------*/
35 /* GPIO_MODE Constant Definitions */
36 /*---------------------------------------------------------------------------------------------------------*/
37 #define GPIO_MODE_INPUT 0x0UL
38 #define GPIO_MODE_OUTPUT 0x1UL
39 #define GPIO_MODE_OPEN_DRAIN 0x2UL
40 #define GPIO_MODE_QUASI 0x3UL
43 /*---------------------------------------------------------------------------------------------------------*/
44 /* GPIO Interrupt Type Constant Definitions */
45 /*---------------------------------------------------------------------------------------------------------*/
46 #define GPIO_INT_RISING 0x00010000UL
47 #define GPIO_INT_FALLING 0x00000001UL
48 #define GPIO_INT_BOTH_EDGE 0x00010001UL
49 #define GPIO_INT_HIGH 0x01010000UL
50 #define GPIO_INT_LOW 0x01000001UL
53 /*---------------------------------------------------------------------------------------------------------*/
54 /* GPIO_INTTYPE Constant Definitions */
55 /*---------------------------------------------------------------------------------------------------------*/
56 #define GPIO_INTTYPE_EDGE 0UL
57 #define GPIO_INTTYPE_LEVEL 1UL
59 /*---------------------------------------------------------------------------------------------------------*/
60 /* GPIO Slew Rate Type Constant Definitions */
61 /*---------------------------------------------------------------------------------------------------------*/
62 #define GPIO_SLEWCTL_NORMAL 0x0UL
63 #define GPIO_SLEWCTL_HIGH 0x1UL
64 #define GPIO_SLEWCTL_FAST 0x2UL
66 /*---------------------------------------------------------------------------------------------------------*/
67 /* GPIO Pull-up And Pull-down Type Constant Definitions */
68 /*---------------------------------------------------------------------------------------------------------*/
69 #define GPIO_PUSEL_DISABLE 0x0UL
70 #define GPIO_PUSEL_PULL_UP 0x1UL
71 #define GPIO_PUSEL_PULL_DOWN 0x2UL
74 /*---------------------------------------------------------------------------------------------------------*/
75 /* GPIO_DBCTL Constant Definitions */
76 /*---------------------------------------------------------------------------------------------------------*/
77 #define GPIO_DBCTL_ICLK_ON 0x00000020UL
78 #define GPIO_DBCTL_ICLK_OFF 0x00000000UL
80 #define GPIO_DBCTL_DBCLKSRC_LIRC 0x00000010UL
81 #define GPIO_DBCTL_DBCLKSRC_HCLK 0x00000000UL
83 #define GPIO_DBCTL_DBCLKSEL_1 0x00000000UL
84 #define GPIO_DBCTL_DBCLKSEL_2 0x00000001UL
85 #define GPIO_DBCTL_DBCLKSEL_4 0x00000002UL
86 #define GPIO_DBCTL_DBCLKSEL_8 0x00000003UL
87 #define GPIO_DBCTL_DBCLKSEL_16 0x00000004UL
88 #define GPIO_DBCTL_DBCLKSEL_32 0x00000005UL
89 #define GPIO_DBCTL_DBCLKSEL_64 0x00000006UL
90 #define GPIO_DBCTL_DBCLKSEL_128 0x00000007UL
91 #define GPIO_DBCTL_DBCLKSEL_256 0x00000008UL
92 #define GPIO_DBCTL_DBCLKSEL_512 0x00000009UL
93 #define GPIO_DBCTL_DBCLKSEL_1024 0x0000000AUL
94 #define GPIO_DBCTL_DBCLKSEL_2048 0x0000000BUL
95 #define GPIO_DBCTL_DBCLKSEL_4096 0x0000000CUL
96 #define GPIO_DBCTL_DBCLKSEL_8192 0x0000000DUL
97 #define GPIO_DBCTL_DBCLKSEL_16384 0x0000000EUL
98 #define GPIO_DBCTL_DBCLKSEL_32768 0x0000000FUL
101 /* Define GPIO Pin Data Input/Output. It could be used to control each I/O pin by pin address mapping.
102  Example 1:
103 
104  PA0 = 1;
105 
106  It is used to set GPIO PA.0 to high;
107 
108  Example 2:
109 
110  if (PA0)
111  PA0 = 0;
112 
113  If GPIO PA.0 pin status is high, then set GPIO PA.0 data output to low.
114  */
115 #define GPIO_PIN_DATA(port, pin) (*((volatile uint32_t *)((GPIO_PIN_DATA_BASE+(0x40*(port))) + ((pin)<<2))))
116 #define PA0 GPIO_PIN_DATA(0, 0 )
117 #define PA1 GPIO_PIN_DATA(0, 1 )
118 #define PA2 GPIO_PIN_DATA(0, 2 )
119 #define PA3 GPIO_PIN_DATA(0, 3 )
120 #define PA4 GPIO_PIN_DATA(0, 4 )
121 #define PA5 GPIO_PIN_DATA(0, 5 )
122 #define PA6 GPIO_PIN_DATA(0, 6 )
123 #define PA7 GPIO_PIN_DATA(0, 7 )
124 #define PA8 GPIO_PIN_DATA(0, 8 )
125 #define PA9 GPIO_PIN_DATA(0, 9 )
126 #define PA10 GPIO_PIN_DATA(0, 10)
127 #define PA11 GPIO_PIN_DATA(0, 11)
128 #define PA12 GPIO_PIN_DATA(0, 12)
129 #define PA13 GPIO_PIN_DATA(0, 13)
130 #define PA14 GPIO_PIN_DATA(0, 14)
131 #define PA15 GPIO_PIN_DATA(0, 15)
132 #define PB0 GPIO_PIN_DATA(1, 0 )
133 #define PB1 GPIO_PIN_DATA(1, 1 )
134 #define PB2 GPIO_PIN_DATA(1, 2 )
135 #define PB3 GPIO_PIN_DATA(1, 3 )
136 #define PB4 GPIO_PIN_DATA(1, 4 )
137 #define PB5 GPIO_PIN_DATA(1, 5 )
138 #define PB6 GPIO_PIN_DATA(1, 6 )
139 #define PB7 GPIO_PIN_DATA(1, 7 )
140 #define PB8 GPIO_PIN_DATA(1, 8 )
141 #define PB9 GPIO_PIN_DATA(1, 9 )
142 #define PB10 GPIO_PIN_DATA(1, 10)
143 #define PB11 GPIO_PIN_DATA(1, 11)
144 #define PB12 GPIO_PIN_DATA(1, 12)
145 #define PB13 GPIO_PIN_DATA(1, 13)
146 #define PB14 GPIO_PIN_DATA(1, 14)
147 #define PB15 GPIO_PIN_DATA(1, 15)
148 #define PC0 GPIO_PIN_DATA(2, 0 )
149 #define PC1 GPIO_PIN_DATA(2, 1 )
150 #define PC2 GPIO_PIN_DATA(2, 2 )
151 #define PC3 GPIO_PIN_DATA(2, 3 )
152 #define PC4 GPIO_PIN_DATA(2, 4 )
153 #define PC5 GPIO_PIN_DATA(2, 5 )
154 #define PC6 GPIO_PIN_DATA(2, 6 )
155 #define PC7 GPIO_PIN_DATA(2, 7 )
156 #define PC8 GPIO_PIN_DATA(2, 8 )
157 #define PC9 GPIO_PIN_DATA(2, 9 )
158 #define PC10 GPIO_PIN_DATA(2, 10)
159 #define PC11 GPIO_PIN_DATA(2, 11)
160 #define PC12 GPIO_PIN_DATA(2, 12)
161 #define PC13 GPIO_PIN_DATA(2, 13)
162 #define PC14 GPIO_PIN_DATA(2, 14)
163 #define PD0 GPIO_PIN_DATA(3, 0 )
164 #define PD1 GPIO_PIN_DATA(3, 1 )
165 #define PD2 GPIO_PIN_DATA(3, 2 )
166 #define PD3 GPIO_PIN_DATA(3, 3 )
167 #define PD4 GPIO_PIN_DATA(3, 4 )
168 #define PD5 GPIO_PIN_DATA(3, 5 )
169 #define PD6 GPIO_PIN_DATA(3, 6 )
170 #define PD7 GPIO_PIN_DATA(3, 7 )
171 #define PD8 GPIO_PIN_DATA(3, 8 )
172 #define PD9 GPIO_PIN_DATA(3, 9 )
173 #define PD10 GPIO_PIN_DATA(3, 10)
174 #define PD11 GPIO_PIN_DATA(3, 11)
175 #define PD12 GPIO_PIN_DATA(3, 12)
176 #define PD13 GPIO_PIN_DATA(3, 13)
177 #define PD14 GPIO_PIN_DATA(3, 14)
178 #define PE0 GPIO_PIN_DATA(4, 0 )
179 #define PE1 GPIO_PIN_DATA(4, 1 )
180 #define PE2 GPIO_PIN_DATA(4, 2 )
181 #define PE3 GPIO_PIN_DATA(4, 3 )
182 #define PE4 GPIO_PIN_DATA(4, 4 )
183 #define PE5 GPIO_PIN_DATA(4, 5 )
184 #define PE6 GPIO_PIN_DATA(4, 6 )
185 #define PE7 GPIO_PIN_DATA(4, 7 )
186 #define PE8 GPIO_PIN_DATA(4, 8 )
187 #define PE9 GPIO_PIN_DATA(4, 9 )
188 #define PE10 GPIO_PIN_DATA(4, 10)
189 #define PE11 GPIO_PIN_DATA(4, 11)
190 #define PE12 GPIO_PIN_DATA(4, 12)
191 #define PE13 GPIO_PIN_DATA(4, 13)
192 #define PE14 GPIO_PIN_DATA(4, 14)
193 #define PE15 GPIO_PIN_DATA(4, 15)
194 #define PF0 GPIO_PIN_DATA(5, 0 )
195 #define PF1 GPIO_PIN_DATA(5, 1 )
196 #define PF2 GPIO_PIN_DATA(5, 2 )
197 #define PF3 GPIO_PIN_DATA(5, 3 )
198 #define PF4 GPIO_PIN_DATA(5, 4 )
199 #define PF5 GPIO_PIN_DATA(5, 5 )
200 #define PF6 GPIO_PIN_DATA(5, 6 )
201 #define PF7 GPIO_PIN_DATA(5, 7 )
202 #define PF8 GPIO_PIN_DATA(5, 8 )
203 #define PF9 GPIO_PIN_DATA(5, 9 )
204 #define PF10 GPIO_PIN_DATA(5, 10)
205 #define PF11 GPIO_PIN_DATA(5, 11)
206 #define PG0 GPIO_PIN_DATA(6, 0 )
207 #define PG1 GPIO_PIN_DATA(6, 1 )
208 #define PG2 GPIO_PIN_DATA(6, 2 )
209 #define PG3 GPIO_PIN_DATA(6, 3 )
210 #define PG4 GPIO_PIN_DATA(6, 4 )
211 #define PG5 GPIO_PIN_DATA(6, 5 )
212 #define PG6 GPIO_PIN_DATA(6, 6 )
213 #define PG7 GPIO_PIN_DATA(6, 7 )
214 #define PG8 GPIO_PIN_DATA(6, 8 )
215 #define PG9 GPIO_PIN_DATA(6, 9 )
216 #define PG10 GPIO_PIN_DATA(6, 10)
217 #define PG11 GPIO_PIN_DATA(6, 11)
218 #define PG12 GPIO_PIN_DATA(6, 12)
219 #define PG13 GPIO_PIN_DATA(6, 13)
220 #define PG14 GPIO_PIN_DATA(6, 14)
221 #define PG15 GPIO_PIN_DATA(6, 15)
222 #define PH0 GPIO_PIN_DATA(7, 0 )
223 #define PH1 GPIO_PIN_DATA(7, 1 )
224 #define PH2 GPIO_PIN_DATA(7, 2 )
225 #define PH3 GPIO_PIN_DATA(7, 3 )
226 #define PH4 GPIO_PIN_DATA(7, 4 )
227 #define PH5 GPIO_PIN_DATA(7, 5 )
228 #define PH6 GPIO_PIN_DATA(7, 6 )
229 #define PH7 GPIO_PIN_DATA(7, 7 )
230 #define PH8 GPIO_PIN_DATA(7, 8 )
231 #define PH9 GPIO_PIN_DATA(7, 9 )
232 #define PH10 GPIO_PIN_DATA(7, 10)
233 #define PH11 GPIO_PIN_DATA(7, 11)
236  /* end of group GPIO_EXPORTED_CONSTANTS */
237 
238 
257 #define GPIO_CLR_INT_FLAG(port, u32PinMask) ((port)->INTSRC = (u32PinMask))
258 
273 #define GPIO_DISABLE_DEBOUNCE(port, u32PinMask) ((port)->DBEN &= ~(u32PinMask))
274 
288 #define GPIO_ENABLE_DEBOUNCE(port, u32PinMask) ((port)->DBEN |= (u32PinMask))
289 
304 #define GPIO_DISABLE_DIGITAL_PATH(port, u32PinMask) ((port)->DINOFF |= ((u32PinMask)<<16))
305 
320 #define GPIO_ENABLE_DIGITAL_PATH(port, u32PinMask) ((port)->DINOFF &= ~((u32PinMask)<<16))
321 
336 #define GPIO_DISABLE_DOUT_MASK(port, u32PinMask) ((port)->DATMSK &= ~(u32PinMask))
337 
352 #define GPIO_ENABLE_DOUT_MASK(port, u32PinMask) ((port)->DATMSK |= (u32PinMask))
353 
369 #define GPIO_GET_INT_FLAG(port, u32PinMask) ((port)->INTSRC & (u32PinMask))
370 
402 #define GPIO_SET_DEBOUNCE_TIME(u32ClkSrc, u32ClkSel) (GPIO->DBCTL = (GPIO_DBCTL_ICLKON_Msk | (u32ClkSrc) | (u32ClkSel)))
403 
414 #define GPIO_GET_IN_DATA(port) ((port)->PIN)
415 
427 #define GPIO_SET_OUT_DATA(port, u32Data) ((port)->DOUT = (u32Data))
428 
439 #define GPIO_TOGGLE(u32Pin) ((u32Pin) ^= 1)
440 
441 
458 #define GPIO_EnableEINT GPIO_EnableInt
459 
474 #define GPIO_DisableEINT GPIO_DisableInt
475 
476 
477 void GPIO_SetMode(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode);
478 void GPIO_EnableInt(GPIO_T *port, uint32_t u32Pin, uint32_t u32IntAttribs);
479 void GPIO_DisableInt(GPIO_T *port, uint32_t u32Pin);
480 void GPIO_SetSlewCtl(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode);
481 void GPIO_SetPullCtl(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode);
482 
483  /* end of group GPIO_EXPORTED_FUNCTIONS */
485  /* end of group GPIO_Driver */
487  /* end of group Standard_Driver */
489 
490 
491 #ifdef __cplusplus
492 }
493 #endif
494 
495 #endif /* __GPIO_H__ */
496 
497 /*** (C) COPYRIGHT 2013~2016 Nuvoton Technology Corp. ***/
void GPIO_SetPullCtl(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode)
Set GPIO Pull-up and Pull-down control.
Definition: gpio.c:133
void GPIO_EnableInt(GPIO_T *port, uint32_t u32Pin, uint32_t u32IntAttribs)
Enable GPIO interrupt.
Definition: gpio.c:67
void GPIO_SetSlewCtl(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode)
Set GPIO slew rate control.
Definition: gpio.c:106
void GPIO_DisableInt(GPIO_T *port, uint32_t u32Pin)
Disable GPIO interrupt.
Definition: gpio.c:87
void GPIO_SetMode(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode)
Set GPIO operation mode.
Definition: gpio.c:39