diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2011-04-06 22:39:12 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2011-04-06 22:39:12 +0200 |
| commit | f85ef93bb342001adecd9fe33bb7182f608390b1 (patch) | |
| tree | e43aaefeb9d01fc01ccfbb4cfe2f6f93ab764d78 /usr/src/dkms_source_tree/input-mt.h | |
Initial version of hid-multitouch-dkms packagev1.0.0
This is identical to jikos multitouch tree from 06APR2011.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'usr/src/dkms_source_tree/input-mt.h')
| -rw-r--r-- | usr/src/dkms_source_tree/input-mt.h | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/usr/src/dkms_source_tree/input-mt.h b/usr/src/dkms_source_tree/input-mt.h new file mode 100644 index 0000000..e53d274 --- /dev/null +++ b/usr/src/dkms_source_tree/input-mt.h | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | #ifndef _INPUT_MT_LOCAL_H | ||
| 2 | #define _INPUT_MT_LOCAL_H | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Input Multitouch Library | ||
| 6 | * | ||
| 7 | * Copyright (c) 2010 Henrik Rydberg | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify it | ||
| 10 | * under the terms of the GNU General Public License version 2 as published by | ||
| 11 | * the Free Software Foundation. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/version.h> | ||
| 15 | |||
| 16 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38) | ||
| 17 | |||
| 18 | #include <linux/input/mt.h> | ||
| 19 | |||
| 20 | #else | ||
| 21 | |||
| 22 | #include <linux/input.h> | ||
| 23 | |||
| 24 | #define MT_TOOL_MAX 1 | ||
| 25 | |||
| 26 | #define TRKID_MAX 0xffff | ||
| 27 | #define TRKID_SGN ((TRKID_MAX + 1) >> 1) | ||
| 28 | |||
| 29 | static int trkid; | ||
| 30 | |||
| 31 | static inline void input_abs_set_res(struct input_dev *dev, | ||
| 32 | unsigned int axis, int val) | ||
| 33 | { | ||
| 34 | dev->absres[axis] = val; | ||
| 35 | } | ||
| 36 | |||
| 37 | static inline void input_mt_set_value(struct input_mt_slot *slot, | ||
| 38 | unsigned code, int value) | ||
| 39 | { | ||
| 40 | slot->abs[code - ABS_MT_FIRST] = value; | ||
| 41 | } | ||
| 42 | |||
| 43 | static inline int input_mt_get_value(const struct input_mt_slot *slot, | ||
| 44 | unsigned code) | ||
| 45 | { | ||
| 46 | return slot->abs[code - ABS_MT_FIRST]; | ||
| 47 | } | ||
| 48 | |||
| 49 | static inline int input_mt_new_trkid(struct input_dev *dev) | ||
| 50 | { | ||
| 51 | return trkid++ & TRKID_MAX; | ||
| 52 | } | ||
| 53 | |||
| 54 | /** | ||
| 55 | * input_mt_init_slots() - initialize MT input slots | ||
| 56 | * @dev: input device supporting MT events and finger tracking | ||
| 57 | * @num_slots: number of slots used by the device | ||
| 58 | * | ||
| 59 | * This function allocates all necessary memory for MT slot handling | ||
| 60 | * in the input device, prepares the ABS_MT_SLOT and | ||
| 61 | * ABS_MT_TRACKING_ID events for use and sets up appropriate buffers. | ||
| 62 | * May be called repeatedly. Returns -EINVAL if attempting to | ||
| 63 | * reinitialize with a different number of slots. | ||
| 64 | */ | ||
| 65 | static int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots) | ||
| 66 | { | ||
| 67 | int ret; | ||
| 68 | |||
| 69 | if (dev->mt) | ||
| 70 | return dev->mtsize != num_slots ? -EINVAL : 0; | ||
| 71 | |||
| 72 | ret = input_mt_create_slots(dev, num_slots); | ||
| 73 | if (ret) | ||
| 74 | return ret; | ||
| 75 | |||
| 76 | input_set_abs_params(dev, ABS_MT_TRACKING_ID, 0, TRKID_MAX, 0, 0); | ||
| 77 | input_set_events_per_packet(dev, 6 * num_slots); | ||
| 78 | |||
| 79 | return 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | /** | ||
| 83 | * input_mt_report_state() - report contact state | ||
| 84 | * @dev: input device with allocated MT slots | ||
| 85 | * @active: true if contact is active, false otherwise | ||
| 86 | * | ||
| 87 | * Reports an active touch via ABS_MT_TRACKING_ID. If active is | ||
| 88 | * true and the slot is currently inactive, a new tracking id is | ||
| 89 | * assigned to the slot. | ||
| 90 | */ | ||
| 91 | static void input_mt_report_slot_state(struct input_dev *dev, unsigned type, | ||
| 92 | bool active) | ||
| 93 | { | ||
| 94 | struct input_mt_slot *mt = dev->mt; | ||
| 95 | int id; | ||
| 96 | |||
| 97 | if (!mt || !active) { | ||
| 98 | input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, -1); | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | id = input_mt_get_value(&mt[dev->slot], ABS_MT_TRACKING_ID); | ||
| 103 | if (id < 0) | ||
| 104 | id = input_mt_new_trkid(dev); | ||
| 105 | input_event(dev, EV_ABS, ABS_MT_TRACKING_ID, id); | ||
| 106 | } | ||
| 107 | |||
| 108 | /** | ||
| 109 | * input_mt_report_pointer_emulation() - common pointer emulation | ||
| 110 | * @dev: input device with allocated MT slots | ||
| 111 | * | ||
| 112 | * Performs legacy pointer emulation via BTN_TOUCH. | ||
| 113 | */ | ||
| 114 | static void input_mt_report_pointer_emulation(struct input_dev *dev, bool more) | ||
| 115 | { | ||
| 116 | struct input_mt_slot *oldest = 0; | ||
| 117 | int oldid = trkid; | ||
| 118 | int count = 0; | ||
| 119 | int i; | ||
| 120 | |||
| 121 | for (i = 0; i < dev->mtsize; ++i) { | ||
| 122 | struct input_mt_slot *ps = &dev->mt[i]; | ||
| 123 | int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID); | ||
| 124 | |||
| 125 | if (id < 0) | ||
| 126 | continue; | ||
| 127 | if ((id - oldid) & TRKID_SGN) { | ||
| 128 | oldest = ps; | ||
| 129 | oldid = id; | ||
| 130 | } | ||
| 131 | count++; | ||
| 132 | } | ||
| 133 | |||
| 134 | input_event(dev, EV_KEY, BTN_TOUCH, count > 0); | ||
| 135 | input_event(dev, EV_KEY, BTN_TOOL_FINGER, count == 1); | ||
| 136 | input_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, count == 2); | ||
| 137 | input_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, count == 3); | ||
| 138 | input_event(dev, EV_KEY, BTN_TOOL_QUADTAP, count > 3); | ||
| 139 | |||
| 140 | if (oldest) { | ||
| 141 | int x = input_mt_get_value(oldest, ABS_MT_POSITION_X); | ||
| 142 | int y = input_mt_get_value(oldest, ABS_MT_POSITION_Y); | ||
| 143 | int p = input_mt_get_value(oldest, ABS_MT_PRESSURE); | ||
| 144 | |||
| 145 | input_event(dev, EV_ABS, ABS_X, x); | ||
| 146 | input_event(dev, EV_ABS, ABS_Y, y); | ||
| 147 | input_event(dev, EV_ABS, ABS_PRESSURE, p); | ||
| 148 | } else { | ||
| 149 | input_event(dev, EV_ABS, ABS_PRESSURE, 0); | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | #endif | ||
| 154 | |||
| 155 | #endif | ||
