驱动_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以对应的常量名称显示

    

 

 

 https://blog.csdn.net/weixin_47397155/article/details/122879201   很好

 

 

 

             

 

posted @   panda_w  阅读(290)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示