Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / dmx / input / usb-other.c
CommitLineData
a09e091a
JB
1/*
2 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
3 *
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28/*
29 * Authors:
30 * Rickard E. (Rik) Faith <faith@redhat.com>
31 *
32 */
33
34/** \file
35 *
36 * This code implements a low-level device driver for a non-keyboard,
37 * non-mouse USB device (e.g., a joystick or gamepad). */
38
39#ifdef HAVE_DMX_CONFIG_H
40#include <dmx-config.h>
41#endif
42
43#include "usb-private.h"
44
45/*****************************************************************************/
46/* Define some macros to make it easier to move this file to another
47 * part of the Xserver tree. All calls to the dmx* layer are #defined
48 * here for the .c file. The .h file will also have to be edited. */
49#include "dmxinputinit.h"
50#include "usb-other.h"
51
52#define GETPRIV myPrivate *priv \
53 = ((DMXLocalInputInfoPtr)(pDev->devicePrivate))->private
54
55#define LOG0(f) dmxLog(dmxDebug,f)
56#define LOG1(f,a) dmxLog(dmxDebug,f,a)
57#define LOG2(f,a,b) dmxLog(dmxDebug,f,a,b)
58#define LOG3(f,a,b,c) dmxLog(dmxDebug,f,a,b,c)
59#define FATAL0(f) dmxLog(dmxFatal,f)
60#define FATAL1(f,a) dmxLog(dmxFatal,f,a)
61#define FATAL2(f,a,b) dmxLog(dmxFatal,f,a,b)
62#define MOTIONPROC dmxMotionProcPtr
63#define ENQUEUEPROC dmxEnqueueProcPtr
64#define CHECKPROC dmxCheckSpecialProcPtr
65#define BLOCK DMXBlockType
66
67/* End of interface definitions. */
68/*****************************************************************************/
69
70/** Read the USB device using #usbRead. */
71void
72othUSBRead(DevicePtr pDev,
73 MOTIONPROC motion,
74 ENQUEUEPROC enqueue, CHECKPROC checkspecial, BLOCK block)
75{
76 usbRead(pDev, motion, enqueue, 0xffff, block);
77}
78
79/** Initialize \a pDev using #usbInit. */
80void
81othUSBInit(DevicePtr pDev)
82{
83 usbInit(pDev, usbOther);
84}
85
86/** Turn \a pDev on (i.e., take input from \a pDev). */
87int
88othUSBOn(DevicePtr pDev)
89{
90 GETPRIV;
91
92 if (priv->fd < 0)
93 othUSBInit(pDev);
94 return priv->fd;
95}
96
97/** Fill the \a info structure with information needed to initialize \a
98 * pDev. */
99void
100othUSBGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
101{
102 GETPRIV;
103 int i, j;
104 static KeySym keyboard_mapping = NoSymbol;
105 int absolute[5];
106
107#define test_bit(bit) (priv->mask[(bit)/8] & (1 << ((bit)%8)))
108
109 /* Some USB mice devices return key
110 * events from their pair'd
111 * keyboard... */
112 info->keyClass = 1;
113 info->keySyms.minKeyCode = 8;
114 info->keySyms.maxKeyCode = 8;
115 info->keySyms.mapWidth = 1;
116 info->keySyms.map = &keyboard_mapping;
117
118 for (i = 0; i < EV_MAX; i++) {
119 if (test_bit(i)) {
120 switch (i) {
121 case EV_KEY:
122 /* See above */
123 break;
124 case EV_REL:
125 info->valuatorClass = 1;
126 if (info->numRelAxes + info->numAbsAxes > DMX_MAX_AXES - 1) {
127 info->numRelAxes = DMX_MAX_AXES - info->numAbsAxes - 1;
128 dmxLog(dmxWarning, "Can only use %d relative axes\n",
129 info->numRelAxes);
130 }
131 else
132 info->numRelAxes = priv->numRel;
133 info->minval[0] = 0;
134 info->maxval[0] = 0;
135 info->res[0] = 1;
136 info->minres[0] = 0;
137 info->maxres[0] = 1;
138 break;
139 case EV_ABS:
140 info->valuatorClass = 1;
141 if (info->numRelAxes + info->numAbsAxes > DMX_MAX_AXES - 1) {
142 info->numAbsAxes = DMX_MAX_AXES - info->numRelAxes - 1;
143 dmxLog(dmxWarning, "Can only use %d absolute axes\n",
144 info->numAbsAxes);
145 }
146 else
147 info->numAbsAxes = priv->numAbs;
148 for (j = 0; j < info->numAbsAxes; j++) {
149 ioctl(priv->fd, EVIOCGABS(j), absolute);
150 info->minval[1 + j] = absolute[1];
151 info->maxval[1 + j] = absolute[2];
152 info->res[1 + j] = absolute[3];
153 info->minres[1 + j] = absolute[3];
154 info->maxres[1 + j] = absolute[3];
155 }
156 break;
157 case EV_LED:
158 info->ledFeedbackClass = 0; /* Not supported at this time */
159 break;
160 case EV_SND:
161 info->belFeedbackClass = 0; /* Not supported at this time */
162 break;
163 }
164 }
165 }
166}