查看: 1975|回复: 0

linux 按键驱动代码分析

[复制链接]

该用户从未签到

发表于 2017-1-12 16:19:47 | 显示全部楼层 |阅读模式
分享到:
   linux 按键驱动代码分析

、按键驱动
1、对按键驱动添加设备信息
  按键的驱动定义在Gpio_keys.c (drivers\input\keyboard)  文件中,我们知道,只有平台设备和平台驱动两者的name名字一致才可以注册成功一个驱动。这里,内核代码中没有对按键平台信息的定 义,
     文件中对按键平台设备信息的定义,其中struct gpio_keys_button定义在Gpio_keys.h (include\Linux)文件中,其定义为:
struct gpio_keys_button {
      /* Configurationparameters */

      unsigned int code;      /* input event code (KEY_*, SW_*) */
/*************************************************************************************
按键对应的编码,其定义在Input.h(arch\arm\boot\dts\include\dt-bindings\input)中,这里只是告诉内核本按键的编码对应关系,可以根据Input.h的设置自己选择编码。

*******************************************************************************/


      int gpio;        /* -1 if this key does not support gpio*/
/*************************************************************************************
设置按键对应引脚,linux内核给每个gpio引脚设置了编号,每个编号对应一个引脚。

*******************************************************************************/


      int active_low;
/*************************************************************************************
设置按键低电平(低电平有效)

*******************************************************************************/

      const char *desc;
/*************************************************************************************
给按键起个名字,相当于led4 led5 led6等

*******************************************************************************/

      unsigned int type;       /* input event type (EV_KEY, EV_SW,EV_ABS) */
/*************************************************************************************
给设备设置按键类型,各种类型定义在Input.h (include\uapi\linux)文件中,主要有

EV_SYN 0x00 同步事件 EV_KEY0x01按键事件 EV_REL 0x02相对坐标 EV_ABS 0x03绝对坐标

EV_MSC 0x04 其它      EV_LED 0x11  LED    EV_SND 0x12声音     EV_REP 0x14 Repeat

EV_FF 0x15 力反馈 。。。。。。。

默认类型是EV_KEY(Documentation\devicetree\bindings\gpio \gpio_keys.txt)

*******************************************************************************/

      int wakeup;         /* configure the button as a wake-upsource */
/*************************************************************************************
设置是否设置为唤醒源

*******************************************************************************/

      int debounce_interval;       /* debounce ticks interval in msecs */
/*************************************************************************************
设置消抖间隔时间,单位毫秒,默认为5毫秒(Documentation\devicetree\bindings\gpio\gpio_keys.txt)

*******************************************************************************/


      bool can_disable;//设置是否共享中断
      int value;             /* axis value for EV_ABS */
/*************************************************************************************
绝对坐标值

*******************************************************************************/


      unsigned int irq;  /* Irq number in case of interrupt keys */
/*************************************************************************************
irq中断号的设定

*******************************************************************************/


};
结构体介绍完毕,那么就仿照Mach-mini2440.c在Common-smdk.c定义设备信息如下:

#include <linux/gpio_keys.h>
#include <linux/input.h>

static struct gpio_keys_button am335x_evm_gpio_buttons[] = {
        {

                .code                   = BTN_0,

                .gpio                   = GPIO_TO_PIN(0, 22),

                .desc                   = "SW1",

        },

        {

                .code                   = BTN_1,

                .gpio                   = GPIO_TO_PIN(0, 23),

                .desc                   = "SW2",

        },

        {

                .code                   = BTN_2,

                .gpio                   = GPIO_TO_PIN(0, 26),

                .desc                   = "SW3",

        },

        {

                .code                   = BTN_3,

                .gpio                   = GPIO_TO_PIN(0, 27),

                .desc                   = "SW4",

        },

};


回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /2 下一条

手机版|小黑屋|与非网

GMT+8, 2024-4-19 13:53 , Processed in 0.113248 second(s), 15 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.