blob: 8490480ce4327beb95bb5936c8d55609a7ce7c82 [file] [log] [blame]
Henrik Rydbergeacaad02009-04-28 07:49:21 -07001Multi-touch (MT) Protocol
2-------------------------
3 Copyright (C) 2009 Henrik Rydberg <rydberg@euromail.se>
4
5
6Introduction
7------------
8
9In order to utilize the full power of the new multi-touch devices, a way to
10report detailed finger data to user space is needed. This document
11describes the multi-touch (MT) protocol which allows kernel drivers to
12report details for an arbitrary number of fingers.
13
14
15Usage
16-----
17
18Anonymous finger details are sent sequentially as separate packets of ABS
19events. Only the ABS_MT events are recognized as part of a finger
20packet. The end of a packet is marked by calling the input_mt_sync()
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -070021function, which generates a SYN_MT_REPORT event. This instructs the
22receiver to accept the data for the current finger and prepare to receive
23another. The end of a multi-touch transfer is marked by calling the usual
24input_sync() function. This instructs the receiver to act upon events
25accumulated since last EV_SYN/SYN_REPORT and prepare to receive a new
26set of events/packets.
Henrik Rydbergeacaad02009-04-28 07:49:21 -070027
28A set of ABS_MT events with the desired properties is defined. The events
29are divided into categories, to allow for partial implementation. The
Henrik Rydbergf6bdc232010-01-28 22:28:28 -080030minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which
31allows for multiple fingers to be tracked. If the device supports it, the
32ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size
33of the contact area and approaching finger, respectively.
34
35The TOUCH and WIDTH parameters have a geometrical interpretation; imagine
36looking through a window at someone gently holding a finger against the
37glass. You will see two regions, one inner region consisting of the part
38of the finger actually touching the glass, and one outer region formed by
39the perimeter of the finger. The diameter of the inner region is the
40ABS_MT_TOUCH_MAJOR, the diameter of the outer region is
41ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger harder
42against the glass. The inner region will increase, and in general, the
43ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller than
44unity, is related to the finger pressure. For pressure-based devices,
45ABS_MT_PRESSURE may be used to provide the pressure on the contact area
46instead.
47
48In addition to the MAJOR parameters, the oval shape of the finger can be
49described by adding the MINOR parameters, such that MAJOR and MINOR are the
50major and minor axis of an ellipse. Finally, the orientation of the oval
51shape can be describe with the ORIENTATION parameter.
52
53The ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is a
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -070054finger or a pen or something else. Devices with more granular information
55may specify general shapes as blobs, i.e., as a sequence of rectangular
56shapes grouped together by an ABS_MT_BLOB_ID. Finally, for the few devices
57that currently support it, the ABS_MT_TRACKING_ID event may be used to
58report finger tracking from hardware [5].
59
60Here is what a minimal event sequence for a two-finger touch would look
61like:
62
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -070063 ABS_MT_POSITION_X
64 ABS_MT_POSITION_Y
65 SYN_MT_REPORT
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -070066 ABS_MT_POSITION_X
67 ABS_MT_POSITION_Y
68 SYN_MT_REPORT
69 SYN_REPORT
Henrik Rydbergeacaad02009-04-28 07:49:21 -070070
71
72Event Semantics
73---------------
74
75The word "contact" is used to describe a tool which is in direct contact
76with the surface. A finger, a pen or a rubber all classify as contacts.
77
78ABS_MT_TOUCH_MAJOR
79
80The length of the major axis of the contact. The length should be given in
81surface units. If the surface has an X times Y resolution, the largest
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -070082possible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [4].
Henrik Rydbergeacaad02009-04-28 07:49:21 -070083
84ABS_MT_TOUCH_MINOR
85
86The length, in surface units, of the minor axis of the contact. If the
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -070087contact is circular, this event can be omitted [4].
Henrik Rydbergeacaad02009-04-28 07:49:21 -070088
89ABS_MT_WIDTH_MAJOR
90
91The length, in surface units, of the major axis of the approaching
92tool. This should be understood as the size of the tool itself. The
93orientation of the contact and the approaching tool are assumed to be the
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -070094same [4].
Henrik Rydbergeacaad02009-04-28 07:49:21 -070095
96ABS_MT_WIDTH_MINOR
97
98The length, in surface units, of the minor axis of the approaching
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -070099tool. Omit if circular [4].
Henrik Rydbergeacaad02009-04-28 07:49:21 -0700100
101The above four values can be used to derive additional information about
102the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates
103the notion of pressure. The fingers of the hand and the palm all have
104different characteristic widths [1].
105
Henrik Rydbergf6bdc232010-01-28 22:28:28 -0800106ABS_MT_PRESSURE
107
108The pressure, in arbitrary units, on the contact area. May be used instead
109of TOUCH and WIDTH for pressure-based devices or any device with a spatial
110signal intensity distribution.
111
Henrik Rydbergeacaad02009-04-28 07:49:21 -0700112ABS_MT_ORIENTATION
113
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -0700114The orientation of the ellipse. The value should describe a signed quarter
115of a revolution clockwise around the touch center. The signed value range
116is arbitrary, but zero should be returned for a finger aligned along the Y
117axis of the surface, a negative value when finger is turned to the left, and
118a positive value when finger turned to the right. When completely aligned with
119the X axis, the range max should be returned. Orientation can be omitted
120if the touching object is circular, or if the information is not available
121in the kernel driver. Partial orientation support is possible if the device
122can distinguish between the two axis, but not (uniquely) any values in
123between. In such cases, the range of ABS_MT_ORIENTATION should be [0, 1]
124[4].
Henrik Rydbergeacaad02009-04-28 07:49:21 -0700125
126ABS_MT_POSITION_X
127
128The surface X coordinate of the center of the touching ellipse.
129
130ABS_MT_POSITION_Y
131
132The surface Y coordinate of the center of the touching ellipse.
133
134ABS_MT_TOOL_TYPE
135
136The type of approaching tool. A lot of kernel drivers cannot distinguish
137between different tool types, such as a finger or a pen. In such cases, the
138event should be omitted. The protocol currently supports MT_TOOL_FINGER and
139MT_TOOL_PEN [2].
140
141ABS_MT_BLOB_ID
142
143The BLOB_ID groups several packets together into one arbitrarily shaped
144contact. This is a low-level anonymous grouping, and should not be confused
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -0700145with the high-level trackingID [5]. Most kernel drivers will not have blob
146capability, and can safely omit the event.
147
148ABS_MT_TRACKING_ID
149
150The TRACKING_ID identifies an initiated contact throughout its life cycle
151[5]. There are currently only a few devices that support it, so this event
152should normally be omitted.
153
154
155Event Computation
156-----------------
157
158The flora of different hardware unavoidably leads to some devices fitting
159better to the MT protocol than others. To simplify and unify the mapping,
160this section gives recipes for how to compute certain events.
161
162For devices reporting contacts as rectangular shapes, signed orientation
163cannot be obtained. Assuming X and Y are the lengths of the sides of the
164touching rectangle, here is a simple formula that retains the most
165information possible:
166
167 ABS_MT_TOUCH_MAJOR := max(X, Y)
168 ABS_MT_TOUCH_MINOR := min(X, Y)
169 ABS_MT_ORIENTATION := bool(X > Y)
170
171The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that
172the device can distinguish between a finger along the Y axis (0) and a
173finger along the X axis (1).
Henrik Rydbergeacaad02009-04-28 07:49:21 -0700174
175
176Finger Tracking
177---------------
178
179The kernel driver should generate an arbitrary enumeration of the set of
180anonymous contacts currently on the surface. The order in which the packets
181appear in the event stream is not important.
182
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -0700183The process of finger tracking, i.e., to assign a unique trackingID to each
Henrik Rydbergeacaad02009-04-28 07:49:21 -0700184initiated contact on the surface, is left to user space; preferably the
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -0700185multi-touch X driver [3]. In that driver, the trackingID stays the same and
Henrik Rydbergeacaad02009-04-28 07:49:21 -0700186unique until the contact vanishes (when the finger leaves the surface). The
187problem of assigning a set of anonymous fingers to a set of identified
188fingers is a euclidian bipartite matching problem at each event update, and
189relies on a sufficiently rapid update rate.
190
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -0700191There are a few devices that support trackingID in hardware. User space can
192make use of these native identifiers to reduce bandwidth and cpu usage.
193
194
Henrik Rydbergf6bdc232010-01-28 22:28:28 -0800195Gestures
196--------
197
198In the specific application of creating gesture events, the TOUCH and WIDTH
199parameters can be used to, e.g., approximate finger pressure or distinguish
200between index finger and thumb. With the addition of the MINOR parameters,
201one can also distinguish between a sweeping finger and a pointing finger,
202and with ORIENTATION, one can detect twisting of fingers.
203
204
Henrik Rydbergeacaad02009-04-28 07:49:21 -0700205Notes
206-----
207
208In order to stay compatible with existing applications, the data
209reported in a finger packet must not be recognized as single-touch
210events. In addition, all finger data must bypass input filtering,
211since subsequent events of the same type refer to different fingers.
212
213The first kernel driver to utilize the MT protocol is the bcm5974 driver,
214where examples can be found.
215
216[1] With the extension ABS_MT_APPROACH_X and ABS_MT_APPROACH_Y, the
217difference between the contact position and the approaching tool position
218could be used to derive tilt.
219[2] The list can of course be extended.
220[3] The multi-touch X driver is currently in the prototyping stage. At the
221time of writing (April 2009), the MT protocol is not yet merged, and the
222prototype implements finger matching, basic mouse support and two-finger
223scrolling. The project aims at improving the quality of current multi-touch
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -0700224functionality available in the Synaptics X driver, and in addition
Henrik Rydbergeacaad02009-04-28 07:49:21 -0700225implement more advanced gestures.
Henrik Rydbergf9fcfc32009-05-23 09:51:21 -0700226[4] See the section on event computation.
227[5] See the section on finger tracking.