1 /* 2 * Copyright (c) 2006-2022, 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_GD32VF103V 23 #include "gd32vf103_gpio.h" 24 #endif 25 26 #define __GD32_PORT(port) GPIO##port 27 28 29 #define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \ 30 GPIO##port, GPIO_PIN_##pin, \ 31 GPIO_PORT_SOURCE_GPIO##port, \ 32 GPIO_PIN_SOURCE_##pin} 33 34 #define GD32_PIN_DEFAULT {-1, (rcu_periph_enum)0, 0, 0, 0, 0} 35 36 #define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIO_BASE)/(0x0400UL) )) + PIN) 37 38 #define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu)) 39 #define PIN_NO(pin) ((uint8_t)((pin) & 0xFu)) 40 41 #define PIN_GDPORT(pin) (GPIO_BASE + (0x400u * PIN_PORT(pin))) 42 #define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin))) 43 44 struct pin_index 45 { 46 rt_int16_t index; 47 rcu_periph_enum clk; 48 rt_uint32_t gpio_periph; 49 rt_uint32_t pin; 50 rt_uint8_t port_src; 51 rt_uint8_t pin_src; 52 }; 53 54 struct pin_irq_map 55 { 56 rt_uint16_t pinbit; 57 IRQn_Type irqno; 58 }; 59 60 #ifdef __cplusplus 61 } 62 #endif 63 64 #endif /* __DRV_GPIO_H__ */ 65 66