zoukankan      html  css  js  c++  java
  • linux gpio控制之sysfs接口

    在3.14及之后的linux中对gpio提供了sysfs接口,说明文档:Documents/gpio/sysfs.txt。

    Platforms which use the "gpiolib" implementors framework may choose to configure a sysfs user interface to GPIOs.This is different from the debugfs interface, since it provides control over GPIO direction and value instead of just showing a gpio state summary. Plus, it could be present on production systems without debugging support.

    Note that standard kernel drivers exist for common "LEDs and Buttons" GPIO tasks:  "leds-gpio" and "gpio_keys", respectively. Use those instead of talking directly to the GPIOs; they integrate with kernel frameworks better than your userspace code could.

    1. 目录

    /sys/class/gpio

    2. 操作

    1) echo 29 > export
    2) 此时会产生一个gpio29 的目录.
    3) cd gpio29
    4) 关注以下几个文件:
            direction 这个文件是控制你是输出还是输入模式
                    如果想设置为输入:echo in > direction
                    如果想设置为输出:echo out > direction
            value 这个文件是在输出模式时,控制高低电平
                    高电平:echo 1 > value
                    低电平:echo 0 > value
            edge 这个控制中断触发模式
                    无: echo none > edge
                    上升沿触发:echo rising > edge
                    下降沿触发:echo falling > edge
                    轮询:echo both > edge
            active_low: 这个按照官方的说法是这个翻转电平,输入非零的数即上升沿变为下降沿。
                    o: echo 0 > active_low
                    非零的数: echo 3 > active_low
    5)关闭这个GPIO控制。
            cd /sys/class/gpio/
            echo 29 > unexport

    参考:

    1. http://blog.csdn.net/mirkerson/article/details/8464290

    2. https://www.cnblogs.com/chenfulin5/p/6274076.html

  • 相关阅读:
    坚持
    随笔
    C++:对象和类
    STEP7 V14 安装和激活
    c++:cout
    C 格式化字符串处理函数
    WIn:消极处理机制
    Python:requests发送json格式数据
    Python:logging日志功能的基本使用
    PLC:西门子测试
  • 原文地址:https://www.cnblogs.com/embedded-linux/p/8576686.html
Copyright © 2011-2022 走看看