mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-14 03:32:18 +08:00
Add FREEBSD USB input device files
This commit is contained in:
parent
41d2784207
commit
3e7de301c1
2636
freebsd/sys/dev/usb/input/atp.c
Normal file
2636
freebsd/sys/dev/usb/input/atp.c
Normal file
File diff suppressed because it is too large
Load Diff
446
freebsd/sys/dev/usb/input/uep.c
Normal file
446
freebsd/sys/dev/usb/input/uep.c
Normal file
@ -0,0 +1,446 @@
|
||||
#include <machine/rtems-bsd-kernel-space.h>
|
||||
|
||||
/*-
|
||||
* Copyright 2010, Gleb Smirnoff <glebius@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
* http://www.eeti.com.tw/pdf/Software%20Programming%20Guide_v2.0.pdf
|
||||
*/
|
||||
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/callout.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <rtems/bsd/sys/lock.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/systm.h>
|
||||
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
#include <dev/usb/usbhid.h>
|
||||
#include <rtems/bsd/local/usbdevs.h>
|
||||
|
||||
#include <sys/ioccom.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/tty.h>
|
||||
|
||||
#define USB_DEBUG_VAR uep_debug
|
||||
#include <dev/usb/usb_debug.h>
|
||||
|
||||
#ifdef USB_DEBUG
|
||||
static int uep_debug = 0;
|
||||
|
||||
static SYSCTL_NODE(_hw_usb, OID_AUTO, uep, CTLFLAG_RW, 0, "USB uep");
|
||||
SYSCTL_INT(_hw_usb_uep, OID_AUTO, debug, CTLFLAG_RWTUN,
|
||||
&uep_debug, 0, "Debug level");
|
||||
#endif
|
||||
|
||||
#define UEP_MAX_X 2047
|
||||
#define UEP_MAX_Y 2047
|
||||
|
||||
#define UEP_DOWN 0x01
|
||||
#define UEP_PACKET_LEN_MAX 16
|
||||
#define UEP_PACKET_LEN_REPORT 5
|
||||
#define UEP_PACKET_LEN_REPORT2 6
|
||||
#define UEP_PACKET_DIAG 0x0a
|
||||
#define UEP_PACKET_REPORT_MASK 0xe0
|
||||
#define UEP_PACKET_REPORT 0x80
|
||||
#define UEP_PACKET_REPORT_PRESSURE 0xc0
|
||||
#define UEP_PACKET_REPORT_PLAYER 0xa0
|
||||
#define UEP_PACKET_LEN_MASK
|
||||
|
||||
#define UEP_FIFO_BUF_SIZE 8 /* bytes */
|
||||
#define UEP_FIFO_QUEUE_MAXLEN 50 /* units */
|
||||
|
||||
enum {
|
||||
UEP_INTR_DT,
|
||||
UEP_N_TRANSFER,
|
||||
};
|
||||
|
||||
struct uep_softc {
|
||||
struct mtx mtx;
|
||||
|
||||
struct usb_xfer *xfer[UEP_N_TRANSFER];
|
||||
struct usb_fifo_sc fifo;
|
||||
|
||||
u_int pollrate;
|
||||
u_int state;
|
||||
#define UEP_ENABLED 0x01
|
||||
|
||||
/* Reassembling buffer. */
|
||||
u_char buf[UEP_PACKET_LEN_MAX];
|
||||
uint8_t buf_len;
|
||||
};
|
||||
|
||||
static usb_callback_t uep_intr_callback;
|
||||
|
||||
static device_probe_t uep_probe;
|
||||
static device_attach_t uep_attach;
|
||||
static device_detach_t uep_detach;
|
||||
|
||||
static usb_fifo_cmd_t uep_start_read;
|
||||
static usb_fifo_cmd_t uep_stop_read;
|
||||
static usb_fifo_open_t uep_open;
|
||||
static usb_fifo_close_t uep_close;
|
||||
|
||||
static void uep_put_queue(struct uep_softc *, u_char *);
|
||||
|
||||
static struct usb_fifo_methods uep_fifo_methods = {
|
||||
.f_open = &uep_open,
|
||||
.f_close = &uep_close,
|
||||
.f_start_read = &uep_start_read,
|
||||
.f_stop_read = &uep_stop_read,
|
||||
.basename[0] = "uep",
|
||||
};
|
||||
|
||||
static int
|
||||
get_pkt_len(u_char *buf)
|
||||
{
|
||||
if (buf[0] == UEP_PACKET_DIAG) {
|
||||
int len;
|
||||
|
||||
len = buf[1] + 2;
|
||||
if (len > UEP_PACKET_LEN_MAX) {
|
||||
DPRINTF("bad packet len %u\n", len);
|
||||
return (UEP_PACKET_LEN_MAX);
|
||||
}
|
||||
|
||||
return (len);
|
||||
}
|
||||
|
||||
switch (buf[0] & UEP_PACKET_REPORT_MASK) {
|
||||
case UEP_PACKET_REPORT:
|
||||
return (UEP_PACKET_LEN_REPORT);
|
||||
case UEP_PACKET_REPORT_PRESSURE:
|
||||
case UEP_PACKET_REPORT_PLAYER:
|
||||
case UEP_PACKET_REPORT_PRESSURE | UEP_PACKET_REPORT_PLAYER:
|
||||
return (UEP_PACKET_LEN_REPORT2);
|
||||
default:
|
||||
DPRINTF("bad packet len 0\n");
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
uep_process_pkt(struct uep_softc *sc, u_char *buf)
|
||||
{
|
||||
int32_t x, y;
|
||||
|
||||
if ((buf[0] & 0xFE) != 0x80) {
|
||||
DPRINTF("bad input packet format 0x%.2x\n", buf[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Packet format is 5 bytes:
|
||||
*
|
||||
* 1000000T
|
||||
* 0000AAAA
|
||||
* 0AAAAAAA
|
||||
* 0000BBBB
|
||||
* 0BBBBBBB
|
||||
*
|
||||
* T: 1=touched 0=not touched
|
||||
* A: bits of axis A position, MSB to LSB
|
||||
* B: bits of axis B position, MSB to LSB
|
||||
*
|
||||
* For the unit I have, which is CTF1020-S from CarTFT.com,
|
||||
* A = X and B = Y. But in NetBSD uep(4) it is other way round :)
|
||||
*
|
||||
* The controller sends a stream of T=1 events while the
|
||||
* panel is touched, followed by a single T=0 event.
|
||||
*
|
||||
*/
|
||||
|
||||
x = (buf[1] << 7) | buf[2];
|
||||
y = (buf[3] << 7) | buf[4];
|
||||
|
||||
DPRINTFN(2, "x %u y %u\n", x, y);
|
||||
|
||||
uep_put_queue(sc, buf);
|
||||
}
|
||||
|
||||
static void
|
||||
uep_intr_callback(struct usb_xfer *xfer, usb_error_t error)
|
||||
{
|
||||
struct uep_softc *sc = usbd_xfer_softc(xfer);
|
||||
int len;
|
||||
|
||||
usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
|
||||
|
||||
switch (USB_GET_STATE(xfer)) {
|
||||
case USB_ST_TRANSFERRED:
|
||||
{
|
||||
struct usb_page_cache *pc;
|
||||
u_char buf[17], *p;
|
||||
int pkt_len;
|
||||
|
||||
if (len > (int)sizeof(buf)) {
|
||||
DPRINTF("bad input length %d\n", len);
|
||||
goto tr_setup;
|
||||
}
|
||||
|
||||
pc = usbd_xfer_get_frame(xfer, 0);
|
||||
usbd_copy_out(pc, 0, buf, len);
|
||||
|
||||
/*
|
||||
* The below code mimics Linux a lot. I don't know
|
||||
* why NetBSD reads complete packets, but we need
|
||||
* to reassamble 'em like Linux does (tries?).
|
||||
*/
|
||||
if (sc->buf_len > 0) {
|
||||
int res;
|
||||
|
||||
if (sc->buf_len == 1)
|
||||
sc->buf[1] = buf[0];
|
||||
|
||||
if ((pkt_len = get_pkt_len(sc->buf)) == 0)
|
||||
goto tr_setup;
|
||||
|
||||
res = pkt_len - sc->buf_len;
|
||||
memcpy(sc->buf + sc->buf_len, buf, res);
|
||||
uep_process_pkt(sc, sc->buf);
|
||||
sc->buf_len = 0;
|
||||
|
||||
p = buf + res;
|
||||
len -= res;
|
||||
} else
|
||||
p = buf;
|
||||
|
||||
if (len == 1) {
|
||||
sc->buf[0] = buf[0];
|
||||
sc->buf_len = 1;
|
||||
|
||||
goto tr_setup;
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
if ((pkt_len = get_pkt_len(p)) == 0)
|
||||
goto tr_setup;
|
||||
|
||||
/* full packet: process */
|
||||
if (pkt_len <= len) {
|
||||
uep_process_pkt(sc, p);
|
||||
} else {
|
||||
/* incomplete packet: save in buffer */
|
||||
memcpy(sc->buf, p, len);
|
||||
sc->buf_len = len;
|
||||
}
|
||||
p += pkt_len;
|
||||
len -= pkt_len;
|
||||
}
|
||||
}
|
||||
case USB_ST_SETUP:
|
||||
tr_setup:
|
||||
/* check if we can put more data into the FIFO */
|
||||
if (usb_fifo_put_bytes_max(sc->fifo.fp[USB_FIFO_RX]) != 0) {
|
||||
usbd_xfer_set_frame_len(xfer, 0,
|
||||
usbd_xfer_max_len(xfer));
|
||||
usbd_transfer_submit(xfer);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (error != USB_ERR_CANCELLED) {
|
||||
/* try clear stall first */
|
||||
usbd_xfer_set_stall(xfer);
|
||||
goto tr_setup;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct usb_config uep_config[UEP_N_TRANSFER] = {
|
||||
[UEP_INTR_DT] = {
|
||||
.type = UE_INTERRUPT,
|
||||
.endpoint = UE_ADDR_ANY,
|
||||
.direction = UE_DIR_IN,
|
||||
.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
|
||||
.bufsize = 0, /* use wMaxPacketSize */
|
||||
.callback = &uep_intr_callback,
|
||||
},
|
||||
};
|
||||
|
||||
static const STRUCT_USB_HOST_ID uep_devs[] = {
|
||||
{USB_VPI(USB_VENDOR_EGALAX, USB_PRODUCT_EGALAX_TPANEL, 0)},
|
||||
{USB_VPI(USB_VENDOR_EGALAX, USB_PRODUCT_EGALAX_TPANEL2, 0)},
|
||||
{USB_VPI(USB_VENDOR_EGALAX2, USB_PRODUCT_EGALAX2_TPANEL, 0)},
|
||||
};
|
||||
|
||||
static int
|
||||
uep_probe(device_t dev)
|
||||
{
|
||||
struct usb_attach_arg *uaa = device_get_ivars(dev);
|
||||
|
||||
if (uaa->usb_mode != USB_MODE_HOST)
|
||||
return (ENXIO);
|
||||
if (uaa->info.bConfigIndex != 0)
|
||||
return (ENXIO);
|
||||
if (uaa->info.bIfaceIndex != 0)
|
||||
return (ENXIO);
|
||||
|
||||
return (usbd_lookup_id_by_uaa(uep_devs, sizeof(uep_devs), uaa));
|
||||
}
|
||||
|
||||
static int
|
||||
uep_attach(device_t dev)
|
||||
{
|
||||
struct usb_attach_arg *uaa = device_get_ivars(dev);
|
||||
struct uep_softc *sc = device_get_softc(dev);
|
||||
int error;
|
||||
|
||||
device_set_usb_desc(dev);
|
||||
|
||||
mtx_init(&sc->mtx, "uep lock", NULL, MTX_DEF);
|
||||
|
||||
error = usbd_transfer_setup(uaa->device, &uaa->info.bIfaceIndex,
|
||||
sc->xfer, uep_config, UEP_N_TRANSFER, sc, &sc->mtx);
|
||||
|
||||
if (error) {
|
||||
DPRINTF("usbd_transfer_setup error=%s\n", usbd_errstr(error));
|
||||
goto detach;
|
||||
}
|
||||
|
||||
error = usb_fifo_attach(uaa->device, sc, &sc->mtx, &uep_fifo_methods,
|
||||
&sc->fifo, device_get_unit(dev), -1, uaa->info.bIfaceIndex,
|
||||
UID_ROOT, GID_OPERATOR, 0644);
|
||||
|
||||
if (error) {
|
||||
DPRINTF("usb_fifo_attach error=%s\n", usbd_errstr(error));
|
||||
goto detach;
|
||||
}
|
||||
|
||||
sc->buf_len = 0;
|
||||
|
||||
return (0);
|
||||
|
||||
detach:
|
||||
uep_detach(dev);
|
||||
|
||||
return (ENOMEM); /* XXX */
|
||||
}
|
||||
|
||||
static int
|
||||
uep_detach(device_t dev)
|
||||
{
|
||||
struct uep_softc *sc = device_get_softc(dev);
|
||||
|
||||
usb_fifo_detach(&sc->fifo);
|
||||
|
||||
usbd_transfer_unsetup(sc->xfer, UEP_N_TRANSFER);
|
||||
|
||||
mtx_destroy(&sc->mtx);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
uep_start_read(struct usb_fifo *fifo)
|
||||
{
|
||||
struct uep_softc *sc = usb_fifo_softc(fifo);
|
||||
u_int rate;
|
||||
|
||||
if ((rate = sc->pollrate) > 1000)
|
||||
rate = 1000;
|
||||
|
||||
if (rate > 0 && sc->xfer[UEP_INTR_DT] != NULL) {
|
||||
usbd_transfer_stop(sc->xfer[UEP_INTR_DT]);
|
||||
usbd_xfer_set_interval(sc->xfer[UEP_INTR_DT], 1000 / rate);
|
||||
sc->pollrate = 0;
|
||||
}
|
||||
|
||||
usbd_transfer_start(sc->xfer[UEP_INTR_DT]);
|
||||
}
|
||||
|
||||
static void
|
||||
uep_stop_read(struct usb_fifo *fifo)
|
||||
{
|
||||
struct uep_softc *sc = usb_fifo_softc(fifo);
|
||||
|
||||
usbd_transfer_stop(sc->xfer[UEP_INTR_DT]);
|
||||
}
|
||||
|
||||
static void
|
||||
uep_put_queue(struct uep_softc *sc, u_char *buf)
|
||||
{
|
||||
usb_fifo_put_data_linear(sc->fifo.fp[USB_FIFO_RX], buf,
|
||||
UEP_PACKET_LEN_REPORT, 1);
|
||||
}
|
||||
|
||||
static int
|
||||
uep_open(struct usb_fifo *fifo, int fflags)
|
||||
{
|
||||
if (fflags & FREAD) {
|
||||
struct uep_softc *sc = usb_fifo_softc(fifo);
|
||||
|
||||
if (sc->state & UEP_ENABLED)
|
||||
return (EBUSY);
|
||||
if (usb_fifo_alloc_buffer(fifo, UEP_FIFO_BUF_SIZE,
|
||||
UEP_FIFO_QUEUE_MAXLEN))
|
||||
return (ENOMEM);
|
||||
|
||||
sc->state |= UEP_ENABLED;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
uep_close(struct usb_fifo *fifo, int fflags)
|
||||
{
|
||||
if (fflags & FREAD) {
|
||||
struct uep_softc *sc = usb_fifo_softc(fifo);
|
||||
|
||||
sc->state &= ~(UEP_ENABLED);
|
||||
usb_fifo_free_buffer(fifo);
|
||||
}
|
||||
}
|
||||
|
||||
static devclass_t uep_devclass;
|
||||
|
||||
static device_method_t uep_methods[] = {
|
||||
DEVMETHOD(device_probe, uep_probe),
|
||||
DEVMETHOD(device_attach, uep_attach),
|
||||
DEVMETHOD(device_detach, uep_detach),
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
static driver_t uep_driver = {
|
||||
.name = "uep",
|
||||
.methods = uep_methods,
|
||||
.size = sizeof(struct uep_softc),
|
||||
};
|
||||
|
||||
DRIVER_MODULE(uep, uhub, uep_driver, uep_devclass, NULL, NULL);
|
||||
MODULE_DEPEND(uep, usb, 1, 1, 1);
|
||||
MODULE_VERSION(uep, 1);
|
||||
USB_PNP_HOST_INFO(uep_devs);
|
883
freebsd/sys/dev/usb/input/uhid.c
Normal file
883
freebsd/sys/dev/usb/input/uhid.c
Normal file
@ -0,0 +1,883 @@
|
||||
#include <machine/rtems-bsd-kernel-space.h>
|
||||
|
||||
/* $NetBSD: uhid.c,v 1.46 2001/11/13 06:24:55 lukem Exp $ */
|
||||
|
||||
/* Also already merged from NetBSD:
|
||||
* $NetBSD: uhid.c,v 1.54 2002/09/23 05:51:21 simonb Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Lennart Augustsson (lennart@augustsson.net) at
|
||||
* Carlstedt Research & Technology.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf
|
||||
*/
|
||||
|
||||
#include <sys/stdint.h>
|
||||
#include <sys/stddef.h>
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/module.h>
|
||||
#include <rtems/bsd/sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/condvar.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/sx.h>
|
||||
#include <rtems/bsd/sys/unistd.h>
|
||||
#include <sys/callout.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/priv.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
||||
#include <rtems/bsd/local/usbdevs.h>
|
||||
#include <dev/usb/usb.h>
|
||||
#include <dev/usb/usbdi.h>
|
||||
#include <dev/usb/usbdi_util.h>
|
||||
#include <dev/usb/usbhid.h>
|
||||
#include <dev/usb/usb_ioctl.h>
|
||||
|
||||
#define USB_DEBUG_VAR uhid_debug
|
||||
#include <dev/usb/usb_debug.h>
|
||||
|
||||
#include <dev/usb/input/usb_rdesc.h>
|
||||
#include <dev/usb/quirk/usb_quirk.h>
|
||||
|
||||
#ifdef USB_DEBUG
|
||||
static int uhid_debug = 0;
|
||||
|
||||
static SYSCTL_NODE(_hw_usb, OID_AUTO, uhid, CTLFLAG_RW, 0, "USB uhid");
|
||||
SYSCTL_INT(_hw_usb_uhid, OID_AUTO, debug, CTLFLAG_RWTUN,
|
||||
&uhid_debug, 0, "Debug level");
|
||||
#endif
|
||||
|
||||
#define UHID_BSIZE 1024 /* bytes, buffer size */
|
||||
#define UHID_FRAME_NUM 50 /* bytes, frame number */
|
||||
|
||||
enum {
|
||||
UHID_INTR_DT_WR,
|
||||
UHID_INTR_DT_RD,
|
||||
UHID_CTRL_DT_WR,
|
||||
UHID_CTRL_DT_RD,
|
||||
UHID_N_TRANSFER,
|
||||
};
|
||||
|
||||
struct uhid_softc {
|
||||
struct usb_fifo_sc sc_fifo;
|
||||
struct mtx sc_mtx;
|
||||
|
||||
struct usb_xfer *sc_xfer[UHID_N_TRANSFER];
|
||||
struct usb_device *sc_udev;
|
||||
void *sc_repdesc_ptr;
|
||||
|
||||
uint32_t sc_isize;
|
||||
uint32_t sc_osize;
|
||||
uint32_t sc_fsize;
|
||||
|
||||
uint16_t sc_repdesc_size;
|
||||
|
||||
uint8_t sc_iface_no;
|
||||
uint8_t sc_iface_index;
|
||||
uint8_t sc_iid;
|
||||
uint8_t sc_oid;
|
||||
uint8_t sc_fid;
|
||||
uint8_t sc_flags;
|
||||
#define UHID_FLAG_IMMED 0x01 /* set if read should be immediate */
|
||||
#define UHID_FLAG_STATIC_DESC 0x04 /* set if report descriptors are
|
||||
* static */
|
||||
};
|
||||
|
||||
static const uint8_t uhid_xb360gp_report_descr[] = {UHID_XB360GP_REPORT_DESCR()};
|
||||
static const uint8_t uhid_graphire_report_descr[] = {UHID_GRAPHIRE_REPORT_DESCR()};
|
||||
static const uint8_t uhid_graphire3_4x5_report_descr[] = {UHID_GRAPHIRE3_4X5_REPORT_DESCR()};
|
||||
|
||||
/* prototypes */
|
||||
|
||||
static device_probe_t uhid_probe;
|
||||
static device_attach_t uhid_attach;
|
||||
static device_detach_t uhid_detach;
|
||||
|
||||
static usb_callback_t uhid_intr_write_callback;
|
||||
static usb_callback_t uhid_intr_read_callback;
|
||||
static usb_callback_t uhid_write_callback;
|
||||
static usb_callback_t uhid_read_callback;
|
||||
|
||||
static usb_fifo_cmd_t uhid_start_read;
|
||||
static usb_fifo_cmd_t uhid_stop_read;
|
||||
static usb_fifo_cmd_t uhid_start_write;
|
||||
static usb_fifo_cmd_t uhid_stop_write;
|
||||
static usb_fifo_open_t uhid_open;
|
||||
static usb_fifo_close_t uhid_close;
|
||||
static usb_fifo_ioctl_t uhid_ioctl;
|
||||
|
||||
static struct usb_fifo_methods uhid_fifo_methods = {
|
||||
.f_open = &uhid_open,
|
||||
.f_close = &uhid_close,
|
||||
.f_ioctl = &uhid_ioctl,
|
||||
.f_start_read = &uhid_start_read,
|
||||
.f_stop_read = &uhid_stop_read,
|
||||
.f_start_write = &uhid_start_write,
|
||||
.f_stop_write = &uhid_stop_write,
|
||||
.basename[0] = "uhid",
|
||||
};
|
||||
|
||||
static void
|
||||
uhid_intr_write_callback(struct usb_xfer *xfer, usb_error_t error)
|
||||
{
|
||||
struct uhid_softc *sc = usbd_xfer_softc(xfer);
|
||||
struct usb_page_cache *pc;
|
||||
int actlen;
|
||||
|
||||
switch (USB_GET_STATE(xfer)) {
|
||||
case USB_ST_TRANSFERRED:
|
||||
case USB_ST_SETUP:
|
||||
tr_setup:
|
||||
pc = usbd_xfer_get_frame(xfer, 0);
|
||||
if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
|
||||
0, usbd_xfer_max_len(xfer), &actlen, 0)) {
|
||||
usbd_xfer_set_frame_len(xfer, 0, actlen);
|
||||
usbd_transfer_submit(xfer);
|
||||
}
|
||||
return;
|
||||
|
||||
default: /* Error */
|
||||
if (error != USB_ERR_CANCELLED) {
|
||||
/* try to clear stall first */
|
||||
usbd_xfer_set_stall(xfer);
|
||||
goto tr_setup;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_intr_read_callback(struct usb_xfer *xfer, usb_error_t error)
|
||||
{
|
||||
struct uhid_softc *sc = usbd_xfer_softc(xfer);
|
||||
struct usb_page_cache *pc;
|
||||
int actlen;
|
||||
|
||||
usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
|
||||
|
||||
switch (USB_GET_STATE(xfer)) {
|
||||
case USB_ST_TRANSFERRED:
|
||||
DPRINTF("transferred!\n");
|
||||
|
||||
pc = usbd_xfer_get_frame(xfer, 0);
|
||||
|
||||
/*
|
||||
* If the ID byte is non zero we allow descriptors
|
||||
* having multiple sizes:
|
||||
*/
|
||||
if ((actlen >= (int)sc->sc_isize) ||
|
||||
((actlen > 0) && (sc->sc_iid != 0))) {
|
||||
/* limit report length to the maximum */
|
||||
if (actlen > (int)sc->sc_isize)
|
||||
actlen = sc->sc_isize;
|
||||
usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc,
|
||||
0, actlen, 1);
|
||||
} else {
|
||||
/* ignore it */
|
||||
DPRINTF("ignored transfer, %d bytes\n", actlen);
|
||||
}
|
||||
|
||||
case USB_ST_SETUP:
|
||||
re_submit:
|
||||
if (usb_fifo_put_bytes_max(
|
||||
sc->sc_fifo.fp[USB_FIFO_RX]) != 0) {
|
||||
usbd_xfer_set_frame_len(xfer, 0, sc->sc_isize);
|
||||
usbd_transfer_submit(xfer);
|
||||
}
|
||||
return;
|
||||
|
||||
default: /* Error */
|
||||
if (error != USB_ERR_CANCELLED) {
|
||||
/* try to clear stall first */
|
||||
usbd_xfer_set_stall(xfer);
|
||||
goto re_submit;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_fill_set_report(struct usb_device_request *req, uint8_t iface_no,
|
||||
uint8_t type, uint8_t id, uint16_t size)
|
||||
{
|
||||
req->bmRequestType = UT_WRITE_CLASS_INTERFACE;
|
||||
req->bRequest = UR_SET_REPORT;
|
||||
USETW2(req->wValue, type, id);
|
||||
req->wIndex[0] = iface_no;
|
||||
req->wIndex[1] = 0;
|
||||
USETW(req->wLength, size);
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_fill_get_report(struct usb_device_request *req, uint8_t iface_no,
|
||||
uint8_t type, uint8_t id, uint16_t size)
|
||||
{
|
||||
req->bmRequestType = UT_READ_CLASS_INTERFACE;
|
||||
req->bRequest = UR_GET_REPORT;
|
||||
USETW2(req->wValue, type, id);
|
||||
req->wIndex[0] = iface_no;
|
||||
req->wIndex[1] = 0;
|
||||
USETW(req->wLength, size);
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_write_callback(struct usb_xfer *xfer, usb_error_t error)
|
||||
{
|
||||
struct uhid_softc *sc = usbd_xfer_softc(xfer);
|
||||
struct usb_device_request req;
|
||||
struct usb_page_cache *pc;
|
||||
uint32_t size = sc->sc_osize;
|
||||
uint32_t actlen;
|
||||
uint8_t id;
|
||||
|
||||
switch (USB_GET_STATE(xfer)) {
|
||||
case USB_ST_TRANSFERRED:
|
||||
case USB_ST_SETUP:
|
||||
/* try to extract the ID byte */
|
||||
if (sc->sc_oid) {
|
||||
pc = usbd_xfer_get_frame(xfer, 0);
|
||||
if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
|
||||
0, 1, &actlen, 0)) {
|
||||
if (actlen != 1) {
|
||||
goto tr_error;
|
||||
}
|
||||
usbd_copy_out(pc, 0, &id, 1);
|
||||
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (size) {
|
||||
size--;
|
||||
}
|
||||
} else {
|
||||
id = 0;
|
||||
}
|
||||
|
||||
pc = usbd_xfer_get_frame(xfer, 1);
|
||||
if (usb_fifo_get_data(sc->sc_fifo.fp[USB_FIFO_TX], pc,
|
||||
0, UHID_BSIZE, &actlen, 1)) {
|
||||
if (actlen != size) {
|
||||
goto tr_error;
|
||||
}
|
||||
uhid_fill_set_report
|
||||
(&req, sc->sc_iface_no,
|
||||
UHID_OUTPUT_REPORT, id, size);
|
||||
|
||||
pc = usbd_xfer_get_frame(xfer, 0);
|
||||
usbd_copy_in(pc, 0, &req, sizeof(req));
|
||||
|
||||
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
|
||||
usbd_xfer_set_frame_len(xfer, 1, size);
|
||||
usbd_xfer_set_frames(xfer, size ? 2 : 1);
|
||||
usbd_transfer_submit(xfer);
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
tr_error:
|
||||
/* bomb out */
|
||||
usb_fifo_get_data_error(sc->sc_fifo.fp[USB_FIFO_TX]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_read_callback(struct usb_xfer *xfer, usb_error_t error)
|
||||
{
|
||||
struct uhid_softc *sc = usbd_xfer_softc(xfer);
|
||||
struct usb_device_request req;
|
||||
struct usb_page_cache *pc;
|
||||
|
||||
pc = usbd_xfer_get_frame(xfer, 0);
|
||||
|
||||
switch (USB_GET_STATE(xfer)) {
|
||||
case USB_ST_TRANSFERRED:
|
||||
usb_fifo_put_data(sc->sc_fifo.fp[USB_FIFO_RX], pc, sizeof(req),
|
||||
sc->sc_isize, 1);
|
||||
return;
|
||||
|
||||
case USB_ST_SETUP:
|
||||
|
||||
if (usb_fifo_put_bytes_max(sc->sc_fifo.fp[USB_FIFO_RX]) > 0) {
|
||||
|
||||
uhid_fill_get_report
|
||||
(&req, sc->sc_iface_no, UHID_INPUT_REPORT,
|
||||
sc->sc_iid, sc->sc_isize);
|
||||
|
||||
usbd_copy_in(pc, 0, &req, sizeof(req));
|
||||
|
||||
usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
|
||||
usbd_xfer_set_frame_len(xfer, 1, sc->sc_isize);
|
||||
usbd_xfer_set_frames(xfer, sc->sc_isize ? 2 : 1);
|
||||
usbd_transfer_submit(xfer);
|
||||
}
|
||||
return;
|
||||
|
||||
default: /* Error */
|
||||
/* bomb out */
|
||||
usb_fifo_put_data_error(sc->sc_fifo.fp[USB_FIFO_RX]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct usb_config uhid_config[UHID_N_TRANSFER] = {
|
||||
|
||||
[UHID_INTR_DT_WR] = {
|
||||
.type = UE_INTERRUPT,
|
||||
.endpoint = UE_ADDR_ANY,
|
||||
.direction = UE_DIR_OUT,
|
||||
.flags = {.pipe_bof = 1,.no_pipe_ok = 1, },
|
||||
.bufsize = UHID_BSIZE,
|
||||
.callback = &uhid_intr_write_callback,
|
||||
},
|
||||
|
||||
[UHID_INTR_DT_RD] = {
|
||||
.type = UE_INTERRUPT,
|
||||
.endpoint = UE_ADDR_ANY,
|
||||
.direction = UE_DIR_IN,
|
||||
.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
|
||||
.bufsize = UHID_BSIZE,
|
||||
.callback = &uhid_intr_read_callback,
|
||||
},
|
||||
|
||||
[UHID_CTRL_DT_WR] = {
|
||||
.type = UE_CONTROL,
|
||||
.endpoint = 0x00, /* Control pipe */
|
||||
.direction = UE_DIR_ANY,
|
||||
.bufsize = sizeof(struct usb_device_request) + UHID_BSIZE,
|
||||
.callback = &uhid_write_callback,
|
||||
.timeout = 1000, /* 1 second */
|
||||
},
|
||||
|
||||
[UHID_CTRL_DT_RD] = {
|
||||
.type = UE_CONTROL,
|
||||
.endpoint = 0x00, /* Control pipe */
|
||||
.direction = UE_DIR_ANY,
|
||||
.bufsize = sizeof(struct usb_device_request) + UHID_BSIZE,
|
||||
.callback = &uhid_read_callback,
|
||||
.timeout = 1000, /* 1 second */
|
||||
},
|
||||
};
|
||||
|
||||
static void
|
||||
uhid_start_read(struct usb_fifo *fifo)
|
||||
{
|
||||
struct uhid_softc *sc = usb_fifo_softc(fifo);
|
||||
|
||||
if (sc->sc_flags & UHID_FLAG_IMMED) {
|
||||
usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_RD]);
|
||||
} else {
|
||||
usbd_transfer_start(sc->sc_xfer[UHID_INTR_DT_RD]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_stop_read(struct usb_fifo *fifo)
|
||||
{
|
||||
struct uhid_softc *sc = usb_fifo_softc(fifo);
|
||||
|
||||
usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_RD]);
|
||||
usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_RD]);
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_start_write(struct usb_fifo *fifo)
|
||||
{
|
||||
struct uhid_softc *sc = usb_fifo_softc(fifo);
|
||||
|
||||
if ((sc->sc_flags & UHID_FLAG_IMMED) ||
|
||||
sc->sc_xfer[UHID_INTR_DT_WR] == NULL) {
|
||||
usbd_transfer_start(sc->sc_xfer[UHID_CTRL_DT_WR]);
|
||||
} else {
|
||||
usbd_transfer_start(sc->sc_xfer[UHID_INTR_DT_WR]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_stop_write(struct usb_fifo *fifo)
|
||||
{
|
||||
struct uhid_softc *sc = usb_fifo_softc(fifo);
|
||||
|
||||
usbd_transfer_stop(sc->sc_xfer[UHID_CTRL_DT_WR]);
|
||||
usbd_transfer_stop(sc->sc_xfer[UHID_INTR_DT_WR]);
|
||||
}
|
||||
|
||||
static int
|
||||
uhid_get_report(struct uhid_softc *sc, uint8_t type,
|
||||
uint8_t id, void *kern_data, void *user_data,
|
||||
uint16_t len)
|
||||
{
|
||||
int err;
|
||||
uint8_t free_data = 0;
|
||||
|
||||
if (kern_data == NULL) {
|
||||
kern_data = malloc(len, M_USBDEV, M_WAITOK);
|
||||
if (kern_data == NULL) {
|
||||
err = ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
free_data = 1;
|
||||
}
|
||||
err = usbd_req_get_report(sc->sc_udev, NULL, kern_data,
|
||||
len, sc->sc_iface_index, type, id);
|
||||
if (err) {
|
||||
err = ENXIO;
|
||||
goto done;
|
||||
}
|
||||
if (user_data) {
|
||||
/* dummy buffer */
|
||||
err = copyout(kern_data, user_data, len);
|
||||
if (err) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (free_data) {
|
||||
free(kern_data, M_USBDEV);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
static int
|
||||
uhid_set_report(struct uhid_softc *sc, uint8_t type,
|
||||
uint8_t id, void *kern_data, void *user_data,
|
||||
uint16_t len)
|
||||
{
|
||||
int err;
|
||||
uint8_t free_data = 0;
|
||||
|
||||
if (kern_data == NULL) {
|
||||
kern_data = malloc(len, M_USBDEV, M_WAITOK);
|
||||
if (kern_data == NULL) {
|
||||
err = ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
free_data = 1;
|
||||
err = copyin(user_data, kern_data, len);
|
||||
if (err) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
err = usbd_req_set_report(sc->sc_udev, NULL, kern_data,
|
||||
len, sc->sc_iface_index, type, id);
|
||||
if (err) {
|
||||
err = ENXIO;
|
||||
goto done;
|
||||
}
|
||||
done:
|
||||
if (free_data) {
|
||||
free(kern_data, M_USBDEV);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
static int
|
||||
uhid_open(struct usb_fifo *fifo, int fflags)
|
||||
{
|
||||
struct uhid_softc *sc = usb_fifo_softc(fifo);
|
||||
|
||||
/*
|
||||
* The buffers are one byte larger than maximum so that one
|
||||
* can detect too large read/writes and short transfers:
|
||||
*/
|
||||
if (fflags & FREAD) {
|
||||
/* reset flags */
|
||||
mtx_lock(&sc->sc_mtx);
|
||||
sc->sc_flags &= ~UHID_FLAG_IMMED;
|
||||
mtx_unlock(&sc->sc_mtx);
|
||||
|
||||
if (usb_fifo_alloc_buffer(fifo,
|
||||
sc->sc_isize + 1, UHID_FRAME_NUM)) {
|
||||
return (ENOMEM);
|
||||
}
|
||||
}
|
||||
if (fflags & FWRITE) {
|
||||
if (usb_fifo_alloc_buffer(fifo,
|
||||
sc->sc_osize + 1, UHID_FRAME_NUM)) {
|
||||
return (ENOMEM);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
uhid_close(struct usb_fifo *fifo, int fflags)
|
||||
{
|
||||
if (fflags & (FREAD | FWRITE)) {
|
||||
usb_fifo_free_buffer(fifo);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
uhid_ioctl(struct usb_fifo *fifo, u_long cmd, void *addr,
|
||||
int fflags)
|
||||
{
|
||||
struct uhid_softc *sc = usb_fifo_softc(fifo);
|
||||
struct usb_gen_descriptor *ugd;
|
||||
uint32_t size;
|
||||
int error = 0;
|
||||
uint8_t id;
|
||||
|
||||
switch (cmd) {
|
||||
case USB_GET_REPORT_DESC:
|
||||
ugd = addr;
|
||||
if (sc->sc_repdesc_size > ugd->ugd_maxlen) {
|
||||
size = ugd->ugd_maxlen;
|
||||
} else {
|
||||
size = sc->sc_repdesc_size;
|
||||
}
|
||||
ugd->ugd_actlen = size;
|
||||
if (ugd->ugd_data == NULL)
|
||||
break; /* descriptor length only */
|
||||
error = copyout(sc->sc_repdesc_ptr, ugd->ugd_data, size);
|
||||
break;
|
||||
|
||||
case USB_SET_IMMED:
|
||||
if (!(fflags & FREAD)) {
|
||||
error = EPERM;
|
||||
break;
|
||||
}
|
||||
if (*(int *)addr) {
|
||||
|
||||
/* do a test read */
|
||||
|
||||
error = uhid_get_report(sc, UHID_INPUT_REPORT,
|
||||
sc->sc_iid, NULL, NULL, sc->sc_isize);
|
||||
if (error) {
|
||||
break;
|
||||
}
|
||||
mtx_lock(&sc->sc_mtx);
|
||||
sc->sc_flags |= UHID_FLAG_IMMED;
|
||||
mtx_unlock(&sc->sc_mtx);
|
||||
} else {
|
||||
mtx_lock(&sc->sc_mtx);
|
||||
sc->sc_flags &= ~UHID_FLAG_IMMED;
|
||||
mtx_unlock(&sc->sc_mtx);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_GET_REPORT:
|
||||
if (!(fflags & FREAD)) {
|
||||
error = EPERM;
|
||||
break;
|
||||
}
|
||||
ugd = addr;
|
||||
switch (ugd->ugd_report_type) {
|
||||
case UHID_INPUT_REPORT:
|
||||
size = sc->sc_isize;
|
||||
id = sc->sc_iid;
|
||||
break;
|
||||
case UHID_OUTPUT_REPORT:
|
||||
size = sc->sc_osize;
|
||||
id = sc->sc_oid;
|
||||
break;
|
||||
case UHID_FEATURE_REPORT:
|
||||
size = sc->sc_fsize;
|
||||
id = sc->sc_fid;
|
||||
break;
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
if (id != 0)
|
||||
copyin(ugd->ugd_data, &id, 1);
|
||||
error = uhid_get_report(sc, ugd->ugd_report_type, id,
|
||||
NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
|
||||
break;
|
||||
|
||||
case USB_SET_REPORT:
|
||||
if (!(fflags & FWRITE)) {
|
||||
error = EPERM;
|
||||
break;
|
||||
}
|
||||
ugd = addr;
|
||||
switch (ugd->ugd_report_type) {
|
||||
case UHID_INPUT_REPORT:
|
||||
size = sc->sc_isize;
|
||||
id = sc->sc_iid;
|
||||
break;
|
||||
case UHID_OUTPUT_REPORT:
|
||||
size = sc->sc_osize;
|
||||
id = sc->sc_oid;
|
||||
break;
|
||||
case UHID_FEATURE_REPORT:
|
||||
size = sc->sc_fsize;
|
||||
id = sc->sc_fid;
|
||||
break;
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
if (id != 0)
|
||||
copyin(ugd->ugd_data, &id, 1);
|
||||
error = uhid_set_report(sc, ugd->ugd_report_type, id,
|
||||
NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
|
||||
break;
|
||||
|
||||
case USB_GET_REPORT_ID:
|
||||
*(int *)addr = 0; /* XXX: we only support reportid 0? */
|
||||
break;
|
||||
|
||||
default:
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
static const STRUCT_USB_HOST_ID uhid_devs[] = {
|
||||
/* generic HID class */
|
||||
{USB_IFACE_CLASS(UICLASS_HID),},
|
||||
/* the Xbox 360 gamepad doesn't use the HID class */
|
||||
{USB_IFACE_CLASS(UICLASS_VENDOR),
|
||||
USB_IFACE_SUBCLASS(UISUBCLASS_XBOX360_CONTROLLER),
|
||||
USB_IFACE_PROTOCOL(UIPROTO_XBOX360_GAMEPAD),},
|
||||
};
|
||||
|
||||
static int
|
||||
uhid_probe(device_t dev)
|
||||
{
|
||||
struct usb_attach_arg *uaa = device_get_ivars(dev);
|
||||
int error;
|
||||
|
||||
DPRINTFN(11, "\n");
|
||||
|
||||
if (uaa->usb_mode != USB_MODE_HOST)
|
||||
return (ENXIO);
|
||||
|
||||
error = usbd_lookup_id_by_uaa(uhid_devs, sizeof(uhid_devs), uaa);
|
||||
if (error)
|
||||
return (error);
|
||||
|
||||
if (usb_test_quirk(uaa, UQ_HID_IGNORE))
|
||||
return (ENXIO);
|
||||
|
||||
/*
|
||||
* Don't attach to mouse and keyboard devices, hence then no
|
||||
* "nomatch" event is generated and then ums and ukbd won't
|
||||
* attach properly when loaded.
|
||||
*/
|
||||
if ((uaa->info.bInterfaceClass == UICLASS_HID) &&
|
||||
(uaa->info.bInterfaceSubClass == UISUBCLASS_BOOT) &&
|
||||
(((uaa->info.bInterfaceProtocol == UIPROTO_BOOT_KEYBOARD) &&
|
||||
!usb_test_quirk(uaa, UQ_KBD_IGNORE)) ||
|
||||
((uaa->info.bInterfaceProtocol == UIPROTO_MOUSE) &&
|
||||
!usb_test_quirk(uaa, UQ_UMS_IGNORE))))
|
||||
return (ENXIO);
|
||||
|
||||
return (BUS_PROBE_GENERIC);
|
||||
}
|
||||
|
||||
static int
|
||||
uhid_attach(device_t dev)
|
||||
{
|
||||
struct usb_attach_arg *uaa = device_get_ivars(dev);
|
||||
struct uhid_softc *sc = device_get_softc(dev);
|
||||
int unit = device_get_unit(dev);
|
||||
int error = 0;
|
||||
|
||||
DPRINTFN(10, "sc=%p\n", sc);
|
||||
|
||||
device_set_usb_desc(dev);
|
||||
|
||||
mtx_init(&sc->sc_mtx, "uhid lock", NULL, MTX_DEF | MTX_RECURSE);
|
||||
|
||||
sc->sc_udev = uaa->device;
|
||||
|
||||
sc->sc_iface_no = uaa->info.bIfaceNum;
|
||||
sc->sc_iface_index = uaa->info.bIfaceIndex;
|
||||
|
||||
error = usbd_transfer_setup(uaa->device,
|
||||
&uaa->info.bIfaceIndex, sc->sc_xfer, uhid_config,
|
||||
UHID_N_TRANSFER, sc, &sc->sc_mtx);
|
||||
|
||||
if (error) {
|
||||
DPRINTF("error=%s\n", usbd_errstr(error));
|
||||
goto detach;
|
||||
}
|
||||
if (uaa->info.idVendor == USB_VENDOR_WACOM) {
|
||||
|
||||
/* the report descriptor for the Wacom Graphire is broken */
|
||||
|
||||
if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE) {
|
||||
|
||||
sc->sc_repdesc_size = sizeof(uhid_graphire_report_descr);
|
||||
sc->sc_repdesc_ptr = __DECONST(void *, &uhid_graphire_report_descr);
|
||||
sc->sc_flags |= UHID_FLAG_STATIC_DESC;
|
||||
|
||||
} else if (uaa->info.idProduct == USB_PRODUCT_WACOM_GRAPHIRE3_4X5) {
|
||||
|
||||
static uint8_t reportbuf[] = {2, 2, 2};
|
||||
|
||||
/*
|
||||
* The Graphire3 needs 0x0202 to be written to
|
||||
* feature report ID 2 before it'll start
|
||||
* returning digitizer data.
|
||||
*/
|
||||
error = usbd_req_set_report(uaa->device, NULL,
|
||||
reportbuf, sizeof(reportbuf),
|
||||
uaa->info.bIfaceIndex, UHID_FEATURE_REPORT, 2);
|
||||
|
||||
if (error) {
|
||||
DPRINTF("set report failed, error=%s (ignored)\n",
|
||||
usbd_errstr(error));
|
||||
}
|
||||
sc->sc_repdesc_size = sizeof(uhid_graphire3_4x5_report_descr);
|
||||
sc->sc_repdesc_ptr = __DECONST(void *, &uhid_graphire3_4x5_report_descr);
|
||||
sc->sc_flags |= UHID_FLAG_STATIC_DESC;
|
||||
}
|
||||
} else if ((uaa->info.bInterfaceClass == UICLASS_VENDOR) &&
|
||||
(uaa->info.bInterfaceSubClass == UISUBCLASS_XBOX360_CONTROLLER) &&
|
||||
(uaa->info.bInterfaceProtocol == UIPROTO_XBOX360_GAMEPAD)) {
|
||||
static const uint8_t reportbuf[3] = {1, 3, 0};
|
||||
/*
|
||||
* Turn off the four LEDs on the gamepad which
|
||||
* are blinking by default:
|
||||
*/
|
||||
error = usbd_req_set_report(uaa->device, NULL,
|
||||
__DECONST(void *, reportbuf), sizeof(reportbuf),
|
||||
uaa->info.bIfaceIndex, UHID_OUTPUT_REPORT, 0);
|
||||
if (error) {
|
||||
DPRINTF("set output report failed, error=%s (ignored)\n",
|
||||
usbd_errstr(error));
|
||||
}
|
||||
/* the Xbox 360 gamepad has no report descriptor */
|
||||
sc->sc_repdesc_size = sizeof(uhid_xb360gp_report_descr);
|
||||
sc->sc_repdesc_ptr = __DECONST(void *, &uhid_xb360gp_report_descr);
|
||||
sc->sc_flags |= UHID_FLAG_STATIC_DESC;
|
||||
}
|
||||
if (sc->sc_repdesc_ptr == NULL) {
|
||||
|
||||
error = usbd_req_get_hid_desc(uaa->device, NULL,
|
||||
&sc->sc_repdesc_ptr, &sc->sc_repdesc_size,
|
||||
M_USBDEV, uaa->info.bIfaceIndex);
|
||||
|
||||
if (error) {
|
||||
device_printf(dev, "no report descriptor\n");
|
||||
goto detach;
|
||||
}
|
||||
}
|
||||
error = usbd_req_set_idle(uaa->device, NULL,
|
||||
uaa->info.bIfaceIndex, 0, 0);
|
||||
|
||||
if (error) {
|
||||
DPRINTF("set idle failed, error=%s (ignored)\n",
|
||||
usbd_errstr(error));
|
||||
}
|
||||
sc->sc_isize = hid_report_size
|
||||
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_input, &sc->sc_iid);
|
||||
|
||||
sc->sc_osize = hid_report_size
|
||||
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_output, &sc->sc_oid);
|
||||
|
||||
sc->sc_fsize = hid_report_size
|
||||
(sc->sc_repdesc_ptr, sc->sc_repdesc_size, hid_feature, &sc->sc_fid);
|
||||
|
||||
if (sc->sc_isize > UHID_BSIZE) {
|
||||
DPRINTF("input size is too large, "
|
||||
"%d bytes (truncating)\n",
|
||||
sc->sc_isize);
|
||||
sc->sc_isize = UHID_BSIZE;
|
||||
}
|
||||
if (sc->sc_osize > UHID_BSIZE) {
|
||||
DPRINTF("output size is too large, "
|
||||
"%d bytes (truncating)\n",
|
||||
sc->sc_osize);
|
||||
sc->sc_osize = UHID_BSIZE;
|
||||
}
|
||||
if (sc->sc_fsize > UHID_BSIZE) {
|
||||
DPRINTF("feature size is too large, "
|
||||
"%d bytes (truncating)\n",
|
||||
sc->sc_fsize);
|
||||
sc->sc_fsize = UHID_BSIZE;
|
||||
}
|
||||
|
||||
error = usb_fifo_attach(uaa->device, sc, &sc->sc_mtx,
|
||||
&uhid_fifo_methods, &sc->sc_fifo,
|
||||
unit, -1, uaa->info.bIfaceIndex,
|
||||
UID_ROOT, GID_OPERATOR, 0644);
|
||||
if (error) {
|
||||
goto detach;
|
||||
}
|
||||
return (0); /* success */
|
||||
|
||||
detach:
|
||||
uhid_detach(dev);
|
||||
return (ENOMEM);
|
||||
}
|
||||
|
||||
static int
|
||||
uhid_detach(device_t dev)
|
||||
{
|
||||
struct uhid_softc *sc = device_get_softc(dev);
|
||||
|
||||
usb_fifo_detach(&sc->sc_fifo);
|
||||
|
||||
usbd_transfer_unsetup(sc->sc_xfer, UHID_N_TRANSFER);
|
||||
|
||||
if (sc->sc_repdesc_ptr) {
|
||||
if (!(sc->sc_flags & UHID_FLAG_STATIC_DESC)) {
|
||||
free(sc->sc_repdesc_ptr, M_USBDEV);
|
||||
}
|
||||
}
|
||||
mtx_destroy(&sc->sc_mtx);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static devclass_t uhid_devclass;
|
||||
|
||||
static device_method_t uhid_methods[] = {
|
||||
DEVMETHOD(device_probe, uhid_probe),
|
||||
DEVMETHOD(device_attach, uhid_attach),
|
||||
DEVMETHOD(device_detach, uhid_detach),
|
||||
|
||||
DEVMETHOD_END
|
||||
};
|
||||
|
||||
static driver_t uhid_driver = {
|
||||
.name = "uhid",
|
||||
.methods = uhid_methods,
|
||||
.size = sizeof(struct uhid_softc),
|
||||
};
|
||||
|
||||
DRIVER_MODULE(uhid, uhub, uhid_driver, uhid_devclass, NULL, 0);
|
||||
MODULE_DEPEND(uhid, usb, 1, 1, 1);
|
||||
MODULE_VERSION(uhid, 1);
|
||||
USB_PNP_HOST_INFO(uhid_devs);
|
2309
freebsd/sys/dev/usb/input/ukbd.c
Normal file
2309
freebsd/sys/dev/usb/input/ukbd.c
Normal file
File diff suppressed because it is too large
Load Diff
1231
freebsd/sys/dev/usb/input/ums.c
Normal file
1231
freebsd/sys/dev/usb/input/ums.c
Normal file
File diff suppressed because it is too large
Load Diff
276
freebsd/sys/dev/usb/input/usb_rdesc.h
Normal file
276
freebsd/sys/dev/usb/input/usb_rdesc.h
Normal file
@ -0,0 +1,276 @@
|
||||
/*-
|
||||
* Copyright (c) 2000 Nick Hibma <n_hibma@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Copyright (c) 2005 Ed Schouten <ed@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*
|
||||
* This file contains replacements for broken HID report descriptors.
|
||||
*/
|
||||
|
||||
#define UHID_GRAPHIRE_REPORT_DESCR(...) \
|
||||
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
|
||||
0x09, 0x01, /* USAGE (Digitizer) */\
|
||||
0xa1, 0x01, /* COLLECTION (Application) */\
|
||||
0x85, 0x02, /* REPORT_ID (2) */\
|
||||
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
|
||||
0x09, 0x01, /* USAGE (Digitizer) */\
|
||||
0xa1, 0x00, /* COLLECTION (Physical) */\
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */\
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */\
|
||||
0x09, 0x33, /* USAGE (Touch) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x09, 0x44, /* USAGE (Barrel Switch) */\
|
||||
0x95, 0x02, /* REPORT_COUNT (2) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x09, 0x00, /* USAGE (Undefined) */\
|
||||
0x95, 0x02, /* REPORT_COUNT (2) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x81, 0x03, /* INPUT (Cnst,Var,Abs) */\
|
||||
0x09, 0x3c, /* USAGE (Invert) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x09, 0x38, /* USAGE (Transducer Index) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x09, 0x32, /* USAGE (In Range) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */\
|
||||
0x09, 0x30, /* USAGE (X) */\
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */\
|
||||
0x26, 0xde, 0x27, /* LOGICAL_MAXIMUM (10206) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x10, /* REPORT_SIZE (16) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x09, 0x31, /* USAGE (Y) */\
|
||||
0x26, 0xfe, 0x1c, /* LOGICAL_MAXIMUM (7422) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x10, /* REPORT_SIZE (16) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
|
||||
0x09, 0x30, /* USAGE (Tip Pressure) */\
|
||||
0x26, 0xff, 0x01, /* LOGICAL_MAXIMUM (511) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x10, /* REPORT_SIZE (16) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0xc0, /* END_COLLECTION */\
|
||||
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
|
||||
0x09, 0x00, /* USAGE (Undefined) */\
|
||||
0x85, 0x02, /* REPORT_ID (2) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0xb1, 0x02, /* FEATURE (Data,Var,Abs) */\
|
||||
0x09, 0x00, /* USAGE (Undefined) */\
|
||||
0x85, 0x03, /* REPORT_ID (3) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0xb1, 0x02, /* FEATURE (Data,Var,Abs) */\
|
||||
0xc0, /* END_COLLECTION */\
|
||||
|
||||
#define UHID_GRAPHIRE3_4X5_REPORT_DESCR(...) \
|
||||
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */\
|
||||
0x09, 0x02, /* USAGE (Mouse) */\
|
||||
0xa1, 0x01, /* COLLECTION (Application) */\
|
||||
0x85, 0x01, /* REPORT_ID (1) */\
|
||||
0x09, 0x01, /* USAGE (Pointer) */\
|
||||
0xa1, 0x00, /* COLLECTION (Physical) */\
|
||||
0x05, 0x09, /* USAGE_PAGE (Button) */\
|
||||
0x19, 0x01, /* USAGE_MINIMUM (Button 1) */\
|
||||
0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */\
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */\
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */\
|
||||
0x95, 0x03, /* REPORT_COUNT (3) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x75, 0x05, /* REPORT_SIZE (5) */\
|
||||
0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */\
|
||||
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */\
|
||||
0x09, 0x30, /* USAGE (X) */\
|
||||
0x09, 0x31, /* USAGE (Y) */\
|
||||
0x09, 0x38, /* USAGE (Wheel) */\
|
||||
0x15, 0x81, /* LOGICAL_MINIMUM (-127) */\
|
||||
0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */\
|
||||
0x75, 0x08, /* REPORT_SIZE (8) */\
|
||||
0x95, 0x03, /* REPORT_COUNT (3) */\
|
||||
0x81, 0x06, /* INPUT (Data,Var,Rel) */\
|
||||
0xc0, /* END_COLLECTION */\
|
||||
0xc0, /* END_COLLECTION */\
|
||||
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
|
||||
0x09, 0x01, /* USAGE (Pointer) */\
|
||||
0xa1, 0x01, /* COLLECTION (Applicaption) */\
|
||||
0x85, 0x02, /* REPORT_ID (2) */\
|
||||
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
|
||||
0x09, 0x01, /* USAGE (Digitizer) */\
|
||||
0xa1, 0x00, /* COLLECTION (Physical) */\
|
||||
0x09, 0x33, /* USAGE (Touch) */\
|
||||
0x09, 0x44, /* USAGE (Barrel Switch) */\
|
||||
0x09, 0x44, /* USAGE (Barrel Switch) */\
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */\
|
||||
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x95, 0x03, /* REPORT_COUNT (3) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x95, 0x02, /* REPORT_COUNT (2) */\
|
||||
0x81, 0x01, /* INPUT (Cnst,Ary,Abs) */\
|
||||
0x09, 0x3c, /* USAGE (Invert) */\
|
||||
0x09, 0x38, /* USAGE (Transducer Index) */\
|
||||
0x09, 0x32, /* USAGE (In Range) */\
|
||||
0x75, 0x01, /* REPORT_SIZE (1) */\
|
||||
0x95, 0x03, /* REPORT_COUNT (3) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */\
|
||||
0x09, 0x30, /* USAGE (X) */\
|
||||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */\
|
||||
0x26, 0xde, 0x27, /* LOGICAL_MAXIMUM (10206) */\
|
||||
0x75, 0x10, /* REPORT_SIZE (16) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x09, 0x31, /* USAGE (Y) */\
|
||||
0x26, 0xfe, 0x1c, /* LOGICAL_MAXIMUM (7422) */\
|
||||
0x75, 0x10, /* REPORT_SIZE (16) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
|
||||
0x09, 0x30, /* USAGE (Tip Pressure) */\
|
||||
0x26, 0xff, 0x01, /* LOGICAL_MAXIMUM (511) */\
|
||||
0x75, 0x10, /* REPORT_SIZE (16) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0x81, 0x02, /* INPUT (Data,Var,Abs) */\
|
||||
0xc0, /* END_COLLECTION */\
|
||||
0x05, 0x0d, /* USAGE_PAGE (Digitizers) */\
|
||||
0x09, 0x00, /* USAGE (Undefined) */\
|
||||
0x85, 0x02, /* REPORT_ID (2) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0xb1, 0x02, /* FEATURE (Data,Var,Abs) */\
|
||||
0x09, 0x00, /* USAGE (Undefined) */\
|
||||
0x85, 0x03, /* REPORT_ID (3) */\
|
||||
0x95, 0x01, /* REPORT_COUNT (1) */\
|
||||
0xb1, 0x02, /* FEATURE (Data,Var,Abs) */\
|
||||
0xc0 /* END_COLLECTION */\
|
||||
|
||||
/*
|
||||
* The descriptor has no output report format, thus preventing you from
|
||||
* controlling the LEDs and the built-in rumblers.
|
||||
*/
|
||||
#define UHID_XB360GP_REPORT_DESCR(...) \
|
||||
0x05, 0x01, /* USAGE PAGE (Generic Desktop) */\
|
||||
0x09, 0x05, /* USAGE (Gamepad) */\
|
||||
0xa1, 0x01, /* COLLECTION (Application) */\
|
||||
/* Unused */\
|
||||
0x75, 0x08, /* REPORT SIZE (8) */\
|
||||
0x95, 0x01, /* REPORT COUNT (1) */\
|
||||
0x81, 0x01, /* INPUT (Constant) */\
|
||||
/* Byte count */\
|
||||
0x75, 0x08, /* REPORT SIZE (8) */\
|
||||
0x95, 0x01, /* REPORT COUNT (1) */\
|
||||
0x05, 0x01, /* USAGE PAGE (Generic Desktop) */\
|
||||
0x09, 0x3b, /* USAGE (Byte Count) */\
|
||||
0x81, 0x01, /* INPUT (Constant) */\
|
||||
/* D-Pad */\
|
||||
0x05, 0x01, /* USAGE PAGE (Generic Desktop) */\
|
||||
0x09, 0x01, /* USAGE (Pointer) */\
|
||||
0xa1, 0x00, /* COLLECTION (Physical) */\
|
||||
0x75, 0x01, /* REPORT SIZE (1) */\
|
||||
0x15, 0x00, /* LOGICAL MINIMUM (0) */\
|
||||
0x25, 0x01, /* LOGICAL MAXIMUM (1) */\
|
||||
0x35, 0x00, /* PHYSICAL MINIMUM (0) */\
|
||||
0x45, 0x01, /* PHYSICAL MAXIMUM (1) */\
|
||||
0x95, 0x04, /* REPORT COUNT (4) */\
|
||||
0x05, 0x01, /* USAGE PAGE (Generic Desktop) */\
|
||||
0x09, 0x90, /* USAGE (D-Pad Up) */\
|
||||
0x09, 0x91, /* USAGE (D-Pad Down) */\
|
||||
0x09, 0x93, /* USAGE (D-Pad Left) */\
|
||||
0x09, 0x92, /* USAGE (D-Pad Right) */\
|
||||
0x81, 0x02, /* INPUT (Data, Variable, Absolute) */\
|
||||
0xc0, /* END COLLECTION */\
|
||||
/* Buttons 5-11 */\
|
||||
0x75, 0x01, /* REPORT SIZE (1) */\
|
||||
0x15, 0x00, /* LOGICAL MINIMUM (0) */\
|
||||
0x25, 0x01, /* LOGICAL MAXIMUM (1) */\
|
||||
0x35, 0x00, /* PHYSICAL MINIMUM (0) */\
|
||||
0x45, 0x01, /* PHYSICAL MAXIMUM (1) */\
|
||||
0x95, 0x07, /* REPORT COUNT (7) */\
|
||||
0x05, 0x09, /* USAGE PAGE (Button) */\
|
||||
0x09, 0x08, /* USAGE (Button 8) */\
|
||||
0x09, 0x07, /* USAGE (Button 7) */\
|
||||
0x09, 0x09, /* USAGE (Button 9) */\
|
||||
0x09, 0x0a, /* USAGE (Button 10) */\
|
||||
0x09, 0x05, /* USAGE (Button 5) */\
|
||||
0x09, 0x06, /* USAGE (Button 6) */\
|
||||
0x09, 0x0b, /* USAGE (Button 11) */\
|
||||
0x81, 0x02, /* INPUT (Data, Variable, Absolute) */\
|
||||
/* Unused */\
|
||||
0x75, 0x01, /* REPORT SIZE (1) */\
|
||||
0x95, 0x01, /* REPORT COUNT (1) */\
|
||||
0x81, 0x01, /* INPUT (Constant) */\
|
||||
/* Buttons 1-4 */\
|
||||
0x75, 0x01, /* REPORT SIZE (1) */\
|
||||
0x15, 0x00, /* LOGICAL MINIMUM (0) */\
|
||||
0x25, 0x01, /* LOGICAL MAXIMUM (1) */\
|
||||
0x35, 0x00, /* PHYSICAL MINIMUM (0) */\
|
||||
0x45, 0x01, /* PHYSICAL MAXIMUM (1) */\
|
||||
0x95, 0x04, /* REPORT COUNT (4) */\
|
||||
0x05, 0x09, /* USAGE PAGE (Button) */\
|
||||
0x19, 0x01, /* USAGE MINIMUM (Button 1) */\
|
||||
0x29, 0x04, /* USAGE MAXIMUM (Button 4) */\
|
||||
0x81, 0x02, /* INPUT (Data, Variable, Absolute) */\
|
||||
/* Triggers */\
|
||||
0x75, 0x08, /* REPORT SIZE (8) */\
|
||||
0x15, 0x00, /* LOGICAL MINIMUM (0) */\
|
||||
0x26, 0xff, 0x00, /* LOGICAL MAXIMUM (255) */\
|
||||
0x35, 0x00, /* PHYSICAL MINIMUM (0) */\
|
||||
0x46, 0xff, 0x00, /* PHYSICAL MAXIMUM (255) */\
|
||||
0x95, 0x02, /* REPORT SIZE (2) */\
|
||||
0x05, 0x01, /* USAGE PAGE (Generic Desktop) */\
|
||||
0x09, 0x32, /* USAGE (Z) */\
|
||||
0x09, 0x35, /* USAGE (Rz) */\
|
||||
0x81, 0x02, /* INPUT (Data, Variable, Absolute) */\
|
||||
/* Sticks */\
|
||||
0x75, 0x10, /* REPORT SIZE (16) */\
|
||||
0x16, 0x00, 0x80, /* LOGICAL MINIMUM (-32768) */\
|
||||
0x26, 0xff, 0x7f, /* LOGICAL MAXIMUM (32767) */\
|
||||
0x36, 0x00, 0x80, /* PHYSICAL MINIMUM (-32768) */\
|
||||
0x46, 0xff, 0x7f, /* PHYSICAL MAXIMUM (32767) */\
|
||||
0x95, 0x04, /* REPORT COUNT (4) */\
|
||||
0x05, 0x01, /* USAGE PAGE (Generic Desktop) */\
|
||||
0x09, 0x30, /* USAGE (X) */\
|
||||
0x09, 0x31, /* USAGE (Y) */\
|
||||
0x09, 0x33, /* USAGE (Rx) */\
|
||||
0x09, 0x34, /* USAGE (Ry) */\
|
||||
0x81, 0x02, /* INPUT (Data, Variable, Absolute) */\
|
||||
/* Unused */\
|
||||
0x75, 0x30, /* REPORT SIZE (48) */\
|
||||
0x95, 0x01, /* REPORT COUNT (1) */\
|
||||
0x81, 0x01, /* INPUT (Constant) */\
|
||||
0xc0 /* END COLLECTION */\
|
||||
|
1405
freebsd/sys/dev/usb/input/wsp.c
Normal file
1405
freebsd/sys/dev/usb/input/wsp.c
Normal file
File diff suppressed because it is too large
Load Diff
395
freebsd/sys/sys/mouse.h
Normal file
395
freebsd/sys/sys/mouse.h
Normal file
@ -0,0 +1,395 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993 Erik Forsberg.
|
||||
* Copyright (c) 1996, 1997 Kazutaka YOKOTA
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _SYS_MOUSE_H_
|
||||
#define _SYS_MOUSE_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioccom.h>
|
||||
|
||||
/* ioctls */
|
||||
#define MOUSE_GETSTATUS _IOR('M', 0, mousestatus_t)
|
||||
#define MOUSE_GETHWINFO _IOR('M', 1, mousehw_t)
|
||||
#define MOUSE_GETMODE _IOR('M', 2, mousemode_t)
|
||||
#define MOUSE_SETMODE _IOW('M', 3, mousemode_t)
|
||||
#define MOUSE_GETLEVEL _IOR('M', 4, int)
|
||||
#define MOUSE_SETLEVEL _IOW('M', 5, int)
|
||||
#define MOUSE_GETVARS _IOR('M', 6, mousevar_t)
|
||||
#define MOUSE_SETVARS _IOW('M', 7, mousevar_t)
|
||||
#define MOUSE_READSTATE _IOWR('M', 8, mousedata_t)
|
||||
#define MOUSE_READDATA _IOWR('M', 9, mousedata_t)
|
||||
|
||||
#ifdef notyet
|
||||
#define MOUSE_SETRESOLUTION _IOW('M', 10, int)
|
||||
#define MOUSE_SETSCALING _IOW('M', 11, int)
|
||||
#define MOUSE_SETRATE _IOW('M', 12, int)
|
||||
#define MOUSE_GETHWID _IOR('M', 13, int)
|
||||
#endif
|
||||
|
||||
#define MOUSE_SYN_GETHWINFO _IOR('M', 100, synapticshw_t)
|
||||
|
||||
/* mouse status block */
|
||||
typedef struct mousestatus {
|
||||
int flags; /* state change flags */
|
||||
int button; /* button status */
|
||||
int obutton; /* previous button status */
|
||||
int dx; /* x movement */
|
||||
int dy; /* y movement */
|
||||
int dz; /* z movement */
|
||||
} mousestatus_t;
|
||||
|
||||
/* button */
|
||||
#define MOUSE_BUTTON1DOWN 0x0001 /* left */
|
||||
#define MOUSE_BUTTON2DOWN 0x0002 /* middle */
|
||||
#define MOUSE_BUTTON3DOWN 0x0004 /* right */
|
||||
#define MOUSE_BUTTON4DOWN 0x0008
|
||||
#define MOUSE_BUTTON5DOWN 0x0010
|
||||
#define MOUSE_BUTTON6DOWN 0x0020
|
||||
#define MOUSE_BUTTON7DOWN 0x0040
|
||||
#define MOUSE_BUTTON8DOWN 0x0080
|
||||
#define MOUSE_MAXBUTTON 31
|
||||
#define MOUSE_STDBUTTONS 0x0007 /* buttons 1-3 */
|
||||
#define MOUSE_EXTBUTTONS 0x7ffffff8 /* the others (28 of them!) */
|
||||
#define MOUSE_BUTTONS (MOUSE_STDBUTTONS | MOUSE_EXTBUTTONS)
|
||||
|
||||
/* flags */
|
||||
#define MOUSE_STDBUTTONSCHANGED MOUSE_STDBUTTONS
|
||||
#define MOUSE_EXTBUTTONSCHANGED MOUSE_EXTBUTTONS
|
||||
#define MOUSE_BUTTONSCHANGED MOUSE_BUTTONS
|
||||
#define MOUSE_POSCHANGED 0x80000000
|
||||
|
||||
typedef struct mousehw {
|
||||
int buttons; /* -1 if unknown */
|
||||
int iftype; /* MOUSE_IF_XXX */
|
||||
int type; /* mouse/track ball/pad... */
|
||||
int model; /* I/F dependent model ID: MOUSE_MODEL_XXX */
|
||||
int hwid; /* I/F dependent hardware ID
|
||||
* for the PS/2 mouse, it will be PSM_XXX_ID
|
||||
*/
|
||||
} mousehw_t;
|
||||
|
||||
typedef struct synapticshw {
|
||||
int infoMajor;
|
||||
int infoMinor;
|
||||
int infoRot180;
|
||||
int infoPortrait;
|
||||
int infoSensor;
|
||||
int infoHardware;
|
||||
int infoNewAbs;
|
||||
int capPen;
|
||||
int infoSimplC;
|
||||
int infoGeometry;
|
||||
int capExtended;
|
||||
int capSleep;
|
||||
int capFourButtons;
|
||||
int capMultiFinger;
|
||||
int capPalmDetect;
|
||||
int capPassthrough;
|
||||
int capMiddle;
|
||||
int capLowPower;
|
||||
int capMultiFingerReport;
|
||||
int capBallistics;
|
||||
int nExtendedButtons;
|
||||
int nExtendedQueries;
|
||||
int capClickPad;
|
||||
int capDeluxeLEDs;
|
||||
int noAbsoluteFilter;
|
||||
int capReportsV;
|
||||
int capUniformClickPad;
|
||||
int capReportsMin;
|
||||
int capInterTouch;
|
||||
int capReportsMax;
|
||||
int capClearPad;
|
||||
int capAdvancedGestures;
|
||||
int multiFingerMode;
|
||||
int capCoveredPad;
|
||||
int verticalScroll;
|
||||
int horizontalScroll;
|
||||
int verticalWheel;
|
||||
int capEWmode;
|
||||
int minimumXCoord;
|
||||
int minimumYCoord;
|
||||
int maximumXCoord;
|
||||
int maximumYCoord;
|
||||
int infoXupmm;
|
||||
int infoYupmm;
|
||||
} synapticshw_t;
|
||||
|
||||
/* iftype */
|
||||
#define MOUSE_IF_UNKNOWN (-1)
|
||||
#define MOUSE_IF_SERIAL 0
|
||||
#define MOUSE_IF_BUS 1
|
||||
#define MOUSE_IF_INPORT 2
|
||||
#define MOUSE_IF_PS2 3
|
||||
#define MOUSE_IF_SYSMOUSE 4
|
||||
#define MOUSE_IF_USB 5
|
||||
|
||||
/* type */
|
||||
#define MOUSE_UNKNOWN (-1) /* should be treated as a mouse */
|
||||
#define MOUSE_MOUSE 0
|
||||
#define MOUSE_TRACKBALL 1
|
||||
#define MOUSE_STICK 2
|
||||
#define MOUSE_PAD 3
|
||||
|
||||
/* model */
|
||||
#define MOUSE_MODEL_UNKNOWN (-1)
|
||||
#define MOUSE_MODEL_GENERIC 0
|
||||
#define MOUSE_MODEL_GLIDEPOINT 1
|
||||
#define MOUSE_MODEL_NETSCROLL 2
|
||||
#define MOUSE_MODEL_NET 3
|
||||
#define MOUSE_MODEL_INTELLI 4
|
||||
#define MOUSE_MODEL_THINK 5
|
||||
#define MOUSE_MODEL_EASYSCROLL 6
|
||||
#define MOUSE_MODEL_MOUSEMANPLUS 7
|
||||
#define MOUSE_MODEL_KIDSPAD 8
|
||||
#define MOUSE_MODEL_VERSAPAD 9
|
||||
#define MOUSE_MODEL_EXPLORER 10
|
||||
#define MOUSE_MODEL_4D 11
|
||||
#define MOUSE_MODEL_4DPLUS 12
|
||||
#define MOUSE_MODEL_SYNAPTICS 13
|
||||
#define MOUSE_MODEL_TRACKPOINT 14
|
||||
#define MOUSE_MODEL_ELANTECH 15
|
||||
|
||||
typedef struct mousemode {
|
||||
int protocol; /* MOUSE_PROTO_XXX */
|
||||
int rate; /* report rate (per sec), -1 if unknown */
|
||||
int resolution; /* MOUSE_RES_XXX, -1 if unknown */
|
||||
int accelfactor; /* accelation factor (must be 1 or greater) */
|
||||
int level; /* driver operation level */
|
||||
int packetsize; /* the length of the data packet */
|
||||
unsigned char syncmask[2]; /* sync. data bits in the header byte */
|
||||
} mousemode_t;
|
||||
|
||||
/* protocol */
|
||||
/*
|
||||
* Serial protocols:
|
||||
* Microsoft, MouseSystems, Logitech, MM series, MouseMan, Hitachi Tablet,
|
||||
* GlidePoint, IntelliMouse, Thinking Mouse, MouseRemote, Kidspad,
|
||||
* VersaPad
|
||||
* Bus mouse protocols:
|
||||
* bus, InPort
|
||||
* PS/2 mouse protocol:
|
||||
* PS/2
|
||||
*/
|
||||
#define MOUSE_PROTO_UNKNOWN (-1)
|
||||
#define MOUSE_PROTO_MS 0 /* Microsoft Serial, 3 bytes */
|
||||
#define MOUSE_PROTO_MSC 1 /* Mouse Systems, 5 bytes */
|
||||
#define MOUSE_PROTO_LOGI 2 /* Logitech, 3 bytes */
|
||||
#define MOUSE_PROTO_MM 3 /* MM series, 3 bytes */
|
||||
#define MOUSE_PROTO_LOGIMOUSEMAN 4 /* Logitech MouseMan 3/4 bytes */
|
||||
#define MOUSE_PROTO_BUS 5 /* MS/Logitech bus mouse */
|
||||
#define MOUSE_PROTO_INPORT 6 /* MS/ATI InPort mouse */
|
||||
#define MOUSE_PROTO_PS2 7 /* PS/2 mouse, 3 bytes */
|
||||
#define MOUSE_PROTO_HITTAB 8 /* Hitachi Tablet 3 bytes */
|
||||
#define MOUSE_PROTO_GLIDEPOINT 9 /* ALPS GlidePoint, 3/4 bytes */
|
||||
#define MOUSE_PROTO_INTELLI 10 /* MS IntelliMouse, 4 bytes */
|
||||
#define MOUSE_PROTO_THINK 11 /* Kensington Thinking Mouse, 3/4 bytes */
|
||||
#define MOUSE_PROTO_SYSMOUSE 12 /* /dev/sysmouse */
|
||||
#define MOUSE_PROTO_X10MOUSEREM 13 /* X10 MouseRemote, 3 bytes */
|
||||
#define MOUSE_PROTO_KIDSPAD 14 /* Genius Kidspad */
|
||||
#define MOUSE_PROTO_VERSAPAD 15 /* Interlink VersaPad, 6 bytes */
|
||||
#define MOUSE_PROTO_JOGDIAL 16 /* Vaio's JogDial */
|
||||
#define MOUSE_PROTO_GTCO_DIGIPAD 17
|
||||
|
||||
#define MOUSE_RES_UNKNOWN (-1)
|
||||
#define MOUSE_RES_DEFAULT 0
|
||||
#define MOUSE_RES_LOW (-2)
|
||||
#define MOUSE_RES_MEDIUMLOW (-3)
|
||||
#define MOUSE_RES_MEDIUMHIGH (-4)
|
||||
#define MOUSE_RES_HIGH (-5)
|
||||
|
||||
typedef struct mousedata {
|
||||
int len; /* # of data in the buffer */
|
||||
int buf[16]; /* data buffer */
|
||||
} mousedata_t;
|
||||
|
||||
#if (defined(MOUSE_GETVARS))
|
||||
|
||||
typedef struct mousevar {
|
||||
int var[16];
|
||||
} mousevar_t;
|
||||
|
||||
/* magic numbers in var[0] */
|
||||
#define MOUSE_VARS_PS2_SIG 0x00325350 /* 'PS2' */
|
||||
#define MOUSE_VARS_BUS_SIG 0x00535542 /* 'BUS' */
|
||||
#define MOUSE_VARS_INPORT_SIG 0x00504e49 /* 'INP' */
|
||||
|
||||
#endif /* MOUSE_GETVARS */
|
||||
|
||||
/* Synaptics Touchpad */
|
||||
#define MOUSE_SYNAPTICS_PACKETSIZE 6 /* '3' works better */
|
||||
|
||||
/* Elantech Touchpad */
|
||||
#define MOUSE_ELANTECH_PACKETSIZE 6
|
||||
|
||||
/* Microsoft Serial mouse data packet */
|
||||
#define MOUSE_MSS_PACKETSIZE 3
|
||||
#define MOUSE_MSS_SYNCMASK 0x40
|
||||
#define MOUSE_MSS_SYNC 0x40
|
||||
#define MOUSE_MSS_BUTTONS 0x30
|
||||
#define MOUSE_MSS_BUTTON1DOWN 0x20 /* left */
|
||||
#define MOUSE_MSS_BUTTON2DOWN 0x00 /* no middle button */
|
||||
#define MOUSE_MSS_BUTTON3DOWN 0x10 /* right */
|
||||
|
||||
/* Logitech MouseMan data packet (M+ protocol) */
|
||||
#define MOUSE_LMAN_BUTTON2DOWN 0x20 /* middle button, the 4th byte */
|
||||
|
||||
/* ALPS GlidePoint extension (variant of M+ protocol) */
|
||||
#define MOUSE_ALPS_BUTTON2DOWN 0x20 /* middle button, the 4th byte */
|
||||
#define MOUSE_ALPS_TAP 0x10 /* `tapping' action, the 4th byte */
|
||||
|
||||
/* Kinsington Thinking Mouse extension (variant of M+ protocol) */
|
||||
#define MOUSE_THINK_BUTTON2DOWN 0x20 /* lower-left button, the 4th byte */
|
||||
#define MOUSE_THINK_BUTTON4DOWN 0x10 /* lower-right button, the 4th byte */
|
||||
|
||||
/* MS IntelliMouse (variant of MS Serial) */
|
||||
#define MOUSE_INTELLI_PACKETSIZE 4
|
||||
#define MOUSE_INTELLI_BUTTON2DOWN 0x10 /* middle button in the 4th byte */
|
||||
|
||||
/* Mouse Systems Corp. mouse data packet */
|
||||
#define MOUSE_MSC_PACKETSIZE 5
|
||||
#define MOUSE_MSC_SYNCMASK 0xf8
|
||||
#define MOUSE_MSC_SYNC 0x80
|
||||
#define MOUSE_MSC_BUTTONS 0x07
|
||||
#define MOUSE_MSC_BUTTON1UP 0x04 /* left */
|
||||
#define MOUSE_MSC_BUTTON2UP 0x02 /* middle */
|
||||
#define MOUSE_MSC_BUTTON3UP 0x01 /* right */
|
||||
#define MOUSE_MSC_MAXBUTTON 3
|
||||
|
||||
/* MM series mouse data packet */
|
||||
#define MOUSE_MM_PACKETSIZE 3
|
||||
#define MOUSE_MM_SYNCMASK 0xe0
|
||||
#define MOUSE_MM_SYNC 0x80
|
||||
#define MOUSE_MM_BUTTONS 0x07
|
||||
#define MOUSE_MM_BUTTON1DOWN 0x04 /* left */
|
||||
#define MOUSE_MM_BUTTON2DOWN 0x02 /* middle */
|
||||
#define MOUSE_MM_BUTTON3DOWN 0x01 /* right */
|
||||
#define MOUSE_MM_XPOSITIVE 0x10
|
||||
#define MOUSE_MM_YPOSITIVE 0x08
|
||||
|
||||
/* PS/2 mouse data packet */
|
||||
#define MOUSE_PS2_PACKETSIZE 3
|
||||
#define MOUSE_PS2_SYNCMASK 0xc8
|
||||
#define MOUSE_PS2_SYNC 0x08
|
||||
#define MOUSE_PS2_BUTTONS 0x07 /* 0x03 for 2 button mouse */
|
||||
#define MOUSE_PS2_BUTTON1DOWN 0x01 /* left */
|
||||
#define MOUSE_PS2_BUTTON2DOWN 0x04 /* middle */
|
||||
#define MOUSE_PS2_BUTTON3DOWN 0x02 /* right */
|
||||
#define MOUSE_PS2_TAP MOUSE_PS2_SYNC /* GlidePoint (PS/2) `tapping'
|
||||
* Yes! this is the same bit
|
||||
* as SYNC!
|
||||
*/
|
||||
|
||||
#define MOUSE_PS2_XNEG 0x10
|
||||
#define MOUSE_PS2_YNEG 0x20
|
||||
#define MOUSE_PS2_XOVERFLOW 0x40
|
||||
#define MOUSE_PS2_YOVERFLOW 0x80
|
||||
|
||||
/* Logitech MouseMan+ (PS/2) data packet (PS/2++ protocol) */
|
||||
#define MOUSE_PS2PLUS_SYNCMASK 0x48
|
||||
#define MOUSE_PS2PLUS_SYNC 0x48
|
||||
#define MOUSE_PS2PLUS_ZNEG 0x08 /* sign bit */
|
||||
#define MOUSE_PS2PLUS_BUTTON4DOWN 0x10 /* 4th button on MouseMan+ */
|
||||
#define MOUSE_PS2PLUS_BUTTON5DOWN 0x20
|
||||
|
||||
/* IBM ScrollPoint (PS/2) also uses PS/2++ protocol */
|
||||
#define MOUSE_SPOINT_ZNEG 0x80 /* sign bits */
|
||||
#define MOUSE_SPOINT_WNEG 0x08
|
||||
|
||||
/* MS IntelliMouse (PS/2) data packet */
|
||||
#define MOUSE_PS2INTELLI_PACKETSIZE 4
|
||||
/* some compatible mice have additional buttons */
|
||||
#define MOUSE_PS2INTELLI_BUTTON4DOWN 0x40
|
||||
#define MOUSE_PS2INTELLI_BUTTON5DOWN 0x80
|
||||
|
||||
/* MS IntelliMouse Explorer (PS/2) data packet (variation of IntelliMouse) */
|
||||
#define MOUSE_EXPLORER_ZNEG 0x08 /* sign bit */
|
||||
/* IntelliMouse Explorer has additional button data in the fourth byte */
|
||||
#define MOUSE_EXPLORER_BUTTON4DOWN 0x10
|
||||
#define MOUSE_EXPLORER_BUTTON5DOWN 0x20
|
||||
|
||||
/* Interlink VersaPad (serial I/F) data packet */
|
||||
#define MOUSE_VERSA_PACKETSIZE 6
|
||||
#define MOUSE_VERSA_IN_USE 0x04
|
||||
#define MOUSE_VERSA_SYNCMASK 0xc3
|
||||
#define MOUSE_VERSA_SYNC 0xc0
|
||||
#define MOUSE_VERSA_BUTTONS 0x30
|
||||
#define MOUSE_VERSA_BUTTON1DOWN 0x20 /* left */
|
||||
#define MOUSE_VERSA_BUTTON2DOWN 0x00 /* middle */
|
||||
#define MOUSE_VERSA_BUTTON3DOWN 0x10 /* right */
|
||||
#define MOUSE_VERSA_TAP 0x08
|
||||
|
||||
/* Interlink VersaPad (PS/2 I/F) data packet */
|
||||
#define MOUSE_PS2VERSA_PACKETSIZE 6
|
||||
#define MOUSE_PS2VERSA_IN_USE 0x10
|
||||
#define MOUSE_PS2VERSA_SYNCMASK 0xe8
|
||||
#define MOUSE_PS2VERSA_SYNC 0xc8
|
||||
#define MOUSE_PS2VERSA_BUTTONS 0x05
|
||||
#define MOUSE_PS2VERSA_BUTTON1DOWN 0x04 /* left */
|
||||
#define MOUSE_PS2VERSA_BUTTON2DOWN 0x00 /* middle */
|
||||
#define MOUSE_PS2VERSA_BUTTON3DOWN 0x01 /* right */
|
||||
#define MOUSE_PS2VERSA_TAP 0x02
|
||||
|
||||
/* A4 Tech 4D Mouse (PS/2) data packet */
|
||||
#define MOUSE_4D_PACKETSIZE 3
|
||||
#define MOUSE_4D_WHEELBITS 0xf0
|
||||
|
||||
/* A4 Tech 4D+ Mouse (PS/2) data packet */
|
||||
#define MOUSE_4DPLUS_PACKETSIZE 3
|
||||
#define MOUSE_4DPLUS_ZNEG 0x04 /* sign bit */
|
||||
#define MOUSE_4DPLUS_BUTTON4DOWN 0x08
|
||||
|
||||
/* sysmouse extended data packet */
|
||||
/*
|
||||
* /dev/sysmouse sends data in two formats, depending on the protocol
|
||||
* level. At the level 0, format is exactly the same as MousSystems'
|
||||
* five byte packet. At the level 1, the first five bytes are the same
|
||||
* as at the level 0. There are additional three bytes which shows
|
||||
* `dz' and the states of additional buttons. `dz' is expressed as the
|
||||
* sum of the byte 5 and 6 which contain signed seven bit values.
|
||||
* The states of the button 4 though 10 are in the bit 0 though 6 in
|
||||
* the byte 7 respectively: 1 indicates the button is up.
|
||||
*/
|
||||
#define MOUSE_SYS_PACKETSIZE 8
|
||||
#define MOUSE_SYS_SYNCMASK 0xf8
|
||||
#define MOUSE_SYS_SYNC 0x80
|
||||
#define MOUSE_SYS_BUTTON1UP 0x04 /* left, 1st byte */
|
||||
#define MOUSE_SYS_BUTTON2UP 0x02 /* middle, 1st byte */
|
||||
#define MOUSE_SYS_BUTTON3UP 0x01 /* right, 1st byte */
|
||||
#define MOUSE_SYS_BUTTON4UP 0x0001 /* 7th byte */
|
||||
#define MOUSE_SYS_BUTTON5UP 0x0002
|
||||
#define MOUSE_SYS_BUTTON6UP 0x0004
|
||||
#define MOUSE_SYS_BUTTON7UP 0x0008
|
||||
#define MOUSE_SYS_BUTTON8UP 0x0010
|
||||
#define MOUSE_SYS_BUTTON9UP 0x0020
|
||||
#define MOUSE_SYS_BUTTON10UP 0x0040
|
||||
#define MOUSE_SYS_MAXBUTTON 10
|
||||
#define MOUSE_SYS_STDBUTTONS 0x07
|
||||
#define MOUSE_SYS_EXTBUTTONS 0x7f /* the others */
|
||||
|
||||
/* Mouse remote socket */
|
||||
#define _PATH_MOUSEREMOTE "/var/run/MouseRemote"
|
||||
|
||||
#endif /* _SYS_MOUSE_H_ */
|
Loading…
x
Reference in New Issue
Block a user