6#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
43uint32_t ch32_get_gpio_periph(GPIO_TypeDef* port);
54 CH32GPIO(GPIO_TypeDef* port, uint16_t pin,
58 inline bool Read()
override {
return (port_->INDR & pin_) != (uint32_t)Bit_RESET; }
60 inline void Write(
bool value)
override
78 GPIO_InitTypeDef gpio_init = {};
79 gpio_init.GPIO_Pin = pin_;
80 gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
88 gpio_init.GPIO_Mode = (config.
pull ==
Pull::UP) ? GPIO_Mode_IPU
90 : GPIO_Mode_IN_FLOATING;
94 gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
98 gpio_init.GPIO_Mode = GPIO_Mode_Out_OD;
102 GPIO_Init(port_, &gpio_init);
107 ConfigureEXTI(EXTI_Trigger_Rising);
110 ConfigureEXTI(EXTI_Trigger_Falling);
113 ConfigureEXTI(EXTI_Trigger_Rising_Falling);
119 return ErrorCode::OK;
124 static void CheckInterrupt(uint32_t line);
134 void ConfigureEXTI(EXTITrigger_TypeDef trigger);
136 static uint8_t GetEXTIID(uint16_t pin);
CH32 GPIO 驱动实现 / CH32 GPIO driver implementation.
ErrorCode SetConfig(Configuration config) override
配置 GPIO 引脚参数。Configures the GPIO pin settings.
void Write(bool value) override
写入 GPIO 引脚状态。Writes the GPIO pin state.
ErrorCode DisableInterrupt() override
禁用 GPIO 引脚中断。Disables the GPIO pin interrupt.
bool Read() override
读取 GPIO 引脚状态。Reads the GPIO pin state.
CH32GPIO(GPIO_TypeDef *port, uint16_t pin, GPIO::Direction direction=GPIO::Direction::OUTPUT_PUSH_PULL, GPIO::Pull pull=GPIO::Pull::NONE, IRQn_Type irq=NonMaskableInt_IRQn)
构造 GPIO 对象 / Construct GPIO object
ErrorCode EnableInterrupt() override
使能 GPIO 引脚中断。Enables the GPIO pin interrupt.
static CH32GPIO * map_[16]
EXTI 线路映射表 / EXTI line map.
通用输入输出(GPIO)接口类。General Purpose Input/Output (GPIO) interface class.
Direction
定义 GPIO 引脚的方向类型。Defines the direction types for GPIO pins.
@ OUTPUT_PUSH_PULL
推挽输出模式。Push-pull output mode.
@ RISING_INTERRUPT
上升沿中断模式。Rising edge interrupt mode.
@ FALL_RISING_INTERRUPT
双沿触发中断模式。Both edge interrupt mode.
@ OUTPUT_OPEN_DRAIN
开漏输出模式。Open-drain output mode.
@ FALL_INTERRUPT
下降沿中断模式。Falling edge interrupt mode.
Pull
定义 GPIO 引脚的上拉/下拉模式。Defines the pull-up/pull-down configurations for GPIO pins.
@ NONE
无上拉或下拉。No pull-up or pull-down.
@ DOWN
下拉模式。Pull-down mode.
存储 GPIO 配置参数的结构体。Structure storing GPIO configuration parameters.
Pull pull
GPIO 上拉/下拉配置。GPIO pull-up/pull-down configuration.
Direction direction
GPIO 引脚方向。GPIO pin direction.