(相关资料图)
/kernel/include/linux/leds.h // 重要,led相关结构体,宏定义,trigger等目录 /kernel/driver/leds/ 下led-class.c // 定义led class及相关接口led-core.c // export 了闪烁,设置亮灭等接口led-gpio.c // "leds-gpio" 驱动leds.h // 提供几个接口,如:led_init_core
trigger 框架核心文件:目录 /kernel/driver/leds/ 下 led-triggers.c // export了许多接口,包括:led_trigger_register目录 /kernel/driver/leds/trigger 下 ledtrig-backlight.c ledtrig-camera.c ledtrig-cpu.c ledtrig-default-on.c ledtrig-disk.c ledtrig-gpio.c ledtrig-heartbeat.c // 心跳灯效果 ledtrig-mtd.c ledtrig-oneshot.c ledtrig-panic.c ledtrig-timer.c // 定时器ledtrig-transient.c
以参考上面的trigger例子写自己的trigger,或者改造,需要在make menuconfig里面选上才会编译,如下:
步骤 一 : dts配置① leds节点是在rk3588-evb.dtsi文件中定义
#include "rk3588-evb.dtsi"
② 定义四个led节点: (检查gpio是否被复用)
使用命令:dmesg | grep cannot检查是否有gpio冲突,有冲突的话驱动代码会中断,后面的dts就不会生效。
&leds { status = "okay"; compatible = "gpio-leds"; pinctrl-names = "default"; pinctrl-0 = < &work1_led_gpio >, < &work2_led_gpio >,< &work3_led_gpio >,< &work4_led_gpio >; work1_led: work1{ default-state = "off"; gpios = < &gpio4 RK_PD2 GPIO_ACTIVE_HIGH >; }; work2_led: work2{ default-state = "off"; gpios = < &gpio4 RK_PD3 GPIO_ACTIVE_HIGH >; }; work3_led: work3{ default-state = "off"; gpios = < &gpio4 RK_PD4 GPIO_ACTIVE_HIGH >; }; work4_led: work4{ default-state = "off"; gpios = < &gpio4 RK_PD5 GPIO_ACTIVE_HIGH >; };};&pinctrl { leds{ work1_led_gpio: work1-led-gpio{ rockchip,pins = < 4 RK_PD2 RK_FUNC_GPIO &pcfg_pull_down >; }; work2_led_gpio: work2-led-gpio{ rockchip,pins = < 4 RK_PD3 RK_FUNC_GPIO &pcfg_pull_down >; }; work3_led_gpio: work3-led-gpio{ rockchip,pins = < 4 RK_PD4 RK_FUNC_GPIO &pcfg_pull_down >; }; work4_led_gpio: work4-led-gpio{ rockchip,pins = < 4 RK_PD5 RK_FUNC_GPIO &pcfg_pull_down >; }; }; }
步骤二:调试,验证:在用户空间操作led
使用了驱动框架后可以不需要编写应用程序就可以测试led是否能正常被点亮与熄灭,这些都可以在sysfs文件系统中完成。在装载驱动后可以在/sys/class/leds/目录下看到对应的led设备目录,如本文中的work1(填充设备时的设备名字段)。
brightness power ueventmax_brightness subsystem
echo 1 > brightness
echo 0 > brightness
审核编辑:汤梓红