内核中带有GPIO控制LED的驱动,通用的驱动文件为:drivers/leds/leds-gpio.c
硬件接法:
LED1 --> GPF0
LED2 --> GPF1
LED3 --> GPF2
LED4 --> GPF3
低电平点亮,高电平熄灭
在mach-xc2440.c中添加LED驱动的支持:
加入必要的头文件:
#include
在xc2440_devices[ ]结构体中加入:
&xc2440_device_led,
构建LED设备的platform_device:
- static struct platform_device xc2440_device_led = {
-
.name = "leds-gpio",
-
.id = -1,
-
.dev = {
-
.platform_data = &xc2440_gpio_led_pdata,
-
},
-
};
构建LED设备的platform_data:
- /* LEDS */
-
static struct gpio_led xc2440_leds[] = {
-
[0] = {
-
.name = "led1",
-
.gpio = S3C2410_GPF(0),
-
.active_low = 1,
-
},
-
[1] = {
-
.name = "led2",
-
.gpio = S3C2410_GPF(1),
-
.active_low = 1,
-
},
-
[2] = {
-
.name = "led3",
-
.gpio = S3C2410_GPF(2),
-
.active_low = 1,
-
},
-
[3] = {
-
.name = "led4",
-
.gpio = S3C2410_GPF(3),
-
.active_low = 1,
-
},
-
};
-
-
static struct gpio_led_platform_data xc2440_gpio_led_pdata = {
-
.num_leds = ARRAY_SIZE(xc2440_leds),
-
.leds = xc2440_leds,
-
};
参数说明:
name: led的name,一个字符串
gpio:操作它的GPIO管脚
active_low:为1是低电平点亮,为0是高电平点亮
配置内核,支持LED驱动:
- Device Drivers --->
- [*] LED Support --->
- <*> LED Support for GPIO connected LEDs
- [*] Platform device bindings for GPIO LEDs(NEW)
查看设备:
/sys/class/leds/ledx (x为0,1,2,3)
操作方法:
#echo 1 > /sys/class/leds/led0/brightness 让LED0亮
#echo 0 > /sys/class/leds/led0/brightness 让LED0灭
阅读(322) | 评论(0) | 转发(0) |