struct input_dev — represents an input device

/*** big struct, for reference when using it ***/

 struct input_dev {
  const char * name;  // name of device
  const char * phys;  //physical path to device in system hierarchy
  const char * uniq; //unique identification code for the device
  struct input_id id;//id of the device 
  unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];
  //bitmap of device properties and quirks 
  unsigned long evbit[BITS_TO_LONGS(EV_CNT)];
//bitmap of types of events supported by the device (EV_KEY, EV_REL, etc.)
  unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
//bitmap of keys/buttons this device has
  unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
//bitmap of relative axes for the device
  unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
//bitmap of absolute axes for the device
  unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
//bitmap of miscellaneous events supported by the device
  unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
//bitmap of leds present on the device
  unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
//bitmap of sound effects supported by the device
  unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
//bitmap of force feedback effects supported by the device
  unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
//bitmap of switches present on the device
  unsigned int hint_events_per_packet;
//average number of events generated by the device in a packet (between EV_SYN/SYN_REPORT events). Used by event handlers to estimate size of the buffer needed to hold events.
  unsigned int keycodemax;
//size of keycode table
  unsigned int keycodesize;
//size of elements in keycode table
  void * keycode;
//map of scancodes to keycodes for this device.
  int (* setkeycode) (struct input_dev *dev,const struct input_keymap_entry *ke,unsigned int *old_keycode);
//optional method to alter current keymap, used to implement sparse keymaps. If not supplied default mechanism will be used. The method is being called while holding event_lock and thus must not sleep
  int (* getkeycode) (struct input_dev *dev,struct input_keymap_entry *ke);
//optional legacy method to retrieve current keymap.
  struct ff_device * ff;
//force feedback structure associated with the device if device supports force feedback effects
  unsigned int repeat_key;
//stores key code of the last key pressed; used to implement software autorepeat
  struct timer_list timer;
//timer for software autorepeat
  int rep[REP_CNT];
//current values for autorepeat parameters (delay, rate)
  struct input_mt * mt;
//pointer to multitouch state
  struct input_absinfo * absinfo;
//array of struct input_absinfo elements holding information about absolute axes (current value, min, max, flat, fuzz, resolution)
  unsigned long key[BITS_TO_LONGS(KEY_CNT)];
//reflects current state of device's keys/buttons
  unsigned long led[BITS_TO_LONGS(LED_CNT)];
//reflects current state of device's LEDs
  unsigned long snd[BITS_TO_LONGS(SND_CNT)];
//reflects current state of sound effects
  unsigned long sw[BITS_TO_LONGS(SW_CNT)];
//reflects current state of device's switches
  int (* open) (struct input_dev *dev);
// this method is called when the very first user calls input_open_device. The driver must prepare the device to start generating events (start polling thread, request an IRQ, submit URB, etc.)
  void (* close) (struct input_dev *dev);
//this method is called when the very last user calls input_close_device.
  int (* flush) (struct input_dev *dev, struct file *file);
//purges the device. Most commonly used to get rid of force feedback effects loaded into the device when disconnecting from it
  int (* event) (struct input_dev *dev, unsigned int type, unsigned int code, int value);
//event handler for events sent _to_ the device, like EV_LED or EV_SND. The device is expected to carry out the requested action (turn on a LED, play sound, etc.) The call is protected by event_lock and must not sleep
  struct input_handle __rcu * grab;
//input handle that currently has the device grabbed (via EVIOCGRAB ioctl). When a handle grabs a device it becomes sole recipient for all input events coming from the device
  spinlock_t event_lock;
//this spinlock is is taken when input core receives and processes a new event for the device (in input_event). Code that accesses and/or modifies parameters of a device (such as keymap or absmin, absmax, absfuzz, etc.) after device has been registered with input core must take this lock.
  struct mutex mutex;
//serializes calls to open, close and flush methods
  unsigned int users;
//stores number of users (input handlers) that opened this device. It is used by input_open_device and input_close_device to make sure that dev->openis only called when the first user opens device and dev->close is called when the very last user closes the device
  bool going_away;
