• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2     \file  gd32vf103_gpio.h
3     \brief definitions for the GPIO
4 
5     \version 2019-06-5, V1.0.0, firmware for GD32VF103
6 */
7 
8 /*
9     Copyright (c) 2019, GigaDevice Semiconductor Inc.
10 
11     Redistribution and use in source and binary forms, with or without modification,
12 are permitted provided that the following conditions are met:
13 
14     1. Redistributions of source code must retain the above copyright notice, this
15        list of conditions and the following disclaimer.
16     2. Redistributions in binary form must reproduce the above copyright notice,
17        this list of conditions and the following disclaimer in the documentation
18        and/or other materials provided with the distribution.
19     3. Neither the name of the copyright holder nor the names of its contributors
20        may be used to endorse or promote products derived from this software without
21        specific prior written permission.
22 
23     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 OF SUCH DAMAGE.
33 */
34 
35 #ifndef GD32VF103_GPIO_H
36 #define GD32VF103_GPIO_H
37 
38 #include "gd32vf103.h"
39 #include "gd32vf103_rcu.h"
40 #include "gd32vf103_dbg.h"
41 
42 /* GPIOx(x=A,B,C,D,E) definitions */
43 #define GPIOA                      (GPIO_BASE + 0x00000000U)
44 #define GPIOB                      (GPIO_BASE + 0x00000400U)
45 #define GPIOC                      (GPIO_BASE + 0x00000800U)
46 #define GPIOD                      (GPIO_BASE + 0x00000C00U)
47 #define GPIOE                      (GPIO_BASE + 0x00001000U)
48 
49 /* AFIO definitions */
50 #define AFIO                       AFIO_BASE
51 
52 /* registers definitions */
53 
54 /* GPIO registers definitions */
55 #define GPIO_CTL0(gpiox)           REG32((gpiox) + 0x00U)    /*!< GPIO port control register 0 */
56 #define GPIO_CTL1(gpiox)           REG32((gpiox) + 0x04U)    /*!< GPIO port control register 1 */
57 #define GPIO_ISTAT(gpiox)          REG32((gpiox) + 0x08U)    /*!< GPIO port input status register */
58 #define GPIO_OCTL(gpiox)           REG32((gpiox) + 0x0CU)    /*!< GPIO port output control register */
59 #define GPIO_BOP(gpiox)            REG32((gpiox) + 0x10U)    /*!< GPIO port bit operation register */
60 #define GPIO_BC(gpiox)             REG32((gpiox) + 0x14U)    /*!< GPIO bit clear register */
61 #define GPIO_LOCK(gpiox)           REG32((gpiox) + 0x18U)    /*!< GPIO port configuration lock register */
62 
63 /* AFIO registers definitions */
64 #define AFIO_EC                    REG32(AFIO + 0x00U)       /*!< AFIO event control register */
65 #define AFIO_PCF0                  REG32(AFIO + 0x04U)       /*!< AFIO port configuration register 0 */
66 #define AFIO_EXTISS0               REG32(AFIO + 0x08U)       /*!< AFIO port EXTI sources selection register 0 */
67 #define AFIO_EXTISS1               REG32(AFIO + 0x0CU)       /*!< AFIO port EXTI sources selection register 1 */
68 #define AFIO_EXTISS2               REG32(AFIO + 0x10U)       /*!< AFIO port EXTI sources selection register 2 */
69 #define AFIO_EXTISS3               REG32(AFIO + 0x14U)       /*!< AFIO port EXTI sources selection register 3 */
70 #define AFIO_PCF1                  REG32(AFIO + 0x1CU)       /*!< AFIO port configuration register 1 */
71 
72 /* bits definitions */
73 /* GPIO_CTL0 */
74 #define GPIO_CTL0_MD0              BITS(0, 1)                /*!< port 0 mode bits */
75 #define GPIO_CTL0_CTL0             BITS(2, 3)                /*!< pin 0 configuration bits */
76 #define GPIO_CTL0_MD1              BITS(4, 5)                /*!< port 1 mode bits */
77 #define GPIO_CTL0_CTL1             BITS(6, 7)                /*!< pin 1 configuration bits */
78 #define GPIO_CTL0_MD2              BITS(8, 9)                /*!< port 2 mode bits */
79 #define GPIO_CTL0_CTL2             BITS(10, 11)              /*!< pin 2 configuration bits */
80 #define GPIO_CTL0_MD3              BITS(12, 13)              /*!< port 3 mode bits */
81 #define GPIO_CTL0_CTL3             BITS(14, 15)              /*!< pin 3 configuration bits */
82 #define GPIO_CTL0_MD4              BITS(16, 17)              /*!< port 4 mode bits */
83 #define GPIO_CTL0_CTL4             BITS(18, 19)              /*!< pin 4 configuration bits */
84 #define GPIO_CTL0_MD5              BITS(20, 21)              /*!< port 5 mode bits */
85 #define GPIO_CTL0_CTL5             BITS(22, 23)              /*!< pin 5 configuration bits */
86 #define GPIO_CTL0_MD6              BITS(24, 25)              /*!< port 6 mode bits */
87 #define GPIO_CTL0_CTL6             BITS(26, 27)              /*!< pin 6 configuration bits */
88 #define GPIO_CTL0_MD7              BITS(28, 29)              /*!< port 7 mode bits */
89 #define GPIO_CTL0_CTL7             BITS(30, 31)              /*!< pin 7 configuration bits */
90 
91 /* GPIO_CTL1 */
92 #define GPIO_CTL1_MD8              BITS(0, 1)                /*!< port 8 mode bits */
93 #define GPIO_CTL1_CTL8             BITS(2, 3)                /*!< pin 8 configuration bits */
94 #define GPIO_CTL1_MD9              BITS(4, 5)                /*!< port 9 mode bits */
95 #define GPIO_CTL1_CTL9             BITS(6, 7)                /*!< pin 9 configuration bits */
96 #define GPIO_CTL1_MD10             BITS(8, 9)                /*!< port 10 mode bits */
97 #define GPIO_CTL1_CTL10            BITS(10, 11)              /*!< pin 10 configuration bits */
98 #define GPIO_CTL1_MD11             BITS(12, 13)              /*!< port 11 mode bits */
99 #define GPIO_CTL1_CTL11            BITS(14, 15)              /*!< pin 11 configuration bits */
100 #define GPIO_CTL1_MD12             BITS(16, 17)              /*!< port 12 mode bits */
101 #define GPIO_CTL1_CTL12            BITS(18, 19)              /*!< pin 12 configuration bits */
102 #define GPIO_CTL1_MD13             BITS(20, 21)              /*!< port 13 mode bits */
103 #define GPIO_CTL1_CTL13            BITS(22, 23)              /*!< pin 13 configuration bits */
104 #define GPIO_CTL1_MD14             BITS(24, 25)              /*!< port 14 mode bits */
105 #define GPIO_CTL1_CTL14            BITS(26, 27)              /*!< pin 14 configuration bits */
106 #define GPIO_CTL1_MD15             BITS(28, 29)              /*!< port 15 mode bits */
107 #define GPIO_CTL1_CTL15            BITS(30, 31)              /*!< pin 15 configuration bits */
108 
109 /* GPIO_ISTAT */
110 #define GPIO_ISTAT_ISTAT0          BIT(0)                    /*!< pin 0 input status */
111 #define GPIO_ISTAT_ISTAT1          BIT(1)                    /*!< pin 1 input status */
112 #define GPIO_ISTAT_ISTAT2          BIT(2)                    /*!< pin 2 input status */
113 #define GPIO_ISTAT_ISTAT3          BIT(3)                    /*!< pin 3 input status */
114 #define GPIO_ISTAT_ISTAT4          BIT(4)                    /*!< pin 4 input status */
115 #define GPIO_ISTAT_ISTAT5          BIT(5)                    /*!< pin 5 input status */
116 #define GPIO_ISTAT_ISTAT6          BIT(6)                    /*!< pin 6 input status */
117 #define GPIO_ISTAT_ISTAT7          BIT(7)                    /*!< pin 7 input status */
118 #define GPIO_ISTAT_ISTAT8          BIT(8)                    /*!< pin 8 input status */
119 #define GPIO_ISTAT_ISTAT9          BIT(9)                    /*!< pin 9 input status */
120 #define GPIO_ISTAT_ISTAT10         BIT(10)                   /*!< pin 10 input status */
121 #define GPIO_ISTAT_ISTAT11         BIT(11)                   /*!< pin 11 input status */
122 #define GPIO_ISTAT_ISTAT12         BIT(12)                   /*!< pin 12 input status */
123 #define GPIO_ISTAT_ISTAT13         BIT(13)                   /*!< pin 13 input status */
124 #define GPIO_ISTAT_ISTAT14         BIT(14)                   /*!< pin 14 input status */
125 #define GPIO_ISTAT_ISTAT15         BIT(15)                   /*!< pin 15 input status */
126 
127 /* GPIO_OCTL */
128 #define GPIO_OCTL_OCTL0            BIT(0)                    /*!< pin 0 output bit */
129 #define GPIO_OCTL_OCTL1            BIT(1)                    /*!< pin 1 output bit */
130 #define GPIO_OCTL_OCTL2            BIT(2)                    /*!< pin 2 output bit */
131 #define GPIO_OCTL_OCTL3            BIT(3)                    /*!< pin 3 output bit */
132 #define GPIO_OCTL_OCTL4            BIT(4)                    /*!< pin 4 output bit */
133 #define GPIO_OCTL_OCTL5            BIT(5)                    /*!< pin 5 output bit */
134 #define GPIO_OCTL_OCTL6            BIT(6)                    /*!< pin 6 output bit */
135 #define GPIO_OCTL_OCTL7            BIT(7)                    /*!< pin 7 output bit */
136 #define GPIO_OCTL_OCTL8            BIT(8)                    /*!< pin 8 output bit */
137 #define GPIO_OCTL_OCTL9            BIT(9)                    /*!< pin 9 output bit */
138 #define GPIO_OCTL_OCTL10           BIT(10)                   /*!< pin 10 output bit */
139 #define GPIO_OCTL_OCTL11           BIT(11)                   /*!< pin 11 output bit */
140 #define GPIO_OCTL_OCTL12           BIT(12)                   /*!< pin 12 output bit */
141 #define GPIO_OCTL_OCTL13           BIT(13)                   /*!< pin 13 output bit */
142 #define GPIO_OCTL_OCTL14           BIT(14)                   /*!< pin 14 output bit */
143 #define GPIO_OCTL_OCTL15           BIT(15)                   /*!< pin 15 output bit */
144 
145 /* GPIO_BOP */
146 #define GPIO_BOP_BOP0              BIT(0)                    /*!< pin 0 set bit */
147 #define GPIO_BOP_BOP1              BIT(1)                    /*!< pin 1 set bit */
148 #define GPIO_BOP_BOP2              BIT(2)                    /*!< pin 2 set bit */
149 #define GPIO_BOP_BOP3              BIT(3)                    /*!< pin 3 set bit */
150 #define GPIO_BOP_BOP4              BIT(4)                    /*!< pin 4 set bit */
151 #define GPIO_BOP_BOP5              BIT(5)                    /*!< pin 5 set bit */
152 #define GPIO_BOP_BOP6              BIT(6)                    /*!< pin 6 set bit */
153 #define GPIO_BOP_BOP7              BIT(7)                    /*!< pin 7 set bit */
154 #define GPIO_BOP_BOP8              BIT(8)                    /*!< pin 8 set bit */
155 #define GPIO_BOP_BOP9              BIT(9)                    /*!< pin 9 set bit */
156 #define GPIO_BOP_BOP10             BIT(10)                   /*!< pin 10 set bit */
157 #define GPIO_BOP_BOP11             BIT(11)                   /*!< pin 11 set bit */
158 #define GPIO_BOP_BOP12             BIT(12)                   /*!< pin 12 set bit */
159 #define GPIO_BOP_BOP13             BIT(13)                   /*!< pin 13 set bit */
160 #define GPIO_BOP_BOP14             BIT(14)                   /*!< pin 14 set bit */
161 #define GPIO_BOP_BOP15             BIT(15)                   /*!< pin 15 set bit */
162 #define GPIO_BOP_CR0               BIT(16)                   /*!< pin 0 clear bit */
163 #define GPIO_BOP_CR1               BIT(17)                   /*!< pin 1 clear bit */
164 #define GPIO_BOP_CR2               BIT(18)                   /*!< pin 2 clear bit */
165 #define GPIO_BOP_CR3               BIT(19)                   /*!< pin 3 clear bit */
166 #define GPIO_BOP_CR4               BIT(20)                   /*!< pin 4 clear bit */
167 #define GPIO_BOP_CR5               BIT(21)                   /*!< pin 5 clear bit */
168 #define GPIO_BOP_CR6               BIT(22)                   /*!< pin 6 clear bit */
169 #define GPIO_BOP_CR7               BIT(23)                   /*!< pin 7 clear bit */
170 #define GPIO_BOP_CR8               BIT(24)                   /*!< pin 8 clear bit */
171 #define GPIO_BOP_CR9               BIT(25)                   /*!< pin 9 clear bit */
172 #define GPIO_BOP_CR10              BIT(26)                   /*!< pin 10 clear bit */
173 #define GPIO_BOP_CR11              BIT(27)                   /*!< pin 11 clear bit */
174 #define GPIO_BOP_CR12              BIT(28)                   /*!< pin 12 clear bit */
175 #define GPIO_BOP_CR13              BIT(29)                   /*!< pin 13 clear bit */
176 #define GPIO_BOP_CR14              BIT(30)                   /*!< pin 14 clear bit */
177 #define GPIO_BOP_CR15              BIT(31)                   /*!< pin 15 clear bit */
178 
179 /* GPIO_BC */
180 #define GPIO_BC_CR0                BIT(0)                    /*!< pin 0 clear bit */
181 #define GPIO_BC_CR1                BIT(1)                    /*!< pin 1 clear bit */
182 #define GPIO_BC_CR2                BIT(2)                    /*!< pin 2 clear bit */
183 #define GPIO_BC_CR3                BIT(3)                    /*!< pin 3 clear bit */
184 #define GPIO_BC_CR4                BIT(4)                    /*!< pin 4 clear bit */
185 #define GPIO_BC_CR5                BIT(5)                    /*!< pin 5 clear bit */
186 #define GPIO_BC_CR6                BIT(6)                    /*!< pin 6 clear bit */
187 #define GPIO_BC_CR7                BIT(7)                    /*!< pin 7 clear bit */
188 #define GPIO_BC_CR8                BIT(8)                    /*!< pin 8 clear bit */
189 #define GPIO_BC_CR9                BIT(9)                    /*!< pin 9 clear bit */
190 #define GPIO_BC_CR10               BIT(10)                   /*!< pin 10 clear bit */
191 #define GPIO_BC_CR11               BIT(11)                   /*!< pin 11 clear bit */
192 #define GPIO_BC_CR12               BIT(12)                   /*!< pin 12 clear bit */
193 #define GPIO_BC_CR13               BIT(13)                   /*!< pin 13 clear bit */
194 #define GPIO_BC_CR14               BIT(14)                   /*!< pin 14 clear bit */
195 #define GPIO_BC_CR15               BIT(15)                   /*!< pin 15 clear bit */
196 
197 /* GPIO_LOCK */
198 #define GPIO_LOCK_LK0              BIT(0)                    /*!< pin 0 lock bit */
199 #define GPIO_LOCK_LK1              BIT(1)                    /*!< pin 1 lock bit */
200 #define GPIO_LOCK_LK2              BIT(2)                    /*!< pin 2 lock bit */
201 #define GPIO_LOCK_LK3              BIT(3)                    /*!< pin 3 lock bit */
202 #define GPIO_LOCK_LK4              BIT(4)                    /*!< pin 4 lock bit */
203 #define GPIO_LOCK_LK5              BIT(5)                    /*!< pin 5 lock bit */
204 #define GPIO_LOCK_LK6              BIT(6)                    /*!< pin 6 lock bit */
205 #define GPIO_LOCK_LK7              BIT(7)                    /*!< pin 7 lock bit */
206 #define GPIO_LOCK_LK8              BIT(8)                    /*!< pin 8 lock bit */
207 #define GPIO_LOCK_LK9              BIT(9)                    /*!< pin 9 lock bit */
208 #define GPIO_LOCK_LK10             BIT(10)                   /*!< pin 10 lock bit */
209 #define GPIO_LOCK_LK11             BIT(11)                   /*!< pin 11 lock bit */
210 #define GPIO_LOCK_LK12             BIT(12)                   /*!< pin 12 lock bit */
211 #define GPIO_LOCK_LK13             BIT(13)                   /*!< pin 13 lock bit */
212 #define GPIO_LOCK_LK14             BIT(14)                   /*!< pin 14 lock bit */
213 #define GPIO_LOCK_LK15             BIT(15)                   /*!< pin 15 lock bit */
214 #define GPIO_LOCK_LKK              BIT(16)                   /*!< pin sequence lock key */
215 
216 /* AFIO_EC */
217 #define AFIO_EC_PIN                BITS(0, 3)                /*!< event output pin selection */
218 #define AFIO_EC_PORT               BITS(4, 6)                /*!< event output port selection */
219 #define AFIO_EC_EOE                BIT(7)                    /*!< event output enable */
220 
221 /* AFIO_PCF0 */
222 #define AFIO_PCF0_SPI0_REMAP             BIT(0)              /*!< SPI0 remapping */
223 #define AFIO_PCF0_I2C0_REMAP             BIT(1)              /*!< I2C0 remapping */
224 #define AFIO_PCF0_USART0_REMAP           BIT(2)              /*!< USART0 remapping */
225 #define AFIO_PCF0_USART1_REMAP           BIT(3)              /*!< USART1 remapping */
226 #define AFIO_PCF0_USART2_REMAP           BITS(4, 5)          /*!< USART2 remapping */
227 #define AFIO_PCF0_TIMER0_REMAP           BITS(6, 7)          /*!< TIMER0 remapping */
228 #define AFIO_PCF0_TIMER1_REMAP           BITS(8, 9)          /*!< TIMER1 remapping */
229 #define AFIO_PCF0_TIMER2_REMAP           BITS(10, 11)        /*!< TIMER2 remapping */
230 #define AFIO_PCF0_TIMER3_REMAP           BIT(12)             /*!< TIMER3 remapping */
231 #define AFIO_PCF0_CAN_REMAP              BITS(13, 14)        /*!< CAN remapping */
232 #define AFIO_PCF0_PD01_REMAP             BIT(15)             /*!< port D0/port D1 mapping on OSC_IN/OSC_OUT */
233 #define AFIO_PCF0_TIMER4CH3_IREMAP       BIT(16)             /*!< TIMER3 channel3 internal remapping */
234 #define AFIO_PCF0_SWJ_CFG                BITS(24, 26)        /*!< serial wire JTAG configuration */
235 #define AFIO_PCF0_SPI2_REMAP             BIT(28)             /*!< SPI2/I2S2 remapping */
236 #define AFIO_PCF0_TIMER1_ITI1_REMAP      BIT(29)             /*!< TIMER1 internal trigger 1 remapping */
237 
238 /* AFIO_EXTISS0 */
239 #define AFIO_EXTI0_SS                    BITS(0, 3)          /*!< EXTI 0 sources selection */
240 #define AFIO_EXTI1_SS                    BITS(4, 7)          /*!< EXTI 1 sources selection */
241 #define AFIO_EXTI2_SS                    BITS(8, 11)         /*!< EXTI 2 sources selection */
242 #define AFIO_EXTI3_SS                    BITS(12, 15)        /*!< EXTI 3 sources selection */
243 
244 /* AFIO_EXTISS1 */
245 #define AFIO_EXTI4_SS                    BITS(0, 3)          /*!< EXTI 4 sources selection */
246 #define AFIO_EXTI5_SS                    BITS(4, 7)          /*!< EXTI 5 sources selection */
247 #define AFIO_EXTI6_SS                    BITS(8, 11)         /*!< EXTI 6 sources selection */
248 #define AFIO_EXTI7_SS                    BITS(12, 15)        /*!< EXTI 7 sources selection */
249 
250 /* AFIO_EXTISS2 */
251 #define AFIO_EXTI8_SS                    BITS(0, 3)          /*!< EXTI 8 sources selection */
252 #define AFIO_EXTI9_SS                    BITS(4, 7)          /*!< EXTI 9 sources selection */
253 #define AFIO_EXTI10_SS                   BITS(8, 11)         /*!< EXTI 10 sources selection */
254 #define AFIO_EXTI11_SS                   BITS(12, 15)        /*!< EXTI 11 sources selection */
255 
256 /* AFIO_EXTISS3 */
257 #define AFIO_EXTI12_SS                   BITS(0, 3)          /*!< EXTI 12 sources selection */
258 #define AFIO_EXTI13_SS                   BITS(4, 7)          /*!< EXTI 13 sources selection */
259 #define AFIO_EXTI14_SS                   BITS(8, 11)         /*!< EXTI 14 sources selection */
260 #define AFIO_EXTI15_SS                   BITS(12, 15)        /*!< EXTI 15 sources selection */
261 
262 /* AFIO_PCF1 */
263 #define AFIO_PCF1_EXMC_NADV              BIT(10)             /*!< EXMC_NADV connect/disconnect */
264 
265 /* constants definitions */
266 typedef FlagStatus bit_status;
267 
268 /* GPIO mode values set */
269 #define GPIO_MODE_SET(n, mode)           ((uint32_t)((uint32_t)(mode) << (4U * (n))))
270 #define GPIO_MODE_MASK(n)                (0xFU << (4U * (n)))
271 
272 /* GPIO mode definitions */
273 #define GPIO_MODE_AIN                    ((uint8_t)0x00U)          /*!< analog input mode */
274 #define GPIO_MODE_IN_FLOATING            ((uint8_t)0x04U)          /*!< floating input mode */
275 #define GPIO_MODE_IPD                    ((uint8_t)0x28U)          /*!< pull-down input mode */
276 #define GPIO_MODE_IPU                    ((uint8_t)0x48U)          /*!< pull-up input mode */
277 #define GPIO_MODE_OUT_OD                 ((uint8_t)0x14U)          /*!< GPIO output with open-drain */
278 #define GPIO_MODE_OUT_PP                 ((uint8_t)0x10U)          /*!< GPIO output with push-pull */
279 #define GPIO_MODE_AF_OD                  ((uint8_t)0x1CU)          /*!< AFIO output with open-drain */
280 #define GPIO_MODE_AF_PP                  ((uint8_t)0x18U)          /*!< AFIO output with push-pull */
281 
282 /* GPIO output max speed value */
283 #define GPIO_OSPEED_10MHZ                ((uint8_t)0x01U)          /*!< output max speed 10MHz */
284 #define GPIO_OSPEED_2MHZ                 ((uint8_t)0x02U)          /*!< output max speed 2MHz */
285 #define GPIO_OSPEED_50MHZ                ((uint8_t)0x03U)          /*!< output max speed 50MHz */
286 
287 /* GPIO event output port definitions */
288 #define GPIO_EVENT_PORT_GPIOA            ((uint8_t)0x00U)          /*!< event output port A */
289 #define GPIO_EVENT_PORT_GPIOB            ((uint8_t)0x01U)          /*!< event output port B */
290 #define GPIO_EVENT_PORT_GPIOC            ((uint8_t)0x02U)          /*!< event output port C */
291 #define GPIO_EVENT_PORT_GPIOD            ((uint8_t)0x03U)          /*!< event output port D */
292 #define GPIO_EVENT_PORT_GPIOE            ((uint8_t)0x04U)          /*!< event output port E */
293 
294 /* GPIO output port source definitions */
295 #define GPIO_PORT_SOURCE_GPIOA           ((uint8_t)0x00U)          /*!< output port source A */
296 #define GPIO_PORT_SOURCE_GPIOB           ((uint8_t)0x01U)          /*!< output port source B */
297 #define GPIO_PORT_SOURCE_GPIOC           ((uint8_t)0x02U)          /*!< output port source C */
298 #define GPIO_PORT_SOURCE_GPIOD           ((uint8_t)0x03U)          /*!< output port source D */
299 #define GPIO_PORT_SOURCE_GPIOE           ((uint8_t)0x04U)          /*!< output port source E */
300 
301 /* GPIO event output pin definitions */
302 #define GPIO_EVENT_PIN_0                 ((uint8_t)0x00U)          /*!< GPIO event pin 0 */
303 #define GPIO_EVENT_PIN_1                 ((uint8_t)0x01U)          /*!< GPIO event pin 1 */
304 #define GPIO_EVENT_PIN_2                 ((uint8_t)0x02U)          /*!< GPIO event pin 2 */
305 #define GPIO_EVENT_PIN_3                 ((uint8_t)0x03U)          /*!< GPIO event pin 3 */
306 #define GPIO_EVENT_PIN_4                 ((uint8_t)0x04U)          /*!< GPIO event pin 4 */
307 #define GPIO_EVENT_PIN_5                 ((uint8_t)0x05U)          /*!< GPIO event pin 5 */
308 #define GPIO_EVENT_PIN_6                 ((uint8_t)0x06U)          /*!< GPIO event pin 6 */
309 #define GPIO_EVENT_PIN_7                 ((uint8_t)0x07U)          /*!< GPIO event pin 7 */
310 #define GPIO_EVENT_PIN_8                 ((uint8_t)0x08U)          /*!< GPIO event pin 8 */
311 #define GPIO_EVENT_PIN_9                 ((uint8_t)0x09U)          /*!< GPIO event pin 9 */
312 #define GPIO_EVENT_PIN_10                ((uint8_t)0x0AU)          /*!< GPIO event pin 10 */
313 #define GPIO_EVENT_PIN_11                ((uint8_t)0x0BU)          /*!< GPIO event pin 11 */
314 #define GPIO_EVENT_PIN_12                ((uint8_t)0x0CU)          /*!< GPIO event pin 12 */
315 #define GPIO_EVENT_PIN_13                ((uint8_t)0x0DU)          /*!< GPIO event pin 13 */
316 #define GPIO_EVENT_PIN_14                ((uint8_t)0x0EU)          /*!< GPIO event pin 14 */
317 #define GPIO_EVENT_PIN_15                ((uint8_t)0x0FU)          /*!< GPIO event pin 15 */
318 
319 /* GPIO output pin source definitions */
320 #define GPIO_PIN_SOURCE_0                ((uint8_t)0x00U)          /*!< GPIO pin source 0 */
321 #define GPIO_PIN_SOURCE_1                ((uint8_t)0x01U)          /*!< GPIO pin source 1 */
322 #define GPIO_PIN_SOURCE_2                ((uint8_t)0x02U)          /*!< GPIO pin source 2 */
323 #define GPIO_PIN_SOURCE_3                ((uint8_t)0x03U)          /*!< GPIO pin source 3 */
324 #define GPIO_PIN_SOURCE_4                ((uint8_t)0x04U)          /*!< GPIO pin source 4 */
325 #define GPIO_PIN_SOURCE_5                ((uint8_t)0x05U)          /*!< GPIO pin source 5 */
326 #define GPIO_PIN_SOURCE_6                ((uint8_t)0x06U)          /*!< GPIO pin source 6 */
327 #define GPIO_PIN_SOURCE_7                ((uint8_t)0x07U)          /*!< GPIO pin source 7 */
328 #define GPIO_PIN_SOURCE_8                ((uint8_t)0x08U)          /*!< GPIO pin source 8 */
329 #define GPIO_PIN_SOURCE_9                ((uint8_t)0x09U)          /*!< GPIO pin source 9 */
330 #define GPIO_PIN_SOURCE_10               ((uint8_t)0x0AU)          /*!< GPIO pin source 10 */
331 #define GPIO_PIN_SOURCE_11               ((uint8_t)0x0BU)          /*!< GPIO pin source 11 */
332 #define GPIO_PIN_SOURCE_12               ((uint8_t)0x0CU)          /*!< GPIO pin source 12 */
333 #define GPIO_PIN_SOURCE_13               ((uint8_t)0x0DU)          /*!< GPIO pin source 13 */
334 #define GPIO_PIN_SOURCE_14               ((uint8_t)0x0EU)          /*!< GPIO pin source 14 */
335 #define GPIO_PIN_SOURCE_15               ((uint8_t)0x0FU)          /*!< GPIO pin source 15 */
336 
337 /* GPIO pin definitions */
338 #define GPIO_PIN_0                       BIT(0)                    /*!< GPIO pin 0 */
339 #define GPIO_PIN_1                       BIT(1)                    /*!< GPIO pin 1 */
340 #define GPIO_PIN_2                       BIT(2)                    /*!< GPIO pin 2 */
341 #define GPIO_PIN_3                       BIT(3)                    /*!< GPIO pin 3 */
342 #define GPIO_PIN_4                       BIT(4)                    /*!< GPIO pin 4 */
343 #define GPIO_PIN_5                       BIT(5)                    /*!< GPIO pin 5 */
344 #define GPIO_PIN_6                       BIT(6)                    /*!< GPIO pin 6 */
345 #define GPIO_PIN_7                       BIT(7)                    /*!< GPIO pin 7 */
346 #define GPIO_PIN_8                       BIT(8)                    /*!< GPIO pin 8 */
347 #define GPIO_PIN_9                       BIT(9)                    /*!< GPIO pin 9 */
348 #define GPIO_PIN_10                      BIT(10)                   /*!< GPIO pin 10 */
349 #define GPIO_PIN_11                      BIT(11)                   /*!< GPIO pin 11 */
350 #define GPIO_PIN_12                      BIT(12)                   /*!< GPIO pin 12 */
351 #define GPIO_PIN_13                      BIT(13)                   /*!< GPIO pin 13 */
352 #define GPIO_PIN_14                      BIT(14)                   /*!< GPIO pin 14 */
353 #define GPIO_PIN_15                      BIT(15)                   /*!< GPIO pin 15 */
354 #define GPIO_PIN_ALL                     BITS(0, 15)               /*!< GPIO pin all */
355 
356 /* GPIO remap definitions */
357 #define GPIO_SPI0_REMAP                  ((uint32_t)0x00000001U)   /*!< SPI0 remapping */
358 #define GPIO_I2C0_REMAP                  ((uint32_t)0x00000002U)   /*!< I2C0 remapping */
359 #define GPIO_USART0_REMAP                ((uint32_t)0x00000004U)   /*!< USART0 remapping */
360 #define GPIO_USART1_REMAP                ((uint32_t)0x00000008U)   /*!< USART1 remapping */
361 #define GPIO_USART2_PARTIAL_REMAP        ((uint32_t)0x00140010U)   /*!< USART2 partial remapping */
362 #define GPIO_USART2_FULL_REMAP           ((uint32_t)0x00140030U)   /*!< USART2 full remapping */
363 #define GPIO_TIMER0_PARTIAL_REMAP        ((uint32_t)0x00160040U)   /*!< TIMER0 partial remapping */
364 #define GPIO_TIMER0_FULL_REMAP           ((uint32_t)0x001600C0U)   /*!< TIMER0 full remapping */
365 #define GPIO_TIMER1_PARTIAL_REMAP0       ((uint32_t)0x00180100U)   /*!< TIMER1 partial remapping */
366 #define GPIO_TIMER1_PARTIAL_REMAP1       ((uint32_t)0x00180200U)   /*!< TIMER1 partial remapping */
367 #define GPIO_TIMER1_FULL_REMAP           ((uint32_t)0x00180300U)   /*!< TIMER1 full remapping */
368 #define GPIO_TIMER2_PARTIAL_REMAP        ((uint32_t)0x001A0800U)   /*!< TIMER2 partial remapping */
369 #define GPIO_TIMER2_FULL_REMAP           ((uint32_t)0x001A0C00U)   /*!< TIMER2 full remapping */
370 #define GPIO_TIMER3_REMAP                ((uint32_t)0x00001000U)   /*!< TIMER3 remapping */
371 #define GPIO_CAN0_PARTIAL_REMAP          ((uint32_t)0x001D4000U)   /*!< CAN0 partial remapping */
372 #define GPIO_CAN0_FULL_REMAP             ((uint32_t)0x001D6000U)   /*!< CAN0 full remapping */
373 #define GPIO_PD01_REMAP                  ((uint32_t)0x00008000U)   /*!< PD01 remapping */
374 #define GPIO_TIMER4CH3_IREMAP            ((uint32_t)0x00200001U)   /*!< TIMER4 channel3 internal remapping */
375 #define GPIO_CAN1_REMAP                  ((uint32_t)0x00200040U)   /*!< CAN1 remapping */
376 #define GPIO_SWJ_NONJTRST_REMAP          ((uint32_t)0x00300100U)   /*!< JTAG-DP,but without NJTRST */
377 #define GPIO_SWJ_DISABLE_REMAP           ((uint32_t)0x00300200U)   /*!< JTAG-DP disabled */
378 #define GPIO_SPI2_REMAP                  ((uint32_t)0x00201100U)   /*!< SPI2 remapping */
379 #define GPIO_TIMER1ITI1_REMAP            ((uint32_t)0x00202000U)   /*!< TIMER1 internal trigger 1 remapping */
380 #define GPIO_EXMC_NADV_REMAP             ((uint32_t)0x80000400U)   /*!< EXMC_NADV connect/disconnect */
381 
382 /* function declarations */
383 /* reset GPIO port */
384 void gpio_deinit(uint32_t gpio_periph);
385 /* reset alternate function I/O(AFIO) */
386 void gpio_afio_deinit(void);
387 /* GPIO parameter initialization */
388 void gpio_init(uint32_t gpio_periph,uint32_t mode,uint32_t speed,uint32_t pin);
389 
390 /* set GPIO pin bit */
391 void gpio_bit_set(uint32_t gpio_periph, uint32_t pin);
392 /* reset GPIO pin bit */
393 void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin);
394 /* write data to the specified GPIO pin */
395 void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value);
396 /* write data to the specified GPIO port */
397 void gpio_port_write(uint32_t gpio_periph, uint16_t data);
398 
399 /* get GPIO pin input status */
400 FlagStatus gpio_input_bit_get(uint32_t gpio_periph, uint32_t pin);
401 /* get GPIO port input status */
402 uint16_t gpio_input_port_get(uint32_t gpio_periph);
403 /* get GPIO pin output status */
404 FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin);
405 /* get GPIO port output status */
406 uint16_t gpio_output_port_get(uint32_t gpio_periph);
407 
408 /* configure GPIO pin remap */
409 void gpio_pin_remap_config(uint32_t remap, ControlStatus newvalue);
410 
411 /* select GPIO pin exti sources */
412 void gpio_exti_source_select(uint8_t output_port, uint8_t output_pin);
413 /* configure GPIO pin event output */
414 void gpio_event_output_config(uint8_t output_port, uint8_t output_pin);
415 /* enable GPIO pin event output */
416 void gpio_event_output_enable(void);
417 /* disable GPIO pin event output */
418 void gpio_event_output_disable(void);
419 
420 /* lock GPIO pin bit */
421 void gpio_pin_lock(uint32_t gpio_periph, uint32_t pin);
422 
423 #endif /* GD32VF103_GPIO_H */
424