1#ifndef _TSLIB_H_
2#define _TSLIB_H_
3/*
4 * tslib/src/tslib.h
5 *
6 * Copyright (C) 2016 Martin Kepplinger <martink@posteo.de>
7 * Copyright (C) 2001 Russell King.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22 * USA
23 *
24 * SPDX-License-Identifier: LGPL-2.1
25 *
26 *
27 * Touch screen library interface definitions.
28 */
29#ifdef __cplusplus
30extern "C" {
31#endif /* __cplusplus */
32#include <stdarg.h>
33#include <sys/time.h>
34
35#ifdef WIN32
36 #define TSIMPORT __declspec(dllimport)
37 #define TSEXPORT __declspec(dllexport)
38 #define TSLOCAL
39#else
40 #define TSIMPORT
41 #ifdef GCC_HASCLASSVISIBILITY
42 #define TSEXPORT __attribute__ ((visibility("default")))
43 #define TSLOCAL __attribute__ ((visibility("hidden")))
44 #else
45 #define TSEXPORT
46 #define TSLOCAL
47 #endif
48#endif
49
50#ifdef TSLIB_INTERNAL
51 #define TSAPI TSEXPORT
52#else
53 #define TSAPI TSIMPORT
54#endif /* TSLIB_INTERNAL */
55
56struct tsdev;
57
58struct ts_sample {
59 int x;
60 int y;
61 unsigned int pressure;
62 struct timeval tv;
63};
64
65struct ts_sample_mt {
66 /* ABS_MT_* event codes. linux/include/uapi/linux/input-event-codes.h
67 * has the definitions.
68 */
69 int x;
70 int y;
71 unsigned int pressure;
72 int slot;
73 int tracking_id;
74
75 int tool_type;
76 int tool_x;
77 int tool_y;
78 unsigned int touch_major;
79 unsigned int width_major;
80 unsigned int touch_minor;
81 unsigned int width_minor;
82 int orientation;
83 int distance;
84 int blob_id;
85
86 struct timeval tv;
87
88 /* BTN_TOUCH state */
89 short pen_down;
90
91 /* valid is set != 0 if this sample
92 * contains new data; see below for the
93 * bits that get set.
94 * valid is set to 0 otherwise
95 */
96 short valid;
97};
98
99#define TSLIB_MT_VALID (1 << 0) /* any new data */
100#define TSLIB_MT_VALID_TOOL (1 << 1) /* new tool_x or tool_y data */
101
102struct ts_lib_version_data {
103 const char *package_version;
104 int version_num;
105 unsigned int features; /* bitmask, see below */
106};
107
108#define TSLIB_VERSION_MT (1 << 0) /* multitouch support */
109#define TSLIB_VERSION_OPEN_RESTRICTED (1 << 1) /* ts_open_restricted() */
110#define TSLIB_VERSION_EVENTPATH (1 << 2) /* ts_get_eventpath() */
111#define TSLIB_VERSION_VERSION (1 << 3) /* tslib_version() */
112
113enum ts_param {
114 TS_SCREEN_RES = 0, /* 2 integer args, x and y */
115 TS_SCREEN_ROT /* 1 integer arg, 1 = rotate */
116};
117
118struct ts_module_conf {
119 char *name;
120 char *params;
121 int raw;
122 int nr;
123
124 struct ts_module_conf *next;
125 struct ts_module_conf *prev;
126};
127
128/*
129 * Close the touchscreen device, free all resources.
130 */
131TSAPI int ts_close(struct tsdev *);
132
133/*
134 * Reloads all modules - useful to reload calibration data.
135 */
136TSAPI int ts_reconfig(struct tsdev *);
137
138/*
139 * Configure the touchscreen device.
140 */
141TSAPI int ts_config(struct tsdev *);
142
143/*
144 * Changes a setting.
145 */
146TSAPI int ts_option(struct tsdev *, enum ts_param, ...);
147
148/*
149 * Change this hook to point to your custom error handling function.
150 */
151extern TSAPI int (*ts_error_fn)(const char *fmt, va_list ap);
152
153/*
154 * Implement this to override open() for the input device and return the fd.
155 */
156extern TSAPI int (*ts_open_restricted)(const char *path, int flags, void *user_data);
157
158/*
159 * Implement this to override close().
160 */
161extern TSAPI void (*ts_close_restricted)(int fd, void *user_data);
162
163/*
164 * Returns the file descriptor in use for the touchscreen device.
165 */
166TSAPI int ts_fd(struct tsdev *);
167
168/*
169 * Load a filter/scaling module
170 */
171TSAPI int ts_load_module(struct tsdev *, const char *mod, const char *params);
172
173/*
174 * Open the touchscreen device.
175 */
176TSAPI struct tsdev *ts_open(const char *dev_name, int nonblock);
177
178/*
179 * Find, open and configure the touchscreen device.
180 */
181TSAPI struct tsdev *ts_setup(const char *dev_name, int nonblock);
182
183/*
184 * Return a scaled touchscreen sample.
185 */
186TSAPI int ts_read(struct tsdev *, struct ts_sample *, int);
187
188/*
189 * Returns a raw, unscaled sample from the touchscreen.
190 */
191TSAPI int ts_read_raw(struct tsdev *, struct ts_sample *, int);
192
193/*
194 * Return a scaled touchscreen multitouch sample.
195 */
196TSAPI int ts_read_mt(struct tsdev *, struct ts_sample_mt **, int slots, int nr);
197
198/*
199 * Return a raw, unscaled touchscreen multitouch sample.
200 */
201TSAPI int ts_read_raw_mt(struct tsdev *, struct ts_sample_mt **, int slots, int nr);
202
203/*
204 * This function returns a pointer to a static copy of the version info struct.
205 */
206TSAPI struct ts_lib_version_data *ts_libversion(void);
207
208/*
209 * Get the list of (commented-in) ts.conf module lines (as structs)
210 */
211TSAPI struct ts_module_conf *ts_conf_get(struct tsdev *ts);
212
213/*
214 * Write the list of modules to ts.conf
215 */
216TSAPI int ts_conf_set(struct ts_module_conf *conf);
217
218/*
219 * This function returns the path to the opened touchscreen input device file.
220 */
221TSAPI char *ts_get_eventpath(struct tsdev *tsdev);
222
223/*
224 * This simply returns tslib's version string
225 */
226TSAPI char *tslib_version(void);
227
228/*
229 * This prints tslib's logo to stdout, with pos preceding spaces
230 */
231TSAPI void (unsigned int pos);
232
233#ifdef __cplusplus
234}
235#endif /* __cplusplus */
236#endif /* _TSLIB_H_ */
237