multi-touch-protocol.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. Multi-touch (MT) Protocol
  2. -------------------------
  3. Copyright (C) 2009 Henrik Rydberg <rydberg@euromail.se>
  4. Introduction
  5. ------------
  6. In order to utilize the full power of the new multi-touch devices, a way to
  7. report detailed finger data to user space is needed. This document
  8. describes the multi-touch (MT) protocol which allows kernel drivers to
  9. report details for an arbitrary number of fingers.
  10. Usage
  11. -----
  12. Anonymous finger details are sent sequentially as separate packets of ABS
  13. events. Only the ABS_MT events are recognized as part of a finger
  14. packet. The end of a packet is marked by calling the input_mt_sync()
  15. function, which generates a SYN_MT_REPORT event. This instructs the
  16. receiver to accept the data for the current finger and prepare to receive
  17. another. The end of a multi-touch transfer is marked by calling the usual
  18. input_sync() function. This instructs the receiver to act upon events
  19. accumulated since last EV_SYN/SYN_REPORT and prepare to receive a new
  20. set of events/packets.
  21. A set of ABS_MT events with the desired properties is defined. The events
  22. are divided into categories, to allow for partial implementation. The
  23. minimum set consists of ABS_MT_TOUCH_MAJOR, ABS_MT_POSITION_X and
  24. ABS_MT_POSITION_Y, which allows for multiple fingers to be tracked. If the
  25. device supports it, the ABS_MT_WIDTH_MAJOR may be used to provide the size
  26. of the approaching finger. Anisotropy and direction may be specified with
  27. ABS_MT_TOUCH_MINOR, ABS_MT_WIDTH_MINOR and ABS_MT_ORIENTATION. The
  28. ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is a
  29. finger or a pen or something else. Devices with more granular information
  30. may specify general shapes as blobs, i.e., as a sequence of rectangular
  31. shapes grouped together by an ABS_MT_BLOB_ID. Finally, for the few devices
  32. that currently support it, the ABS_MT_TRACKING_ID event may be used to
  33. report finger tracking from hardware [5].
  34. Here is what a minimal event sequence for a two-finger touch would look
  35. like:
  36. ABS_MT_TOUCH_MAJOR
  37. ABS_MT_POSITION_X
  38. ABS_MT_POSITION_Y
  39. SYN_MT_REPORT
  40. ABS_MT_TOUCH_MAJOR
  41. ABS_MT_POSITION_X
  42. ABS_MT_POSITION_Y
  43. SYN_MT_REPORT
  44. SYN_REPORT
  45. Event Semantics
  46. ---------------
  47. The word "contact" is used to describe a tool which is in direct contact
  48. with the surface. A finger, a pen or a rubber all classify as contacts.
  49. ABS_MT_TOUCH_MAJOR
  50. The length of the major axis of the contact. The length should be given in
  51. surface units. If the surface has an X times Y resolution, the largest
  52. possible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [4].
  53. ABS_MT_TOUCH_MINOR
  54. The length, in surface units, of the minor axis of the contact. If the
  55. contact is circular, this event can be omitted [4].
  56. ABS_MT_WIDTH_MAJOR
  57. The length, in surface units, of the major axis of the approaching
  58. tool. This should be understood as the size of the tool itself. The
  59. orientation of the contact and the approaching tool are assumed to be the
  60. same [4].
  61. ABS_MT_WIDTH_MINOR
  62. The length, in surface units, of the minor axis of the approaching
  63. tool. Omit if circular [4].
  64. The above four values can be used to derive additional information about
  65. the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates
  66. the notion of pressure. The fingers of the hand and the palm all have
  67. different characteristic widths [1].
  68. ABS_MT_ORIENTATION
  69. The orientation of the ellipse. The value should describe a signed quarter
  70. of a revolution clockwise around the touch center. The signed value range
  71. is arbitrary, but zero should be returned for a finger aligned along the Y
  72. axis of the surface, a negative value when finger is turned to the left, and
  73. a positive value when finger turned to the right. When completely aligned with
  74. the X axis, the range max should be returned. Orientation can be omitted
  75. if the touching object is circular, or if the information is not available
  76. in the kernel driver. Partial orientation support is possible if the device
  77. can distinguish between the two axis, but not (uniquely) any values in
  78. between. In such cases, the range of ABS_MT_ORIENTATION should be [0, 1]
  79. [4].
  80. ABS_MT_POSITION_X
  81. The surface X coordinate of the center of the touching ellipse.
  82. ABS_MT_POSITION_Y
  83. The surface Y coordinate of the center of the touching ellipse.
  84. ABS_MT_TOOL_TYPE
  85. The type of approaching tool. A lot of kernel drivers cannot distinguish
  86. between different tool types, such as a finger or a pen. In such cases, the
  87. event should be omitted. The protocol currently supports MT_TOOL_FINGER and
  88. MT_TOOL_PEN [2].
  89. ABS_MT_BLOB_ID
  90. The BLOB_ID groups several packets together into one arbitrarily shaped
  91. contact. This is a low-level anonymous grouping, and should not be confused
  92. with the high-level trackingID [5]. Most kernel drivers will not have blob
  93. capability, and can safely omit the event.
  94. ABS_MT_TRACKING_ID
  95. The TRACKING_ID identifies an initiated contact throughout its life cycle
  96. [5]. There are currently only a few devices that support it, so this event
  97. should normally be omitted.
  98. Event Computation
  99. -----------------
  100. The flora of different hardware unavoidably leads to some devices fitting
  101. better to the MT protocol than others. To simplify and unify the mapping,
  102. this section gives recipes for how to compute certain events.
  103. For devices reporting contacts as rectangular shapes, signed orientation
  104. cannot be obtained. Assuming X and Y are the lengths of the sides of the
  105. touching rectangle, here is a simple formula that retains the most
  106. information possible:
  107. ABS_MT_TOUCH_MAJOR := max(X, Y)
  108. ABS_MT_TOUCH_MINOR := min(X, Y)
  109. ABS_MT_ORIENTATION := bool(X > Y)
  110. The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that
  111. the device can distinguish between a finger along the Y axis (0) and a
  112. finger along the X axis (1).
  113. Finger Tracking
  114. ---------------
  115. The kernel driver should generate an arbitrary enumeration of the set of
  116. anonymous contacts currently on the surface. The order in which the packets
  117. appear in the event stream is not important.
  118. The process of finger tracking, i.e., to assign a unique trackingID to each
  119. initiated contact on the surface, is left to user space; preferably the
  120. multi-touch X driver [3]. In that driver, the trackingID stays the same and
  121. unique until the contact vanishes (when the finger leaves the surface). The
  122. problem of assigning a set of anonymous fingers to a set of identified
  123. fingers is a euclidian bipartite matching problem at each event update, and
  124. relies on a sufficiently rapid update rate.
  125. There are a few devices that support trackingID in hardware. User space can
  126. make use of these native identifiers to reduce bandwidth and cpu usage.
  127. Notes
  128. -----
  129. In order to stay compatible with existing applications, the data
  130. reported in a finger packet must not be recognized as single-touch
  131. events. In addition, all finger data must bypass input filtering,
  132. since subsequent events of the same type refer to different fingers.
  133. The first kernel driver to utilize the MT protocol is the bcm5974 driver,
  134. where examples can be found.
  135. [1] With the extension ABS_MT_APPROACH_X and ABS_MT_APPROACH_Y, the
  136. difference between the contact position and the approaching tool position
  137. could be used to derive tilt.
  138. [2] The list can of course be extended.
  139. [3] The multi-touch X driver is currently in the prototyping stage. At the
  140. time of writing (April 2009), the MT protocol is not yet merged, and the
  141. prototype implements finger matching, basic mouse support and two-finger
  142. scrolling. The project aims at improving the quality of current multi-touch
  143. functionality available in the Synaptics X driver, and in addition
  144. implement more advanced gestures.
  145. [4] See the section on event computation.
  146. [5] See the section on finger tracking.