LEDs
Linux内核的LED子系统是一种重要的框架,用于管理和控制设备上的LED指示灯。在嵌入式系统和物联网设备中,LED子系统发挥着关键作用,为开发者提供了一种统一的方式来控制和定制LED的行为和效果。
1. Linux 子系统框架图
led子系统主要核心文件:
driver/leds/led-class.c
driver/leds/led-core.c
driver/leds/led-triggers.c
还有一些其他文件,按照自己配置情况是否选用
kernel_imx_dev/drivers/leds$ ls
built-in.a leds-apu.c leds-da903x.c leds-ip30.c leds-locomo.c leds-max77693.c leds-pca963x.c leds-ti-lmu-common.c
Kconfig leds-ariel.c leds-da9052.c leds-ipaq-micro.c leds-lp3944.c leds-max8997.c leds-pm8058.c leds-tlc591xx.c
led-class.c leds-as3645a.c leds-dac124s085.c leds-is31fl319x.c leds-lp3952.c leds-mc13783.c leds-powernv.c leds-tps6105x.c
led-class-flash.c leds-asic3.c leds-el15203000.c leds-is31fl32xx.c leds-lp50xx.c leds-menf21bmc.c leds-pwm.c leds-turris-omnia.c
led-class-flash.o leds-aw2013.c leds-fsg.c leds-ktd2692.c leds-lp5521.c leds-mlxcpld.c leds-rb532.c leds-wm831x-status.c
led-class-multicolor.c leds-bcm6328.c leds-gpio.c leds-lm3530.c leds-lp5523.c leds-mlxreg.c leds-regulator.c leds-wm8350.c
led-class.o leds-bcm6358.c leds-gpio.ko leds-lm3532.c leds-lp5562.c leds-mt6323.c leds-s3c24xx.c leds-wrap.c
led-core.c leds-bd2802.c leds-gpio.mod leds-lm3533.c leds-lp55xx-common.c leds-net48xx.c leds-sc27xx-bltc.c led-triggers.c
led-core.o leds-blinkm.c leds-gpio.mod.c leds-lm355x.c leds-lp55xx-common.h leds-netxbig.c leds-sgm3140.c led-triggers.o
leds-88pm860x.c leds-clevo-mail.c leds-gpio.mod.o leds-lm3601x.c leds-lp8501.c leds-nic78bx.c leds-spi-byte.c Makefile
leds-aat1290.c leds-cobalt-qube.c leds-gpio.o leds-lm36274.c leds-lp8788.c leds-ns2.c leds-ss4200.c modules.order
leds-acer-a500.c leds-cobalt-raq.c leds-gpio-register.c leds-lm3642.c leds-lp8860.c leds-ot200.c leds-sunfire.c TODO
leds-adp5520.c leds-cpcap.c leds.h leds-lm3692x.c leds-lt3593.c leds-pca9532.c leds-syscon.c trigger
leds-an30259a.c leds-cr0014114.c leds-hp6xx.c leds-lm3697.c leds-max77650.c leds-pca955x.c leds-tca6507.c uleds.c
2. LED子系统使用的场景
3. LED子系统使用
修改设备树
leds {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = < &pinctrl_leds >;
vibrator {
label = "vibrator";
gpios = < &gpio5 2 GPIO_ACTIVE_HIGH >;
default-state = "off";
};
led0 {
label = "heartbeat";
gpios = < &gpio4 10 GPIO_ACTIVE_LOW >;
default-state = "on";
/*linux,default-trigger = "heartbeat";*/
};
led1 {
label = "led1";
gpios = < &gpio3 20 GPIO_ACTIVE_HIGH >;
default-state = "on";
};
led2 {
label = "led2";
gpios = < &gpio1 15 GPIO_ACTIVE_HIGH >;
default-state = "off";
};
};
内核配置相关
需要开启
CONFIG_LEDS_TRIGGERS 和 CONFIG_LEDS_TRIGGER_TIMER
编译完毕后,内核加载驱动后可以看到相关:
evk_8mq:/ # ls /sys/class/leds/
heartbeat led1 led2 mmc0:: mmc1:: vibrator
evk_8mq:/ # cd /sys/class/leds/led1
evk_8mq:/sys/class/leds/led1 # ls
brightness device max_brightness power subsystem trigger uevent
控制LED亮灭
evk_8mq:/sys/class/leds/led1 # echo 0 > brightness
evk_8mq:/sys/class/leds/led1 # echo 1 > brightness
查看触发方式:
evk_8mq:/sys/class/leds/led1 # cat trigger
[none] rc-feedback rfkill-any rfkill-none timer transient mmc1 mmc0 tcpm-source-psy-0-0022-online bq25700-charger-online cw2015-battery-charging-or-full cw2015-battery-charging cw2015-battery-full cw2015-battery-charging-blink-full-solid rfkill0
看到[none],表明是空,没有使用任何触发方式,这里将举例子,设置灯亮1秒钟:
采用timer 实现
evk_8mq:/sys/class/leds/heartbeat # echo timer > trigger
evk_8mq:/sys/class/leds/heartbeat # ls
brightness delay_on max_brightness subsystem uevent
delay_off device power trigger
#设置灯亮1秒钟
evk_8mq:/sys/class/leds/heartbeat # echo 1000 > delay_on
#灭1秒钟
evk_8mq:/sys/class/leds/heartbeat # echo 1000 > delay_off
采用transient实现
evk_8mq:/sys/class/leds/led1 # echo transient > trigger
evk_8mq:/sys/class/leds/led1 # ls
activate device max_brightness state trigger
brightness duration power subsystem uevent
#控制LED1 亮一秒熄灭:
echo 1 > state
echo 1000 > duration
echo 1 > activate
在设备树中,可以看到里面有一个
/ linux,default-trigger = "heartbeat"; /
这个可以在设备树选定它做为什么触发,这里是心跳方式
4. LED的trigger
LED的trigger (部分)种类和作用
全部0条评论
快来发表一下你的评论吧 !