操作环境:
开发板:mini2440
CPU:(samsung)s3c2440
Linux版本:Linux-2.6.32.2
需要在linux内核配置里选上相关的配置。在内核源码目录下:
-
make menuconfig ARCH=arm CROSS_COMPILE=arm-linux-
-
-
Device Drivers --->
-
Input device support --->
-
[*] Keyboards --->
-
<*> GPIO Buttons
gpio_keys.h
-
#ifndef _GPIO_KEYS_H
-
#define _GPIO_KEYS_H
-
-
struct gpio_keys_button {
-
/* Configuration parameters */
-
int code; /* input event code (KEY_*, SW_*) */
-
int gpio;
-
int active_low;
-
char *desc;
-
int type; /* input event type (EV_KEY, EV_SW) */
-
int wakeup; /* configure the button as a wake-up source */
-
int debounce_interval; /* debounce ticks interval in msecs */
-
};
-
-
-
struct gpio_keys_platform_data {
-
struct gpio_keys_button *buttons;
-
int nbuttons;
-
unsigned int rep:1; /* enable input subsystem auto repeat */
-
-
const char *name; /* input device name */
-
-
};
-
-
#endif
mach-mini2440.c 中添加
-
#include
-
#include
-
#include
-
#include
-
#include
-
-
/* gpio-keys */
-
-
static struct gpio_keys_button s3c2440_gpio_keys_button[]=
-
{
-
{KEY_1, S3C2410_GPG(0), 1, "mygpio-key1", EV_KEY, 0, 100},
-
{KEY_2, S3C2410_GPG(3), 1, "mygpio-key2", EV_KEY, 0, 100},
-
{KEY_3, S3C2410_GPG(5), 1, "mygpio-key3", EV_KEY, 0, 100},
-
{KEY_4, S3C2410_GPG(6), 1, "mygpio-key4", EV_KEY, 0, 100},
-
{KEY_5, S3C2410_GPG(7), 1, "mygpio-key5", EV_KEY, 0, 100},
-
{KEY_6, S3C2410_GPG(11), 1, "mygpio-key6", EV_KEY, 0, 100},
-
};
-
-
static struct gpio_keys_platform_data s3c2440_gpio_keys_data=
-
{
-
.buttons=s3c2440_gpio_keys_button,
-
.nbuttons=ARRAY_SIZE(s3c2440_gpio_keys_button),
-
.rep = 1,
-
.name = "mygpio-keys",
-
};
-
-
static struct platform_device s3c2440_gpio_keys = {
-
.name = "gpio-keys",
-
.dev = {
-
.platform_data = &s3c2440_gpio_keys_data,
-
},
-
-
};
-
-
/* devices we initialise */
-
-
static struct platform_device *mini2440_devices[] __initdata = {
-
&s3c_device_usb,
-
&s3c_device_rtc,
-
&s3c_device_lcd,
-
&s3c_device_wdt,
-
&s3c_device_i2c0,
-
&s3c_device_iis,
-
&mini2440_device_eth,
-
&s3c24xx_uda134x,
-
&s3c_device_nand,
-
&s3c_device_sdi,
-
&s3c_device_usbgadget,
-
&s3c2440_gpio_keys,//only add this
-
};
重新编译内核并移植
使用hexdump命令,可以查看二进制数据。
-
struct input_event {
-
struct timeval time; //事件发生的时间(占据8字节)
-
__u16 type; //事件类型(占据2字节,比如按键类型事件,EV_KEY是1)
-
__u16 code; //事件的具体类型(占据2字节,比如按键L和S他们代表的十六进制数值)
-
__s32 value; //值(例如松开还是按下(占据4字节,1表示按下,0表示松开))
-
};
阅读(806) | 评论(0) | 转发(0) |