libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
gpio.hpp
1#pragma once
2
3#include "libxr.hpp"
4
5namespace LibXR
6{
7
13class GPIO
14{
15 public:
29
35 enum class Pull : uint8_t
36 {
37 NONE,
38 UP,
39 DOWN
40 };
41
51
53
58
62 GPIO() {}
63
67 virtual ~GPIO() = default;
68
74 virtual bool Read() = 0;
75
81 virtual void Write(bool value) = 0;
82
88
94
100 virtual ErrorCode SetConfig(Configuration config) = 0;
101
108 {
109 callback_ = callback;
110 return ErrorCode::OK;
111 }
112};
113
114} // namespace LibXR
通用输入输出(GPIO)接口类。 General Purpose Input/Output (GPIO) interface class.
Definition gpio.hpp:14
Callback callback_
GPIO 事件的回调函数 / Callback function for GPIO events.
Definition gpio.hpp:57
virtual bool Read()=0
读取 GPIO 引脚状态 / Reads the GPIO pin state.
virtual ErrorCode SetConfig(Configuration config)=0
配置 GPIO 引脚参数 / Configures the GPIO pin settings.
virtual ErrorCode EnableInterrupt()=0
使能 GPIO 引脚中断 / Enables the GPIO pin interrupt.
virtual ErrorCode DisableInterrupt()=0
禁用 GPIO 引脚中断 / Disables the GPIO pin interrupt.
virtual ~GPIO()=default
虚析构函数 / Virtual destructor.
Direction
定义 GPIO 引脚的方向类型 / Defines the direction types for GPIO pins.
Definition gpio.hpp:21
@ 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.
@ INPUT
输入模式 / Input mode.
@ FALL_INTERRUPT
下降沿中断模式 / Falling edge interrupt mode.
ErrorCode RegisterCallback(Callback callback)
注册 GPIO 事件回调函数 / Registers a callback function for GPIO events.
Definition gpio.hpp:107
virtual void Write(bool value)=0
写入 GPIO 引脚状态 / Writes the GPIO pin state.
GPIO()
默认构造函数 / Default constructor.
Definition gpio.hpp:62
Pull
定义 GPIO 引脚的上拉/下拉模式。 Defines the pull-up/pull-down configurations for GPIO pins.
Definition gpio.hpp:36
@ NONE
无上拉或下拉 / No pull-up or pull-down.
@ DOWN
下拉模式 / Pull-down mode.
@ UP
上拉模式 / Pull-up mode.
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
@ OK
操作成功 / Operation successful
存储 GPIO 配置参数的结构体 / Structure storing GPIO configuration parameters.
Definition gpio.hpp:47
Pull pull
GPIO 上拉/下拉配置 / GPIO pull-up/pull-down configuration.
Definition gpio.hpp:49
Direction direction
GPIO 引脚方向 / GPIO pin direction.
Definition gpio.hpp:48