驱动_Input输入子系统


 

<结构体>

struct input_handler {
      void *private;
      void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
      struct input_handle* (*connect)(struct input_handler *handler, struct input_dev *dev, struct input_device_id *id);
      void (*disconnect)(struct input_handle *handle);
 
      const struct file_operations *fops;      //提供给用户对设备操作的函数指针
      int minor;
      char *name;
 
      struct input_device_id *id_table;      //与input_dev匹配用的id
      struct input_device_id *blacklist;      //标记的黑名单
 
      struct list_head      h_list;            //用于链接和该handler相关的handle
      struct list_head      node;            //用于将该handler链入input_handler_list
};
struct input_handle {
      void *private;
      int open;      //记录设备打开次数
      char *name;
      struct input_dev *dev;      //指向所属的input_dev
      struct input_handler *handler;      //指向所属的input_handler
      struct list_head      d_node;            //用于链入所指向的input_dev的handle链表
      struct list_head      h_node;            //用于链入所指向的input_handler的handle链表
};

  struct input_dev {
    const char *name;
    const char *phys;
    const char *uniq;
    struct input_id id;

    //位表
    unsigned long evbit[BITS_TO_LONGS(EV_CNT)]; //表示能够产生哪种类型的数据:EV_KEY,EV_ABS
    unsigned long keybit[BITS_TO_LONGS(KEY_CNT)]; //表示能够产生哪些按键数据
    unsigned long relbit[BITS_TO_LONGS(REL_CNT)]; //表示能够产生哪些相对坐标数据
    unsigned long absbit[BITS_TO_LONGS(ABS_CNT)]; //表示能够产生哪些绝对坐标数据
    unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
    unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
    unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
    unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
    unsigned long swbit[BITS_TO_LONGS(SW_CNT)];

    struct device dev; //父类

    struct list_head h_list;
    struct list_head node; //链表的节点
  };

  struct input_event {   //上报给用户的输入设备的数据包的类型
    struct timeval time; //时间戳
    __u16 type; //读到的数据类型:EV_KEY,EV_ABS,EV_REL
    __u16 code; //编码值
    __s32 value; //状态
  };

 <笔记>


1.input handler    用户交互,不知数据,只知上传

2.input_core   维护了两个链表,为上下层提供接口,他不是总线!!

3.input device      硬件交互,知道数据,不知上传

4.编程:

  1,分配一个 input device对象
  2,初始化input device对象
  3,注册input device对象
  4,硬件初始化,获取到硬件的数据,上报给input handler

5.代码:

   key:https://www.cnblogs.com/panda-w/p/10943249.html

    ts  :https://www.cnblogs.com/panda-w/p/10949993.html

6.input_core层也实现了一个fops,但只实现了open,就回到了input_handler层,所以他第一个打开 

7.一个设备对应一个connect方法,对应一个设备节点,对应一个event对象,对应一个input_handle,对应一个event_client缓冲队列,所以数据上报不会混乱

8.应用程序会根据设备号找到对应的缓冲队列

9. getevent -l   :type、code、value以对应的常量名称显示

    

             

Stay hungry, stay foolish 待续。。。
原文地址:https://www.cnblogs.com/panda-w/p/10922744.html