2 * Copyright (c) 2016 Oleksandr Tymoshenko <gonzo@FreeBSD.org>
3 * Copyright (c) 2015-2016 Vladimir Kondratyev <wulf@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
30 #ifndef _EVDEV_INPUT_H
31 #define _EVDEV_INPUT_H
33 #include <sys/ioccom.h>
35 #include <sys/types.h>
37 #include "input-event-codes.h"
39 #define input_event_sec time.tv_sec
40 #define input_event_usec time.tv_usec
49 #define EV_VERSION 0x010001
58 struct input_absinfo {
67 #define INPUT_KEYMAP_BY_INDEX (1 << 0)
69 struct input_keymap_entry {
77 #define EVDEV_IOC_MAGIC 'E'
78 #define EVIOCGVERSION _IOR(EVDEV_IOC_MAGIC, 0x01, int) /* get driver version */
79 #define EVIOCGID _IOR(EVDEV_IOC_MAGIC, 0x02, struct input_id) /* get device ID */
80 #define EVIOCGREP _IOR(EVDEV_IOC_MAGIC, 0x03, unsigned int[2]) /* get repeat settings */
81 #define EVIOCSREP _IOW(EVDEV_IOC_MAGIC, 0x03, unsigned int[2]) /* set repeat settings */
83 #define EVIOCGKEYCODE _IOWR(EVDEV_IOC_MAGIC, 0x04, unsigned int[2]) /* get keycode */
84 #define EVIOCGKEYCODE_V2 _IOWR(EVDEV_IOC_MAGIC, 0x04, struct input_keymap_entry)
85 #define EVIOCSKEYCODE _IOW(EVDEV_IOC_MAGIC, 0x04, unsigned int[2]) /* set keycode */
86 #define EVIOCSKEYCODE_V2 _IOW(EVDEV_IOC_MAGIC, 0x04, struct input_keymap_entry)
88 #define EVIOCGNAME(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x06, len) /* get device name */
89 #define EVIOCGPHYS(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x07, len) /* get physical location */
90 #define EVIOCGUNIQ(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x08, len) /* get unique identifier */
91 #define EVIOCGPROP(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x09, len) /* get device properties */
93 #define EVIOCGMTSLOTS(len) _IOC(IOC_INOUT, EVDEV_IOC_MAGIC, 0x0a, len) /* get MT slots values */
95 #define EVIOCGKEY(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x18, len) /* get global key state */
96 #define EVIOCGLED(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x19, len) /* get all LEDs */
97 #define EVIOCGSND(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x1a, len) /* get all sounds status */
98 #define EVIOCGSW(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x1b, len) /* get all switch states */
100 #define EVIOCGBIT(ev,len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x20 + (ev), len) /* get event bits */
101 #define EVIOCGABS(abs) _IOR(EVDEV_IOC_MAGIC, 0x40 + (abs), struct input_absinfo) /* get abs value/limits */
102 #define EVIOCSABS(abs) _IOW(EVDEV_IOC_MAGIC, 0xc0 + (abs), struct input_absinfo) /* set abs value/limits */
104 #define EVIOCSFF _IOW(EVDEV_IOC_MAGIC, 0x80, struct ff_effect) /* send a force effect to a force feedback device */
105 #define EVIOCRMFF _IOWINT(EVDEV_IOC_MAGIC, 0x81) /* Erase a force effect */
106 #define EVIOCGEFFECTS _IOR(EVDEV_IOC_MAGIC, 0x84, int) /* Report number of effects playable at the same time */
108 #define EVIOCGRAB _IOWINT(EVDEV_IOC_MAGIC, 0x90) /* Grab/Release device */
109 #define EVIOCREVOKE _IOWINT(EVDEV_IOC_MAGIC, 0x91) /* Revoke device access */
111 #define EVIOCSCLOCKID _IOW(EVDEV_IOC_MAGIC, 0xa0, int) /* Set clockid to be used for timestamps */
123 #define BUS_ISAPNP 0x02
126 #define BUS_BLUETOOTH 0x05
127 #define BUS_VIRTUAL 0x06
130 #define BUS_I8042 0x11
131 #define BUS_XTKBD 0x12
132 #define BUS_RS232 0x13
133 #define BUS_GAMEPORT 0x14
134 #define BUS_PARPORT 0x15
135 #define BUS_AMIGA 0x16
138 #define BUS_HOST 0x19
140 #define BUS_ATARI 0x1B
144 #define BUS_INTEL_ISHTP 0x1F
149 #define MT_TOOL_FINGER 0
150 #define MT_TOOL_PEN 1
151 #define MT_TOOL_PALM 2
152 #define MT_TOOL_MAX 2
155 * Values describing the status of a force-feedback effect
157 #define FF_STATUS_STOPPED 0x00
158 #define FF_STATUS_PLAYING 0x01
159 #define FF_STATUS_MAX 0x01
161 /* scheduling info for force feedback effect */
163 uint16_t length; /* length of the effect (ms) */
164 uint16_t delay; /* delay before effect starts (ms) */
167 /* trigger for force feedback effect */
169 uint16_t button; /* trigger button number */
170 uint16_t interval; /* delay between re-triggers */
173 /* force feedback effect envelop */
175 uint16_t attack_length; /* duration of the attach (ms) */
176 uint16_t attack_level; /* level at the beginning (0x0000 - 0x7fff) */
177 uint16_t fade_length; /* duratin of fade (ms) */
178 uint16_t fade_level; /* level at the end of fade */
181 struct ff_constant_effect {
183 struct ff_envelope envelope;
186 struct ff_ramp_effect {
189 struct ff_envelope envelope;
192 struct ff_condition_effect {
193 /* maximum level when joystick moved to respective side */
194 uint16_t right_saturation;
196 uint16_t left_saturation;
197 /* how fast force grows when joystick move to the respective side */
201 uint16_t deadband; /* size of dead zone when no force is produced */
202 int16_t center; /* center of dead zone */
206 * Force feedback periodic effect types
209 #define FF_SQUARE 0x58
210 #define FF_TRIANGLE 0x59
212 #define FF_SAW_UP 0x5b
213 #define FF_SAW_DOWN 0x5c
214 #define FF_CUSTOM 0x5d
216 #define FF_WAVEFORM_MIN FF_SQUARE
217 #define FF_WAVEFORM_MAX FF_CUSTOM
219 struct ff_periodic_effect {
221 uint16_t period; /* ms */
222 int16_t magnitude; /* peak */
223 int16_t offset; /* mean, roughly */
224 uint16_t phase; /* horizontal shift */
225 struct ff_envelope envelope;
226 uint32_t custom_len; /* FF_CUSTOM waveform only */
227 int16_t *custom_data; /* FF_CUSTOM waveform only */
230 struct ff_rumble_effect {
231 uint16_t strong_magnitude; /* magnitude of the heavy motor */
232 uint16_t weak_magnitude; /* magnitude of the light motor */
236 * Force feedback effect types
239 #define FF_RUMBLE 0x50
240 #define FF_PERIODIC 0x51
241 #define FF_CONSTANT 0x52
242 #define FF_SPRING 0x53
243 #define FF_FRICTION 0x54
244 #define FF_DAMPER 0x55
245 #define FF_INERTIA 0x56
248 #define FF_EFFECT_MIN FF_RUMBLE
249 #define FF_EFFECT_MAX FF_RAMP
254 uint16_t direction; /* [0 .. 360) degrees -> [0 .. 0x10000) */
255 struct ff_trigger trigger;
256 struct ff_replay replay;
259 struct ff_constant_effect constant;
260 struct ff_ramp_effect ramp;
261 struct ff_periodic_effect periodic;
262 struct ff_condition_effect condition[2]; /* One for each axis */
263 struct ff_rumble_effect rumble;
268 * force feedback device properties
272 #define FF_AUTOCENTER 0x61
275 #define FF_CNT (FF_MAX+1)
277 #endif /* _EVDEV_INPUT_H */