1 /* 2 * Copyright (c) 2006-2025, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2021-08-20 BruceOu the first version 9 */ 10 11 #ifndef __DRV_GPIO_H__ 12 #define __DRV_GPIO_H__ 13 14 #include <rtthread.h> 15 #include <rtdevice.h> 16 #include <board.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 #if defined SOC_SERIES_GD32F10x 23 #include "gd32f10x_gpio.h" 24 #elif defined SOC_SERIES_GD32F20x 25 #include "gd32f20x_gpio.h" 26 #elif defined SOC_SERIES_GD32F30x 27 #include "gd32f30x_gpio.h" 28 #elif defined SOC_SERIES_GD32F4xx 29 #include "gd32f4xx_gpio.h" 30 #elif defined SOC_SERIES_GD32H7xx 31 #include "gd32h7xx_gpio.h" 32 #elif defined SOC_SERIES_GD32E50x 33 #include "gd32e50x_gpio.h" 34 #elif defined SOC_SERIES_GD32F5xx 35 #include "gd32f5xx_gpio.h" 36 #elif defined SOC_SERIES_GD32E23x 37 #include "gd32e23x_gpio.h" 38 #endif 39 40 #define __GD32_PORT(port) GPIO##port 41 42 #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx || defined SOC_SERIES_GD32E23x 43 #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \ 44 GPIO##port, GPIO_PIN_##pin, \ 45 EXTI_SOURCE_GPIO##port, \ 46 EXTI_SOURCE_PIN##pin} 47 #else 48 #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \ 49 GPIO##port, GPIO_PIN_##pin, \ 50 GPIO_PORT_SOURCE_GPIO##port, \ 51 GPIO_PIN_SOURCE_##pin} 52 53 #endif 54 55 #define GD32_PIN_DEFAULT {-1, (rcu_periph_enum)0, 0, 0, 0, 0} 56 57 #define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIO_BASE)/(0x0400UL) )) + PIN) 58 59 #define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu)) 60 #define PIN_NO(pin) ((uint8_t)((pin) & 0xFu)) 61 62 #define PIN_GDPORT(pin) (GPIO_BASE + (0x400u * PIN_PORT(pin))) 63 #define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin))) 64 65 struct pin_index 66 { 67 rt_int16_t index; 68 rcu_periph_enum clk; 69 rt_uint32_t gpio_periph; 70 rt_uint32_t pin; 71 rt_uint8_t port_src; 72 rt_uint8_t pin_src; 73 }; 74 75 struct pin_irq_map 76 { 77 rt_uint16_t pinbit; 78 IRQn_Type irqno; 79 }; 80 81 #ifdef __cplusplus 82 } 83 #endif 84 85 #endif /* __DRV_GPIO_H__ */ 86 87