input 输入设备平台驱动

原文:http://blog.163.com/jlz_325/blog/static/19174000920111175129216/

linux 3.1内核的驱动路(3) ---- input 输入设备平台驱动 

1,主机环境:VMare下linux5.7 ,384内存。

2,编译编译环境:arm-linux-gcc v4.4.3

3,开发板:FL2440,4M nor flash,256M nand flash。

 

移植参照MINI2440的示例代码:

1:  首先是平台设备的注册

#include <linux/module.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <mach/regs-gpio.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/io.h>
#include <linux/gpio_keys.h>
#include <linux/input.h>

/*平台资源的定义*/
static struct gpio_keys_button FL2440_buttons[] = {
 {
  .gpio  = S3C2410_GPF(0),  /* K1 */
  .code  = KEY_F1,
  .desc  = "Button 1",
  .active_low = 1,
 },
 {
  .gpio  = S3C2410_GPF(2),  /* K2 */
  .code  = KEY_F2,
  .desc  = "Button 2",
  .active_low = 1,
 },
 {
  .gpio  = S3C2410_GPF(3),  /* K3 */
  .code  = KEY_F3,
  .desc  = "Button 3",
  .active_low = 1,
 },
 {
  .gpio  = S3C2410_GPF(4),  /* K4 */
  .code  = KEY_POWER,
  .desc  = "Button 4",
  .active_low = 1,
 },
};

static struct gpio_keys_platform_data FL2440_button_data = {
 .buttons = FL2440_buttons,
 .nbuttons = ARRAY_SIZE(FL2440_buttons),
};

static void my_dev_release(struct device *dev)
{
 
}

static struct platform_device FL2440_button_device = {
 .name  = "gpio-keys",
 .id  = -1,
 .dev  = {
  .platform_data = &FL2440_button_data,
  .release = my_dev_release,
 }
};

static int __init platform_init(void)
{
    /*平台设备的注册*/
    platform_device_register(&FL2440_button_device);
   
    return 0;
}

static void __exit platform_exit(void)
{
    platform_device_unregister(&FL2440_button_device);
}

module_init(platform_init);
module_exit(platform_exit);

MODULE_AUTHOR("Smart.zhao");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:FL2440buttons");

 

2:  下面是平台驱动的注册。

        直接使用drivers\intput\keyboard\gpio_keys.c作为平台驱动。

 

3: 当加载完驱动,设备后系统会有以下提示

intpu: gpio-keys as /devices/platform/gpio-keys/input/intput0

4:  测试平台设备和驱动是否正常工作。

以下是测试代码:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
#include <linux/input.h>

int main(void)
{
 int buttons_fd;
 int key_value,i=0,count;

 struct input_event ev_key;

 buttons_fd = open("/dev/event0", O_RDWR);
 if (buttons_fd < 0) {
  perror("open device buttons");
  exit(1);
 }

 for (;;) {
  count = read(buttons_fd,&ev_key,sizeof(struct input_event));

  for(i=0; i<(int)count/sizeof(struct input_event); i++)
   if(EV_KEY==ev_key.type)
    printf("type:%d,code:%d,value:%d\n", ev_key.type,ev_key.code,ev_key.value);

   if(EV_SYN==ev_key.type)
    printf("syn event\n\n");
 }

 close(buttons_fd);
 return 0;
}

 

5:  如果有需要加入内核的话,那么只需要把平台设备的代码加入到arch\arm\plat-s3c24xx\common-smdk.c中即可。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值