first commit
This commit is contained in:
42
components/io_device_control/README.md
Normal file
42
components/io_device_control/README.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# io_device_control
|
||||
|
||||
`io_device_control` 组件用于统一管理项目中的简单 IO 外设控制。
|
||||
|
||||
当前定义:
|
||||
|
||||
- `GPIO1`:水泵控制(高电平有效)
|
||||
- `GPIO0`:光照控制(高电平有效)
|
||||
|
||||
## 对外接口
|
||||
|
||||
头文件:`include/io_device_control.h`
|
||||
|
||||
- `esp_err_t io_device_control_init(void);`
|
||||
- 初始化 GPIO 输出方向,并将水泵与光照默认置为关闭(低电平)。
|
||||
- `esp_err_t io_device_control_set_pump(bool on);`
|
||||
- 控制水泵开关,`true` 为开,`false` 为关。
|
||||
- `esp_err_t io_device_control_set_light(bool on);`
|
||||
- 控制光照开关,`true` 为开,`false` 为关。
|
||||
|
||||
## 使用方式
|
||||
|
||||
在 `app_main` 中先初始化,后续在业务逻辑中按需调用控制接口。
|
||||
|
||||
```c
|
||||
#include "esp_check.h"
|
||||
#include "io_device_control.h"
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(io_device_control_init());
|
||||
|
||||
// 后续按需调用
|
||||
// ESP_ERROR_CHECK(io_device_control_set_pump(true));
|
||||
// ESP_ERROR_CHECK(io_device_control_set_light(true));
|
||||
}
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 控制接口在未初始化时会返回 `ESP_ERR_INVALID_STATE`。
|
||||
- 若硬件驱动电路为反相,请在硬件层或组件内部统一处理,不建议在业务层散落取反逻辑。
|
||||
Reference in New Issue
Block a user