TA的每日心情 | 郁闷 2024-9-18 16:57 |
---|
签到天数: 48 天 连续签到: 1 天 [LV.5]常住居民I
|
1、libgpiod简介及在SDK中来源
之前在linux用户空间操作gpio一直使用的是sys/class/gpio来操作,米尔MTD-T507H开发环境下下除了可以使用sys/class/gpio外,还提供了另外一种方法,那就是libgpiod。在Ubuntu安装libgpiod可以使用命令sudo apt install gpiod
libgpiod其实是一个软件包/库,里边包含了一些列命令,有gpioset、gpioget、gpiodetect、gpioinfo、gpiofind 和 gpiomon 等命令。
gpioset命令(参考:gpioset 命令 – 人人都懂物联网 (getiot.tech))
- root@ubt-virtual-machine:~/t507/t507# gpioset -h
- Usage: gpioset [OPTIONS] <chip name/number> <offset1>=<value1> <offset2>=<value2> ...
- Set GPIO line values of a GPIO chip
- Options:
- -h, --help: display this message and exit
- -v, --version: display the version and exit
- -l, --active-low: set the line active state to low
- -m, --mode=[exit|wait|time|signal] (defaults to 'exit'):
- tell the program what to do after setting values
- -s, --sec=SEC: specify the number of seconds to wait (only valid for --mode=time)
- -u, --usec=USEC: specify the number of microseconds to wait (only valid for --mode=time)
- -b, --background: after setting values: detach from the controlling terminal
- Modes:
- exit: set values and exit immediately
- wait: set values and wait for user to press ENTER
- time: set values and sleep for a specified amount of time
- signal: set values and wait for SIGINT or SIGTERM
复制代码 gpioget命令
- root@ubt-virtual-machine:~/t507/t507# gpioget -h
- Usage: gpioget [OPTIONS] <chip name/number> <offset 1> <offset 2> ...
- Read line value(s) from a GPIO chip
- Options:
- -h, --help: display this message and exit
- -v, --version: display the version and exit
- -l, --active-low: set the line active state to low
复制代码 gpiodetect命令
- root@ubt-virtual-machine:~/t507/t507# gpiodetect -h
- Usage: gpiodetect [OPTIONS]
- List all GPIO chips, print their labels and number of GPIO lines.
- Options:
- -h, --help: display this message and exit
- -v, --version: display the version and exit
复制代码 gpioinfo命令
- root@ubt-virtual-machine:~/t507/t507# gpioinfo -h
- Usage: gpioinfo [OPTIONS] <gpiochip1> ...
- Print information about all lines of the specified GPIO chip(s) (or all gpiochips if none are specified).
- Options:
- -h, --help: display this message and exit
- -v, --version: display the version and exit
复制代码 gpiofind命令
- root@ubt-virtual-machine:~/t507/t507# gpiofind -h
- Usage: gpiofind [OPTIONS] <name>
- Find a GPIO line by name. The output of this command can be used as input for gpioget/set.
- Options:
- -h, --help: display this message and exit
- -v, --version: display the version and exit
复制代码 gpiomon命令
- root@ubt-virtual-machine:~/t507/t507# gpiomon -h
- Usage: gpiomon [OPTIONS] <chip name/number> <offset 1> <offset 2> ...
- Wait for events on GPIO lines
- Options:
- -h, --help: display this message and exit
- -v, --version: display the version and exit
- -l, --active-low: set the line active state to low
- -n, --num-events=NUM: exit after processing NUM events
- -s, --silent: don't print event info
- -r, --rising-edge: only process rising edge events
- -f, --falling-edge: only process falling edge events
- -F, --format=FMT specify custom output format
- Format specifiers:
- %o: GPIO line offset
- %e: event type (0 - falling edge, 1 rising edge)
- %s: seconds part of the event timestamp
- %n: nanoseconds part of the event timestamp
复制代码
在SDK里搜索libgpiod,可见libgpiod应该是来自于buildroot下的源码libgpiod-1.2.1.tar.xz
再搜索
可知最后编译出来的libgpiob位于以下目录
./out/myir/full/longan/buildroot/build/libgpiod-1.2.1/src/tools/
./out/myir/full/longan/buildroot/target/usr/bin/
./out/myir/full/longan/buildroot/host/aarch64-buildroot-linux-gnu/sysroot/usr/bin/
2、libgpiod在米尔MTD-T507H开发板上的使用
在开发板下搜索,可知libgpiod命令在./usr/bin/目录下
这里我们发现米尔MTD-T507环境里还多了一个gpio命令,像是针对T507开发的命令,查看文档,该命令功能如下
这里通过使用控制板载心跳LED D40来验证gpio命令的使用
- [root@myir:/]# echo none > /sys/class/leds/blue/trigger 取消心跳灯触发功能
- [root@myir:/]# echo 0 > /sys/class/leds/blue/brightness 开灯
- [root@myir:/]# echo 1 > /sys/class/leds/blue/brightness 关灯
- [root@myir:/]# gpio -s PE19 1 0 0 0 开灯
- set PE19 function=1 复用为功能1(即IO功能)
- set PE19 data=0
- set PE19 dlevel=0
- set PE19 pull=0
- [root@myir:/]# gpio -s PE19 1 1 0 0 关灯
- set PE19 function=1
- set PE19 data=1
- set PE19 dlevel=0
- set PE19 pull=0
复制代码
相对于/sys/class/gpio,使用上述gpio命令可以一步到位设置gpio,比较方便。
其他命令可按照-h说明进行使用。
|
|