内核中带有GPIO控制按键的驱动,属于input子系统驱动,通用的驱动文件为:drivers/input/keyboard/gpio-keys.c
硬件接法:
KEY1 ---> GPF4
KEY2 ---> GPF5
KEY3 ---> GPF6
KEY4 ---> GPF7
低电平触发中断
在mach-xc2440.c中添加按键驱动的支持:
加入必要的头文件:
#include
#include
在xc2440_devices[ ]结构体中加入:
&xc2440_device_button,
实现platform_device:
- static struct platform_device xc2440_button_device = {
-
.name = "gpio-keys",
-
.id = -1,
-
.dev = {
-
.platform_data = &xc2440_button_data,
-
}
-
};
构建按键设备的platform_data:
- /* Buttons */
-
static struct gpio_keys_button xc2440_buttons[] = {
-
{
-
.gpio = S3C2410_GPF(4), /* K1 */
-
.code = KEY_F1,
-
.desc = "Button 1",
-
.active_low = 1,
-
},
-
{
-
.gpio = S3C2410_GPF(5), /* K2 */
-
.code = KEY_F2,
-
.desc = "Button 2",
-
.active_low = 1,
-
},
-
{
-
.gpio = S3C2410_GPF(6), /* K3 */
-
.code = KEY_F3,
-
.desc = "Button 3",
-
.active_low = 1,
-
},
-
{
-
.gpio = S3C2410_GPF(7), /* K4 */
-
.code = KEY_POWER,
-
.desc = "Button 4",
-
.active_low = 1,
-
},
-
};
-
-
Bstatic struct gpio_keys_platform_data xc2440_button_data = {
-
.buttons = xc2440_buttons,
-
.nbuttons = ARRAY_SIZE(xc2440_buttons),
-
};
参数说明:
gpio是连接按键的IO管脚
code是这个按键上报的键值, 在input.h中定义
desc是按键的name
active_low为1是表示低电平触发
配置内核,支持按键驱动:
- Device Drivers --->
- Input devices support --->
- [*]Keyboards --->
- <*> GPIO Buttons
系统启动时输出的调试信息:
input: gpio-keys as /devices/platform/gpio-keys/input/input0
查看设备:
/dev/event0 (注意:原来设备名为event0的设备,设备名会变成event1)
阅读(138) | 评论(0) | 转发(0) |