> For the complete documentation index, see [llms.txt](https://freeioe.gitbook.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://freeioe.gitbook.io/doc/reference/other/utils/gpios.md).

# gpios模块

***

## 控制设备的GPIO

用以帮助应用控制设备GPIO的输出。

### value

设定GPIO的电平状态（value为nil时，获取当前电平状态信息)

```lua
function led:value(value)
end
```

### toggle

切换输出状态，如果当前状态为高电平状态，则切换到低电平状态

```lua
function led:toggle()
end
```

### blink

设定GPIO进入闪烁切换状态。 sec是GPIO高电平时长(浮点数), dark\_sec是GPIO低电平时长。 闪烁会一直执行到取消闪烁

```lua
function led:blink(sec, dark_sec)
end
```

### cancel\_blink

取消GPIO电平闪烁状态

```lua
function led:cancel_blink()
end
```

### 使用示例

```lua
local gpios = require 'utils.gpios'

local pcie_reset = leds.pcie_reset --- 使用名称为pcie_reset的GPIO, /sys/class/gpio下的名称为pcie_reset的GPIO。

pcie_reset:value(1) -- 高电平
pcie_reset:value(0) -- 低电平

pcie_reset:blink(1, 1) -- 闪烁
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://freeioe.gitbook.io/doc/reference/other/utils/gpios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
