• 关于 V831 linux 调用 gpio 的一些通用操作。


    现在推荐看这个【参考学习用】基于全志芯片的GPIO及底层(C/Python)编程 与 linux下/dev/mem分析,这篇作为备份录用途,主要是关于 V831 sun8iw19p1 的 pinctrl gpio 等信息。

    备忘一下:V831 对应 sun8iw19p1 的代号,关于 gpio 部分,我还没做到 Python ,只是在 linux sysfs 接口上验证了一遍。

    我们可以在 SDK 里得知对应的映射关系文件在 /drivers/pinctrl/sunxi/pinctrl-sun8iw19p1.c 。

    • /arch/arm/boot/dts/sun8iw19p1-pinctrl.dtsi

    使用方法有如下:

    https://thoughts.teambition.com/share/600659e9823a3d004a4e1c7a#6000f67283e1f200460df31c

    https://zhuanlan.zhihu.com/p/265359362

    ls -l /sys/class/gpio/ # show gpio
    echo 238 > /sys/class/gpio/export  #export PH14(238), State_LED
    ls -l /sys/class/gpio/ # show gpio
    # output test
    echo "out" > /sys/class/gpio/gpio238/direction # set gpio mode: direction
    echo 0 > /sys/class/gpio/gpio238/value # set gpio output level: low
    echo 1 > /sys/class/gpio/gpio238/value # set gpio output level: height
    # input test
    echo "in" > /sys/class/gpio/gpio238/direction #设置为输入
    cat /sys/class/gpio/gpio192/value #读取电平
    

    because A = 0 > l = 11 output 1 PL3 (11(L) * 32 == 352 + 3)

    echo 355 > /sys/class/gpio/export
    echo "out" > /sys/class/gpio/gpio355/direction
    echo 1 > /sys/class/gpio/gpio355/value
    

    设备树中 pinctrl 的使用

    https://blog.csdn.net/u012830148/article/details/80609337

    GPIO 实现的细节看这个文章解释该结构

    https://blog.csdn.net/zhoutaopower/article/details/98082006

    主要看 gpio_chip 和 gpio 的符号。

    看这篇熟悉如何配置设备树中的驱动和具体的设备,链接到指定的 IO 引脚上。

    https://www.cnblogs.com/aaronLinux/p/5551441.html

    import gpiod
    c = gpiod.chip("gpiochip1")
    # pylint: disable=missing-docstring
    import sys
    import time
    import pytest
    from gpiod import chip, line, line_request
    
    try:
        if len(sys.argv) > 2:
            LED_CHIP = sys.argv[1]
            LED_LINE_OFFSET = int(sys.argv[2])
        else:
            raise Exception()
    # pylint: disable=broad-except
    except Exception:
        print(
            """Usage:
        python3 -m gpiod.test.blink <chip> <line offset>"""
        )
        sys.exit()
    
    c = chip(LED_CHIP)
    
    print("chip name: ", c.name)
    print("chip label: ", c.label)
    print("number of lines: ", c.num_lines)
    
    print()
    
    led = c.get_line(LED_LINE_OFFSET)
    
    print("line offset: ", led.offset)
    print("line name: ", led.name)
    print("line consumer: ", led.consumer)
    print(
        "line direction: ",
        "input" if led.direction == line.DIRECTION_INPUT else "output",
    )
    print(
        "line active state: ",
        "active low" if led.active_state == line.ACTIVE_LOW else "active high",
    )
    print("is line used: ", led.is_used)
    print("is line open drain: ", led.is_open_drain)
    print("is_open_source: ", led.is_open_source)
    print("is line requested: ", led.is_requested)
    
    print("
    request line
    ")
    
    config = line_request()
    config.consumer = "Blink"
    config.request_type = line_request.DIRECTION_OUTPUT
    
    led.request(config)
    
    print("line consumer: ", led.consumer)
    print(
        "line direction: ",
        "input" if led.direction == line.DIRECTION_INPUT else "output",
    )
    print(
        "line active state: ",
        "active low" if led.active_state == line.ACTIVE_LOW else "active high",
    )
    print("is line used: ", led.is_used)
    print("is line open drain: ", led.is_open_drain)
    print("is_open_source: ", led.is_open_source)
    print("is line requested: ", led.is_requested)
    
    while True:
        led.set_value(0)
        time.sleep(0.1)
        led.set_value(1)
        time.sleep(0.1)
    
  • 相关阅读:
    匹配@之前面的部分
    把一个数字的字符串转换为千分符的标识方式?
    下标重置
    linux的time命令

    常用正则
    正则
    PHP 菠菜木马代码
    PHP 木马代码,
    一句话的木马
  • 原文地址:https://www.cnblogs.com/juwan/p/14336100.html
Copyright © 2020-2023  润新知