1 /* 2 * Copyright (c) 2006-2021, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2022-05-16 shelton first version 9 */ 10 11 #ifndef __DRV_GPIO_H__ 12 #define __DRV_GPIO_H__ 13 14 #include <rthw.h> 15 #include <rtdevice.h> 16 #include "drv_common.h" 17 18 #define __AT32_PORT(port) GPIO##port##_BASE 19 20 #define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__AT32_PORT(PORTx) - (rt_base_t)GPIOA_BASE)/(0x0400UL) )) + PIN) 21 22 #define __AT32_PIN(index, gpio, gpio_index) \ 23 { \ 24 index, GPIO##gpio, GPIO_Pins_##gpio_index, \ 25 GPIO_PortSourceGPIO##gpio, GPIO_PinsSource##gpio_index \ 26 } 27 28 #define __AT32_PIN_RESERVE \ 29 { \ 30 -1, 0, 0, 0, 0 \ 31 } 32 33 /* AT32 GPIO driver */ 34 struct pin_index 35 { 36 int index; 37 gpio_type *gpio_x; 38 rt_uint32_t pin; 39 rt_uint32_t portsource; 40 rt_uint32_t pinsource; 41 }; 42 43 struct pin_irq_map 44 { 45 rt_uint16_t pinbit; 46 rt_uint16_t lineno; 47 IRQn_Type irqno; 48 }; 49 50 int rt_hw_pin_init(void); 51 52 #endif /* __DRV_GPIO_H__ */ 53 54