笔记:linux中LED驱动设备树配置和用法

设备树中节点配置

设备树中的LED驱动一般是这样写,LED驱动可以控制GPIO的电平变化,生成文件节点很方便

cpp 复制代码
leds: leds {
		compatible = "gpio-leds";
		gpio_demo: gpio_demo {
			label = "gpio_demo";
			gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_HIGH>;
			linux,default-trigger = "default-off";
			default-state = "on";
		};
}

字段解释

|----------------------------------------------|------------------------------------------------|
| compatible = "gpio-leds"; | 对应了驱动中 drivers/leds/leds-gpio.c这个驱动文件 |
| label = "gpio_demo"; | 这个名字会在文件系统中生成对应的设备节点 /sys/class/leds/gpio_demo |
| linux,default-trigger = "default-off"; | 指的是led的触发方式 default-off是默认none作为普通的功能来使用 |
| gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_HIGH>; | 前面两个参数是设置哪个GPIO 后面一个参数是指的高低电平有效 |
| default-state = "on"; | 默认状态 on或者off |

设置方式和电平的关系

设置方式 默认电平 brightness=0 brightness>0
gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_HIGH>; linux,default-trigger = "default-off"; default-state = "on"
gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_HIGH>; linux,default-trigger = "default-off"; default-state = "off"
gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_LOW>; linux,default-trigger = "default-off"; default-state = "on"
gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_LOW>; linux,default-trigger = "default-off"; default-state = "off"

触发方式

触发方式linux,default-trigger = "default-off";

触发方式类型可以参考使用内核里面的支持项,源码在drivers\leds\trigger下面

drivers/leds/trigger/ledtrig-activity.c

drivers/leds/trigger/ledtrig-audio.c

drivers/leds/trigger/ledtrig-backlight.c

drivers/leds/trigger/ledtrig-camera.c

drivers/leds/trigger/ledtrig-cpu.c

drivers/leds/trigger/ledtrig-default-on.c

drivers/leds/trigger/ledtrig-disk.c

drivers/leds/trigger/ledtrig-gpio.c

drivers/leds/trigger/ledtrig-heartbeat.c

drivers/leds/trigger/ledtrig-mtd.c

drivers/leds/trigger/ledtrig-multi-control.c

drivers/leds/trigger/ledtrig-netdev.c

drivers/leds/trigger/ledtrig-oneshot.c

drivers/leds/trigger/ledtrig-panic.c

drivers/leds/trigger/ledtrig-pattern.c

drivers/leds/trigger/ledtrig-timer.c

drivers/leds/trigger/ledtrig-transient.c

常用的有timer heartbeat oneshot

使用的时候需要检测内核config中是否有开启,使用哪个就开启哪个

CONFIG_LEDS_TRIGGER_TIMER=y

CONFIG_LEDS_TRIGGER_HEARTBEAT=y

CONFIG_LEDS_TRIGGER_BACKLIGHT=y

CONFIG_LEDS_TRIGGER_DEFAULT_ON=y

CONFIG_LEDS_TRIGGER_ONESHOT=y

以timer和oneshot举例

timer

leds: leds {

compatible = "gpio-leds";

gpio_demo: gpio_demo {

label = "gpio_demo";

gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_HIGH>;

linux,default-trigger = "timer";

default-state = "on";

};

}

echo 500 > /sys/class/leds/gpio_demo/delay_on

echo 500 > /sys/class/leds/gpio_demo/delay_off

这样操作后GPIO电平就会高500ms低500ms

oneshot

leds: leds {

compatible = "gpio-leds";

gpio_demo: gpio_demo {

label = "gpio_demo";

gpios = <&gpio0 RK_PC0 GPIO_ACTIVE_HIGH>;

linux,default-trigger = "oneshot";

default-state = "on";

};

}

echo 1000 > /sys/class/leds/gpio_demo/delay_on

echo 1 > /sys/class/leds/gpio_demo/short

这样就会让电平变高1秒后变低

如果invert设置1后那么就是变低1秒后变高

相关推荐
非 白1 小时前
数据结构——树
数据结构·笔记·考研
Christal_pyy3 小时前
树莓派4基于Debian GNU/Linux 12 (Bookworm)添加多个静态ipv4网络
linux·网络·debian
csbDD4 小时前
2025年网络安全(黑客技术)三个月自学手册
linux·网络·python·安全·web安全
E___V___E4 小时前
MySQL数据库入门到大蛇尚硅谷宋红康老师笔记 高级篇 part 2
数据库·笔记·mysql
李狗蛋儿啊4 小时前
zero自动化框架搭建---Git安装详解
运维·git·自动化
小金的学习笔记5 小时前
如何在本地和服务器新建mysql用户和密码
运维·服务器·mysql
s_fox_5 小时前
nginx ngx_http_module(7) 指令详解
运维·nginx·http
EasyNVR5 小时前
EasyRTC智能硬件:实时畅联、沉浸互动、消音护航
运维·服务器·网络·安全·音视频·webrtc·p2p
CarryBest5 小时前
Jenkins 环境搭建---基于 Docker
运维·jenkins
若云止水6 小时前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_process_options
运维·nginx