Chinaunix首页 | 论坛 | 博客
  • 博客访问: 933426
  • 博文数量: 70
  • 博客积分: 1741
  • 博客等级: 上尉
  • 技术积分: 2476
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-05 14:46
个人简介

全志全系列芯片产品方案开发 A20/A33/A64/A40/A60/A83/A63/H3/H5/H6/H8

文章存档

2018年(1)

2012年(20)

2011年(49)

分类: LINUX

2011-12-01 22:30:09

内核中带有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:
  1. static struct platform_device xc2440_button_device = {
  2.     .name        = "gpio-keys",
  3.     .id        = -1,
  4.     .dev        = {
  5.         .platform_data    = &xc2440_button_data,
  6.     }
  7. };

构建按键设备的platform_data:
  1. /* Buttons */
  2. static struct gpio_keys_button xc2440_buttons[] = {
  3.     {
  4.         .gpio        = S3C2410_GPF(4),        /* K1 */
  5.         .code        = KEY_F1,
  6.         .desc        = "Button 1",
  7.         .active_low    = 1,
  8.     },
  9.     {
  10.         .gpio        = S3C2410_GPF(5),        /* K2 */
  11.         .code        = KEY_F2,
  12.         .desc        = "Button 2",
  13.         .active_low    = 1,
  14.     },
  15.     {
  16.         .gpio        = S3C2410_GPF(6),        /* K3 */
  17.         .code        = KEY_F3,
  18.         .desc        = "Button 3",
  19.         .active_low    = 1,
  20.     },
  21.     {
  22.         .gpio        = S3C2410_GPF(7),        /* K4 */
  23.         .code        = KEY_POWER,
  24.         .desc        = "Button 4",
  25.         .active_low    = 1,
  26.     },
  27. };

  28. Bstatic struct gpio_keys_platform_data xc2440_button_data = {
  29.     .buttons    = xc2440_buttons,
  30.     .nbuttons    = ARRAY_SIZE(xc2440_buttons),
  31. };

参数说明:
gpio是连接按键的IO管脚
code是这个按键上报的键值, 在input.h中定义
desc是按键的name
active_low为1是表示低电平触发

配置内核,支持按键驱动:
  1. Device Drivers --->
  2.     Input devices support --->
  3. [*]Keyboards --->
  4.     <*> GPIO Buttons

系统启动时输出的调试信息:
input: gpio-keys as /devices/platform/gpio-keys/input/input0

查看设备:
/dev/event0    (注意:原来设备名为event0的设备,设备名会变成event1)

阅读(2550) | 评论(0) | 转发(4) |
给主人留下些什么吧!~~