查看: 846|回复: 0

米尔MTD-T507H开发板试用--libgpiod 软件包的使用

[复制链接]
  • TA的每日心情
    奋斗
    2023-11-29 16:33
  • 签到天数: 45 天

    连续签到: 1 天

    [LV.5]常住居民I

    发表于 2022-7-31 23:39:02 | 显示全部楼层 |阅读模式
    分享到:
    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)
    1. root@ubt-virtual-machine:~/t507/t507# gpioset -h
    2. Usage: gpioset [OPTIONS] <chip name/number> <offset1>=<value1> <offset2>=<value2> ...
    3. Set GPIO line values of a GPIO chip
    4. Options:
    5.   -h, --help:           display this message and exit
    6.   -v, --version:        display the version and exit
    7.   -l, --active-low:     set the line active state to low
    8.   -m, --mode=[exit|wait|time|signal] (defaults to 'exit'):
    9.                 tell the program what to do after setting values
    10.   -s, --sec=SEC:        specify the number of seconds to wait (only valid for --mode=time)
    11.   -u, --usec=USEC:      specify the number of microseconds to wait (only valid for --mode=time)
    12.   -b, --background:     after setting values: detach from the controlling terminal

    13. Modes:
    14.   exit:         set values and exit immediately
    15.   wait:         set values and wait for user to press ENTER
    16.   time:         set values and sleep for a specified amount of time
    17.   signal:       set values and wait for SIGINT or SIGTERM
    复制代码
    gpioget命令
    1. root@ubt-virtual-machine:~/t507/t507# gpioget -h
    2. Usage: gpioget [OPTIONS] <chip name/number> <offset 1> <offset 2> ...
    3. Read line value(s) from a GPIO chip
    4. Options:
    5.   -h, --help:           display this message and exit
    6.   -v, --version:        display the version and exit
    7.   -l, --active-low:     set the line active state to low
    复制代码
    gpiodetect命令
    1. root@ubt-virtual-machine:~/t507/t507# gpiodetect -h
    2. Usage: gpiodetect [OPTIONS]
    3. List all GPIO chips, print their labels and number of GPIO lines.
    4. Options:
    5.   -h, --help:           display this message and exit
    6.   -v, --version:        display the version and exit
    复制代码
    gpioinfo命令
    1. root@ubt-virtual-machine:~/t507/t507# gpioinfo -h
    2. Usage: gpioinfo [OPTIONS] <gpiochip1> ...
    3. Print information about all lines of the specified GPIO chip(s) (or all gpiochips if none are specified).
    4. Options:
    5.   -h, --help:           display this message and exit
    6.   -v, --version:        display the version and exit
    复制代码
    gpiofind命令
    1. root@ubt-virtual-machine:~/t507/t507# gpiofind -h
    2. Usage: gpiofind [OPTIONS] <name>
    3. Find a GPIO line by name. The output of this command can be used as input for gpioget/set.
    4. Options:
    5.   -h, --help:           display this message and exit
    6.   -v, --version:        display the version and exit
    复制代码
    gpiomon命令
    1. root@ubt-virtual-machine:~/t507/t507# gpiomon -h
    2. Usage: gpiomon [OPTIONS] <chip name/number> <offset 1> <offset 2> ...
    3. Wait for events on GPIO lines
    4. Options:
    5.   -h, --help:           display this message and exit
    6.   -v, --version:        display the version and exit
    7.   -l, --active-low:     set the line active state to low
    8.   -n, --num-events=NUM: exit after processing NUM events
    9.   -s, --silent:         don't print event info
    10.   -r, --rising-edge:    only process rising edge events
    11.   -f, --falling-edge:   only process falling edge events
    12.   -F, --format=FMT      specify custom output format

    13. Format specifiers:
    14.   %o:  GPIO line offset
    15.   %e:  event type (0 - falling edge, 1 rising edge)
    16.   %s:  seconds part of the event timestamp
    17.   %n:  nanoseconds part of the event timestamp
    复制代码


    在SDK里搜索libgpiod,可见libgpiod应该是来自于buildroot下的源码libgpiod-1.2.1.tar.xz
    1.PNG
    再搜索
    2.PNG
    可知最后编译出来的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/目录下
    3.PNG
    这里我们发现米尔MTD-T507环境里还多了一个gpio命令,像是针对T507开发的命令,查看文档,该命令功能如下
    4.PNG

    这里通过使用控制板载心跳LED D40来验证gpio命令的使用
    1. [root@myir:/]# echo none > /sys/class/leds/blue/trigger 取消心跳灯触发功能
    2. [root@myir:/]# echo 0 > /sys/class/leds/blue/brightness 开灯
    3. [root@myir:/]# echo 1 > /sys/class/leds/blue/brightness 关灯
    4. [root@myir:/]# gpio -s PE19 1 0 0 0 开灯
    5. set PE19 function=1 复用为功能1(即IO功能)
    6. set PE19 data=0
    7. set PE19 dlevel=0
    8. set PE19 pull=0
    9. [root@myir:/]# gpio -s PE19 1 1 0 0 关灯
    10. set PE19 function=1
    11. set PE19 data=1
    12. set PE19 dlevel=0
    13. set PE19 pull=0
    复制代码

    相对于/sys/class/gpio,使用上述gpio命令可以一步到位设置gpio,比较方便。
    其他命令可按照-h说明进行使用。
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-20 20:12 , Processed in 0.114525 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.