libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::ESP32GPIO Class Reference
Inheritance diagram for LibXR::ESP32GPIO:
Collaboration diagram for LibXR::ESP32GPIO:

Public Member Functions

 ESP32GPIO (gpio_num_t gpio_num)
 
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.
 
ErrorCode DisableInterrupt () override
 禁用 GPIO 引脚中断。Disables the GPIO pin interrupt.
 
ErrorCode SetConfig (Configuration config) override
 配置 GPIO 引脚参数。Configures the GPIO pin 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 Member Functions

static void IRAM_ATTR InterruptDispatcher (void *arg)
 

Private Attributes

gpio_num_t gpio_num_
 

Static Private Attributes

static bool isr_service_installed_ = false
 
static ESP32GPIOmap_ [GPIO_NUM_MAX]
 

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.
 

Detailed Description

Definition at line 9 of file esp_gpio.hpp.

Constructor & Destructor Documentation

◆ ESP32GPIO()

LibXR::ESP32GPIO::ESP32GPIO ( gpio_num_t  gpio_num)
inlineexplicit

Definition at line 12 of file esp_gpio.hpp.

12: gpio_num_(gpio_num) { map_[gpio_num_] = this; }
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

Member Function Documentation

◆ DisableInterrupt()

ErrorCode LibXR::ESP32GPIO::DisableInterrupt ( )
inlineoverridevirtual

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

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

Implements LibXR::GPIO.

Definition at line 35 of file esp_gpio.hpp.

36 {
37 gpio_intr_disable(gpio_num_);
38 gpio_isr_handler_remove(gpio_num_);
39 return ErrorCode::OK;
40 }

◆ EnableInterrupt()

ErrorCode LibXR::ESP32GPIO::EnableInterrupt ( )
inlineoverridevirtual

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

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

Implements LibXR::GPIO.

Definition at line 22 of file esp_gpio.hpp.

23 {
24 if (!isr_service_installed_)
25 {
27 isr_service_installed_ = true;
28 }
29
30 gpio_isr_handler_add(gpio_num_, ESP32GPIO::InterruptDispatcher, (void*)gpio_num_);
31 gpio_intr_enable(gpio_num_);
32 return ErrorCode::OK;
33 }

◆ InterruptDispatcher()

static void IRAM_ATTR LibXR::ESP32GPIO::InterruptDispatcher ( void arg)
inlinestatic

Definition at line 93 of file esp_gpio.hpp.

94 {
95 auto gpio_num = static_cast<gpio_num_t>(reinterpret_cast<uintptr_t>(arg));
96 auto gpio = map_[gpio_num];
97 if (gpio)
98 {
99 gpio->callback_.Run(true);
100 }
101 }
void Run(bool in_isr, PassArgs &&...args) const
执行回调函数,并传递参数。 Executes the callback function, passing the arguments.
Definition libxr_cb.hpp:208
Callback callback_
GPIO 事件的回调函数。Callback function for GPIO events.
Definition gpio.hpp:56

◆ Read()

bool LibXR::ESP32GPIO::Read ( )
inlineoverridevirtual

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

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

Implements LibXR::GPIO.

Definition at line 14 of file esp_gpio.hpp.

14{ return gpio_get_level(gpio_num_) != 0; }

◆ SetConfig()

ErrorCode LibXR::ESP32GPIO::SetConfig ( Configuration  config)
inlineoverridevirtual

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

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

Implements LibXR::GPIO.

Definition at line 42 of file esp_gpio.hpp.

43 {
45 io_conf.pin_bit_mask = 1ULL << gpio_num_;
46
47 switch (config.direction)
48 {
51 break;
54 break;
57 break;
60 io_conf.intr_type = GPIO_INTR_NEGEDGE;
61 break;
64 io_conf.intr_type = GPIO_INTR_POSEDGE;
65 break;
68 io_conf.intr_type = GPIO_INTR_ANYEDGE;
69 break;
70 }
71
72 switch (config.pull)
73 {
74 case Pull::NONE:
75 io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
76 io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
77 break;
78 case Pull::UP:
79 io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
80 io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
81 break;
82 case Pull::DOWN:
83 io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
84 io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
85 break;
86 }
87
89
90 return ErrorCode::OK;
91 }
@ 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.
@ NONE
无上拉或下拉。No pull-up or pull-down.
@ DOWN
下拉模式。Pull-down mode.
@ UP
上拉模式。Pull-up mode.

◆ Write()

ErrorCode LibXR::ESP32GPIO::Write ( bool  value)
inlineoverridevirtual

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

Parameters
value要写入的状态,true 表示高电平,false 表示低电平。The value to write, true for high, false for low.
Returns
操作结果的错误码。Error code indicating the result of the operation.

Implements LibXR::GPIO.

Definition at line 16 of file esp_gpio.hpp.

17 {
18 gpio_set_level(gpio_num_, value ? 1 : 0);
19 return ErrorCode::OK;
20 }

Field Documentation

◆ gpio_num_

gpio_num_t LibXR::ESP32GPIO::gpio_num_
private

Definition at line 104 of file esp_gpio.hpp.

◆ isr_service_installed_

bool LibXR::ESP32GPIO::isr_service_installed_ = false
inlinestaticprivate

Definition at line 105 of file esp_gpio.hpp.

◆ map_

ESP32GPIO* LibXR::ESP32GPIO::map_[GPIO_NUM_MAX]
inlinestaticprivate

Definition at line 106 of file esp_gpio.hpp.


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