multi-touch-protocol.txt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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_POSITION_X and ABS_MT_POSITION_Y, which
  24. allows for multiple fingers to be tracked. If the device supports it, the
  25. ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size
  26. of the contact area and approaching finger, respectively.
  27. The TOUCH and WIDTH parameters have a geometrical interpretation; imagine
  28. looking through a window at someone gently holding a finger against the
  29. glass. You will see two regions, one inner region consisting of the part
  30. of the finger actually touching the glass, and one outer region formed by
  31. the perimeter of the finger. The diameter of the inner region is the
  32. ABS_MT_TOUCH_MAJOR, the diameter of the outer region is
  33. ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger harder
  34. against the glass. The inner region will increase, and in general, the
  35. ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller than
  36. unity, is related to the finger pressure. For pressure-based devices,
  37. ABS_MT_PRESSURE may be used to provide the pressure on the contact area
  38. instead.
  39. In addition to the MAJOR parameters, the oval shape of the finger can be
  40. described by adding the MINOR parameters, such that MAJOR and MINOR are the
  41. major and minor axis of an ellipse. Finally, the orientation of the oval
  42. shape can be describe with the ORIENTATION parameter.
  43. The ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is a
  44. finger or a pen or something else. Devices with more granular information
  45. may specify general shapes as blobs, i.e., as a sequence of rectangular
  46. shapes grouped together by an ABS_MT_BLOB_ID. Finally, for the few devices
  47. that currently support it, the ABS_MT_TRACKING_ID event may be used to
  48. report finger tracking from hardware [5].
  49. Here is what a minimal event sequence for a two-finger touch would look
  50. like:
  51. ABS_MT_POSITION_X
  52. ABS_MT_POSITION_Y
  53. SYN_MT_REPORT
  54. ABS_MT_POSITION_X
  55. ABS_MT_POSITION_Y
  56. SYN_MT_REPORT
  57. SYN_REPORT
  58. Event Semantics
  59. ---------------
  60. The word "contact" is used to describe a tool which is in direct contact
  61. with the surface. A finger, a pen or a rubber all classify as contacts.
  62. ABS_MT_TOUCH_MAJOR
  63. The length of the major axis of the contact. The length should be given in
  64. surface units. If the surface has an X times Y resolution, the largest
  65. possible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [4].
  66. ABS_MT_TOUCH_MINOR
  67. The length, in surface units, of the minor axis of the contact. If the
  68. contact is circular, this event can be omitted [4].
  69. ABS_MT_WIDTH_MAJOR
  70. The length, in surface units, of the major axis of the approaching
  71. tool. This should be understood as the size of the tool itself. The
  72. orientation of the contact and the approaching tool are assumed to be the
  73. same [4].
  74. ABS_MT_WIDTH_MINOR
  75. The length, in surface units, of the minor axis of the approaching
  76. tool. Omit if circular [4].
  77. The above four values can be used to derive additional information about
  78. the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates
  79. the notion of pressure. The fingers of the hand and the palm all have
  80. different characteristic widths [1].
  81. ABS_MT_PRESSURE
  82. The pressure, in arbitrary units, on the contact area. May be used instead
  83. of TOUCH and WIDTH for pressure-based devices or any device with a spatial
  84. signal intensity distribution.
  85. ABS_MT_ORIENTATION
  86. The orientation of the ellipse. The value should describe a signed quarter
  87. of a revolution clockwise around the touch center. The signed value range
  88. is arbitrary, but zero should be returned for a finger aligned along the Y
  89. axis of the surface, a negative value when finger is turned to the left, and
  90. a positive value when finger turned to the right. When completely aligned with
  91. the X axis, the range max should be returned. Orientation can be omitted
  92. if the touching object is circular, or if the information is not available
  93. in the kernel driver. Partial orientation support is possible if the device
  94. can distinguish between the two axis, but not (uniquely) any values in
  95. between. In such cases, the range of ABS_MT_ORIENTATION should be [0, 1]
  96. [4].
  97. ABS_MT_POSITION_X
  98. The surface X coordinate of the center of the touching ellipse.
  99. ABS_MT_POSITION_Y
  100. The surface Y coordinate of the center of the touching ellipse.
  101. ABS_MT_TOOL_TYPE
  102. The type of approaching tool. A lot of kernel drivers cannot distinguish
  103. between different tool types, such as a finger or a pen. In such cases, the
  104. event should be omitted. The protocol currently supports MT_TOOL_FINGER and
  105. MT_TOOL_PEN [2].
  106. ABS_MT_BLOB_ID
  107. The BLOB_ID groups several packets together into one arbitrarily shaped
  108. contact. This is a low-level anonymous grouping, and should not be confused
  109. with the high-level trackingID [5]. Most kernel drivers will not have blob
  110. capability, and can safely omit the event.
  111. ABS_MT_TRACKING_ID
  112. The TRACKING_ID identifies an initiated contact throughout its life cycle
  113. [5]. There are currently only a few devices that support it, so this event
  114. should normally be omitted.
  115. Event Computation
  116. -----------------
  117. The flora of different hardware unavoidably leads to some devices fitting
  118. better to the MT protocol than others. To simplify and unify the mapping,
  119. this section gives recipes for how to compute certain events.
  120. For devices reporting contacts as rectangular shapes, signed orientation
  121. cannot be obtained. Assuming X and Y are the lengths of the sides of the
  122. touching rectangle, here is a simple formula that retains the most
  123. information possible:
  124. ABS_MT_TOUCH_MAJOR := max(X, Y)
  125. ABS_MT_TOUCH_MINOR := min(X, Y)
  126. ABS_MT_ORIENTATION := bool(X > Y)
  127. The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that
  128. the device can distinguish between a finger along the Y axis (0) and a
  129. finger along the X axis (1).
  130. Finger Tracking
  131. ---------------
  132. The kernel driver should generate an arbitrary enumeration of the set of
  133. anonymous contacts currently on the surface. The order in which the packets
  134. appear in the event stream is not important.
  135. The process of finger tracking, i.e., to assign a unique trackingID to each
  136. initiated contact on the surface, is left to user space; preferably the
  137. multi-touch X driver [3]. In that driver, the trackingID stays the same and
  138. unique until the contact vanishes (when the finger leaves the surface). The
  139. problem of assigning a set of anonymous fingers to a set of identified
  140. fingers is a euclidian bipartite matching problem at each event update, and
  141. relies on a sufficiently rapid update rate.
  142. There are a few devices that support trackingID in hardware. User space can
  143. make use of these native identifiers to reduce bandwidth and cpu usage.
  144. Gestures
  145. --------
  146. In the specific application of creating gesture events, the TOUCH and WIDTH
  147. parameters can be used to, e.g., approximate finger pressure or distinguish
  148. between index finger and thumb. With the addition of the MINOR parameters,
  149. one can also distinguish between a sweeping finger and a pointing finger,
  150. and with ORIENTATION, one can detect twisting of fingers.
  151. Notes
  152. -----
  153. In order to stay compatible with existing applications, the data
  154. reported in a finger packet must not be recognized as single-touch
  155. events. In addition, all finger data must bypass input filtering,
  156. since subsequent events of the same type refer to different fingers.
  157. The first kernel driver to utilize the MT protocol is the bcm5974 driver,
  158. where examples can be found.
  159. [1] With the extension ABS_MT_APPROACH_X and ABS_MT_APPROACH_Y, the
  160. difference between the contact position and the approaching tool position
  161. could be used to derive tilt.
  162. [2] The list can of course be extended.
  163. [3] The multi-touch X driver is currently in the prototyping stage. At the
  164. time of writing (April 2009), the MT protocol is not yet merged, and the
  165. prototype implements finger matching, basic mouse support and two-finger
  166. scrolling. The project aims at improving the quality of current multi-touch
  167. functionality available in the Synaptics X driver, and in addition
  168. implement more advanced gestures.
  169. [4] See the section on event computation.
  170. [5] See the section on finger tracking.