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: stable/11/sys/dev/evdev/input.h 362207 2020-06-15 22:35:39Z wulf $ 28 */ 29 30#ifndef _EVDEV_INPUT_H 31#define _EVDEV_INPUT_H 32 33#ifndef __KERNEL__ 34#include <sys/ioccom.h> 35#include <sys/time.h> 36#include <sys/types.h> 37#endif 38 39#include "input-event-codes.h" 40 41#define input_event_sec time.tv_sec 42#define input_event_usec time.tv_usec 43 44struct input_event { 45 struct timeval time; 46 uint16_t type; 47 uint16_t code; 48 int32_t value; 49}; 50 51#define EV_VERSION 0x010001 52 53struct input_id { 54 uint16_t bustype; 55 uint16_t vendor; 56 uint16_t product; 57 uint16_t version; 58}; 59 60struct input_absinfo { 61 int32_t value; 62 int32_t minimum; 63 int32_t maximum; 64 int32_t fuzz; 65 int32_t flat; 66 int32_t resolution; 67}; 68 69#define INPUT_KEYMAP_BY_INDEX (1 << 0) 70 71struct input_keymap_entry { 72 uint8_t flags; 73 uint8_t len; 74 uint16_t index; 75 uint32_t keycode; 76 uint8_t scancode[32]; 77}; 78 79#define EVDEV_IOC_MAGIC 'E' 80#define EVIOCGVERSION _IOR(EVDEV_IOC_MAGIC, 0x01, int) /* get driver version */ 81#define EVIOCGID _IOR(EVDEV_IOC_MAGIC, 0x02, struct input_id) /* get device ID */ 82#define EVIOCGREP _IOR(EVDEV_IOC_MAGIC, 0x03, unsigned int[2]) /* get repeat settings */ 83#define EVIOCSREP _IOW(EVDEV_IOC_MAGIC, 0x03, unsigned int[2]) /* set repeat settings */ 84 85#define EVIOCGKEYCODE _IOWR(EVDEV_IOC_MAGIC, 0x04, unsigned int[2]) /* get keycode */ 86#define EVIOCGKEYCODE_V2 _IOWR(EVDEV_IOC_MAGIC, 0x04, struct input_keymap_entry) 87#define EVIOCSKEYCODE _IOW(EVDEV_IOC_MAGIC, 0x04, unsigned int[2]) /* set keycode */ 88#define EVIOCSKEYCODE_V2 _IOW(EVDEV_IOC_MAGIC, 0x04, struct input_keymap_entry) 89 90#define EVIOCGNAME(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x06, len) /* get device name */ 91#define EVIOCGPHYS(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x07, len) /* get physical location */ 92#define EVIOCGUNIQ(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x08, len) /* get unique identifier */ 93#define EVIOCGPROP(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x09, len) /* get device properties */ 94 95#define EVIOCGMTSLOTS(len) _IOC(IOC_INOUT, EVDEV_IOC_MAGIC, 0x0a, len) /* get MT slots values */ 96 97#define EVIOCGKEY(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x18, len) /* get global key state */ 98#define EVIOCGLED(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x19, len) /* get all LEDs */ 99#define EVIOCGSND(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x1a, len) /* get all sounds status */ 100#define EVIOCGSW(len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x1b, len) /* get all switch states */ 101 102#define EVIOCGBIT(ev,len) _IOC(IOC_OUT, EVDEV_IOC_MAGIC, 0x20 + (ev), len) /* get event bits */ 103#define EVIOCGABS(abs) _IOR(EVDEV_IOC_MAGIC, 0x40 + (abs), struct input_absinfo) /* get abs value/limits */ 104#define EVIOCSABS(abs) _IOW(EVDEV_IOC_MAGIC, 0xc0 + (abs), struct input_absinfo) /* set abs value/limits */ 105 106#define EVIOCSFF _IOW(EVDEV_IOC_MAGIC, 0x80, struct ff_effect) /* send a force effect to a force feedback device */ 107#define EVIOCRMFF _IOWINT(EVDEV_IOC_MAGIC, 0x81) /* Erase a force effect */ 108#define EVIOCGEFFECTS _IOR(EVDEV_IOC_MAGIC, 0x84, int) /* Report number of effects playable at the same time */ 109 110#define EVIOCGRAB _IOWINT(EVDEV_IOC_MAGIC, 0x90) /* Grab/Release device */ 111#define EVIOCREVOKE _IOWINT(EVDEV_IOC_MAGIC, 0x91) /* Revoke device access */ 112 113#define EVIOCSCLOCKID _IOW(EVDEV_IOC_MAGIC, 0xa0, int) /* Set clockid to be used for timestamps */ 114 115/* 116 * IDs. 117 */ 118 119#define ID_BUS 0 120#define ID_VENDOR 1 121#define ID_PRODUCT 2 122#define ID_VERSION 3 123 124#define BUS_PCI 0x01 125#define BUS_ISAPNP 0x02 126#define BUS_USB 0x03 127#define BUS_HIL 0x04 128#define BUS_BLUETOOTH 0x05 129#define BUS_VIRTUAL 0x06 130 131#define BUS_ISA 0x10 132#define BUS_I8042 0x11 133#define BUS_XTKBD 0x12 134#define BUS_RS232 0x13 135#define BUS_GAMEPORT 0x14 136#define BUS_PARPORT 0x15 137#define BUS_AMIGA 0x16 138#define BUS_ADB 0x17 139#define BUS_I2C 0x18 140#define BUS_HOST 0x19 141#define BUS_GSC 0x1A 142#define BUS_ATARI 0x1B 143#define BUS_SPI 0x1C 144#define BUS_RMI 0x1D 145#define BUS_CEC 0x1E 146#define BUS_INTEL_ISHTP 0x1F 147 148/* 149 * MT_TOOL types 150 */ 151#define MT_TOOL_FINGER 0x00 152#define MT_TOOL_PEN 0x01 153#define MT_TOOL_PALM 0x02 154#define MT_TOOL_DIAL 0x0a 155#define MT_TOOL_MAX 0x0f 156 157/* 158 * Values describing the status of a force-feedback effect 159 */ 160#define FF_STATUS_STOPPED 0x00 161#define FF_STATUS_PLAYING 0x01 162#define FF_STATUS_MAX 0x01 163 164/* scheduling info for force feedback effect */ 165struct ff_replay { 166 uint16_t length; /* length of the effect (ms) */ 167 uint16_t delay; /* delay before effect starts (ms) */ 168}; 169 170/* trigger for force feedback effect */ 171struct ff_trigger { 172 uint16_t button; /* trigger button number */ 173 uint16_t interval; /* delay between re-triggers */ 174}; 175 176/* force feedback effect envelop */ 177struct ff_envelope { 178 uint16_t attack_length; /* duration of the attach (ms) */ 179 uint16_t attack_level; /* level at the beginning (0x0000 - 0x7fff) */ 180 uint16_t fade_length; /* duratin of fade (ms) */ 181 uint16_t fade_level; /* level at the end of fade */ 182}; 183 184struct ff_constant_effect { 185 int16_t level; 186 struct ff_envelope envelope; 187}; 188 189struct ff_ramp_effect { 190 int16_t start_level; 191 int16_t end_level; 192 struct ff_envelope envelope; 193}; 194 195struct ff_condition_effect { 196 /* maximum level when joystick moved to respective side */ 197 uint16_t right_saturation; 198 199 uint16_t left_saturation; 200 /* how fast force grows when joystick move to the respective side */ 201 int16_t right_coeff; 202 int16_t left_coeff; 203 204 uint16_t deadband; /* size of dead zone when no force is produced */ 205 int16_t center; /* center of dead zone */ 206}; 207 208/* 209 * Force feedback periodic effect types 210 */ 211 212#define FF_SQUARE 0x58 213#define FF_TRIANGLE 0x59 214#define FF_SINE 0x5a 215#define FF_SAW_UP 0x5b 216#define FF_SAW_DOWN 0x5c 217#define FF_CUSTOM 0x5d 218 219#define FF_WAVEFORM_MIN FF_SQUARE 220#define FF_WAVEFORM_MAX FF_CUSTOM 221 222struct ff_periodic_effect { 223 uint16_t waveform; 224 uint16_t period; /* ms */ 225 int16_t magnitude; /* peak */ 226 int16_t offset; /* mean, roughly */ 227 uint16_t phase; /* horizontal shift */ 228 struct ff_envelope envelope; 229 uint32_t custom_len; /* FF_CUSTOM waveform only */ 230 int16_t *custom_data; /* FF_CUSTOM waveform only */ 231}; 232 233struct ff_rumble_effect { 234 uint16_t strong_magnitude; /* magnitude of the heavy motor */ 235 uint16_t weak_magnitude; /* magnitude of the light motor */ 236}; 237 238/* 239 * Force feedback effect types 240 */ 241 242#define FF_RUMBLE 0x50 243#define FF_PERIODIC 0x51 244#define FF_CONSTANT 0x52 245#define FF_SPRING 0x53 246#define FF_FRICTION 0x54 247#define FF_DAMPER 0x55 248#define FF_INERTIA 0x56 249#define FF_RAMP 0x57 250 251#define FF_EFFECT_MIN FF_RUMBLE 252#define FF_EFFECT_MAX FF_RAMP 253 254struct ff_effect { 255 uint16_t type; 256 int16_t id; 257 uint16_t direction; /* [0 .. 360) degrees -> [0 .. 0x10000) */ 258 struct ff_trigger trigger; 259 struct ff_replay replay; 260 261 union { 262 struct ff_constant_effect constant; 263 struct ff_ramp_effect ramp; 264 struct ff_periodic_effect periodic; 265 struct ff_condition_effect condition[2]; /* One for each axis */ 266 struct ff_rumble_effect rumble; 267 } u; 268}; 269 270/* 271 * force feedback device properties 272 */ 273 274#define FF_GAIN 0x60 275#define FF_AUTOCENTER 0x61 276 277#define FF_MAX 0x7f 278#define FF_CNT (FF_MAX+1) 279 280#endif /* _EVDEV_INPUT_H */ 281