28 LinuxGPIO(
const std::string& chip_path,
unsigned int line_offset);
35 void Write(
bool value)
override;
41 static constexpr size_t EVENT_BUFFER_CAPACITY = 64;
42 static constexpr size_t INTERRUPT_THREAD_STACK_SIZE = 16384;
44 enum class AbiVersion : uint8_t
51 enum class RequestKind : uint8_t
58 std::string chip_path_;
59 unsigned int line_offset_ = 0U;
61 std::atomic<int> request_fd_{-1};
62 std::atomic<AbiVersion> abi_version_{AbiVersion::UNKNOWN};
63 std::atomic<RequestKind> request_kind_{RequestKind::NONE};
65 bool has_config_ =
false;
66 std::atomic<bool> interrupt_enabled_{
false};
67 std::atomic<bool> interrupt_thread_started_{
false};
68 std::atomic<bool> interrupt_thread_exit_{
false};
69 std::atomic<bool> interrupt_poll_active_{
false};
71 int interrupt_wake_pipe_[2] = {-1, -1};
77 void CloseInterruptWakePipe();
78 void NotifyInterruptThread();
79 void WaitForInterruptLoopIdle();
80 void WaitForInterruptThreadStopped();
87 ErrorCode PumpEventQueue(
int fd, AbiVersion abi_version,
size_t& event_count,
88 int timeout_ms)
const;
89 ErrorCode ReadEventsV2(
int fd,
size_t& event_count)
const;
90 ErrorCode ReadEventsV1(
int fd,
size_t& event_count)
const;
91 void StartInterruptThread();
94 static bool IsInterruptDirection(
Direction direction);
通用输入输出(GPIO)接口类。 General Purpose Input/Output (GPIO) interface class.
Direction
定义 GPIO 引脚的方向类型 / Defines the direction types for GPIO pins.
@ INPUT
输入模式 / Input mode.
@ NONE
无上拉或下拉 / No pull-up or pull-down.
基于 Linux GPIO character device uAPI 的 Linux GPIO 实现 Linux GPIO implementation based on the Linux GPIO...
ErrorCode EnableInterrupt() override
使能 GPIO 引脚中断 / Enables the GPIO pin interrupt.
void Write(bool value) override
写入 GPIO 引脚状态 / Writes the GPIO pin state.
bool Read() override
读取 GPIO 引脚状态 / Reads the GPIO pin state.
ErrorCode SetConfig(Configuration config) override
配置 GPIO 引脚参数 / Configures the GPIO pin settings.
ErrorCode DisableInterrupt() override
禁用 GPIO 引脚中断 / Disables the GPIO pin interrupt.
线程管理类,封装 POSIX 线程创建和调度 Thread management class encapsulating POSIX thread creation and scheduling
LibXR 命名空间 / LibXR namespace.
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
存储 GPIO 配置参数的结构体 / Structure storing GPIO configuration parameters.