导航

    全志在线开发者论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 在线文档
    • 社区主页

    【全志T113-S3_100ask】使用内核驱动点灯(控制继电器)

    MR Series
    1
    1
    1421
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Y
      giao LV 6 最后由 编辑

      背景

      开发板上没有led灯,且没用其他引出的GPIO,所以就借rgb屏幕的引脚来点个灯(不过分吧@狗头),实现控制继电器。

      (一)寻找合适的GPIO

      看了好久的原理图,怕与其他功能冲突,所以就使用了 PD13 作为本次实验的引脚。

      该引脚除了作为rgb屏幕的功能外,好像没其他作用了,好,就它了。

      4f64437d6891425bbdf72cd15c831ea1.png

      (二)跳线

      焊接飞线接到继电器上。

      88d1fc81a8da470eb4dab00da065c4d0.png

      (三)修改设备树

      参考开发文档

      Documentation/devicetree/bindings/leds/leds-gpio.txt

      LEDs connected to GPIO lines
      
      Required properties:
      - compatible : should be "gpio-leds".
      
      Each LED is represented as a sub-node of the gpio-leds device.  Each
      node's name represents the name of the corresponding LED.
      
      LED sub-node properties:
      - gpios :  Should specify the LED's GPIO, see "gpios property" in
        Documentation/devicetree/bindings/gpio/gpio.txt.  Active low LEDs should be
        indicated using flags in the GPIO specifier.
      - function :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - color :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - label :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt (deprecated)
      - linux,default-trigger :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - default-state:  (optional) The initial state of the LED.
        see Documentation/devicetree/bindings/leds/common.txt
      - retain-state-suspended: (optional) The suspend state can be retained.Such
        as charge-led gpio.
      - retain-state-shutdown: (optional) Retain the state of the LED on shutdown.
        Useful in BMC systems, for example when the BMC is rebooted while the host
        remains up.
      - panic-indicator : (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      
      Examples:
      
      #include <dt-bindings/gpio/gpio.h>
      #include <dt-bindings/leds/common.h>
      
      leds {
              compatible = "gpio-leds";
              led0 {
                      gpios = <&mcu_pio 0 GPIO_ACTIVE_LOW>;
                      linux,default-trigger = "disk-activity";
                      function = LED_FUNCTION_DISK;
              };
      
              led1 {
                      gpios = <&mcu_pio 1 GPIO_ACTIVE_HIGH>;
                      /* Keep LED on if BIOS detected hardware fault */
                      default-state = "keep";
                      function = LED_FUNCTION_FAULT;
              };
      };
      
      run-control {
              compatible = "gpio-leds";
              led0 {
                      gpios = <&mpc8572 6 GPIO_ACTIVE_HIGH>;
                      color = <LED_COLOR_ID_RED>;
                      default-state = "off";
              };
              led1 {
                      gpios = <&mpc8572 7 GPIO_ACTIVE_HIGH>;
                      color = <LED_COLOR_ID_GREEN>;
                      default-state = "on";
              };
      };
      
      leds {
              compatible = "gpio-leds";
      
              led0 {
                      gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
                      linux,default-trigger = "max8903-charger-charging";
                      retain-state-suspended;
                      function = LED_FUNCTION_CHARGE;
              };
      };
      

      简单来说就是指定 compatible = “gpio-leds” 就好了

      在根节点下添加:

      dtsleds { 
       	compatible = "gpio-leds";
       	led0 { 
      	 	label = "red";
      	  	gpios = <&pio PD 13 GPIO_ACTIVE_HIGH>; 
      	  	default-state = "off"; 
      	}; 
      };
      

      实例:

      ccc98029b00242ca904ebe910195495c.png

      (四)使能内核的LED驱动

      cbb51d2bde1b437a81d953fc17574778.png

      路径参考:

      Symbol: LEDS_GPIO [=y]                                                                                       │
       │ Type  : tristate                                                                                             │
       │ Prompt: LED Support for GPIO connected LEDs                                                                  │
       │   Location:                                                                                                  │
       │     -> Device Drivers                                                                                        │
       │       -> LED Support (NEW_LEDS [=y])                                                                         │
       │   Defined at drivers/leds/Kconfig:307                                                                        │
       │   Depends on: NEW_LEDS [=y] && LEDS_CLASS [=y] && (GPIOLIB [=y] || COMPILE_TEST [=n])                        │
       │   Selected by [n]:                                                                                           │
       │   - PCENGINES_APU2 [=n] && X86 && X86_PLATFORM_DEVICES [=n] && INPUT [=y] && INPUT_KEYBOARD [=y] && \        │
       │ GPIOLIB [=y] && LEDS_CLASS [=y]
      

      然后编译烧写系统。

      (五)测试验证

      1、寻找设备树,在 /proc/device-tree 下

      9ffd69cded23467d85204c0a6efdeb78.png

      2、点亮

      在 /sys/class/leds/red 下可以找到相关的属性

      下面使 brightness 属性为 1 .即可点亮

      echo 1 > /sys/class/leds/red/brightness
      

      继电器接通!!

      关闭的话,使用以下命令即可

      echo 0 > /sys/class/leds/red/brightness
      

      至此测试完毕

      原文链接:https://blog.csdn.net/qq_46079439/article/details/126131219
      作者@第四维度

      1 条回复 最后回复 回复 引用 分享 1
      • 1 / 1
      • First post
        Last post

      Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

      行为准则 | 用户协议 | 隐私权政策