summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-06-17 18:12:58 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-06-17 18:12:58 +0200
commit66e5de9eaefc33ffa6af3617f9ec7a50f10af50d (patch)
tree66535311e0b9c422b30341237fd596fb9ebbdd75 /include
Initial load of mtdev project
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'include')
-rw-r--r--include/mtdev-mapping.h76
-rw-r--r--include/mtdev.h225
2 files changed, 301 insertions, 0 deletions
diff --git a/include/mtdev-mapping.h b/include/mtdev-mapping.h
new file mode 100644
index 0000000..67fa06e
--- /dev/null
+++ b/include/mtdev-mapping.h
@@ -0,0 +1,76 @@
1/*****************************************************************************
2 *
3 * mtdev - MT device event converter (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/* Tables are automatically generated by mtdev-mapgen */
30
31#ifndef _MTDEV_MAPPING_H
32#define _MTDEV_MAPPING_H
33
34#include <mtdev.h>
35
36#define MTDEV_TRACKING_ID 9
37#define MTDEV_POSITION_X 5
38#define MTDEV_POSITION_Y 6
39#define MTDEV_TOUCH_MAJOR 0
40#define MTDEV_TOUCH_MINOR 1
41#define MTDEV_WIDTH_MAJOR 2
42#define MTDEV_WIDTH_MINOR 3
43#define MTDEV_ORIENTATION 4
44
45static const unsigned int mtdev_map_abs2mt[ABS_CNT] = {
46 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
47 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
48 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
49 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
50 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
51 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
52 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008,
53 0x0009, 0x000a, 0x000b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
54};
55
56static const unsigned int mtdev_map_mt2abs[MT_ABS_SIZE] = {
57 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
58 0x0038, 0x0039, 0x003a,
59};
60
61static inline int mtdev_is_absmt(unsigned int code)
62{
63 return mtdev_map_abs2mt[code];
64}
65
66static inline unsigned int mtdev_abs2mt(unsigned int code)
67{
68 return mtdev_map_abs2mt[code] - 1;
69}
70
71static inline unsigned int mtdev_mt2abs(unsigned int mtcode)
72{
73 return mtdev_map_mt2abs[mtcode];
74}
75
76#endif
diff --git a/include/mtdev.h b/include/mtdev.h
new file mode 100644
index 0000000..5f2f6a3
--- /dev/null
+++ b/include/mtdev.h
@@ -0,0 +1,225 @@
1/*****************************************************************************
2 *
3 * mtdev - MT device event converter (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#include <linux/input.h>
33
34/* includes available in 2.6.30-rc5 */
35#ifndef BTN_TOOL_QUADTAP
36#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
37#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
38#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
39#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
40#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
41#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
42#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
43#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
44#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
45#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
46#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
47#define SYN_MT_REPORT 2
48#define MT_TOOL_FINGER 0
49#define MT_TOOL_PEN 1
50#endif
51
52/* includes available in 2.6.33 */
53#ifndef ABS_MT_PRESSURE
54#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
55#endif
56
57/* includes available in 2.6.36 */
58#ifndef ABS_MT_SLOT
59#define ABS_MT_SLOT 0x2f /* MT slot being modified */
60#define MT_SLOT_ABS_EVENTS { \
61 ABS_MT_TOUCH_MAJOR, \
62 ABS_MT_TOUCH_MINOR, \
63 ABS_MT_WIDTH_MAJOR, \
64 ABS_MT_WIDTH_MINOR, \
65 ABS_MT_ORIENTATION, \
66 ABS_MT_POSITION_X, \
67 ABS_MT_POSITION_Y, \
68 ABS_MT_TOOL_TYPE, \
69 ABS_MT_BLOB_ID, \
70 ABS_MT_TRACKING_ID, \
71 ABS_MT_PRESSURE, \
72}
73#endif
74
75#define MT_ABS_SIZE 11
76
77/**
78 * struct mt_caps - protocol capabilities of kernel device
79 * @has_mtdata: true if the device has MT capabilities
80 * @has_slot: true if the device sends MT slots
81 * @nullid: tracking id used to represent null
82 * @slot: slot event properties
83 * @abs: ABS_MT event properties
84 */
85struct mtdev_caps {
86 int has_mtdata;
87 int has_slot;
88 int has_abs[MT_ABS_SIZE];
89 int nullid;
90 struct input_absinfo slot;
91 struct input_absinfo abs[MT_ABS_SIZE];
92};
93
94/**
95 * struct mtdev - represents an input MT device
96 * @caps: the kernel device protocol capabilities
97 * @state: internal mtdev parsing state
98 *
99 * The mtdev structure represents a kernel MT device type B, emitting
100 * MT slot events. The events put into mtdev may be from any MT
101 * device, specifically type A without contact tracking, type A with
102 * contact tracking, or type B with contact tracking. See the kernel
103 * documentation for further details.
104 *
105 */
106struct mtdev {
107 struct mtdev_caps caps;
108 struct mtdev_state *state;
109};
110
111/**
112 * mtdev_init - initialize mtdev converter
113 * @dev: the mtdev to initialize
114 *
115 * Sets up the internal data structures.
116 *
117 * Returns zero on success, negative error number otherwise.
118 */
119int mtdev_init(struct mtdev *dev);
120
121/**
122 * mtdev_configure - configure the mtdev converter
123 * @dev: the mtdev to configure
124 * @fd: file descriptor of the kernel device
125 *
126 * Reads the device properties to set up the protocol capabilities.
127 * If preferred, this can be done by hand, omitting this call.
128 *
129 * Returns zero on success, negative error number otherwise.
130 */
131int mtdev_configure(struct mtdev *dev, int fd);
132
133/**
134 * mtdev_open - open an mtdev converter
135 * @dev: the mtdev to open
136 * @fd: file descriptor of the kernel device
137 *
138 * Initialize the mtdev structure and configure it by reading
139 * the protocol capabilities through the file descriptor.
140 *
141 * Returns zero on success, negative error number otherwise.
142 *
143 * This call combines mtdev_init() and mtdev_configure(), which
144 * may be used separately instead.
145 */
146int mtdev_open(struct mtdev *dev, int fd);
147
148/**
149 * mtdev_fetch - fetch an event from the kernel device
150 * @dev: the mtdev in use
151 * @ev: the kernel input event to fill
152 * @fd: file descriptor of the kernel device
153 *
154 * Fetch a kernel event from the kernel device. The read operation
155 * behaves as dictated by the file descriptior; if O_NONBLOCK is not
156 * set, the read will block until an event is available.
157 *
158 * On success, returns the number of events read. Otherwise, a standard
159 * negative error number is returned.
160 */
161int mtdev_fetch(struct mtdev *dev, struct input_event *ev, int fd);
162
163/**
164 * mtdev_put - put an event into the converter
165 * @dev: the mtdev in use
166 * @ev: the kernel input event to put
167 *
168 * Put a kernel event into the mtdev converter. The event should
169 * come straight from the device.
170 *
171 * This call does not block; if the buffer becomes full, older events
172 * are dropped. The buffer is guaranteed to handle several complete MT
173 * packets.
174 */
175void mtdev_put(struct mtdev *dev, const struct input_event *ev);
176
177/**
178 * mtdev_pull - pull events from the kernel device
179 * @dev: the mtdev in use
180 * @fd: file descriptor of the kernel device
181 * @max_events: max number of events to read
182 *
183 * Read a maxmimum of max_events events from the device, and put them
184 * in the converter. The read operation behaves as dictated by the
185 * file descriptior; if O_NONBLOCK is not set, the read will block
186 * until max_events events are available or the buffer is full.
187 *
188 * On success, returns the number of events read. Otherwise, a standard
189 * negative error number is returned.
190 *
191 * This call combines mtdev_fetch() with mtdev_put(), which
192 * may be used separately instead.
193 */
194int mtdev_pull(struct mtdev *dev, int fd, int max_events);
195
196/**
197 * mtdev_empty - check if there are events to get
198 * @dev: the mtdev in use
199 *
200 * Returns true if the event queue is empty, false otherwise.
201 */
202int mtdev_empty(struct mtdev *dev);
203
204/**
205 * mtdev_get - get canonical events from mtdev
206 * @dev: the mtdev in use
207 * @ev: the input event to fill
208 *
209 * Get a canonical event from mtdev. The events appear as if they came
210 * from a type B device emitting MT slot events.
211 *
212 * The queue must be non-empty before calling this function.
213 */
214void mtdev_get(struct mtdev *dev, struct input_event* ev);
215
216/**
217 * mtdev_close - close the mtdev converter
218 * @dev: the mtdev to close
219 *
220 * Deallocates all memory associated with mtdev, and sets the state
221 * pointer to NULL.
222 */
223void mtdev_close(struct mtdev *dev);
224
225#endif