【全志T113-S3_100ask】使用内核驱动点灯(控制继电器)
-
背景
开发板上没有led灯,且没用其他引出的GPIO,所以就借rgb屏幕的引脚来点个灯(不过分吧@狗头),实现控制继电器。
(一)寻找合适的GPIO
看了好久的原理图,怕与其他功能冲突,所以就使用了 PD13 作为本次实验的引脚。
该引脚除了作为rgb屏幕的功能外,好像没其他作用了,好,就它了。
(二)跳线
焊接飞线接到继电器上。
(三)修改设备树
参考开发文档
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"; }; };
实例:
(四)使能内核的LED驱动
路径参考:
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 下
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
作者@第四维度
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号