xref: /dragonfly/sys/dev/misc/evdev/input.h (revision 70675b40)
1 /*-
2  * Copyright (c) 2016 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3  * Copyright (c) 2015-2016 Vladimir Kondratyev <wulf@FreeBSD.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef	_EVDEV_INPUT_H
31 #define	_EVDEV_INPUT_H
32 
33 #include <sys/ioccom.h>
34 #include <sys/time.h>
35 #include <sys/types.h>
36 
37 #include "input-event-codes.h"
38 
39 struct input_event {
40 	struct timeval	time;
41 	uint16_t	type;
42 	uint16_t	code;
43 	int32_t		value;
44 };
45 
46 #define	EV_VERSION		0x010001
47 
48 struct input_id {
49 	uint16_t	bustype;
50 	uint16_t	vendor;
51 	uint16_t	product;
52 	uint16_t	version;
53 };
54 
55 struct input_absinfo {
56 	int32_t		value;
57 	int32_t		minimum;
58 	int32_t		maximum;
59 	int32_t		fuzz;
60 	int32_t		flat;
61 	int32_t		resolution;
62 };
63 
64 #define	INPUT_KEYMAP_BY_INDEX	(1 << 0)
65 
66 struct input_keymap_entry {
67 	uint8_t		flags;
68 	uint8_t		len;
69 	uint16_t	index;
70 	uint32_t	keycode;
71 	uint8_t		scancode[32];
72 };
73 
74 #define	EVDEV_IOC_MAGIC	'E'
75 #define	EVIOCGVERSION		_IOR(EVDEV_IOC_MAGIC, 0x01, int)		/* get driver version */
76 #define	EVIOCGID		_IOR(EVDEV_IOC_MAGIC, 0x02, struct input_id)	/* get device ID */
77 #define	EVIOCGREP		_IOR(EVDEV_IOC_MAGIC, 0x03, unsigned int[2])	/* get repeat settings */
78 #define	EVIOCSREP		_IOW(EVDEV_IOC_MAGIC, 0x03, unsigned int[2])	/* set repeat settings */
79 
80 #define	EVIOCGKEYCODE		_IOWR(EVDEV_IOC_MAGIC, 0x04, unsigned int[2])	/* get keycode */
81 #define	EVIOCGKEYCODE_V2	_IOWR(EVDEV_IOC_MAGIC, 0x04, struct input_keymap_entry)
82 #define	EVIOCSKEYCODE		_IOW(EVDEV_IOC_MAGIC, 0x04, unsigned int[2])	/* set keycode */
83 #define	EVIOCSKEYCODE_V2	_IOW(EVDEV_IOC_MAGIC, 0x04, struct input_keymap_entry)
84 
85 #define	EVIOCGNAME(len)		_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x06, len)	/* get device name */
86 #define	EVIOCGPHYS(len)		_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x07, len)	/* get physical location */
87 #define	EVIOCGUNIQ(len)		_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x08, len)	/* get unique identifier */
88 #define	EVIOCGPROP(len)		_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x09, len)	/* get device properties */
89 
90 #define	EVIOCGMTSLOTS(len)	_IOC(IOC_INOUT,	EVDEV_IOC_MAGIC, 0x0a, len)	/* get MT slots values */
91 
92 #define	EVIOCGKEY(len)		_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x18, len)	/* get global key state */
93 #define	EVIOCGLED(len)		_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x19, len)	/* get all LEDs */
94 #define	EVIOCGSND(len)		_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x1a, len)	/* get all sounds status */
95 #define	EVIOCGSW(len)		_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x1b, len)	/* get all switch states */
96 
97 #define	EVIOCGBIT(ev,len)	_IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x20 + (ev), len)	/* get event bits */
98 #define	EVIOCGABS(abs)		_IOR(EVDEV_IOC_MAGIC, 0x40 + (abs), struct input_absinfo)	/* get abs value/limits */
99 #define	EVIOCSABS(abs)		_IOW(EVDEV_IOC_MAGIC, 0xc0 + (abs), struct input_absinfo)	/* set abs value/limits */
100 
101 #define	EVIOCSFF		_IOW(EVDEV_IOC_MAGIC, 0x80, struct ff_effect)	/* send a force effect to a force feedback device */
102 #define	EVIOCRMFF		_IOWINT(EVDEV_IOC_MAGIC, 0x81)			/* Erase a force effect */
103 #define	EVIOCGEFFECTS		_IOR(EVDEV_IOC_MAGIC, 0x84, int)		/* Report number of effects playable at the same time */
104 
105 #define	EVIOCGRAB		_IOWINT(EVDEV_IOC_MAGIC, 0x90)			/* Grab/Release device */
106 #define	EVIOCREVOKE		_IOWINT(EVDEV_IOC_MAGIC, 0x91)			/* Revoke device access */
107 
108 #define	EVIOCSCLOCKID		_IOW(EVDEV_IOC_MAGIC, 0xa0, int)		/* Set clockid to be used for timestamps */
109 
110 /*
111  * IDs.
112  */
113 
114 #define	ID_BUS			0
115 #define	ID_VENDOR		1
116 #define	ID_PRODUCT		2
117 #define	ID_VERSION		3
118 
119 #define	BUS_PCI			0x01
120 #define	BUS_ISAPNP		0x02
121 #define	BUS_USB			0x03
122 #define	BUS_HIL			0x04
123 #define	BUS_BLUETOOTH		0x05
124 #define	BUS_VIRTUAL		0x06
125 
126 #define	BUS_ISA			0x10
127 #define	BUS_I8042		0x11
128 #define	BUS_XTKBD		0x12
129 #define	BUS_RS232		0x13
130 #define	BUS_GAMEPORT		0x14
131 #define	BUS_PARPORT		0x15
132 #define	BUS_AMIGA		0x16
133 #define	BUS_ADB			0x17
134 #define	BUS_I2C			0x18
135 #define	BUS_HOST		0x19
136 #define	BUS_GSC			0x1A
137 #define	BUS_ATARI		0x1B
138 #define	BUS_SPI			0x1C
139 
140 /*
141  * MT_TOOL types
142  */
143 #define	MT_TOOL_FINGER		0
144 #define	MT_TOOL_PEN		1
145 #define	MT_TOOL_PALM		2
146 #define	MT_TOOL_MAX		2
147 
148 /*
149  * Values describing the status of a force-feedback effect
150  */
151 #define	FF_STATUS_STOPPED	0x00
152 #define	FF_STATUS_PLAYING	0x01
153 #define	FF_STATUS_MAX		0x01
154 
155 /* scheduling info for force feedback effect */
156 struct ff_replay {
157 	uint16_t	length;		/* length of the effect (ms) */
158 	uint16_t	delay;		/* delay before effect starts (ms) */
159 };
160 
161 /* trigger for force feedback effect */
162 struct ff_trigger {
163 	uint16_t	button;		/* trigger button number */
164 	uint16_t	interval;	/* delay between re-triggers */
165 };
166 
167 /* force feedback effect envelop */
168 struct ff_envelope {
169 	uint16_t	attack_length;	/* duration of the attach (ms) */
170 	uint16_t	attack_level;	/* level at the beginning (0x0000 - 0x7fff) */
171 	uint16_t	fade_length;	/* duratin of fade (ms) */
172 	uint16_t	fade_level;	/* level at the end of fade */
173 };
174 
175 struct ff_constant_effect {
176 	int16_t			level;
177 	struct ff_envelope	envelope;
178 };
179 
180 struct ff_ramp_effect {
181 	int16_t			start_level;
182 	int16_t			end_level;
183 	struct ff_envelope	envelope;
184 };
185 
186 struct ff_condition_effect {
187 	/* maximum level when joystick moved to respective side */
188 	uint16_t	right_saturation;
189 
190 	uint16_t	left_saturation;
191 	/* how fast force grows when joystick move to the respective side */
192 	int16_t		right_coeff;
193 	int16_t		left_coeff;
194 
195 	uint16_t	deadband;	/* size of dead zone when no force is produced */
196 	int16_t		center;		/* center of dead zone */
197 };
198 
199 /*
200  * Force feedback periodic effect types
201  */
202 
203 #define	FF_SQUARE	0x58
204 #define	FF_TRIANGLE	0x59
205 #define	FF_SINE		0x5a
206 #define	FF_SAW_UP	0x5b
207 #define	FF_SAW_DOWN	0x5c
208 #define	FF_CUSTOM	0x5d
209 
210 #define	FF_WAVEFORM_MIN	FF_SQUARE
211 #define	FF_WAVEFORM_MAX	FF_CUSTOM
212 
213 struct ff_periodic_effect {
214 	uint16_t		waveform;
215 	uint16_t		period;		/* ms */
216 	int16_t			magnitude;	/* peak */
217 	int16_t			offset;		/* mean, roughly */
218 	uint16_t		phase;		/* horizontal shift */
219 	struct ff_envelope	envelope;
220 	uint32_t		custom_len;	/* FF_CUSTOM waveform only */
221 	int16_t			*custom_data;	/* FF_CUSTOM waveform only */
222 };
223 
224 struct ff_rumble_effect {
225 	uint16_t	strong_magnitude;	/* magnitude of the heavy motor */
226 	uint16_t	weak_magnitude;		/* magnitude of the light motor */
227 };
228 
229 /*
230  * Force feedback effect types
231  */
232 
233 #define	FF_RUMBLE	0x50
234 #define	FF_PERIODIC	0x51
235 #define	FF_CONSTANT	0x52
236 #define	FF_SPRING	0x53
237 #define	FF_FRICTION	0x54
238 #define	FF_DAMPER	0x55
239 #define	FF_INERTIA	0x56
240 #define	FF_RAMP		0x57
241 
242 #define	FF_EFFECT_MIN	FF_RUMBLE
243 #define	FF_EFFECT_MAX	FF_RAMP
244 
245 struct ff_effect {
246 	uint16_t		type;
247 	int16_t			id;
248 	uint16_t		direction;	/* [0 .. 360) degrees -> [0 .. 0x10000) */
249 	struct ff_trigger	trigger;
250 	struct ff_replay	replay;
251 
252 	union {
253 		struct ff_constant_effect	constant;
254 		struct ff_ramp_effect		ramp;
255 		struct ff_periodic_effect	periodic;
256 		struct ff_condition_effect	condition[2]; /* One for each axis */
257 		struct ff_rumble_effect		rumble;
258 	} u;
259 };
260 
261 /*
262  * force feedback device properties
263  */
264 
265 #define	FF_GAIN		0x60
266 #define	FF_AUTOCENTER	0x61
267 
268 #define	FF_MAX		0x7f
269 #define	FF_CNT		(FF_MAX+1)
270 
271 #endif /* _EVDEV_INPUT_H */
272