libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::GPIO Class Referenceabstract

通用输入输出(GPIO)接口类。 General Purpose Input/Output (GPIO) interface class. More...

#include <gpio.hpp>

Inheritance diagram for LibXR::GPIO:
[legend]
Collaboration diagram for LibXR::GPIO:
[legend]

Classes

struct  Configuration
 存储 GPIO 配置参数的结构体 / Structure storing GPIO configuration parameters. More...
 

Public Types

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<>
 

Public Member Functions

 GPIO ()
 默认构造函数 / Default constructor.
 
virtual ~GPIO ()=default
 虚析构函数 / Virtual destructor.
 
virtual bool Read ()=0
 读取 GPIO 引脚状态 / Reads the GPIO pin state.
 
virtual void Write (bool value)=0
 写入 GPIO 引脚状态 / Writes the GPIO pin state.
 
virtual ErrorCode EnableInterrupt ()=0
 使能 GPIO 引脚中断 / Enables the GPIO pin interrupt.
 
virtual ErrorCode DisableInterrupt ()=0
 禁用 GPIO 引脚中断 / Disables the GPIO pin interrupt.
 
virtual ErrorCode SetConfig (Configuration config)=0
 配置 GPIO 引脚参数 / Configures the GPIO pin settings.
 
ErrorCode RegisterCallback (Callback callback)
 注册 GPIO 事件回调函数 / Registers a callback function for GPIO events.
 

Public Attributes

Callback callback_
 GPIO 事件的回调函数 / Callback function for GPIO events.
 

Detailed Description

通用输入输出(GPIO)接口类。 General Purpose Input/Output (GPIO) interface class.

Definition at line 13 of file gpio.hpp.

Member Typedef Documentation

◆ Callback

Definition at line 52 of file gpio.hpp.

Member Enumeration Documentation

◆ Direction

enum class LibXR::GPIO::Direction : uint8_t
strong

定义 GPIO 引脚的方向类型 / Defines the direction types for GPIO pins.

Enumerator
INPUT 

输入模式 / Input mode.

OUTPUT_PUSH_PULL 

推挽输出模式 / Push-pull output mode.

OUTPUT_OPEN_DRAIN 

开漏输出模式 / Open-drain output mode.

FALL_INTERRUPT 

下降沿中断模式 / Falling edge interrupt mode.

RISING_INTERRUPT 

上升沿中断模式 / Rising edge interrupt mode.

FALL_RISING_INTERRUPT 

双沿触发中断模式 / Both edge interrupt mode.

Definition at line 20 of file gpio.hpp.

21 {
22 INPUT,
28 };
@ 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.

◆ Pull

enum class LibXR::GPIO::Pull : uint8_t
strong

定义 GPIO 引脚的上拉/下拉模式。 Defines the pull-up/pull-down configurations for GPIO pins.

Enumerator
NONE 

无上拉或下拉 / No pull-up or pull-down.

UP 

上拉模式 / Pull-up mode.

DOWN 

下拉模式 / Pull-down mode.

Definition at line 35 of file gpio.hpp.

36 {
37 NONE,
38 UP,
39 DOWN
40 };
@ NONE
无上拉或下拉 / No pull-up or pull-down.
@ DOWN
下拉模式 / Pull-down mode.
@ UP
上拉模式 / Pull-up mode.

Constructor & Destructor Documentation

◆ GPIO()

LibXR::GPIO::GPIO ( )
inline

默认构造函数 / Default constructor.

Definition at line 62 of file gpio.hpp.

62{}

Member Function Documentation

◆ DisableInterrupt()

virtual ErrorCode LibXR::GPIO::DisableInterrupt ( )
pure virtual

禁用 GPIO 引脚中断 / Disables the GPIO pin interrupt.

Returns
操作结果的错误码 / Error code indicating the result of the operation.

Implemented in LibXR::CH32GPIO, LibXR::ESP32GPIO, LibXR::HPMGPIO, LibXR::LinuxGPIO, LibXR::MSPM0GPIO, and LibXR::STM32GPIO.

◆ EnableInterrupt()

virtual ErrorCode LibXR::GPIO::EnableInterrupt ( )
pure virtual

使能 GPIO 引脚中断 / Enables the GPIO pin interrupt.

Returns
操作结果的错误码 / Error code indicating the result of the operation.

Implemented in LibXR::CH32GPIO, LibXR::ESP32GPIO, LibXR::HPMGPIO, LibXR::LinuxGPIO, LibXR::MSPM0GPIO, and LibXR::STM32GPIO.

◆ Read()

virtual bool LibXR::GPIO::Read ( )
pure virtual

读取 GPIO 引脚状态 / Reads the GPIO pin state.

Returns
返回引脚状态,true 表示高电平,false 表示低电平。 Returns the pin state, true for high, false for low.

Implemented in LibXR::CH32GPIO, LibXR::ESP32GPIO, LibXR::HPMGPIO, LibXR::LinuxGPIO, LibXR::MSPM0GPIO, and LibXR::STM32GPIO.

◆ RegisterCallback()

ErrorCode LibXR::GPIO::RegisterCallback ( Callback callback)
inline

注册 GPIO 事件回调函数 / Registers a callback function for GPIO events.

Parameters
callback要注册的回调函数 / The callback function to register.
Returns
操作结果的错误码 / Error code indicating the result of the operation.

Definition at line 107 of file gpio.hpp.

108 {
109 callback_ = callback;
110 return ErrorCode::OK;
111 }
Callback callback_
GPIO 事件的回调函数 / Callback function for GPIO events.
Definition gpio.hpp:57
@ OK
操作成功 / Operation successful

◆ SetConfig()

virtual ErrorCode LibXR::GPIO::SetConfig ( Configuration config)
pure virtual

配置 GPIO 引脚参数 / Configures the GPIO pin settings.

Parameters
config需要应用的 GPIO 配置 / The GPIO configuration to apply.
Returns
操作结果的错误码 / Error code indicating the result of the operation.

Implemented in LibXR::CH32GPIO, LibXR::ESP32GPIO, LibXR::HPMGPIO, LibXR::LinuxGPIO, LibXR::MSPM0GPIO, and LibXR::STM32GPIO.

◆ Write()

virtual void LibXR::GPIO::Write ( bool value)
pure virtual

写入 GPIO 引脚状态 / Writes the GPIO pin state.

Parameters
value要写入的状态,true 表示高电平,false 表示低电平。 The value to write, true for high, false for low.

Implemented in LibXR::CH32GPIO, LibXR::ESP32GPIO, LibXR::HPMGPIO, LibXR::LinuxGPIO, LibXR::MSPM0GPIO, and LibXR::STM32GPIO.

Member Data Documentation

◆ callback_

Callback LibXR::GPIO::callback_

GPIO 事件的回调函数 / Callback function for GPIO events.

Definition at line 57 of file gpio.hpp.


The documentation for this class was generated from the following file: