Back to home page

OSCL-LXR

 
 

    


0001 .. include:: <isonum.txt>
0002 
0003 =========================
0004 Multi-touch (MT) Protocol
0005 =========================
0006 
0007 :Copyright: |copy| 2009-2010    Henrik Rydberg <rydberg@euromail.se>
0008 
0009 
0010 Introduction
0011 ------------
0012 
0013 In order to utilize the full power of the new multi-touch and multi-user
0014 devices, a way to report detailed data from multiple contacts, i.e.,
0015 objects in direct contact with the device surface, is needed.  This
0016 document describes the multi-touch (MT) protocol which allows kernel
0017 drivers to report details for an arbitrary number of contacts.
0018 
0019 The protocol is divided into two types, depending on the capabilities of the
0020 hardware. For devices handling anonymous contacts (type A), the protocol
0021 describes how to send the raw data for all contacts to the receiver. For
0022 devices capable of tracking identifiable contacts (type B), the protocol
0023 describes how to send updates for individual contacts via event slots.
0024 
0025 .. note::
0026    MT protocol type A is obsolete, all kernel drivers have been
0027    converted to use type B.
0028 
0029 Protocol Usage
0030 --------------
0031 
0032 Contact details are sent sequentially as separate packets of ABS_MT
0033 events. Only the ABS_MT events are recognized as part of a contact
0034 packet. Since these events are ignored by current single-touch (ST)
0035 applications, the MT protocol can be implemented on top of the ST protocol
0036 in an existing driver.
0037 
0038 Drivers for type A devices separate contact packets by calling
0039 input_mt_sync() at the end of each packet. This generates a SYN_MT_REPORT
0040 event, which instructs the receiver to accept the data for the current
0041 contact and prepare to receive another.
0042 
0043 Drivers for type B devices separate contact packets by calling
0044 input_mt_slot(), with a slot as argument, at the beginning of each packet.
0045 This generates an ABS_MT_SLOT event, which instructs the receiver to
0046 prepare for updates of the given slot.
0047 
0048 All drivers mark the end of a multi-touch transfer by calling the usual
0049 input_sync() function. This instructs the receiver to act upon events
0050 accumulated since last EV_SYN/SYN_REPORT and prepare to receive a new set
0051 of events/packets.
0052 
0053 The main difference between the stateless type A protocol and the stateful
0054 type B slot protocol lies in the usage of identifiable contacts to reduce
0055 the amount of data sent to userspace. The slot protocol requires the use of
0056 the ABS_MT_TRACKING_ID, either provided by the hardware or computed from
0057 the raw data [#f5]_.
0058 
0059 For type A devices, the kernel driver should generate an arbitrary
0060 enumeration of the full set of anonymous contacts currently on the
0061 surface. The order in which the packets appear in the event stream is not
0062 important.  Event filtering and finger tracking is left to user space [#f3]_.
0063 
0064 For type B devices, the kernel driver should associate a slot with each
0065 identified contact, and use that slot to propagate changes for the contact.
0066 Creation, replacement and destruction of contacts is achieved by modifying
0067 the ABS_MT_TRACKING_ID of the associated slot.  A non-negative tracking id
0068 is interpreted as a contact, and the value -1 denotes an unused slot.  A
0069 tracking id not previously present is considered new, and a tracking id no
0070 longer present is considered removed.  Since only changes are propagated,
0071 the full state of each initiated contact has to reside in the receiving
0072 end.  Upon receiving an MT event, one simply updates the appropriate
0073 attribute of the current slot.
0074 
0075 Some devices identify and/or track more contacts than they can report to the
0076 driver.  A driver for such a device should associate one type B slot with each
0077 contact that is reported by the hardware.  Whenever the identity of the
0078 contact associated with a slot changes, the driver should invalidate that
0079 slot by changing its ABS_MT_TRACKING_ID.  If the hardware signals that it is
0080 tracking more contacts than it is currently reporting, the driver should use
0081 a BTN_TOOL_*TAP event to inform userspace of the total number of contacts
0082 being tracked by the hardware at that moment.  The driver should do this by
0083 explicitly sending the corresponding BTN_TOOL_*TAP event and setting
0084 use_count to false when calling input_mt_report_pointer_emulation().
0085 The driver should only advertise as many slots as the hardware can report.
0086 Userspace can detect that a driver can report more total contacts than slots
0087 by noting that the largest supported BTN_TOOL_*TAP event is larger than the
0088 total number of type B slots reported in the absinfo for the ABS_MT_SLOT axis.
0089 
0090 The minimum value of the ABS_MT_SLOT axis must be 0.
0091 
0092 Protocol Example A
0093 ------------------
0094 
0095 Here is what a minimal event sequence for a two-contact touch would look
0096 like for a type A device::
0097 
0098    ABS_MT_POSITION_X x[0]
0099    ABS_MT_POSITION_Y y[0]
0100    SYN_MT_REPORT
0101    ABS_MT_POSITION_X x[1]
0102    ABS_MT_POSITION_Y y[1]
0103    SYN_MT_REPORT
0104    SYN_REPORT
0105 
0106 The sequence after moving one of the contacts looks exactly the same; the
0107 raw data for all present contacts are sent between every synchronization
0108 with SYN_REPORT.
0109 
0110 Here is the sequence after lifting the first contact::
0111 
0112    ABS_MT_POSITION_X x[1]
0113    ABS_MT_POSITION_Y y[1]
0114    SYN_MT_REPORT
0115    SYN_REPORT
0116 
0117 And here is the sequence after lifting the second contact::
0118 
0119    SYN_MT_REPORT
0120    SYN_REPORT
0121 
0122 If the driver reports one of BTN_TOUCH or ABS_PRESSURE in addition to the
0123 ABS_MT events, the last SYN_MT_REPORT event may be omitted. Otherwise, the
0124 last SYN_REPORT will be dropped by the input core, resulting in no
0125 zero-contact event reaching userland.
0126 
0127 
0128 Protocol Example B
0129 ------------------
0130 
0131 Here is what a minimal event sequence for a two-contact touch would look
0132 like for a type B device::
0133 
0134    ABS_MT_SLOT 0
0135    ABS_MT_TRACKING_ID 45
0136    ABS_MT_POSITION_X x[0]
0137    ABS_MT_POSITION_Y y[0]
0138    ABS_MT_SLOT 1
0139    ABS_MT_TRACKING_ID 46
0140    ABS_MT_POSITION_X x[1]
0141    ABS_MT_POSITION_Y y[1]
0142    SYN_REPORT
0143 
0144 Here is the sequence after moving contact 45 in the x direction::
0145 
0146    ABS_MT_SLOT 0
0147    ABS_MT_POSITION_X x[0]
0148    SYN_REPORT
0149 
0150 Here is the sequence after lifting the contact in slot 0::
0151 
0152    ABS_MT_TRACKING_ID -1
0153    SYN_REPORT
0154 
0155 The slot being modified is already 0, so the ABS_MT_SLOT is omitted.  The
0156 message removes the association of slot 0 with contact 45, thereby
0157 destroying contact 45 and freeing slot 0 to be reused for another contact.
0158 
0159 Finally, here is the sequence after lifting the second contact::
0160 
0161    ABS_MT_SLOT 1
0162    ABS_MT_TRACKING_ID -1
0163    SYN_REPORT
0164 
0165 
0166 Event Usage
0167 -----------
0168 
0169 A set of ABS_MT events with the desired properties is defined. The events
0170 are divided into categories, to allow for partial implementation.  The
0171 minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which
0172 allows for multiple contacts to be tracked.  If the device supports it, the
0173 ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size
0174 of the contact area and approaching tool, respectively.
0175 
0176 The TOUCH and WIDTH parameters have a geometrical interpretation; imagine
0177 looking through a window at someone gently holding a finger against the
0178 glass.  You will see two regions, one inner region consisting of the part
0179 of the finger actually touching the glass, and one outer region formed by
0180 the perimeter of the finger. The center of the touching region (a) is
0181 ABS_MT_POSITION_X/Y and the center of the approaching finger (b) is
0182 ABS_MT_TOOL_X/Y. The touch diameter is ABS_MT_TOUCH_MAJOR and the finger
0183 diameter is ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger
0184 harder against the glass. The touch region will increase, and in general,
0185 the ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller
0186 than unity, is related to the contact pressure. For pressure-based devices,
0187 ABS_MT_PRESSURE may be used to provide the pressure on the contact area
0188 instead. Devices capable of contact hovering can use ABS_MT_DISTANCE to
0189 indicate the distance between the contact and the surface.
0190 
0191 ::
0192 
0193 
0194           Linux MT                               Win8
0195          __________                     _______________________
0196         /          \                   |                       |
0197        /            \                  |                       |
0198       /     ____     \                 |                       |
0199      /     /    \     \                |                       |
0200      \     \  a  \     \               |       a               |
0201       \     \____/      \              |                       |
0202        \                 \             |                       |
0203         \        b        \            |           b           |
0204          \                 \           |                       |
0205           \                 \          |                       |
0206            \                 \         |                       |
0207             \                /         |                       |
0208              \              /          |                       |
0209               \            /           |                       |
0210                \__________/            |_______________________|
0211 
0212 
0213 In addition to the MAJOR parameters, the oval shape of the touch and finger
0214 regions can be described by adding the MINOR parameters, such that MAJOR
0215 and MINOR are the major and minor axis of an ellipse. The orientation of
0216 the touch ellipse can be described with the ORIENTATION parameter, and the
0217 direction of the finger ellipse is given by the vector (a - b).
0218 
0219 For type A devices, further specification of the touch shape is possible
0220 via ABS_MT_BLOB_ID.
0221 
0222 The ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is a
0223 finger or a pen or something else. Finally, the ABS_MT_TRACKING_ID event
0224 may be used to track identified contacts over time [#f5]_.
0225 
0226 In the type B protocol, ABS_MT_TOOL_TYPE and ABS_MT_TRACKING_ID are
0227 implicitly handled by input core; drivers should instead call
0228 input_mt_report_slot_state().
0229 
0230 
0231 Event Semantics
0232 ---------------
0233 
0234 ABS_MT_TOUCH_MAJOR
0235     The length of the major axis of the contact. The length should be given in
0236     surface units. If the surface has an X times Y resolution, the largest
0237     possible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [#f4]_.
0238 
0239 ABS_MT_TOUCH_MINOR
0240     The length, in surface units, of the minor axis of the contact. If the
0241     contact is circular, this event can be omitted [#f4]_.
0242 
0243 ABS_MT_WIDTH_MAJOR
0244     The length, in surface units, of the major axis of the approaching
0245     tool. This should be understood as the size of the tool itself. The
0246     orientation of the contact and the approaching tool are assumed to be the
0247     same [#f4]_.
0248 
0249 ABS_MT_WIDTH_MINOR
0250     The length, in surface units, of the minor axis of the approaching
0251     tool. Omit if circular [#f4]_.
0252 
0253     The above four values can be used to derive additional information about
0254     the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates
0255     the notion of pressure. The fingers of the hand and the palm all have
0256     different characteristic widths.
0257 
0258 ABS_MT_PRESSURE
0259     The pressure, in arbitrary units, on the contact area. May be used instead
0260     of TOUCH and WIDTH for pressure-based devices or any device with a spatial
0261     signal intensity distribution.
0262 
0263     If the resolution is zero, the pressure data is in arbitrary units.
0264     If the resolution is non-zero, the pressure data is in units/gram. See
0265     :ref:`input-event-codes` for details.
0266 
0267 ABS_MT_DISTANCE
0268     The distance, in surface units, between the contact and the surface. Zero
0269     distance means the contact is touching the surface. A positive number means
0270     the contact is hovering above the surface.
0271 
0272 ABS_MT_ORIENTATION
0273     The orientation of the touching ellipse. The value should describe a signed
0274     quarter of a revolution clockwise around the touch center. The signed value
0275     range is arbitrary, but zero should be returned for an ellipse aligned with
0276     the Y axis (north) of the surface, a negative value when the ellipse is
0277     turned to the left, and a positive value when the ellipse is turned to the
0278     right. When aligned with the X axis in the positive direction, the range
0279     max should be returned; when aligned with the X axis in the negative
0280     direction, the range -max should be returned.
0281 
0282     Touch ellipses are symmetrical by default. For devices capable of true 360
0283     degree orientation, the reported orientation must exceed the range max to
0284     indicate more than a quarter of a revolution. For an upside-down finger,
0285     range max * 2 should be returned.
0286 
0287     Orientation can be omitted if the touch area is circular, or if the
0288     information is not available in the kernel driver. Partial orientation
0289     support is possible if the device can distinguish between the two axes, but
0290     not (uniquely) any values in between. In such cases, the range of
0291     ABS_MT_ORIENTATION should be [0, 1] [#f4]_.
0292 
0293 ABS_MT_POSITION_X
0294     The surface X coordinate of the center of the touching ellipse.
0295 
0296 ABS_MT_POSITION_Y
0297     The surface Y coordinate of the center of the touching ellipse.
0298 
0299 ABS_MT_TOOL_X
0300     The surface X coordinate of the center of the approaching tool. Omit if
0301     the device cannot distinguish between the intended touch point and the
0302     tool itself.
0303 
0304 ABS_MT_TOOL_Y
0305     The surface Y coordinate of the center of the approaching tool. Omit if the
0306     device cannot distinguish between the intended touch point and the tool
0307     itself.
0308 
0309     The four position values can be used to separate the position of the touch
0310     from the position of the tool. If both positions are present, the major
0311     tool axis points towards the touch point [#f1]_. Otherwise, the tool axes are
0312     aligned with the touch axes.
0313 
0314 ABS_MT_TOOL_TYPE
0315     The type of approaching tool. A lot of kernel drivers cannot distinguish
0316     between different tool types, such as a finger or a pen. In such cases, the
0317     event should be omitted. The protocol currently mainly supports
0318     MT_TOOL_FINGER, MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_.
0319     For type B devices, this event is handled by input core; drivers should
0320     instead use input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may
0321     change over time while still touching the device, because the firmware may
0322     not be able to determine which tool is being used when it first appears.
0323 
0324 ABS_MT_BLOB_ID
0325     The BLOB_ID groups several packets together into one arbitrarily shaped
0326     contact. The sequence of points forms a polygon which defines the shape of
0327     the contact. This is a low-level anonymous grouping for type A devices, and
0328     should not be confused with the high-level trackingID [#f5]_. Most type A
0329     devices do not have blob capability, so drivers can safely omit this event.
0330 
0331 ABS_MT_TRACKING_ID
0332     The TRACKING_ID identifies an initiated contact throughout its life cycle
0333     [#f5]_. The value range of the TRACKING_ID should be large enough to ensure
0334     unique identification of a contact maintained over an extended period of
0335     time. For type B devices, this event is handled by input core; drivers
0336     should instead use input_mt_report_slot_state().
0337 
0338 
0339 Event Computation
0340 -----------------
0341 
0342 The flora of different hardware unavoidably leads to some devices fitting
0343 better to the MT protocol than others. To simplify and unify the mapping,
0344 this section gives recipes for how to compute certain events.
0345 
0346 For devices reporting contacts as rectangular shapes, signed orientation
0347 cannot be obtained. Assuming X and Y are the lengths of the sides of the
0348 touching rectangle, here is a simple formula that retains the most
0349 information possible::
0350 
0351    ABS_MT_TOUCH_MAJOR := max(X, Y)
0352    ABS_MT_TOUCH_MINOR := min(X, Y)
0353    ABS_MT_ORIENTATION := bool(X > Y)
0354 
0355 The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that
0356 the device can distinguish between a finger along the Y axis (0) and a
0357 finger along the X axis (1).
0358 
0359 For Win8 devices with both T and C coordinates, the position mapping is::
0360 
0361    ABS_MT_POSITION_X := T_X
0362    ABS_MT_POSITION_Y := T_Y
0363    ABS_MT_TOOL_X := C_X
0364    ABS_MT_TOOL_Y := C_Y
0365 
0366 Unfortunately, there is not enough information to specify both the touching
0367 ellipse and the tool ellipse, so one has to resort to approximations.  One
0368 simple scheme, which is compatible with earlier usage, is::
0369 
0370    ABS_MT_TOUCH_MAJOR := min(X, Y)
0371    ABS_MT_TOUCH_MINOR := <not used>
0372    ABS_MT_ORIENTATION := <not used>
0373    ABS_MT_WIDTH_MAJOR := min(X, Y) + distance(T, C)
0374    ABS_MT_WIDTH_MINOR := min(X, Y)
0375 
0376 Rationale: We have no information about the orientation of the touching
0377 ellipse, so approximate it with an inscribed circle instead. The tool
0378 ellipse should align with the vector (T - C), so the diameter must
0379 increase with distance(T, C). Finally, assume that the touch diameter is
0380 equal to the tool thickness, and we arrive at the formulas above.
0381 
0382 Finger Tracking
0383 ---------------
0384 
0385 The process of finger tracking, i.e., to assign a unique trackingID to each
0386 initiated contact on the surface, is a Euclidian Bipartite Matching
0387 problem.  At each event synchronization, the set of actual contacts is
0388 matched to the set of contacts from the previous synchronization. A full
0389 implementation can be found in [#f3]_.
0390 
0391 
0392 Gestures
0393 --------
0394 
0395 In the specific application of creating gesture events, the TOUCH and WIDTH
0396 parameters can be used to, e.g., approximate finger pressure or distinguish
0397 between index finger and thumb. With the addition of the MINOR parameters,
0398 one can also distinguish between a sweeping finger and a pointing finger,
0399 and with ORIENTATION, one can detect twisting of fingers.
0400 
0401 
0402 Notes
0403 -----
0404 
0405 In order to stay compatible with existing applications, the data reported
0406 in a finger packet must not be recognized as single-touch events.
0407 
0408 For type A devices, all finger data bypasses input filtering, since
0409 subsequent events of the same type refer to different fingers.
0410 
0411 .. [#f1] Also, the difference (TOOL_X - POSITION_X) can be used to model tilt.
0412 .. [#f2] The list can of course be extended.
0413 .. [#f3] The mtdev project: http://bitmath.org/code/mtdev/.
0414 .. [#f4] See the section on event computation.
0415 .. [#f5] See the section on finger tracking.