| 1 | /***************************************************************************** |
| 2 | * |
| 3 | * mtdev - Multitouch Protocol Translation Library (MIT license) |
| 4 | * |
| 5 | * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se> |
| 6 | * Copyright (C) 2010 Canonical Ltd. |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 9 | * copy of this software and associated documentation files (the "Software"), |
| 10 | * to deal in the Software without restriction, including without limitation |
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 12 | * and/or sell copies of the Software, and to permit persons to whom the |
| 13 | * Software is furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice (including the next |
| 16 | * paragraph) shall be included in all copies or substantial portions of the |
| 17 | * Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 25 | * DEALINGS IN THE SOFTWARE. |
| 26 | * |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef _MTDEV_H |
| 30 | #define _MTDEV_H |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | #include <linux/input.h> |
| 37 | |
| 38 | /* includes available in 2.6.30-rc5 */ |
| 39 | #ifndef BTN_TOOL_QUADTAP |
| 40 | #define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ |
| 41 | #define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ |
| 42 | #define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */ |
| 43 | #define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ |
| 44 | #define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ |
| 45 | #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ |
| 46 | #define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */ |
| 47 | #define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */ |
| 48 | #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */ |
| 49 | #define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ |
| 50 | #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ |
| 51 | #define SYN_MT_REPORT 2 |
| 52 | #define MT_TOOL_FINGER 0 |
| 53 | #define MT_TOOL_PEN 1 |
| 54 | #endif |
| 55 | |
| 56 | /* includes available in 2.6.33 */ |
| 57 | #ifndef ABS_MT_PRESSURE |
| 58 | #define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ |
| 59 | #endif |
| 60 | |
| 61 | /* includes available in 2.6.36 */ |
| 62 | #ifndef ABS_MT_SLOT |
| 63 | #define ABS_MT_SLOT 0x2f /* MT slot being modified */ |
| 64 | #endif |
| 65 | |
| 66 | /* includes available in 2.6.38 */ |
| 67 | #ifndef ABS_MT_DISTANCE |
| 68 | #define ABS_MT_DISTANCE 0x3b /* Contact hover distance */ |
| 69 | #endif |
| 70 | |
| 71 | /* includes available in 3.4 */ |
| 72 | #ifndef EVIOCGMTSLOTS |
| 73 | #define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len) |
| 74 | #endif |
| 75 | |
| 76 | #define MT_ID_NULL (-1) |
| 77 | #define MT_ID_MIN 0 |
| 78 | #define MT_ID_MAX 65535 |
| 79 | |
| 80 | /** |
| 81 | * mtdev_new_open - create and open a new mtdev |
| 82 | * @fd: file descriptor of the kernel device |
| 83 | * |
| 84 | * Create a new mtdev and open the conversion. |
| 85 | * |
| 86 | * Returns zero in case of failure. |
| 87 | * |
| 88 | * This call combines the plumbing functions mtdev_new() and |
| 89 | * mtdev_open(). |
| 90 | */ |
| 91 | struct mtdev *mtdev_new_open(int fd); |
| 92 | |
| 93 | /** |
| 94 | * mtdev_open - open an mtdev converter |
| 95 | * @dev: the mtdev to open |
| 96 | * @fd: file descriptor of the kernel device |
| 97 | * |
| 98 | * Initialize the mtdev structure and configure it by reading |
| 99 | * the protocol capabilities through the file descriptor. |
| 100 | * |
| 101 | * Returns zero on success, negative error number otherwise. |
| 102 | * |
| 103 | * This call combines the plumbing functions mtdev_init() and |
| 104 | * mtdev_configure(). |
| 105 | */ |
| 106 | int mtdev_open(struct mtdev *dev, int fd); |
| 107 | |
| 108 | /** |
| 109 | * mtdev_has_mt_event - check for event type |
| 110 | * @dev: the mtdev in use |
| 111 | * @code: the ABS_MT code to look for |
| 112 | * |
| 113 | * Returns true if the given event code is present. |
| 114 | */ |
| 115 | int mtdev_has_mt_event(const struct mtdev *dev, int code); |
| 116 | |
| 117 | /** |
| 118 | * mtdev_get_abs_<property> - get abs event property |
| 119 | * @dev: the mtdev in use |
| 120 | * @code: the ABS_MT code to look for |
| 121 | * |
| 122 | * Returns NULL if code is not a valid ABS_MT code. |
| 123 | */ |
| 124 | int mtdev_get_abs_minimum(const struct mtdev *dev, int code); |
| 125 | int mtdev_get_abs_maximum(const struct mtdev *dev, int code); |
| 126 | int mtdev_get_abs_fuzz(const struct mtdev *dev, int code); |
| 127 | int mtdev_get_abs_resolution(const struct mtdev *dev, int code); |
| 128 | |
| 129 | /** |
| 130 | * mtdev_idle - check state of kernel device |
| 131 | * @dev: the mtdev in use |
| 132 | * @fd: file descriptor of the kernel device |
| 133 | * @ms: number of milliseconds to wait for activity |
| 134 | * |
| 135 | * Returns true if the device is idle, i.e., there are no fetched |
| 136 | * events in the pipe and there is nothing to fetch from the device. |
| 137 | */ |
| 138 | int mtdev_idle(struct mtdev *dev, int fd, int ms); |
| 139 | |
| 140 | /** |
| 141 | * mtdev_get - get processed events from mtdev |
| 142 | * @dev: the mtdev in use |
| 143 | * @fd: file descriptor of the kernel device |
| 144 | * @ev: array of input events to fill |
| 145 | * @ev_max: maximum number of events to read |
| 146 | * |
| 147 | * Get a processed event from mtdev. The events appear as if they came |
| 148 | * from a type B device emitting MT slot events. |
| 149 | * |
| 150 | * The read operations involved behave as dictated by the file |
| 151 | * descriptor; if O_NONBLOCK is not set, mtdev_get() will block until |
| 152 | * the specified number of processed events are available. |
| 153 | * |
| 154 | * On success, returns the number of events read. Otherwise, |
| 155 | * a standard negative error number is returned. |
| 156 | * |
| 157 | * This call combines the plumbing functions mtdev_fetch_event(), |
| 158 | * mtdev_put_event() and mtdev_get_event(). |
| 159 | */ |
| 160 | int mtdev_get(struct mtdev *dev, int fd, struct input_event* ev, int ev_max); |
| 161 | |
| 162 | /** |
| 163 | * mtdev_close - close the mtdev converter |
| 164 | * @dev: the mtdev to close |
| 165 | * |
| 166 | * Deallocates all memory associated with mtdev, and clears the mtdev |
| 167 | * structure. |
| 168 | */ |
| 169 | void mtdev_close(struct mtdev *dev); |
| 170 | |
| 171 | /** |
| 172 | * mtdev_close_delete - close conversion and delete mtdev |
| 173 | * @dev: the mtdev in use |
| 174 | * |
| 175 | * Flush pending buffers and deallocate all memory associated with |
| 176 | * mtdev. The device pointer is invalidated. This call combines the |
| 177 | * plumbing functions mtdev_close() and mtdev_delete(). |
| 178 | */ |
| 179 | void mtdev_close_delete(struct mtdev *dev); |
| 180 | |
| 181 | #ifndef MTDEV_NO_LEGACY_API |
| 182 | |
| 183 | #define MT_ABS_SIZE 11 |
| 184 | #ifndef MT_SLOT_ABS_EVENTS |
| 185 | #define MT_SLOT_ABS_EVENTS { \ |
| 186 | ABS_MT_TOUCH_MAJOR, \ |
| 187 | ABS_MT_TOUCH_MINOR, \ |
| 188 | ABS_MT_WIDTH_MAJOR, \ |
| 189 | ABS_MT_WIDTH_MINOR, \ |
| 190 | ABS_MT_ORIENTATION, \ |
| 191 | ABS_MT_POSITION_X, \ |
| 192 | ABS_MT_POSITION_Y, \ |
| 193 | ABS_MT_TOOL_TYPE, \ |
| 194 | ABS_MT_BLOB_ID, \ |
| 195 | ABS_MT_TRACKING_ID, \ |
| 196 | ABS_MT_PRESSURE, \ |
| 197 | } |
| 198 | #endif |
| 199 | |
| 200 | struct mtdev_caps { |
| 201 | int has_mtdata; |
| 202 | int has_slot; |
| 203 | int has_abs[MT_ABS_SIZE]; |
| 204 | struct input_absinfo slot; |
| 205 | struct input_absinfo abs[MT_ABS_SIZE]; |
| 206 | }; |
| 207 | |
| 208 | struct mtdev { |
| 209 | struct mtdev_caps caps; |
| 210 | struct mtdev_state *state; |
| 211 | }; |
| 212 | |
| 213 | #endif |
| 214 | |
| 215 | #ifdef __cplusplus |
| 216 | } |
| 217 | #endif |
| 218 | |
| 219 | #endif |
| 220 | |