libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_gpio.hpp
1#pragma once
2
3#include "gpio.hpp"
4#include "libxr.hpp"
5
6#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
7
8namespace LibXR
9{
10
11typedef enum
12{
13#if defined(GPIOA)
14 CH32_GPIOA,
15#endif
16#if defined(GPIOB)
17 CH32_GPIOB,
18#endif
19#if defined(GPIOC)
20 CH32_GPIOC,
21#endif
22#if defined(GPIOD)
23 CH32_GPIOD,
24#endif
25#if defined(GPIOE)
26 CH32_GPIOE,
27#endif
28#if defined(GPIOF)
29 CH32_GPIOF,
30#endif
31#if defined(GPIOG)
32 CH32_GPIOG,
33#endif
34#if defined(GPIOH)
35 CH32_GPIOH,
36#endif
37#if defined(GPIOI)
38 CH32_GPIOI,
39#endif
40 CH32_GPIO_NUMBER
41} ch32_gpio_group_t;
42
43uint32_t CH32GetGPIOPeriph(GPIO_TypeDef* port);
44
45class CH32GPIO : public GPIO
46{
47 public:
48 CH32GPIO(GPIO_TypeDef* port, uint16_t pin,
50 GPIO::Pull pull = GPIO::Pull::NONE, IRQn_Type irq = NonMaskableInt_IRQn);
51
52 bool Read() override;
53
54 ErrorCode Write(bool value) override;
55
56 ErrorCode EnableInterrupt() override;
57
58 ErrorCode DisableInterrupt() override;
59
60 ErrorCode SetConfig(Configuration config) override;
61
62 void OnInterrupt();
63
64 static void CheckInterrupt(uint32_t line);
65
66 static inline CH32GPIO* map[16] = {nullptr};
67
68 private:
69 GPIO_TypeDef* port_;
70 uint16_t pin_;
71 IRQn_Type irq_;
72
73 void ConfigureEXTI(EXTITrigger_TypeDef trigger);
74
75 static uint8_t GetEXTIID(uint16_t pin);
76};
77
78} // namespace LibXR
ErrorCode SetConfig(Configuration config) override
配置 GPIO 引脚参数。Configures the GPIO pin settings.
ErrorCode DisableInterrupt() override
禁用 GPIO 引脚中断。Disables the GPIO pin interrupt.
bool Read() override
读取 GPIO 引脚状态。Reads the GPIO pin state.
ErrorCode Write(bool value) override
写入 GPIO 引脚状态。Writes the GPIO pin state.
ErrorCode EnableInterrupt() override
使能 GPIO 引脚中断。Enables the GPIO pin interrupt.
通用输入输出(GPIO)接口类。General Purpose Input/Output (GPIO) interface class.
Definition gpio.hpp:13
Direction
定义 GPIO 引脚的方向类型。Defines the direction types for GPIO pins.
Definition gpio.hpp:20
@ OUTPUT_PUSH_PULL
推挽输出模式。Push-pull output mode.
Pull
定义 GPIO 引脚的上拉/下拉模式。Defines the pull-up/pull-down configurations for GPIO pins.
Definition gpio.hpp:35
@ NONE
无上拉或下拉。No pull-up or pull-down.
LibXR 命名空间
Definition ch32_gpio.hpp:9
存储 GPIO 配置参数的结构体。Structure storing GPIO configuration parameters.
Definition gpio.hpp:46