//marks devices that are in a middle of unregistering and causes input_open_device*() fail with -ENODEV.
  struct device dev;
//driver model's view of this device
  struct list_head h_list;
//list of input handles associated with the device. When accessing the list dev->mutex must be held.
  struct list_head node;
//used to place the device onto input_dev_list
  unsigned int num_vals;
//number of values queued in the current frame
  unsigned int max_vals;
//maximum number of values queued in a frame
  struct input_value * vals;
//array of values queued in the current frame
  bool devres_managed;
//indicates that devices is managed with devres framework and needs not be explicitly unregistered or freed.
};

// following are definition of element structure used in struct input_dev

struct input_id {
	__u16 bustype;
	__u16 vendor;
	__u16 product;
	__u16 version;
};

struct input_absinfo {
	__s32 value;//latest reported value for the axis.
	__s32 minimum;//specifies minimum value for the axis.
	__s32 maximum;//specifies maximum value for the axis.
	__s32 fuzz;//specifies fuzz value that is used to filter noise from the event stream.
	__s32 flat;//values that are within this value will be discarded by joydev interface and reported as 0 instead.
	__s32 resolution;//specifies resolution for the values reported for the axis.
};
struct device {}; // too much content in this struct see another article <struct device — The basic device     structure> under the same hierarchy.




在 Linux 内核中,input_dev 结构体表示一个输入设备。它的定义在 `<linux/input.h>` 头文件中,包含了以下成员: - `char *name`:输入设备的名称。 - `struct bus_type *bus`:输入设备所连接的总线类型。 - `unsigned int id.bustype`:输入设备所连接的总线类型。 - `unsigned int id.vendor`:输入设备供应商 ID。 - `unsigned int id.product`:输入设备产品 ID。 - `unsigned int id.version`:输入设备版本号。 - `unsigned long evbit[EV_MAX/32 + 1]`:标志设备支持的事件类型,例如 EV_KEY、EV_REL、EV_ABS、EV_LED、EV_SND、EV_SW 和 EV_MSC 等。 - `unsigned long keybit[KEY_MAX/32 + 1]`:标志设备支持的键位,例如 KEY_ESC、KEY_ENTER、KEY_A 等。 - `unsigned long relbit[REL_MAX/32 + 1]`:标志设备支持的相对坐标事件,例如 REL_X、REL_Y 等。 - `unsigned long absbit[ABS_MAX/32 + 1]`:标志设备支持的绝对坐标事件,例如 ABS_X、ABS_Y 等。 - `unsigned long mscbit[MSC_MAX/32 + 1]`:标志设备支持的杂项事件,例如 MSC_SERIAL、MSC_PULSELED 等。 - `unsigned long key_len`:键位数组的长度。 - `unsigned long rel_len`:相对坐标事件数组的长度。 - `unsigned long abs_len`:绝对坐标事件数组的长度。 - `unsigned long msc_len`:杂项事件数组的长度。 - `unsigned long key_cnt`:键位个数。 - `unsigned long rel_cnt`:相对坐标事件个数。 - `unsigned long abs_cnt`:绝对坐标事件个数。 - `unsigned long msc_cnt`:杂项事件个数。 - `int (*open)(struct input_dev *dev)`:设备打开函数指针。 - `void (*close)(struct input_dev *dev)`:设备关闭函数指针。 - `int (*flush)(struct input_dev *dev, struct file *file)`:设备刷新函数指针。 - `int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value)`:设备事件处理函数指针。 - `int (*set_keycode)(struct input_dev *dev, const struct input_keymap_entry *ke, unsigned int *old_keycode)`:设备设置键位函数指针。 - `int (*getkeycode)(struct input_dev *dev, struct input_keymap_entry *ke)`:设备获取键位函数指针。 - `int (*set_drvdata)(struct input_dev *dev, void *data)`:设备设置私有数据函数指针。 - `void *driver_data`:设备私有数据指针。 这些成员描述了输入设备的基本属性,支持的事件类型和事件处理函数等。在注册输入设备时,需要设置这些成员的值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值