]>
Commit | Line | Data |
---|---|---|
eacaad01 HR |
1 | Multi-touch (MT) Protocol |
2 | ------------------------- | |
22f075a8 | 3 | Copyright (C) 2009-2010 Henrik Rydberg <rydberg@euromail.se> |
eacaad01 HR |
4 | |
5 | ||
6 | Introduction | |
7 | ------------ | |
8 | ||
72c8a94a HR |
9 | In order to utilize the full power of the new multi-touch and multi-user |
10 | devices, a way to report detailed data from multiple contacts, i.e., | |
11 | objects in direct contact with the device surface, is needed. This | |
12 | document describes the multi-touch (MT) protocol which allows kernel | |
13 | drivers to report details for an arbitrary number of contacts. | |
14 | ||
15 | The protocol is divided into two types, depending on the capabilities of the | |
16 | hardware. For devices handling anonymous contacts (type A), the protocol | |
17 | describes how to send the raw data for all contacts to the receiver. For | |
18 | devices capable of tracking identifiable contacts (type B), the protocol | |
19 | describes how to send updates for individual contacts via event slots. | |
20 | ||
21 | ||
22 | Protocol Usage | |
23 | -------------- | |
24 | ||
25 | Contact details are sent sequentially as separate packets of ABS_MT | |
26 | events. Only the ABS_MT events are recognized as part of a contact | |
27 | packet. Since these events are ignored by current single-touch (ST) | |
28 | applications, the MT protocol can be implemented on top of the ST protocol | |
29 | in an existing driver. | |
30 | ||
31 | Drivers for type A devices separate contact packets by calling | |
32 | input_mt_sync() at the end of each packet. This generates a SYN_MT_REPORT | |
33 | event, which instructs the receiver to accept the data for the current | |
34 | contact and prepare to receive another. | |
35 | ||
36 | Drivers for type B devices separate contact packets by calling | |
37 | input_mt_slot(), with a slot as argument, at the beginning of each packet. | |
38 | This generates an ABS_MT_SLOT event, which instructs the receiver to | |
39 | prepare for updates of the given slot. | |
40 | ||
41 | All drivers mark the end of a multi-touch transfer by calling the usual | |
42 | input_sync() function. This instructs the receiver to act upon events | |
43 | accumulated since last EV_SYN/SYN_REPORT and prepare to receive a new set | |
44 | of events/packets. | |
45 | ||
46 | The main difference between the stateless type A protocol and the stateful | |
47 | type B slot protocol lies in the usage of identifiable contacts to reduce | |
48 | the amount of data sent to userspace. The slot protocol requires the use of | |
49 | the ABS_MT_TRACKING_ID, either provided by the hardware or computed from | |
50 | the raw data [5]. | |
51 | ||
52 | For type A devices, the kernel driver should generate an arbitrary | |
53 | enumeration of the full set of anonymous contacts currently on the | |
54 | surface. The order in which the packets appear in the event stream is not | |
55 | important. Event filtering and finger tracking is left to user space [3]. | |
56 | ||
57 | For type B devices, the kernel driver should associate a slot with each | |
58 | identified contact, and use that slot to propagate changes for the contact. | |
59 | Creation, replacement and destruction of contacts is achieved by modifying | |
60 | the ABS_MT_TRACKING_ID of the associated slot. A non-negative tracking id | |
61 | is interpreted as a contact, and the value -1 denotes an unused slot. A | |
62 | tracking id not previously present is considered new, and a tracking id no | |
63 | longer present is considered removed. Since only changes are propagated, | |
64 | the full state of each initiated contact has to reside in the receiving | |
65 | end. Upon receiving an MT event, one simply updates the appropriate | |
66 | attribute of the current slot. | |
67 | ||
a93bd154 DK |
68 | Some devices identify and/or track more contacts than they can report to the |
69 | driver. A driver for such a device should associate one type B slot with each | |
70 | contact that is reported by the hardware. Whenever the identity of the | |
71 | contact associated with a slot changes, the driver should invalidate that | |
72 | slot by changing its ABS_MT_TRACKING_ID. If the hardware signals that it is | |
73 | tracking more contacts than it is currently reporting, the driver should use | |
74 | a BTN_TOOL_*TAP event to inform userspace of the total number of contacts | |
75 | being tracked by the hardware at that moment. The driver should do this by | |
76 | explicitly sending the corresponding BTN_TOOL_*TAP event and setting | |
77 | use_count to false when calling input_mt_report_pointer_emulation(). | |
78 | The driver should only advertise as many slots as the hardware can report. | |
79 | Userspace can detect that a driver can report more total contacts than slots | |
80 | by noting that the largest supported BTN_TOOL_*TAP event is larger than the | |
81 | total number of type B slots reported in the absinfo for the ABS_MT_SLOT axis. | |
72c8a94a | 82 | |
257867dc PH |
83 | The minimum value of the ABS_MT_SLOT axis must be 0. |
84 | ||
72c8a94a HR |
85 | Protocol Example A |
86 | ------------------ | |
87 | ||
88 | Here is what a minimal event sequence for a two-contact touch would look | |
89 | like for a type A device: | |
90 | ||
91 | ABS_MT_POSITION_X x[0] | |
92 | ABS_MT_POSITION_Y y[0] | |
93 | SYN_MT_REPORT | |
94 | ABS_MT_POSITION_X x[1] | |
95 | ABS_MT_POSITION_Y y[1] | |
96 | SYN_MT_REPORT | |
97 | SYN_REPORT | |
eacaad01 | 98 | |
72c8a94a HR |
99 | The sequence after moving one of the contacts looks exactly the same; the |
100 | raw data for all present contacts are sent between every synchronization | |
101 | with SYN_REPORT. | |
eacaad01 | 102 | |
72c8a94a | 103 | Here is the sequence after lifting the first contact: |
eacaad01 | 104 | |
72c8a94a HR |
105 | ABS_MT_POSITION_X x[1] |
106 | ABS_MT_POSITION_Y y[1] | |
107 | SYN_MT_REPORT | |
108 | SYN_REPORT | |
109 | ||
110 | And here is the sequence after lifting the second contact: | |
111 | ||
112 | SYN_MT_REPORT | |
113 | SYN_REPORT | |
114 | ||
115 | If the driver reports one of BTN_TOUCH or ABS_PRESSURE in addition to the | |
116 | ABS_MT events, the last SYN_MT_REPORT event may be omitted. Otherwise, the | |
117 | last SYN_REPORT will be dropped by the input core, resulting in no | |
118 | zero-contact event reaching userland. | |
119 | ||
120 | ||
121 | Protocol Example B | |
122 | ------------------ | |
123 | ||
124 | Here is what a minimal event sequence for a two-contact touch would look | |
125 | like for a type B device: | |
126 | ||
127 | ABS_MT_SLOT 0 | |
128 | ABS_MT_TRACKING_ID 45 | |
129 | ABS_MT_POSITION_X x[0] | |
130 | ABS_MT_POSITION_Y y[0] | |
131 | ABS_MT_SLOT 1 | |
132 | ABS_MT_TRACKING_ID 46 | |
133 | ABS_MT_POSITION_X x[1] | |
134 | ABS_MT_POSITION_Y y[1] | |
135 | SYN_REPORT | |
136 | ||
137 | Here is the sequence after moving contact 45 in the x direction: | |
138 | ||
139 | ABS_MT_SLOT 0 | |
140 | ABS_MT_POSITION_X x[0] | |
141 | SYN_REPORT | |
142 | ||
143 | Here is the sequence after lifting the contact in slot 0: | |
144 | ||
145 | ABS_MT_TRACKING_ID -1 | |
146 | SYN_REPORT | |
147 | ||
148 | The slot being modified is already 0, so the ABS_MT_SLOT is omitted. The | |
149 | message removes the association of slot 0 with contact 45, thereby | |
150 | destroying contact 45 and freeing slot 0 to be reused for another contact. | |
151 | ||
152 | Finally, here is the sequence after lifting the second contact: | |
153 | ||
154 | ABS_MT_SLOT 1 | |
155 | ABS_MT_TRACKING_ID -1 | |
156 | SYN_REPORT | |
157 | ||
158 | ||
159 | Event Usage | |
160 | ----------- | |
eacaad01 HR |
161 | |
162 | A set of ABS_MT events with the desired properties is defined. The events | |
163 | are divided into categories, to allow for partial implementation. The | |
f6bdc230 | 164 | minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which |
72c8a94a | 165 | allows for multiple contacts to be tracked. If the device supports it, the |
f6bdc230 | 166 | ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size |
cab7faca | 167 | of the contact area and approaching tool, respectively. |
f6bdc230 HR |
168 | |
169 | The TOUCH and WIDTH parameters have a geometrical interpretation; imagine | |
170 | looking through a window at someone gently holding a finger against the | |
171 | glass. You will see two regions, one inner region consisting of the part | |
172 | of the finger actually touching the glass, and one outer region formed by | |
cab7faca HR |
173 | the perimeter of the finger. The center of the touching region (a) is |
174 | ABS_MT_POSITION_X/Y and the center of the approaching finger (b) is | |
175 | ABS_MT_TOOL_X/Y. The touch diameter is ABS_MT_TOUCH_MAJOR and the finger | |
176 | diameter is ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger | |
177 | harder against the glass. The touch region will increase, and in general, | |
178 | the ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller | |
179 | than unity, is related to the contact pressure. For pressure-based devices, | |
f6bdc230 | 180 | ABS_MT_PRESSURE may be used to provide the pressure on the contact area |
e42a98b5 HR |
181 | instead. Devices capable of contact hovering can use ABS_MT_DISTANCE to |
182 | indicate the distance between the contact and the surface. | |
f6bdc230 | 183 | |
cab7faca HR |
184 | |
185 | Linux MT Win8 | |
186 | __________ _______________________ | |
187 | / \ | | | |
188 | / \ | | | |
189 | / ____ \ | | | |
190 | / / \ \ | | | |
191 | \ \ a \ \ | a | | |
192 | \ \____/ \ | | | |
193 | \ \ | | | |
194 | \ b \ | b | | |
195 | \ \ | | | |
196 | \ \ | | | |
197 | \ \ | | | |
198 | \ / | | | |
199 | \ / | | | |
200 | \ / | | | |
201 | \__________/ |_______________________| | |
202 | ||
203 | ||
204 | In addition to the MAJOR parameters, the oval shape of the touch and finger | |
205 | regions can be described by adding the MINOR parameters, such that MAJOR | |
206 | and MINOR are the major and minor axis of an ellipse. The orientation of | |
207 | the touch ellipse can be described with the ORIENTATION parameter, and the | |
208 | direction of the finger ellipse is given by the vector (a - b). | |
f6bdc230 | 209 | |
22f075a8 HR |
210 | For type A devices, further specification of the touch shape is possible |
211 | via ABS_MT_BLOB_ID. | |
212 | ||
f6bdc230 | 213 | The ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is a |
22f075a8 HR |
214 | finger or a pen or something else. Finally, the ABS_MT_TRACKING_ID event |
215 | may be used to track identified contacts over time [5]. | |
216 | ||
217 | In the type B protocol, ABS_MT_TOOL_TYPE and ABS_MT_TRACKING_ID are | |
218 | implicitly handled by input core; drivers should instead call | |
219 | input_mt_report_slot_state(). | |
f9fcfc3b | 220 | |
eacaad01 HR |
221 | |
222 | Event Semantics | |
223 | --------------- | |
224 | ||
eacaad01 HR |
225 | ABS_MT_TOUCH_MAJOR |
226 | ||
227 | The length of the major axis of the contact. The length should be given in | |
228 | surface units. If the surface has an X times Y resolution, the largest | |
f9fcfc3b | 229 | possible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [4]. |
eacaad01 HR |
230 | |
231 | ABS_MT_TOUCH_MINOR | |
232 | ||
233 | The length, in surface units, of the minor axis of the contact. If the | |
f9fcfc3b | 234 | contact is circular, this event can be omitted [4]. |
eacaad01 HR |
235 | |
236 | ABS_MT_WIDTH_MAJOR | |
237 | ||
238 | The length, in surface units, of the major axis of the approaching | |
239 | tool. This should be understood as the size of the tool itself. The | |
240 | orientation of the contact and the approaching tool are assumed to be the | |
f9fcfc3b | 241 | same [4]. |
eacaad01 HR |
242 | |
243 | ABS_MT_WIDTH_MINOR | |
244 | ||
245 | The length, in surface units, of the minor axis of the approaching | |
f9fcfc3b | 246 | tool. Omit if circular [4]. |
eacaad01 HR |
247 | |
248 | The above four values can be used to derive additional information about | |
249 | the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates | |
250 | the notion of pressure. The fingers of the hand and the palm all have | |
cab7faca | 251 | different characteristic widths. |
eacaad01 | 252 | |
f6bdc230 HR |
253 | ABS_MT_PRESSURE |
254 | ||
255 | The pressure, in arbitrary units, on the contact area. May be used instead | |
256 | of TOUCH and WIDTH for pressure-based devices or any device with a spatial | |
257 | signal intensity distribution. | |
258 | ||
e42a98b5 HR |
259 | ABS_MT_DISTANCE |
260 | ||
261 | The distance, in surface units, between the contact and the surface. Zero | |
262 | distance means the contact is touching the surface. A positive number means | |
263 | the contact is hovering above the surface. | |
264 | ||
eacaad01 HR |
265 | ABS_MT_ORIENTATION |
266 | ||
cab7faca HR |
267 | The orientation of the touching ellipse. The value should describe a signed |
268 | quarter of a revolution clockwise around the touch center. The signed value | |
269 | range is arbitrary, but zero should be returned for an ellipse aligned with | |
270 | the Y axis of the surface, a negative value when the ellipse is turned to | |
271 | the left, and a positive value when the ellipse is turned to the | |
272 | right. When completely aligned with the X axis, the range max should be | |
273 | returned. | |
274 | ||
275 | Touch ellipsis are symmetrical by default. For devices capable of true 360 | |
276 | degree orientation, the reported orientation must exceed the range max to | |
277 | indicate more than a quarter of a revolution. For an upside-down finger, | |
278 | range max * 2 should be returned. | |
279 | ||
280 | Orientation can be omitted if the touch area is circular, or if the | |
281 | information is not available in the kernel driver. Partial orientation | |
282 | support is possible if the device can distinguish between the two axis, but | |
283 | not (uniquely) any values in between. In such cases, the range of | |
284 | ABS_MT_ORIENTATION should be [0, 1] [4]. | |
eacaad01 HR |
285 | |
286 | ABS_MT_POSITION_X | |
287 | ||
288 | The surface X coordinate of the center of the touching ellipse. | |
289 | ||
290 | ABS_MT_POSITION_Y | |
291 | ||
292 | The surface Y coordinate of the center of the touching ellipse. | |
293 | ||
cab7faca HR |
294 | ABS_MT_TOOL_X |
295 | ||
296 | The surface X coordinate of the center of the approaching tool. Omit if | |
297 | the device cannot distinguish between the intended touch point and the | |
298 | tool itself. | |
299 | ||
300 | ABS_MT_TOOL_Y | |
301 | ||
302 | The surface Y coordinate of the center of the approaching tool. Omit if the | |
303 | device cannot distinguish between the intended touch point and the tool | |
304 | itself. | |
305 | ||
306 | The four position values can be used to separate the position of the touch | |
307 | from the position of the tool. If both positions are present, the major | |
308 | tool axis points towards the touch point [1]. Otherwise, the tool axes are | |
309 | aligned with the touch axes. | |
310 | ||
eacaad01 HR |
311 | ABS_MT_TOOL_TYPE |
312 | ||
313 | The type of approaching tool. A lot of kernel drivers cannot distinguish | |
314 | between different tool types, such as a finger or a pen. In such cases, the | |
315 | event should be omitted. The protocol currently supports MT_TOOL_FINGER and | |
22f075a8 HR |
316 | MT_TOOL_PEN [2]. For type B devices, this event is handled by input core; |
317 | drivers should instead use input_mt_report_slot_state(). | |
eacaad01 HR |
318 | |
319 | ABS_MT_BLOB_ID | |
320 | ||
321 | The BLOB_ID groups several packets together into one arbitrarily shaped | |
22f075a8 HR |
322 | contact. The sequence of points forms a polygon which defines the shape of |
323 | the contact. This is a low-level anonymous grouping for type A devices, and | |
72c8a94a HR |
324 | should not be confused with the high-level trackingID [5]. Most type A |
325 | devices do not have blob capability, so drivers can safely omit this event. | |
f9fcfc3b HR |
326 | |
327 | ABS_MT_TRACKING_ID | |
328 | ||
329 | The TRACKING_ID identifies an initiated contact throughout its life cycle | |
22f075a8 HR |
330 | [5]. The value range of the TRACKING_ID should be large enough to ensure |
331 | unique identification of a contact maintained over an extended period of | |
332 | time. For type B devices, this event is handled by input core; drivers | |
333 | should instead use input_mt_report_slot_state(). | |
f9fcfc3b HR |
334 | |
335 | ||
336 | Event Computation | |
337 | ----------------- | |
338 | ||
339 | The flora of different hardware unavoidably leads to some devices fitting | |
340 | better to the MT protocol than others. To simplify and unify the mapping, | |
341 | this section gives recipes for how to compute certain events. | |
342 | ||
343 | For devices reporting contacts as rectangular shapes, signed orientation | |
344 | cannot be obtained. Assuming X and Y are the lengths of the sides of the | |
345 | touching rectangle, here is a simple formula that retains the most | |
346 | information possible: | |
347 | ||
348 | ABS_MT_TOUCH_MAJOR := max(X, Y) | |
349 | ABS_MT_TOUCH_MINOR := min(X, Y) | |
350 | ABS_MT_ORIENTATION := bool(X > Y) | |
351 | ||
352 | The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that | |
353 | the device can distinguish between a finger along the Y axis (0) and a | |
354 | finger along the X axis (1). | |
eacaad01 | 355 | |
cab7faca HR |
356 | For win8 devices with both T and C coordinates, the position mapping is |
357 | ||
358 | ABS_MT_POSITION_X := T_X | |
359 | ABS_MT_POSITION_Y := T_Y | |
360 | ABS_MT_TOOL_X := C_X | |
361 | ABS_MT_TOOL_X := C_Y | |
362 | ||
363 | Unfortunately, there is not enough information to specify both the touching | |
364 | ellipse and the tool ellipse, so one has to resort to approximations. One | |
365 | simple scheme, which is compatible with earlier usage, is: | |
366 | ||
367 | ABS_MT_TOUCH_MAJOR := min(X, Y) | |
368 | ABS_MT_TOUCH_MINOR := <not used> | |
369 | ABS_MT_ORIENTATION := <not used> | |
370 | ABS_MT_WIDTH_MAJOR := min(X, Y) + distance(T, C) | |
371 | ABS_MT_WIDTH_MINOR := min(X, Y) | |
372 | ||
373 | Rationale: We have no information about the orientation of the touching | |
374 | ellipse, so approximate it with an inscribed circle instead. The tool | |
375 | ellipse should align with the the vector (T - C), so the diameter must | |
376 | increase with distance(T, C). Finally, assume that the touch diameter is | |
377 | equal to the tool thickness, and we arrive at the formulas above. | |
eacaad01 HR |
378 | |
379 | Finger Tracking | |
380 | --------------- | |
381 | ||
f9fcfc3b | 382 | The process of finger tracking, i.e., to assign a unique trackingID to each |
72c8a94a HR |
383 | initiated contact on the surface, is a Euclidian Bipartite Matching |
384 | problem. At each event synchronization, the set of actual contacts is | |
385 | matched to the set of contacts from the previous synchronization. A full | |
386 | implementation can be found in [3]. | |
f9fcfc3b HR |
387 | |
388 | ||
f6bdc230 HR |
389 | Gestures |
390 | -------- | |
391 | ||
392 | In the specific application of creating gesture events, the TOUCH and WIDTH | |
393 | parameters can be used to, e.g., approximate finger pressure or distinguish | |
394 | between index finger and thumb. With the addition of the MINOR parameters, | |
395 | one can also distinguish between a sweeping finger and a pointing finger, | |
396 | and with ORIENTATION, one can detect twisting of fingers. | |
397 | ||
398 | ||
eacaad01 HR |
399 | Notes |
400 | ----- | |
401 | ||
22f075a8 HR |
402 | In order to stay compatible with existing applications, the data reported |
403 | in a finger packet must not be recognized as single-touch events. | |
404 | ||
405 | For type A devices, all finger data bypasses input filtering, since | |
406 | subsequent events of the same type refer to different fingers. | |
eacaad01 | 407 | |
22f075a8 HR |
408 | For example usage of the type A protocol, see the bcm5974 driver. For |
409 | example usage of the type B protocol, see the hid-egalax driver. | |
eacaad01 | 410 | |
cab7faca | 411 | [1] Also, the difference (TOOL_X - POSITION_X) can be used to model tilt. |
eacaad01 | 412 | [2] The list can of course be extended. |
22f075a8 | 413 | [3] The mtdev project: http://bitmath.org/code/mtdev/. |
f9fcfc3b HR |
414 | [4] See the section on event computation. |
415 | [5] See the section on finger tracking. |