2021-09-02 22:38:47 +08:00
|
|
|
/*
|
2022-01-02 09:14:03 +08:00
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
2021-09-02 22:38:47 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2021-08-20 BruceOu the first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DRV_GPIO_H__
|
|
|
|
#define __DRV_GPIO_H__
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rtdevice.h>
|
|
|
|
#include <board.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-06-28 19:43:00 +08:00
|
|
|
#if defined SOC_SERIES_GD32VF103V
|
|
|
|
#include "gd32vf103_gpio.h"
|
2022-01-02 09:14:03 +08:00
|
|
|
#endif
|
2021-09-02 22:38:47 +08:00
|
|
|
|
2022-01-02 09:14:03 +08:00
|
|
|
#define __GD32_PORT(port) GPIO##port
|
2021-09-02 22:38:47 +08:00
|
|
|
|
2022-06-28 19:43:00 +08:00
|
|
|
|
2022-01-02 09:14:03 +08:00
|
|
|
#define GD32_PIN(index, port, pin) {index, RCU_GPIO##port, \
|
2022-01-25 16:37:19 +08:00
|
|
|
GPIO##port, GPIO_PIN_##pin, \
|
2022-01-02 09:14:03 +08:00
|
|
|
GPIO_PORT_SOURCE_GPIO##port, \
|
|
|
|
GPIO_PIN_SOURCE_##pin}
|
|
|
|
|
2021-09-02 22:38:47 +08:00
|
|
|
#define GD32_PIN_DEFAULT {-1, (rcu_periph_enum)0, 0, 0, 0, 0}
|
|
|
|
|
2022-01-02 09:14:03 +08:00
|
|
|
#define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__GD32_PORT(PORTx) - (rt_base_t)GPIO_BASE)/(0x0400UL) )) + PIN)
|
2021-09-02 22:38:47 +08:00
|
|
|
|
2022-06-28 19:43:00 +08:00
|
|
|
#define PIN_PORT(pin) ((uint8_t)(((pin) >> 4) & 0xFu))
|
|
|
|
#define PIN_NO(pin) ((uint8_t)((pin) & 0xFu))
|
2022-01-25 16:37:19 +08:00
|
|
|
|
2022-06-28 19:43:00 +08:00
|
|
|
#define PIN_GDPORT(pin) (GPIO_BASE + (0x400u * PIN_PORT(pin)))
|
|
|
|
#define PIN_GDPIN(pin) ((uint16_t)(1u << PIN_NO(pin)))
|
2022-01-25 16:37:19 +08:00
|
|
|
|
2021-09-02 22:38:47 +08:00
|
|
|
struct pin_index
|
|
|
|
{
|
|
|
|
rt_int16_t index;
|
|
|
|
rcu_periph_enum clk;
|
|
|
|
rt_uint32_t gpio_periph;
|
|
|
|
rt_uint32_t pin;
|
|
|
|
rt_uint8_t port_src;
|
|
|
|
rt_uint8_t pin_src;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pin_irq_map
|
|
|
|
{
|
|
|
|
rt_uint16_t pinbit;
|
|
|
|
IRQn_Type irqno;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __DRV_GPIO_H__ */
|
|
|
|
|