📄 input.h
字号:
* @trigger: trigger conditions (struct ff_trigger) * @replay: scheduling of the effect (struct ff_replay) * @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect, * ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further * defining effect parameters * * This structure is sent through ioctl from the application to the driver. * To create a new effect aplication should set its @id to -1; the kernel * will return assigned @id which can later be used to update or delete * this effect. * * Direction of the effect is encoded as follows: * 0 deg -> 0x0000 (down) * 90 deg -> 0x4000 (left) * 180 deg -> 0x8000 (up) * 270 deg -> 0xC000 (right) */struct ff_effect { __u16 type; __s16 id; __u16 direction; struct ff_trigger trigger; struct ff_replay replay; union { struct ff_constant_effect constant; struct ff_ramp_effect ramp; struct ff_periodic_effect periodic; struct ff_condition_effect condition[2]; /* One for each axis */ struct ff_rumble_effect rumble; } u;};/* * Force feedback effect types */#define FF_RUMBLE 0x50#define FF_PERIODIC 0x51#define FF_CONSTANT 0x52#define FF_SPRING 0x53#define FF_FRICTION 0x54#define FF_DAMPER 0x55#define FF_INERTIA 0x56#define FF_RAMP 0x57#define FF_EFFECT_MIN FF_RUMBLE#define FF_EFFECT_MAX FF_RAMP/* * Force feedback periodic effect types */#define FF_SQUARE 0x58#define FF_TRIANGLE 0x59#define FF_SINE 0x5a#define FF_SAW_UP 0x5b#define FF_SAW_DOWN 0x5c#define FF_CUSTOM 0x5d#define FF_WAVEFORM_MIN FF_SQUARE#define FF_WAVEFORM_MAX FF_CUSTOM/* * Set ff device properties */#define FF_GAIN 0x60#define FF_AUTOCENTER 0x61#define FF_MAX 0x7f#ifdef __KERNEL__/* * In-kernel definitions. */#include <linux/device.h>#include <linux/fs.h>#include <linux/timer.h>#include <linux/mod_devicetable.h>#define NBITS(x) (((x)/BITS_PER_LONG)+1)#define BIT(x) (1UL<<((x)%BITS_PER_LONG))#define LONG(x) ((x)/BITS_PER_LONG)#define INPUT_KEYCODE(dev, scancode) ((dev->keycodesize == 1) ? ((u8*)dev->keycode)[scancode] : \ ((dev->keycodesize == 2) ? ((u16*)dev->keycode)[scancode] : (((u32*)dev->keycode)[scancode])))#define SET_INPUT_KEYCODE(dev, scancode, val) \ ({ unsigned __old; \ switch (dev->keycodesize) { \ case 1: { \ u8 *k = (u8 *)dev->keycode; \ __old = k[scancode]; \ k[scancode] = val; \ break; \ } \ case 2: { \ u16 *k = (u16 *)dev->keycode; \ __old = k[scancode]; \ k[scancode] = val; \ break; \ } \ default: { \ u32 *k = (u32 *)dev->keycode; \ __old = k[scancode]; \ k[scancode] = val; \ break; \ } \ } \ __old; })struct input_dev { void *private; const char *name; const char *phys; const char *uniq; struct input_id id; unsigned long evbit[NBITS(EV_MAX)]; unsigned long keybit[NBITS(KEY_MAX)]; unsigned long relbit[NBITS(REL_MAX)]; unsigned long absbit[NBITS(ABS_MAX)]; unsigned long mscbit[NBITS(MSC_MAX)]; unsigned long ledbit[NBITS(LED_MAX)]; unsigned long sndbit[NBITS(SND_MAX)]; unsigned long ffbit[NBITS(FF_MAX)]; unsigned long swbit[NBITS(SW_MAX)]; unsigned int keycodemax; unsigned int keycodesize; void *keycode; struct ff_device *ff; unsigned int repeat_key; struct timer_list timer; int state; int sync; int abs[ABS_MAX + 1]; int rep[REP_MAX + 1]; unsigned long key[NBITS(KEY_MAX)]; unsigned long led[NBITS(LED_MAX)]; unsigned long snd[NBITS(SND_MAX)]; unsigned long sw[NBITS(SW_MAX)]; int absmax[ABS_MAX + 1]; int absmin[ABS_MAX + 1]; int absfuzz[ABS_MAX + 1]; int absflat[ABS_MAX + 1]; 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); struct input_handle *grab; struct mutex mutex; /* serializes open and close operations */ unsigned int users; struct class_device cdev; struct list_head h_list; struct list_head node;};#define to_input_dev(d) container_of(d, struct input_dev, cdev)/* * Verify that we are in sync with input_device_id mod_devicetable.h #defines */#if EV_MAX != INPUT_DEVICE_ID_EV_MAX#error "EV_MAX and INPUT_DEVICE_ID_EV_MAX do not match"#endif#if KEY_MAX != INPUT_DEVICE_ID_KEY_MAX#error "KEY_MAX and INPUT_DEVICE_ID_KEY_MAX do not match"#endif#if REL_MAX != INPUT_DEVICE_ID_REL_MAX#error "REL_MAX and INPUT_DEVICE_ID_REL_MAX do not match"#endif#if ABS_MAX != INPUT_DEVICE_ID_ABS_MAX#error "ABS_MAX and INPUT_DEVICE_ID_ABS_MAX do not match"#endif#if MSC_MAX != INPUT_DEVICE_ID_MSC_MAX#error "MSC_MAX and INPUT_DEVICE_ID_MSC_MAX do not match"#endif#if LED_MAX != INPUT_DEVICE_ID_LED_MAX#error "LED_MAX and INPUT_DEVICE_ID_LED_MAX do not match"#endif#if SND_MAX != INPUT_DEVICE_ID_SND_MAX#error "SND_MAX and INPUT_DEVICE_ID_SND_MAX do not match"#endif#if FF_MAX != INPUT_DEVICE_ID_FF_MAX#error "FF_MAX and INPUT_DEVICE_ID_FF_MAX do not match"#endif#if SW_MAX != INPUT_DEVICE_ID_SW_MAX#error "SW_MAX and INPUT_DEVICE_ID_SW_MAX do not match"#endif#define INPUT_DEVICE_ID_MATCH_DEVICE \ (INPUT_DEVICE_ID_MATCH_BUS | INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT)#define INPUT_DEVICE_ID_MATCH_DEVICE_AND_VERSION \ (INPUT_DEVICE_ID_MATCH_DEVICE | INPUT_DEVICE_ID_MATCH_VERSION)struct input_handle;/** * struct input_handler - implements one of interfaces for input devices * @private: driver-specific data * @event: event handler * @connect: called when attaching a handler to an input device * @disconnect: disconnects a handler from input device * @start: starts handler for given handle. This function is called by * input core right after connect() method and also when a process * that "grabbed" a device releases it * @fops: file operations this driver implements * @minor: beginning of range of 32 minors for devices this driver * can provide * @name: name of the handler, to be shown in /proc/bus/input/handlers * @id_table: pointer to a table of input_device_ids this driver can * handle * @blacklist: prointer to a table of input_device_ids this driver should * ignore even if they match @id_table * @h_list: list of input handles associated with the handler * @node: for placing the driver onto input_handler_list */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, 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; const struct input_device_id *blacklist; struct list_head h_list; struct list_head node;};struct input_handle { void *private; int open; const char *name; struct input_dev *dev; struct input_handler *handler; struct list_head d_node; struct list_head h_node;};#define to_dev(n) container_of(n,struct input_dev,node)#define to_handler(n) container_of(n,struct input_handler,node);#define to_handle(n) container_of(n,struct input_handle,d_node)#define to_handle_h(n) container_of(n,struct input_handle,h_node)struct input_dev *input_allocate_device(void);void input_free_device(struct input_dev *dev);static inline struct input_dev *input_get_device(struct input_dev *dev){ return to_input_dev(class_device_get(&dev->cdev));}static inline void input_put_device(struct input_dev *dev){ class_device_put(&dev->cdev);}int input_register_device(struct input_dev *);void input_unregister_device(struct input_dev *);int input_register_handler(struct input_handler *);void input_unregister_handler(struct input_handler *);int input_grab_device(struct input_handle *);void input_release_device(struct input_handle *);int input_open_device(struct input_handle *);void input_close_device(struct input_handle *);int input_flush_device(struct input_handle* handle, struct file* file);void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);void input_inject_event(struct input_handle *handle, unsigned int type, unsigned int code, int value);static inline void input_report_key(struct input_dev *dev, unsigned int code, int value){ input_event(dev, EV_KEY, code, !!value);}static inline void input_report_rel(struct input_dev *dev, unsigned int code, int value){ input_event(dev, EV_REL, code, value);}static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value){ input_event(dev, EV_ABS, code, value);}static inline void input_report_ff_status(struct input_dev *dev, unsigned int code, int value){ input_event(dev, EV_FF_STATUS, code, value);}static inline void input_report_switch(struct input_dev *dev, unsigned int code, int value){ input_event(dev, EV_SW, code, !!value);}static inline void input_sync(struct input_dev *dev){ input_event(dev, EV_SYN, SYN_REPORT, 0);}static inline void input_set_abs_params(struct input_dev *dev, int axis, int min, int max, int fuzz, int flat){ dev->absmin[axis] = min; dev->absmax[axis] = max; dev->absfuzz[axis] = fuzz; dev->absflat[axis] = flat; dev->absbit[LONG(axis)] |= BIT(axis);}extern struct class input_class;/** * struct ff_device - force-feedback part of an input device * @upload: Called to upload an new effect into device * @erase: Called to erase an effect from device * @playback: Called to request device to start playing specified effect * @set_gain: Called to set specified gain * @set_autocenter: Called to auto-center device * @destroy: called by input core when parent input device is being * destroyed * @private: driver-specific data, will be freed automatically * @ffbit: bitmap of force feedback capabilities truly supported by * device (not emulated like ones in input_dev->ffbit) * @mutex: mutex for serializing access to the device * @max_effects: maximum number of effects supported by device * @effects: pointer to an array of effects currently loaded into device * @effect_owners: array of effect owners; when file handle owning * an effect gets closed the effcet is automatically erased * * Every force-feedback device must implement upload() and playback() * methods; erase() is optional. set_gain() and set_autocenter() need * only be implemented if driver sets up FF_GAIN and FF_AUTOCENTER * bits. */struct ff_device { int (*upload)(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old); int (*erase)(struct input_dev *dev, int effect_id); int (*playback)(struct input_dev *dev, int effect_id, int value); void (*set_gain)(struct input_dev *dev, u16 gain); void (*set_autocenter)(struct input_dev *dev, u16 magnitude); void (*destroy)(struct ff_device *); void *private; unsigned long ffbit[NBITS(FF_MAX)]; struct mutex mutex; int max_effects; struct ff_effect *effects; struct file *effect_owners[];};int input_ff_create(struct input_dev *dev, int max_effects);void input_ff_destroy(struct input_dev *dev);int input_ff_event(struct input_dev *dev, unsigned int type, unsigned int code, int value);int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, struct file *file);int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file);int input_ff_create_memless(struct input_dev *dev, void *data, int (*play_effect)(struct input_dev *, void *, struct ff_effect *));#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -