|
libxr
1.0
Want to be the best embedded framework
|
基于 libgpiod v2.x 的 Linux GPIO 实现 Linux GPIO implementation using libgpiod v2.x More...
#include <linux_gpio.hpp>
Public Member Functions | |
| LinuxGPIO (const std::string &chip_path, unsigned int line_offset) | |
| 构造 LinuxGPIO 对象。Constructs a LinuxGPIO instance. | |
| LinuxGPIO (const LinuxGPIO &)=delete | |
| LinuxGPIO & | operator= (const LinuxGPIO &)=delete |
| bool | Read () override |
| 读取 GPIO 引脚状态。Reads the GPIO line level. | |
| void | Write (bool value) override |
| 写入 GPIO 引脚状态。Writes a level to the GPIO line. | |
| ErrorCode | EnableInterrupt () override |
| 使能 GPIO 中断处理状态。Enables GPIO interrupt handling state. | |
| ErrorCode | DisableInterrupt () override |
| 禁用 GPIO 中断处理状态。Disables GPIO interrupt handling state. | |
| int | GetFd () const |
| 获取 GPIO request 对应的文件描述符,用于 epoll/poll 注册。 Gets the request file descriptor for epoll/poll registration. | |
| ErrorCode | HandleInterrupt () |
| 非阻塞处理中断事件,排空队列并触发回调。 Handles GPIO interrupt events in non-blocking mode, drains queued events and dispatches callbacks. | |
| ErrorCode | ReadEvent (GPIOEvent &event) |
| 读取单个中断事件。Reads a single interrupt edge event. | |
| ErrorCode | SetConfig (Configuration config) override |
| 配置 GPIO 引脚参数。Configures GPIO line settings. | |
Public Member Functions inherited from LibXR::GPIO | |
| GPIO () | |
| 默认构造函数。Default constructor. | |
| ErrorCode | RegisterCallback (Callback callback) |
| 注册 GPIO 事件回调函数。Registers a callback function for GPIO events. | |
Static Public Attributes | |
| static constexpr size_t | EVENT_BUFFER_CAPACITY = 64 |
Private Member Functions | |
| ErrorCode | ApplyDirection (Direction direction) |
| 根据 GPIO 方向配置 line settings。 Applies line settings according to GPIO direction. | |
| ErrorCode | ApplyPull (Pull pull) |
| 根据 GPIO 上拉/下拉配置 line settings。 Applies line settings according to GPIO pull mode. | |
| bool | EnsureConfigured () const |
| 确保 GPIO 已配置。Ensures GPIO has been configured. | |
| ErrorCode | EnsureInterruptReady () const |
| 确保中断路径已启用。Ensures interrupt path is enabled and ready. | |
Static Private Member Functions | |
| static bool | IsInterruptDirection (Direction direction) |
| 判断 direction 是否为中断方向。Checks whether direction is interrupt mode. | |
Private Attributes | |
| std::string | chip_path_ |
| unsigned int | line_offset_ |
| gpiod_chip * | chip_ = nullptr |
| gpiod_edge_event_buffer * | event_buffer_ |
| 持久化事件缓冲区。Persistent edge event buffer. | |
| gpiod_line_settings * | settings_ = nullptr |
| gpiod_request_config * | req_cfg_ = nullptr |
| gpiod_line_config * | line_cfg_ = nullptr |
| gpiod_line_request * | request_ = nullptr |
| Configuration | current_config_ = {Direction::INPUT, Pull::NONE} |
| bool | has_config_ = false |
| bool | interrupt_enabled_ = false |
Additional Inherited Members | |
Public Types inherited from LibXR::GPIO | |
| enum class | Direction : uint8_t { INPUT , OUTPUT_PUSH_PULL , OUTPUT_OPEN_DRAIN , FALL_INTERRUPT , RISING_INTERRUPT , FALL_RISING_INTERRUPT } |
| 定义 GPIO 引脚的方向类型。Defines the direction types for GPIO pins. More... | |
| enum class | Pull : uint8_t { NONE , UP , DOWN } |
| 定义 GPIO 引脚的上拉/下拉模式。Defines the pull-up/pull-down configurations for GPIO pins. More... | |
| using | Callback = LibXR::Callback<> |
Data Fields inherited from LibXR::GPIO | |
| Callback | callback_ |
| GPIO 事件的回调函数。Callback function for GPIO events. | |
基于 libgpiod v2.x 的 Linux GPIO 实现 Linux GPIO implementation using libgpiod v2.x
Definition at line 42 of file linux_gpio.hpp.
|
inline |
构造 LinuxGPIO 对象。Constructs a LinuxGPIO instance.
| chip_path | GPIO chip 设备路径(如 "/dev/gpiochip0")。 GPIO chip device path (e.g. "/dev/gpiochip0"). |
| line_offset | GPIO line 偏移量。GPIO line offset. |
Definition at line 53 of file linux_gpio.hpp.
|
inlineprivate |
根据 GPIO 方向配置 line settings。 Applies line settings according to GPIO direction.
Definition at line 382 of file linux_gpio.hpp.
|
inlineprivate |
根据 GPIO 上拉/下拉配置 line settings。 Applies line settings according to GPIO pull mode.
Definition at line 475 of file linux_gpio.hpp.
|
inlineoverridevirtual |
禁用 GPIO 中断处理状态。Disables GPIO interrupt handling state.
Implements LibXR::GPIO.
Definition at line 169 of file linux_gpio.hpp.
|
inlineoverridevirtual |
使能 GPIO 中断处理状态。Enables GPIO interrupt handling state.
Implements LibXR::GPIO.
Definition at line 149 of file linux_gpio.hpp.
|
inlineprivate |
确保 GPIO 已配置。Ensures GPIO has been configured.
Definition at line 513 of file linux_gpio.hpp.
|
inlineprivate |
确保中断路径已启用。Ensures interrupt path is enabled and ready.
Definition at line 528 of file linux_gpio.hpp.
|
inline |
获取 GPIO request 对应的文件描述符,用于 epoll/poll 注册。 Gets the request file descriptor for epoll/poll registration.
Definition at line 180 of file linux_gpio.hpp.
|
inline |
非阻塞处理中断事件,排空队列并触发回调。 Handles GPIO interrupt events in non-blocking mode, drains queued events and dispatches callbacks.
Definition at line 198 of file linux_gpio.hpp.
|
inlinestaticprivate |
判断 direction 是否为中断方向。Checks whether direction is interrupt mode.
Definition at line 503 of file linux_gpio.hpp.
|
inlineoverridevirtual |
读取 GPIO 引脚状态。Reads the GPIO line level.
Implements LibXR::GPIO.
Definition at line 108 of file linux_gpio.hpp.
|
inline |
读取单个中断事件。Reads a single interrupt edge event.
| event | 输出事件结构体。Output edge event structure. |
Definition at line 252 of file linux_gpio.hpp.
|
inlineoverridevirtual |
配置 GPIO 引脚参数。Configures GPIO line settings.
| config | GPIO 配置。GPIO configuration. |
Implements LibXR::GPIO.
Definition at line 314 of file linux_gpio.hpp.
|
inlineoverridevirtual |
写入 GPIO 引脚状态。Writes a level to the GPIO line.
| value | true 高电平,false 低电平。True for high level, false for low level. |
Implements LibXR::GPIO.
Definition at line 129 of file linux_gpio.hpp.
|
private |
Definition at line 366 of file linux_gpio.hpp.
|
private |
Definition at line 364 of file linux_gpio.hpp.
|
private |
Definition at line 373 of file linux_gpio.hpp.
|
private |
持久化事件缓冲区。Persistent edge event buffer.
Definition at line 367 of file linux_gpio.hpp.
|
staticconstexpr |
Definition at line 45 of file linux_gpio.hpp.
|
private |
Definition at line 374 of file linux_gpio.hpp.
|
private |
Definition at line 375 of file linux_gpio.hpp.
|
private |
Definition at line 371 of file linux_gpio.hpp.
|
private |
Definition at line 365 of file linux_gpio.hpp.
|
private |
Definition at line 370 of file linux_gpio.hpp.
|
private |
Definition at line 372 of file linux_gpio.hpp.
|
private |
Definition at line 369 of file linux_gpio.hpp.