Linux input设备驱动
Linux input设备驱动
一. 输入设备结构体
1. input_dev 输入设备
struct input_dev {
const char *name; //设备名
const char *phys; //设备系统层的物理路径
const char *uniq; //
struct input_id id; //输入设备id 总线类型;厂商编号,产品id,产品版本
unsigned long evbit[BITS_TO_LONGS(EV_CNT)]; //事件类型标志位
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)]; //led指示灯标志位
unsigned long sndbit[BITS_TO_LONGS(SND_CNT)]; //声音事件
unsigned long ffbit[BITS_TO_LONGS(FF_CNT)]; //强制反馈事件
unsigned long swbit[BITS_TO_LONGS(SW_CNT)]; //开关事件标志位
unsigned int hint_events_per_packet;
unsigned int keycodemax; //键盘码表大小
unsigned int keycodesize; //键盘码大小
void *keycode; //键盘码表指针
int (*setkeycode)(struct input_dev *dev,unsigned int scancode, unsigned int keycode); //设置键盘码
int (*getkeycode)(struct input_dev *dev,unsigned int scancode, unsigned int *keycode); //获取键盘码
int (*setkeycode_new)(struct input_dev *dev,const struct input_keymap_entry *ke,unsigned int *old_keycode);
int (*getkeycode_new)(struct input_dev *dev,struct input_keymap_entry *ke);
struct ff_device *ff; //强制反馈设备
unsigned int repeat_key; //重复按键标志位
struct timer_list timer; //定时器
int rep[REP_CNT]; //重复次数
struct input_mt_slot *mt;
int mtsize;
int slot;
struct input_absinfo *absinfo;
unsigned long key[BITS_TO_LONGS(KEY_CNT)]; //
unsigned long led[BITS_TO_LONGS(LED_CNT)]; //
unsigned long snd[BITS_TO_LONGS(SND_CNT)]; //
unsigned long sw[BITS_TO_LONGS(SW_CNT)]; //
int (*open)(struct input_dev *dev); //open方法
void (*close)(struct input_dev *dev); //close方法
int (*flush)(struct input_dev *dev, struct file *file);
int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
struct input_handle __rcu *grab;
spinlock_t event_lock;
struct mutex mutex;
unsigned int users;
bool going_away;
bool sync;
struct device dev; //设备文件
struct list_head h_list; //input_handler处理器链表头
struct list_head node; //input_device设备链表头
};
2. input_handler 输入处理器
struct input_handler {
void *private; //私有数据
void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value); //事件处理
bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value); //过滤器
bool (*match)(struct input_handler *handler, struct input_dev *dev); //设备匹配
int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id); //设备连接
void (*disconnect)(struct input_handle *handle); //设备断开连接
void (*start)(struct input_handle *handle);
const struct file_operations *fops; //输入操作函数集
int minor; //次设备号
const char *name; //设备名
const struct input_device_id *id_table; //输入设备 id表
struct list_head h_list; //input_handler处理器链表头
struct list_head node; //input_device设备链表头
};
|
评论暂时关闭