- USB HID mouse support ported from Qemu to separate file and C++ object
* removed old-style mouse stuff * TODO: implement USB tablet from Qemu and re-implement Bochs USB keypad - clear out USB hub structures in constructor to avoid segfault - keyboard: mouse capture flag must affect all mouse types
This commit is contained in:
parent
5e4553500b
commit
69e0110c7b
@ -2,7 +2,7 @@ dnl // Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.50)
|
||||
AC_INIT(bochs.h)
|
||||
AC_REVISION([[$Id: configure.in,v 1.333 2007-03-18 11:17:27 vruppert Exp $]])
|
||||
AC_REVISION([[$Id: configure.in,v 1.334 2007-03-21 18:54:41 vruppert Exp $]])
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
AC_CONFIG_HEADER(ltdlconf.h)
|
||||
|
||||
@ -781,7 +781,7 @@ AC_ARG_ENABLE(usb,
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(BX_SUPPORT_PCIUSB, 1)
|
||||
PCI_OBJ="$PCI_OBJ pciusb.o"
|
||||
USBDEV_OBJS="usb_msd.o"
|
||||
USBDEV_OBJS="usb_hid.o usb_msd.o"
|
||||
SCSI_OBJS="scsi_device.o"
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
|
@ -162,8 +162,8 @@ libbx_serial.la: serial.lo serial_raw.lo
|
||||
libbx_vga.la: vga.lo svga_cirrus.lo
|
||||
$(LIBTOOL) --mode=link $(CXX) -module vga.lo svga_cirrus.lo -o libbx_vga.la -rpath $(PLUGIN_PATH)
|
||||
|
||||
libbx_pciusb.la: pciusb.lo usb_msd.lo scsi_device.lo hdimage.lo cdrom.lo
|
||||
$(LIBTOOL) --mode=link $(CXX) -module pciusb.lo usb_msd.lo scsi_device.lo hdimage.lo cdrom.lo -o libbx_pciusb.la -rpath $(PLUGIN_PATH)
|
||||
libbx_pciusb.la: pciusb.lo usb_hid.lo usb_msd.lo scsi_device.lo hdimage.lo cdrom.lo
|
||||
$(LIBTOOL) --mode=link $(CXX) -module pciusb.lo usb_hid.lo usb_msd.lo scsi_device.lo hdimage.lo cdrom.lo -o libbx_pciusb.la -rpath $(PLUGIN_PATH)
|
||||
|
||||
#### building DLLs for win32 (tested on cygwin only)
|
||||
bx_%.dll: %.o
|
||||
@ -197,8 +197,8 @@ bx_serial.dll: serial.o serial_raw.o
|
||||
bx_vga.dll: vga.o svga_cirrus.o
|
||||
$(CXX) $(CXXFLAGS) -shared -o bx_vga.dll vga.o svga_cirrus.o $(WIN32_DLL_IMPORT_LIBRARY)
|
||||
|
||||
bx_pciusb.dll: pciusb.o usb_msd.o scsi_device.o hdimage.o cdrom.o
|
||||
$(CXX) $(CXXFLAGS) -shared -o bx_pciusb.dll pciusb.o usb_msd.o scsi_device.o hdimage.o cdrom.o $(WIN32_DLL_IMPORT_LIBRARY)
|
||||
bx_pciusb.dll: pciusb.o usb_hid.o usb_msd.o scsi_device.o hdimage.o cdrom.o
|
||||
$(CXX) $(CXXFLAGS) -shared -o bx_pciusb.dll pciusb.o usb_hid.o usb_msd.o scsi_device.o hdimage.o cdrom.o $(WIN32_DLL_IMPORT_LIBRARY)
|
||||
|
||||
##### end DLL section
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: keyboard.cc,v 1.128 2007-02-25 13:18:33 vruppert Exp $
|
||||
// $Id: keyboard.cc,v 1.129 2007-03-21 18:54:41 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 MandrakeSoft S.A.
|
||||
@ -126,7 +126,7 @@ void bx_keyb_c::resetinternals(bx_bool powerup)
|
||||
|
||||
void bx_keyb_c::init(void)
|
||||
{
|
||||
BX_DEBUG(("Init $Id: keyboard.cc,v 1.128 2007-02-25 13:18:33 vruppert Exp $"));
|
||||
BX_DEBUG(("Init $Id: keyboard.cc,v 1.129 2007-03-21 18:54:41 vruppert Exp $"));
|
||||
Bit32u i;
|
||||
|
||||
DEV_register_irq(1, "8042 Keyboard controller");
|
||||
@ -1603,6 +1603,7 @@ void bx_keyb_c::create_mouse_packet(bool force_enq)
|
||||
|
||||
void bx_keyb_c::mouse_enabled_changed(bx_bool enabled)
|
||||
{
|
||||
BX_KEY_THIS s.mouse.captured = enabled;
|
||||
#if BX_SUPPORT_PCIUSB
|
||||
// if an usb mouse is connected, notify the device about the status change
|
||||
if (DEV_usb_mouse_connected()) {
|
||||
@ -1618,7 +1619,6 @@ void bx_keyb_c::mouse_enabled_changed(bx_bool enabled)
|
||||
BX_KEY_THIS s.mouse.delayed_dx=0;
|
||||
BX_KEY_THIS s.mouse.delayed_dy=0;
|
||||
BX_KEY_THIS s.mouse.delayed_dz=0;
|
||||
BX_KEY_THIS s.mouse.captured = enabled;
|
||||
BX_DEBUG(("PS/2 mouse %s", enabled?"enabled":"disabled"));
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: pciusb.cc,v 1.51 2007-03-18 17:52:15 vruppert Exp $
|
||||
// $Id: pciusb.cc,v 1.52 2007-03-21 18:54:41 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2004 MandrakeSoft S.A.
|
||||
@ -59,6 +59,7 @@
|
||||
|
||||
#include "iodev.h"
|
||||
#if BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB
|
||||
#include "usb_hid.h"
|
||||
#include "usb_msd.h"
|
||||
|
||||
#define LOG_THIS theUSBDevice->
|
||||
@ -124,6 +125,9 @@ bx_pciusb_c::bx_pciusb_c()
|
||||
{
|
||||
put("USB");
|
||||
settype(PCIUSBLOG);
|
||||
for (int i=0; i<BX_USB_CONFDEV; i++) {
|
||||
memset((void*)&hub[i], 0, sizeof(bx_usb_t));
|
||||
}
|
||||
device_buffer = NULL;
|
||||
}
|
||||
|
||||
@ -221,18 +225,11 @@ void bx_pciusb_c::reset(unsigned type)
|
||||
|
||||
// reset locals
|
||||
BX_USB_THIS busy = 0;
|
||||
BX_USB_THIS last_connect = 0xFF;
|
||||
BX_USB_THIS global_reset = 0;
|
||||
BX_USB_THIS set_address_stk = 0;
|
||||
memset(BX_USB_THIS saved_key, 0, 8);
|
||||
memset(BX_USB_THIS key_pad_packet, 0, 8);
|
||||
|
||||
// mouse packet stuff
|
||||
BX_USB_THIS mouse_delayed_dx = 0;
|
||||
BX_USB_THIS mouse_delayed_dy = 0;
|
||||
BX_USB_THIS mouse_delayed_dz = 0;
|
||||
BX_USB_THIS button_state = 0;
|
||||
|
||||
// Put the USB registers into their RESET state
|
||||
for (i=0; i<BX_USB_CONFDEV; i++) {
|
||||
BX_USB_THIS hub[i].usb_command.max_packet_size = 0;
|
||||
@ -282,7 +279,7 @@ void bx_pciusb_c::reset(unsigned type)
|
||||
}
|
||||
|
||||
BX_USB_THIS keyboard_connected = 0;
|
||||
BX_USB_THIS mouse_connected = 0;
|
||||
BX_USB_THIS mousedev = NULL;
|
||||
|
||||
// include the device(s) initialize code
|
||||
#include "pciusb_devs.h"
|
||||
@ -344,14 +341,6 @@ void bx_pciusb_c::register_state(void)
|
||||
}
|
||||
new bx_shadow_bool_c(list, "busy", &BX_USB_THIS busy);
|
||||
new bx_shadow_num_c(list, "global_reset", &BX_USB_THIS global_reset);
|
||||
new bx_shadow_num_c(list, "mouse_delayed_dx", &BX_USB_THIS mouse_delayed_dx);
|
||||
new bx_shadow_num_c(list, "mouse_delayed_dy", &BX_USB_THIS mouse_delayed_dy);
|
||||
new bx_shadow_num_c(list, "mouse_delayed_dz", &BX_USB_THIS mouse_delayed_dz);
|
||||
new bx_shadow_num_c(list, "button_state", &BX_USB_THIS button_state);
|
||||
new bx_shadow_num_c(list, "mouse_x", &BX_USB_THIS mouse_x);
|
||||
new bx_shadow_num_c(list, "mouse_y", &BX_USB_THIS mouse_y);
|
||||
new bx_shadow_num_c(list, "mouse_z", &BX_USB_THIS mouse_z);
|
||||
new bx_shadow_num_c(list, "b_state", &BX_USB_THIS b_state);
|
||||
bx_list_c *svkey = new bx_list_c(list, "saved_key", 8);
|
||||
for (i=0; i<8; i++) {
|
||||
sprintf(name, "%d", i);
|
||||
@ -385,7 +374,7 @@ void bx_pciusb_c::after_restore_state(void)
|
||||
|
||||
void bx_pciusb_c::init_device(Bit8u port, const char *devname)
|
||||
{
|
||||
Bit8u type = USB_DEV_TYPE_NONE;
|
||||
usbdev_type type = USB_DEV_TYPE_NONE;
|
||||
bx_bool connected = 0;
|
||||
|
||||
if (!strlen(devname) || !strcmp(devname, "none")) return;
|
||||
@ -393,7 +382,10 @@ void bx_pciusb_c::init_device(Bit8u port, const char *devname)
|
||||
if (!strcmp(devname, "mouse")) {
|
||||
type = USB_DEV_TYPE_MOUSE;
|
||||
connected = 1;
|
||||
BX_USB_THIS mouse_connected = 1;
|
||||
BX_USB_THIS hub[0].usb_port[port].device = new usb_hid_device_t(type);
|
||||
if (BX_USB_THIS mousedev == NULL) {
|
||||
BX_USB_THIS mousedev = (usb_hid_device_t*)BX_USB_THIS hub[0].usb_port[port].device;
|
||||
}
|
||||
} else if (!strcmp(devname, "keypad")) {
|
||||
type = USB_DEV_TYPE_KEYPAD;
|
||||
connected = 1;
|
||||
@ -406,10 +398,12 @@ void bx_pciusb_c::init_device(Bit8u port, const char *devname)
|
||||
BX_PANIC(("unknown USB device: %s", devname));
|
||||
return;
|
||||
}
|
||||
for (int i=0; i<USB_CUR_DEVS; i++) {
|
||||
if (BX_USB_THIS hub[0].device[i].dev_type == type) {
|
||||
BX_USB_THIS hub[0].usb_port[port].device_num = i;
|
||||
BX_USB_THIS hub[0].device[i].stall_once &= ~0x80; // clear out the "stall once bit has happened"
|
||||
if (BX_USB_THIS hub[0].usb_port[port].device == NULL) {
|
||||
for (int i=0; i<USB_CUR_DEVS; i++) {
|
||||
if (BX_USB_THIS hub[0].device[i].dev_type == type) {
|
||||
BX_USB_THIS hub[0].usb_port[port].device_num = i;
|
||||
BX_USB_THIS hub[0].device[i].stall_once &= ~0x80; // clear out the "stall once bit has happened"
|
||||
}
|
||||
}
|
||||
}
|
||||
usb_set_connect_status(port, type, connected);
|
||||
@ -1048,23 +1042,6 @@ bx_bool bx_pciusb_c::DoTransfer(Bit32u address, Bit32u queue_num, struct TD *td)
|
||||
BX_USB_THIS set_status(td, 0, 0, 0, 0, 0, 0, cnt-1);
|
||||
break;
|
||||
|
||||
case 2: // mouse
|
||||
if (!BX_USB_THIS mouse_x && !BX_USB_THIS mouse_y) {
|
||||
// if there's no new movement, handle delayed one
|
||||
BX_USB_THIS usb_mouse_enq(0, 0, BX_USB_THIS mouse_z, BX_USB_THIS b_state);
|
||||
}
|
||||
device_buffer[0] = (Bit8u) BX_USB_THIS b_state;
|
||||
device_buffer[1] = (Bit8s) BX_USB_THIS mouse_x;
|
||||
device_buffer[2] = (Bit8s) BX_USB_THIS mouse_y;
|
||||
device_buffer[3] = (Bit8s) BX_USB_THIS mouse_z; // if wheel mouse
|
||||
BX_USB_THIS b_state = 0;
|
||||
BX_USB_THIS mouse_x = 0;
|
||||
BX_USB_THIS mouse_y = 0;
|
||||
BX_USB_THIS mouse_z = 0;
|
||||
DEV_MEM_WRITE_PHYSICAL(td->dword3, cnt, device_buffer);
|
||||
BX_USB_THIS set_status(td, 0, 0, 0, 0, 0, 0, cnt-1);
|
||||
break;
|
||||
|
||||
default:
|
||||
BX_PANIC(("Unknown/unsupported endpt protocol issued an Interrupt In / Bulk packet. protocol %i", protocol));
|
||||
}
|
||||
@ -1131,10 +1108,6 @@ bx_bool bx_pciusb_c::DoTransfer(Bit32u address, Bit32u queue_num, struct TD *td)
|
||||
BX_PANIC(("Keyboard received and OUT packet!"));
|
||||
break;
|
||||
|
||||
case 2: // mouse
|
||||
BX_PANIC(("Mouse received and OUT packet!"));
|
||||
break;
|
||||
|
||||
default:
|
||||
BX_PANIC(("Unknown/unsupported endpt protocol issued an Interrupt Out / Bulk packet. protocol %i", protocol));
|
||||
}
|
||||
@ -1724,9 +1697,9 @@ void bx_pciusb_c::pci_write_handler(Bit8u address, Bit32u value, unsigned io_len
|
||||
|
||||
void bx_pciusb_c::usb_mouse_enabled_changed(bx_bool enable)
|
||||
{
|
||||
BX_USB_THIS mouse_delayed_dx=0;
|
||||
BX_USB_THIS mouse_delayed_dy=0;
|
||||
BX_USB_THIS mouse_delayed_dz=0;
|
||||
if (enable && (BX_USB_THIS mousedev != NULL)) {
|
||||
mousedev->handle_reset();
|
||||
}
|
||||
}
|
||||
|
||||
void bx_pciusb_c::usb_set_connect_status(Bit8u port, int type, bx_bool connected)
|
||||
@ -1785,14 +1758,15 @@ void bx_pciusb_c::usb_set_connect_status(Bit8u port, int type, bx_bool connected
|
||||
BX_USB_THIS hub[0].usb_port[port].line_dminus = 0; // dminus=1 & dplus=0 = low speed (at idle time)
|
||||
BX_USB_THIS hub[0].usb_port[port].line_dplus = 0; // dminus=0 & dplus=1 = high speed (at idle time)
|
||||
if (type == USB_DEV_TYPE_MOUSE) {
|
||||
BX_USB_THIS mouse_connected = 0;
|
||||
if (BX_USB_THIS hub[0].usb_port[port].device == BX_USB_THIS mousedev) {
|
||||
BX_USB_THIS mousedev = NULL;
|
||||
}
|
||||
} else if (type == USB_DEV_TYPE_KEYPAD) {
|
||||
BX_USB_THIS keyboard_connected = 0;
|
||||
} else if (type == USB_DEV_TYPE_DISK) {
|
||||
if (BX_USB_THIS hub[0].usb_port[port].device != NULL) {
|
||||
delete BX_USB_THIS hub[0].usb_port[port].device;
|
||||
BX_USB_THIS hub[0].usb_port[port].device = NULL;
|
||||
}
|
||||
}
|
||||
if (BX_USB_THIS hub[0].usb_port[port].device != NULL) {
|
||||
delete BX_USB_THIS hub[0].usb_port[port].device;
|
||||
BX_USB_THIS hub[0].usb_port[port].device = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1838,9 +1812,7 @@ void bx_pciusb_c::usb_set_connect_status(Bit8u port, int type, bx_bool connected
|
||||
BX_USB_THIS hub[0].usb_port[port].low_speed = 0;
|
||||
BX_USB_THIS hub[0].usb_port[port].line_dminus = 0; // dminus=1 & dplus=0 = low speed (at idle time)
|
||||
BX_USB_THIS hub[0].usb_port[port].line_dplus = 0; // dminus=0 & dplus=1 = high speed (at idle time)
|
||||
if (type == USB_DEV_TYPE_MOUSE) {
|
||||
BX_USB_THIS mouse_connected = 0;
|
||||
} else if (type == USB_DEV_TYPE_KEYPAD) {
|
||||
if (type == USB_DEV_TYPE_KEYPAD) {
|
||||
BX_USB_THIS keyboard_connected = 0;
|
||||
}
|
||||
}
|
||||
@ -1850,45 +1822,9 @@ void bx_pciusb_c::usb_set_connect_status(Bit8u port, int type, bx_bool connected
|
||||
|
||||
void bx_pciusb_c::usb_mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state)
|
||||
{
|
||||
// scale down the motion
|
||||
if ( (delta_x < -1) || (delta_x > 1) )
|
||||
delta_x /= 2;
|
||||
if ( (delta_y < -1) || (delta_y > 1) )
|
||||
delta_y /= 2;
|
||||
|
||||
if(delta_x>127) delta_x=127;
|
||||
if(delta_y>127) delta_y=127;
|
||||
if(delta_x<-128) delta_x=-128;
|
||||
if(delta_y<-128) delta_y=-128;
|
||||
|
||||
BX_USB_THIS mouse_delayed_dx+=delta_x;
|
||||
BX_USB_THIS mouse_delayed_dy-=delta_y;
|
||||
|
||||
if (BX_USB_THIS mouse_delayed_dx > 127) {
|
||||
delta_x = 127;
|
||||
BX_USB_THIS mouse_delayed_dx -= 127;
|
||||
} else if (BX_USB_THIS mouse_delayed_dx < -128) {
|
||||
delta_x = -128;
|
||||
BX_USB_THIS mouse_delayed_dx += 128;
|
||||
} else {
|
||||
delta_x = BX_USB_THIS mouse_delayed_dx;
|
||||
BX_USB_THIS mouse_delayed_dx = 0;
|
||||
if (BX_USB_THIS mousedev != NULL) {
|
||||
mousedev->mouse_enq(delta_x, delta_y, delta_z, button_state);
|
||||
}
|
||||
if (BX_USB_THIS mouse_delayed_dy > 127) {
|
||||
delta_y = 127;
|
||||
BX_USB_THIS mouse_delayed_dy -= 127;
|
||||
} else if (BX_USB_THIS mouse_delayed_dy < -128) {
|
||||
delta_y = -128;
|
||||
BX_USB_THIS mouse_delayed_dy += 128;
|
||||
} else {
|
||||
delta_y = BX_USB_THIS mouse_delayed_dy;
|
||||
BX_USB_THIS mouse_delayed_dy = 0;
|
||||
}
|
||||
|
||||
BX_USB_THIS mouse_x = (Bit8s) delta_x;
|
||||
BX_USB_THIS mouse_y = (Bit8s) delta_y;
|
||||
BX_USB_THIS mouse_z = (Bit8s) delta_z;
|
||||
BX_USB_THIS b_state = (Bit8u) button_state;
|
||||
}
|
||||
|
||||
bx_bool bx_pciusb_c::usb_key_enq(Bit8u *scan_code)
|
||||
@ -1975,7 +1911,7 @@ bx_bool bx_pciusb_c::usb_keyboard_connected()
|
||||
|
||||
bx_bool bx_pciusb_c::usb_mouse_connected()
|
||||
{
|
||||
return BX_USB_THIS mouse_connected;
|
||||
return (BX_USB_THIS mousedev != NULL);
|
||||
}
|
||||
|
||||
// Send an internal message to a USB device
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: pciusb.h,v 1.23 2007-03-18 11:17:28 vruppert Exp $
|
||||
// $Id: pciusb.h,v 1.24 2007-03-21 18:54:41 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2004 MandrakeSoft S.A.
|
||||
@ -42,7 +42,7 @@
|
||||
#define BX_USB_CONFDEV 1 /* only 1 USB hub currently */
|
||||
|
||||
#define USB_NUM_PORTS 2 /* UHCI supports 2 ports per root hub */
|
||||
#define USB_CUR_DEVS 2
|
||||
#define USB_CUR_DEVS 1 /* old-style devices (keypad only) */
|
||||
|
||||
#define USB_TOKEN_IN 0x69
|
||||
#define USB_TOKEN_OUT 0xE1
|
||||
@ -162,10 +162,13 @@ struct KEYPAD {
|
||||
enum usbdev_type {
|
||||
USB_DEV_TYPE_NONE=0,
|
||||
USB_DEV_TYPE_MOUSE,
|
||||
USB_DEV_TYPE_TABLET,
|
||||
USB_DEV_TYPE_KEYPAD,
|
||||
USB_DEV_TYPE_DISK
|
||||
};
|
||||
|
||||
class usb_hid_device_t;
|
||||
|
||||
void usb_dump_packet(Bit8u *data, unsigned size);
|
||||
int set_usb_string(Bit8u *buf, const char *str);
|
||||
|
||||
@ -478,15 +481,6 @@ private:
|
||||
bx_usb_t hub[BX_USB_CONFDEV];
|
||||
Bit8u global_reset;
|
||||
|
||||
int mouse_delayed_dx;
|
||||
int mouse_delayed_dy;
|
||||
int mouse_delayed_dz;
|
||||
unsigned button_state;
|
||||
Bit8s mouse_x;
|
||||
Bit8s mouse_y;
|
||||
Bit8s mouse_z;
|
||||
Bit8u b_state;
|
||||
|
||||
Bit8u saved_key[8];
|
||||
Bit8u key_pad_packet[8];
|
||||
|
||||
@ -496,9 +490,8 @@ private:
|
||||
unsigned set_address_stk;
|
||||
Bit8u set_address[128];
|
||||
|
||||
bx_bool last_connect;
|
||||
bx_bool keyboard_connected;
|
||||
bx_bool mouse_connected;
|
||||
usb_hid_device_t *mousedev;
|
||||
|
||||
USBPacket usb_packet;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: pciusb_devs.h,v 1.9 2007-03-18 11:17:28 vruppert Exp $
|
||||
// $Id: pciusb_devs.h,v 1.10 2007-03-21 18:54:41 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2004 MandrakeSoft S.A.
|
||||
@ -34,18 +34,17 @@
|
||||
|
||||
|
||||
// defines
|
||||
#define USB_CYPRESS 1
|
||||
#define USB_KEYPAD 1
|
||||
|
||||
// don't forget to modify USB_CUR_DEVS to reflect devices
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Cypress USB three button mouse.
|
||||
// This mouse is on port 0 of hub 0 and is the first device.
|
||||
#if USB_CYPRESS
|
||||
// USB 17 button keypad.
|
||||
// This keypad is on port 1 of hub 0 and is the second device.
|
||||
#if USB_KEYPAD
|
||||
|
||||
BX_USB_THIS hub[0].device[0].connect_status = 0;
|
||||
BX_USB_THIS hub[0].device[0].dev_type = USB_DEV_TYPE_MOUSE;
|
||||
BX_USB_THIS hub[0].device[0].dev_type = USB_DEV_TYPE_KEYPAD;
|
||||
|
||||
BX_USB_THIS hub[0].device[0].state = STATE_DEFAULT;
|
||||
BX_USB_THIS hub[0].device[0].address = 0;
|
||||
@ -55,7 +54,6 @@
|
||||
BX_USB_THIS hub[0].device[0].endpt = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.direction = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.configs = 1; // only one config in this device
|
||||
BX_USB_THIS hub[0].device[0].low_speed = 1;
|
||||
|
||||
BX_USB_THIS hub[0].device[0].in_stall = 0;
|
||||
BX_USB_THIS hub[0].device[0].stall_once = 0;
|
||||
@ -63,14 +61,14 @@
|
||||
// device descriptor
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.len = 18;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.type = USB_DT_DEVICE;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.usb_ver = 0x0100;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.usb_ver = 0x0110;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr._class = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.subclass = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.protocol = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.max_packet_size = 8;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.vendorid = 0x0627;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.productid = 0x0001;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.device_rel = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.vendorid = 0x04B4;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.productid = 0x0101;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.device_rel = 0x0001;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.manuf_indx = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.prod_indx = 2;
|
||||
BX_USB_THIS hub[0].device[0].function.device_descr.serial_indx = 0;
|
||||
@ -79,15 +77,15 @@
|
||||
// config descriptor
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].len = 9;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].type = USB_DT_CONFIG;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].tot_len = 34; // size of config+interface+endpt+hid
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].interfaces = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].tot_len = 59; // size of config+interface+endpt+hid
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].interfaces = 2;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].config_val = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].config_indx = 4;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].attrbs = 0xA0; // bus powered, etc
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].max_power = 50;
|
||||
|
||||
// interface descriptor
|
||||
// 0x09, 0x04, 0x00, 0x00, 0x01, 0x03, 0x01, 0x02, 0x05, // interface descriptor
|
||||
// interface descriptor #1
|
||||
// 0x09, 0x04, 0x00, 0x00, 0x01, 0x03, 0x01, 0x01, 0x05, // interface descriptor
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].size = 9;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].type = USB_DT_INTERFACE;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].interface_num = 0;
|
||||
@ -95,147 +93,9 @@
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].num_endpts = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].iclass = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].subclass = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].protocol = 2;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].protocol = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].str_indx = 5;
|
||||
|
||||
// endpoint descriptor
|
||||
// 0x07, 0x05, 0x81, 0x03, 0x03, 0x00, 0x0A, // endpoint descriptor
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].size = 7;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].type = USB_DT_ENDPOINT;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].endpt = 0x81;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].attrib = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].max_size = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].interval = 0x0A;
|
||||
|
||||
// HID descriptor
|
||||
// 0x09, 0x21, 0x00, 0x01, 0x00, 0x01, 0x22, 0x32, 0x00 // hid descriptor
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.size = 9;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.type = 0x21;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.HID_class = 0x0100;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.country_code = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.num_descriptors = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].type = 0x22;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].len = 50;
|
||||
|
||||
// HID descriptor type 0x22 (report descriptor)
|
||||
Bit8u dev0_rep0[] = {
|
||||
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03,
|
||||
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01,
|
||||
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06,
|
||||
0xC0, 0xC0
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].dev_hid_descript_report, dev0_rep0, 50);
|
||||
|
||||
// string descriptors
|
||||
BX_USB_THIS hub[0].device[0].function.str_descriptor.size = 0x04;
|
||||
BX_USB_THIS hub[0].device[0].function.str_descriptor.type = 0x03;
|
||||
BX_USB_THIS hub[0].device[0].function.str_descriptor.langid[0] = 0x0409;
|
||||
|
||||
// string #1
|
||||
BX_USB_THIS hub[0].device[0].function.string[0].size = 24;
|
||||
BX_USB_THIS hub[0].device[0].function.string[0].type = 3;
|
||||
Bit8u dev0_str_1[64] = { 0x43, 0x00, 0x79, 0x00, 0x70, 0x00, 0x72, 0x00, 0x65,
|
||||
0x00, 0x73, 0x00, 0x73, 0x00, 0x20, 0x00, 0x53, 0x00, 0x65, 0x00, 0x6D, 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[0].unicode_str, dev0_str_1, 22);
|
||||
|
||||
// string #2
|
||||
BX_USB_THIS hub[0].device[0].function.string[1].size = 36;
|
||||
BX_USB_THIS hub[0].device[0].function.string[1].type = 3;
|
||||
Bit8u dev0_str_2[64] = { 0x43, 0x00, 0x79, 0x00, 0x70, 0x00, 0x72, 0x00, 0x65,
|
||||
0x00, 0x73, 0x00, 0x73, 0x00, 0x20, 0x00, 0x55, 0x00, 0x53, 0x00, 0x42,
|
||||
0x00, 0x20, 0x00, 0x4D, 0x00, 0x6F, 0x00, 0x75, 0x00, 0x73, 0x00, 0x65, 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[1].unicode_str, dev0_str_2, 34);
|
||||
|
||||
// string #3
|
||||
BX_USB_THIS hub[0].device[0].function.string[2].size = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.string[2].type = 3;
|
||||
memset(BX_USB_THIS hub[0].device[0].function.string[2].unicode_str, 0, 64);
|
||||
|
||||
// string #4
|
||||
BX_USB_THIS hub[0].device[0].function.string[3].size = 20;
|
||||
BX_USB_THIS hub[0].device[0].function.string[3].type = 3;
|
||||
Bit8u dev0_str_4[64] = { 0x48, 0x00, 0x49, 0x00, 0x44, 0x00, 0x20, 0x00, 0x4D,
|
||||
0x00, 0x6F, 0x00, 0x75, 0x00, 0x73, 0x00, 0x65, 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[3].unicode_str, dev0_str_4, 18);
|
||||
|
||||
// string #5
|
||||
BX_USB_THIS hub[0].device[0].function.string[4].size = 50;
|
||||
BX_USB_THIS hub[0].device[0].function.string[4].type = 3;
|
||||
Bit8u dev0_str_5[64] = { 'E', 0x00, 'n', 0x00, 'd', 0x00, 'p', 0x00, 'o', 0x00,
|
||||
'i', 0x00, 'n', 0x00, 't', 0x00, '1', 0x00, ' ', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00,
|
||||
'e', 0x00, 'r', 0x00, 'r', 0x00, 'u', 0x00, 'p', 0x00, 't', 0x00, ' ', 0x00, 'P', 0x00,
|
||||
'i', 0x00, 'p', 0x00, 'e', 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[4].unicode_str, dev0_str_5, 48);
|
||||
|
||||
// this device has no key conversion table
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].lookup_cnt = 0;
|
||||
memset(&BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].lookup, 0, sizeof(struct KEYPAD) * KEYPAD_LEN);
|
||||
|
||||
#endif // USB_CYPRESS
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// USB 17 button keypad.
|
||||
// This keypad is on port 1 of hub 0 and is the second device.
|
||||
#if USB_KEYPAD
|
||||
|
||||
BX_USB_THIS hub[0].device[1].connect_status = 0;
|
||||
BX_USB_THIS hub[0].device[1].dev_type = USB_DEV_TYPE_KEYPAD;
|
||||
|
||||
BX_USB_THIS hub[0].device[1].state = STATE_DEFAULT;
|
||||
BX_USB_THIS hub[0].device[1].address = 0;
|
||||
BX_USB_THIS hub[0].device[1].alt_interface = 0;
|
||||
BX_USB_THIS hub[0].device[1].Interface = 0;
|
||||
BX_USB_THIS hub[0].device[1].config = 0;
|
||||
BX_USB_THIS hub[0].device[1].endpt = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.direction = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.configs = 1; // only one config in this device
|
||||
|
||||
BX_USB_THIS hub[0].device[1].in_stall = 0;
|
||||
BX_USB_THIS hub[0].device[1].stall_once = 0;
|
||||
|
||||
// device descriptor
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.len = 18;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.type = USB_DT_DEVICE;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.usb_ver = 0x0110;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr._class = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.subclass = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.protocol = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.max_packet_size = 8;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.vendorid = 0x04B4;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.productid = 0x0101;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.device_rel = 0x0001;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.manuf_indx = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.prod_indx = 2;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.serial_indx = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_descr.configs = 1;
|
||||
|
||||
// config descriptor
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].len = 9;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].type = USB_DT_CONFIG;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].tot_len = 59; // size of config+interface+endpt+hid
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].interfaces = 2;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].config_val = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].config_indx = 4;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].attrbs = 0xA0; // bus powered, etc
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].max_power = 50;
|
||||
|
||||
// interface descriptor #1
|
||||
// 0x09, 0x04, 0x00, 0x00, 0x01, 0x03, 0x01, 0x01, 0x05, // interface descriptor
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].size = 9;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].type = USB_DT_INTERFACE;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].interface_num = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].alternate = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].num_endpts = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].iclass = 3;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].subclass = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].protocol = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].str_indx = 5;
|
||||
|
||||
// this interface has a key conversion table of len = 18
|
||||
struct KEYPAD dev0_int0[KEYPAD_LEN] = {
|
||||
{ { 0x6C, }, { 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x00 } }, // 7
|
||||
@ -255,27 +115,27 @@
|
||||
{ { 0x79, }, { 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00 } }, // .
|
||||
{ { 0xE0, 0x5A }, { 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00 } }, // Enter
|
||||
};
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].lookup_cnt = 18;
|
||||
memcpy(&BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].lookup, &dev0_int0, sizeof(struct KEYPAD) * KEYPAD_LEN);
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].lookup_cnt = 18;
|
||||
memcpy(&BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].lookup, &dev0_int0, sizeof(struct KEYPAD) * KEYPAD_LEN);
|
||||
|
||||
// endpoint descriptor #1
|
||||
// 0x07, 0x05, 0x81, 0x03, 0x08, 0x00, 0x0A, // endpoint descriptor
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].endpts[0].size = 7;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].endpts[0].type = USB_DT_ENDPOINT;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].endpts[0].endpt = 0x81;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].endpts[0].attrib = 3;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].endpts[0].max_size = 8;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].endpts[0].interval = 0x0A;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].size = 7;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].type = USB_DT_ENDPOINT;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].endpt = 0x81;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].attrib = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].max_size = 8;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].endpts[0].interval = 0x0A;
|
||||
|
||||
// HID descriptor #1
|
||||
// 0x09, 0x21, 0x00, 0x01, 0x00, 0x01, 0x22, 0x41, 0x00 // hid descriptor
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].dev_hid_descript.size = 9;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].dev_hid_descript.type = 0x21;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].dev_hid_descript.HID_class = 0x0100;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].dev_hid_descript.country_code = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].dev_hid_descript.num_descriptors = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].type = 0x22;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].len = 65;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.size = 9;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.type = 0x21;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.HID_class = 0x0100;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.country_code = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.num_descriptors = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].type = 0x22;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].len = 65;
|
||||
|
||||
// HID descriptor type 0x22 (report descriptor) #1
|
||||
Bit8u dev1_rep0[] = {
|
||||
@ -285,32 +145,32 @@
|
||||
0x75, 0x08, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x05, 0x07, 0x19, 0x00, 0x2A, 0xFF, 0x00, 0x81, 0x00,
|
||||
0xC0
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].dev_hid_descript_report, dev1_rep0, 65);
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[0].dev_hid_descript.descriptor[0].dev_hid_descript_report, dev1_rep0, 65);
|
||||
|
||||
// interface descriptor #2
|
||||
// 0x09, 0x04, 0x01, 0x00, 0x01, 0x03, 0x01, 0x02, 0x06, // interface descriptor
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].size = 9;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].type = USB_DT_INTERFACE;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].interface_num = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].alternate = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].num_endpts = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].iclass = 3;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].subclass = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].protocol = 2;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].str_indx = 6;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].size = 9;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].type = USB_DT_INTERFACE;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].interface_num = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].alternate = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].num_endpts = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].iclass = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].subclass = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].protocol = 2;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].str_indx = 6;
|
||||
// this interface has no key conversion table
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].lookup_cnt = 0;
|
||||
memset(&BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].lookup, 0, sizeof(struct KEYPAD) * KEYPAD_LEN);
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].lookup_cnt = 0;
|
||||
memset(&BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].lookup, 0, sizeof(struct KEYPAD) * KEYPAD_LEN);
|
||||
|
||||
// HID descriptor #2
|
||||
// 0x09, 0x21, 0x00, 0x01, 0x00, 0x01, 0x22, 0x32, 0x00 // hid descriptor
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].dev_hid_descript.size = 9;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].dev_hid_descript.type = 0x21;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].dev_hid_descript.HID_class = 0x0100;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].dev_hid_descript.country_code = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].dev_hid_descript.num_descriptors = 1;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].dev_hid_descript.descriptor[0].type = 0x22;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].dev_hid_descript.descriptor[0].len = 50;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].dev_hid_descript.size = 9;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].dev_hid_descript.type = 0x21;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].dev_hid_descript.HID_class = 0x0100;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].dev_hid_descript.country_code = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].dev_hid_descript.num_descriptors = 1;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].dev_hid_descript.descriptor[0].type = 0x22;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].dev_hid_descript.descriptor[0].len = 50;
|
||||
|
||||
// HID descriptor type 0x22 (report descriptor) #2
|
||||
Bit8u dev1_rep1[] = {
|
||||
@ -319,67 +179,67 @@
|
||||
0x02, 0x19, 0x81, 0x29, 0x83, 0x25, 0x01, 0x75, 0x01, 0x95, 0x03, 0x81, 0x02, 0x95, 0x05, 0x81,
|
||||
0x01, 0xC0
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].dev_hid_descript.descriptor[0].dev_hid_descript_report, dev1_rep1, 50);
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].dev_hid_descript.descriptor[0].dev_hid_descript_report, dev1_rep1, 50);
|
||||
|
||||
// endpoint descriptor #2
|
||||
// 0x07, 0x05, 0x82, 0x03, 0x05, 0x00, 0x0A, // endpoint descriptor
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].endpts[0].size = 7;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].endpts[0].type = USB_DT_ENDPOINT;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].endpts[0].endpt = 0x82;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].endpts[0].attrib = 3;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].endpts[0].max_size = 5;
|
||||
BX_USB_THIS hub[0].device[1].function.device_config[0].Interface[1].endpts[0].interval = 0x0A;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].endpts[0].size = 7;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].endpts[0].type = USB_DT_ENDPOINT;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].endpts[0].endpt = 0x82;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].endpts[0].attrib = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].endpts[0].max_size = 5;
|
||||
BX_USB_THIS hub[0].device[0].function.device_config[0].Interface[1].endpts[0].interval = 0x0A;
|
||||
|
||||
// string descriptors
|
||||
BX_USB_THIS hub[0].device[1].function.str_descriptor.size = 0x04;
|
||||
BX_USB_THIS hub[0].device[1].function.str_descriptor.type = 0x03;
|
||||
BX_USB_THIS hub[0].device[1].function.str_descriptor.langid[0] = 0x0409;
|
||||
BX_USB_THIS hub[0].device[0].function.str_descriptor.size = 0x04;
|
||||
BX_USB_THIS hub[0].device[0].function.str_descriptor.type = 0x03;
|
||||
BX_USB_THIS hub[0].device[0].function.str_descriptor.langid[0] = 0x0409;
|
||||
|
||||
// string #1
|
||||
BX_USB_THIS hub[0].device[1].function.string[0].size = 18;
|
||||
BX_USB_THIS hub[0].device[1].function.string[0].type = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.string[0].size = 18;
|
||||
BX_USB_THIS hub[0].device[0].function.string[0].type = 3;
|
||||
Bit8u dev1_str_1[64] = { 'K', 0x00, 'e', 0x00, 'y', 0x00, 'M', 0x00, 'o', 0x00,
|
||||
'u', 0x00, 's', 0x00, 'e', 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[1].function.string[0].unicode_str, dev1_str_1, 16);
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[0].unicode_str, dev1_str_1, 16);
|
||||
|
||||
// string #2
|
||||
BX_USB_THIS hub[0].device[1].function.string[1].size = 34;
|
||||
BX_USB_THIS hub[0].device[1].function.string[1].type = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.string[1].size = 34;
|
||||
BX_USB_THIS hub[0].device[0].function.string[1].type = 3;
|
||||
Bit8u dev1_str_2[64] = { 'U', 0x00, 'S', 0x00, 'B', 0x00, '/', 0x00, 'P', 0x00,
|
||||
'S', 0x00, '2', 0x00, ' ', 0x00, 'K', 0x00, 'E', 0x00, 'Y', 0x00, 'B', 0x00,
|
||||
'O', 0x00, 'A', 0x00, 'R', 0x00, 'D', 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[1].function.string[1].unicode_str, dev1_str_2, 32);
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[1].unicode_str, dev1_str_2, 32);
|
||||
|
||||
// string #3
|
||||
BX_USB_THIS hub[0].device[1].function.string[2].size = 0;
|
||||
BX_USB_THIS hub[0].device[1].function.string[2].type = 3;
|
||||
memset(BX_USB_THIS hub[0].device[1].function.string[2].unicode_str, 0, 64);
|
||||
BX_USB_THIS hub[0].device[0].function.string[2].size = 0;
|
||||
BX_USB_THIS hub[0].device[0].function.string[2].type = 3;
|
||||
memset(BX_USB_THIS hub[0].device[0].function.string[2].unicode_str, 0, 64);
|
||||
|
||||
// string #4
|
||||
BX_USB_THIS hub[0].device[1].function.string[3].size = 26;
|
||||
BX_USB_THIS hub[0].device[1].function.string[3].type = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.string[3].size = 26;
|
||||
BX_USB_THIS hub[0].device[0].function.string[3].type = 3;
|
||||
Bit8u dev1_str_4[64] = { 'H', 0x00, 'I', 0x00, 'D', 0x00, ' ', 0x00, 'K', 0x00,
|
||||
'e', 0x00, 'y', 0x00, 'b', 0x00, 'o', 0x00, 'a', 0x00, 'r', 0x00, 'd', 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[1].function.string[3].unicode_str, dev1_str_4, 24);
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[3].unicode_str, dev1_str_4, 24);
|
||||
|
||||
// string #5
|
||||
BX_USB_THIS hub[0].device[1].function.string[4].size = 28;
|
||||
BX_USB_THIS hub[0].device[1].function.string[4].type = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.string[4].size = 28;
|
||||
BX_USB_THIS hub[0].device[0].function.string[4].type = 3;
|
||||
Bit8u dev1_str_5[64] = { 'E', 0x00, 'P', 0x00, '1', 0x00, ' ', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00,
|
||||
'e', 0x00, 'r', 0x00, 'r', 0x00, 'u', 0x00, 'p', 0x00, 't', 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[1].function.string[4].unicode_str, dev1_str_5, 26);
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[4].unicode_str, dev1_str_5, 26);
|
||||
|
||||
// string #6
|
||||
BX_USB_THIS hub[0].device[1].function.string[5].size = 28;
|
||||
BX_USB_THIS hub[0].device[1].function.string[5].type = 3;
|
||||
BX_USB_THIS hub[0].device[0].function.string[5].size = 28;
|
||||
BX_USB_THIS hub[0].device[0].function.string[5].type = 3;
|
||||
Bit8u dev1_str_6[64] = { 'E', 0x00, 'P', 0x00, '2', 0x00, ' ', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00,
|
||||
'e', 0x00, 'r', 0x00, 'r', 0x00, 'u', 0x00, 'p', 0x00, 't', 0x00,
|
||||
};
|
||||
memcpy(BX_USB_THIS hub[0].device[1].function.string[5].unicode_str, dev1_str_6, 26);
|
||||
memcpy(BX_USB_THIS hub[0].device[0].function.string[5].unicode_str, dev1_str_6, 26);
|
||||
|
||||
|
||||
#endif // USB_KEYPAD
|
||||
|
374
bochs/iodev/usb_hid.cc
Normal file
374
bochs/iodev/usb_hid.cc
Normal file
@ -0,0 +1,374 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: usb_hid.cc,v 1.1 2007-03-21 18:54:41 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2007 Volker Ruppert
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// USB HID emulation support ported from the Qemu project
|
||||
|
||||
|
||||
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
||||
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
||||
// is used to know when we are exporting symbols and when we are importing.
|
||||
#define BX_PLUGGABLE
|
||||
|
||||
#include "iodev.h"
|
||||
#if BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB
|
||||
#include "usb_hid.h"
|
||||
|
||||
#define LOG_THIS
|
||||
|
||||
/* HID interface requests */
|
||||
#define GET_REPORT 0xa101
|
||||
#define GET_IDLE 0xa102
|
||||
#define GET_PROTOCOL 0xa103
|
||||
#define SET_IDLE 0x210a
|
||||
#define SET_PROTOCOL 0x210b
|
||||
|
||||
static const Bit8u bx_mouse_dev_descriptor[] = {
|
||||
0x12, /* u8 bLength; */
|
||||
0x01, /* u8 bDescriptorType; Device */
|
||||
0x00, 0x01, /* u16 bcdUSB; v1.0 */
|
||||
|
||||
0x00, /* u8 bDeviceClass; */
|
||||
0x00, /* u8 bDeviceSubClass; */
|
||||
0x00, /* u8 bDeviceProtocol; [ low/full speeds only ] */
|
||||
0x08, /* u8 bMaxPacketSize0; 8 Bytes */
|
||||
|
||||
0x27, 0x06, /* u16 idVendor; */
|
||||
0x01, 0x00, /* u16 idProduct; */
|
||||
0x00, 0x00, /* u16 bcdDevice */
|
||||
|
||||
0x03, /* u8 iManufacturer; */
|
||||
0x02, /* u8 iProduct; */
|
||||
0x01, /* u8 iSerialNumber; */
|
||||
0x01 /* u8 bNumConfigurations; */
|
||||
};
|
||||
|
||||
static const Bit8u bx_mouse_config_descriptor[] = {
|
||||
/* one configuration */
|
||||
0x09, /* u8 bLength; */
|
||||
0x02, /* u8 bDescriptorType; Configuration */
|
||||
0x22, 0x00, /* u16 wTotalLength; */
|
||||
0x01, /* u8 bNumInterfaces; (1) */
|
||||
0x01, /* u8 bConfigurationValue; */
|
||||
0x04, /* u8 iConfiguration; */
|
||||
0xa0, /* u8 bmAttributes;
|
||||
Bit 7: must be set,
|
||||
6: Self-powered,
|
||||
5: Remote wakeup,
|
||||
4..0: resvd */
|
||||
50, /* u8 MaxPower; */
|
||||
|
||||
/* USB 1.1:
|
||||
* USB 2.0, single TT organization (mandatory):
|
||||
* one interface, protocol 0
|
||||
*
|
||||
* USB 2.0, multiple TT organization (optional):
|
||||
* two interfaces, protocols 1 (like single TT)
|
||||
* and 2 (multiple TT mode) ... config is
|
||||
* sometimes settable
|
||||
* NOT IMPLEMENTED
|
||||
*/
|
||||
|
||||
/* one interface */
|
||||
0x09, /* u8 if_bLength; */
|
||||
0x04, /* u8 if_bDescriptorType; Interface */
|
||||
0x00, /* u8 if_bInterfaceNumber; */
|
||||
0x00, /* u8 if_bAlternateSetting; */
|
||||
0x01, /* u8 if_bNumEndpoints; */
|
||||
0x03, /* u8 if_bInterfaceClass; */
|
||||
0x01, /* u8 if_bInterfaceSubClass; */
|
||||
0x02, /* u8 if_bInterfaceProtocol; [usb1.1 or single tt] */
|
||||
0x05, /* u8 if_iInterface; */
|
||||
|
||||
/* HID descriptor */
|
||||
0x09, /* u8 bLength; */
|
||||
0x21, /* u8 bDescriptorType; */
|
||||
0x01, 0x00, /* u16 HID_class */
|
||||
0x00, /* u8 country_code */
|
||||
0x01, /* u8 num_descriptors */
|
||||
0x22, /* u8 type; Report */
|
||||
50, 0, /* u16 len */
|
||||
|
||||
/* one endpoint (status change endpoint) */
|
||||
0x07, /* u8 ep_bLength; */
|
||||
0x05, /* u8 ep_bDescriptorType; Endpoint */
|
||||
0x81, /* u8 ep_bEndpointAddress; IN Endpoint 1 */
|
||||
0x03, /* u8 ep_bmAttributes; Interrupt */
|
||||
0x03, 0x00, /* u16 ep_wMaxPacketSize; */
|
||||
0x0a, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */
|
||||
};
|
||||
|
||||
static const Bit8u bx_mouse_hid_report_descriptor[] = {
|
||||
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01,
|
||||
0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03,
|
||||
0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01,
|
||||
0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01,
|
||||
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81,
|
||||
0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06,
|
||||
0xC0, 0xC0,
|
||||
};
|
||||
|
||||
usb_hid_device_t::usb_hid_device_t(usbdev_type type)
|
||||
{
|
||||
d.type = type;
|
||||
d.speed = USB_SPEED_FULL;
|
||||
d.connected = 1;
|
||||
memset((void*)&s, 0, sizeof(s));
|
||||
|
||||
put("USBHI");
|
||||
settype(PCIUSBLOG);
|
||||
}
|
||||
|
||||
usb_hid_device_t::~usb_hid_device_t(void)
|
||||
{
|
||||
}
|
||||
|
||||
void usb_hid_device_t::handle_reset()
|
||||
{
|
||||
memset((void*)&s, 0, sizeof(s));
|
||||
BX_DEBUG(("Reset"));
|
||||
}
|
||||
|
||||
int usb_hid_device_t::handle_control(int request, int value, int index, int length, Bit8u *data)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch(request) {
|
||||
case DeviceRequest | USB_REQ_GET_STATUS:
|
||||
data[0] = (1 << USB_DEVICE_SELF_POWERED) |
|
||||
(d.remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
|
||||
data[1] = 0x00;
|
||||
ret = 2;
|
||||
break;
|
||||
case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
|
||||
if (value == USB_DEVICE_REMOTE_WAKEUP) {
|
||||
d.remote_wakeup = 0;
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
ret = 0;
|
||||
break;
|
||||
case DeviceOutRequest | USB_REQ_SET_FEATURE:
|
||||
if (value == USB_DEVICE_REMOTE_WAKEUP) {
|
||||
d.remote_wakeup = 1;
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
ret = 0;
|
||||
break;
|
||||
case DeviceOutRequest | USB_REQ_SET_ADDRESS:
|
||||
d.addr = value;
|
||||
ret = 0;
|
||||
break;
|
||||
case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
|
||||
switch(value >> 8) {
|
||||
case USB_DT_DEVICE:
|
||||
memcpy(data, bx_mouse_dev_descriptor,
|
||||
sizeof(bx_mouse_dev_descriptor));
|
||||
ret = sizeof(bx_mouse_dev_descriptor);
|
||||
break;
|
||||
case USB_DT_CONFIG:
|
||||
if (d.type == USB_DEV_TYPE_MOUSE) {
|
||||
memcpy(data, bx_mouse_config_descriptor,
|
||||
sizeof(bx_mouse_config_descriptor));
|
||||
ret = sizeof(bx_mouse_config_descriptor);
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case USB_DT_STRING:
|
||||
switch(value & 0xff) {
|
||||
case 0:
|
||||
/* language ids */
|
||||
data[0] = 4;
|
||||
data[1] = 3;
|
||||
data[2] = 0x09;
|
||||
data[3] = 0x04;
|
||||
ret = 4;
|
||||
break;
|
||||
case 1:
|
||||
/* serial number */
|
||||
ret = set_usb_string(data, "1");
|
||||
break;
|
||||
case 2:
|
||||
/* product description */
|
||||
if (d.type == USB_DEV_TYPE_MOUSE) {
|
||||
ret = set_usb_string(data, "BOCHS USB Mouse");
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
/* vendor description */
|
||||
ret = set_usb_string(data, "BOCHS");
|
||||
break;
|
||||
case 4:
|
||||
ret = set_usb_string(data, "HID Mouse");
|
||||
break;
|
||||
case 5:
|
||||
ret = set_usb_string(data, "Endpoint1 Interrupt Pipe");
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case DeviceRequest | USB_REQ_GET_CONFIGURATION:
|
||||
data[0] = 1;
|
||||
ret = 1;
|
||||
break;
|
||||
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
|
||||
ret = 0;
|
||||
break;
|
||||
case DeviceRequest | USB_REQ_GET_INTERFACE:
|
||||
data[0] = 0;
|
||||
ret = 1;
|
||||
break;
|
||||
case DeviceOutRequest | USB_REQ_SET_INTERFACE:
|
||||
ret = 0;
|
||||
break;
|
||||
/* hid specific requests */
|
||||
case InterfaceRequest | USB_REQ_GET_DESCRIPTOR:
|
||||
switch(value >> 8) {
|
||||
case 0x22:
|
||||
if (d.type == USB_DEV_TYPE_MOUSE) {
|
||||
memcpy(data, bx_mouse_hid_report_descriptor,
|
||||
sizeof(bx_mouse_hid_report_descriptor));
|
||||
ret = sizeof(bx_mouse_hid_report_descriptor);
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case GET_REPORT:
|
||||
if (d.type == USB_DEV_TYPE_MOUSE) {
|
||||
ret = mouse_poll(data, length);
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case SET_IDLE:
|
||||
ret = 0;
|
||||
break;
|
||||
default:
|
||||
fail:
|
||||
ret = USB_RET_STALL;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usb_hid_device_t::handle_data(USBPacket *p)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch(p->pid) {
|
||||
case USB_TOKEN_IN:
|
||||
if (p->devep == 1) {
|
||||
if (d.type == USB_DEV_TYPE_MOUSE) {
|
||||
ret = mouse_poll(p->data, p->len);
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
} else {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case USB_TOKEN_OUT:
|
||||
default:
|
||||
fail:
|
||||
ret = USB_RET_STALL;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usb_hid_device_t::mouse_poll(Bit8u *buf, int len)
|
||||
{
|
||||
int l;
|
||||
|
||||
if (!s.mouse_x && !s.mouse_y) {
|
||||
// if there's no new movement, handle delayed one
|
||||
mouse_enq(0, 0, s.mouse_z, s.b_state);
|
||||
}
|
||||
buf[0] = (Bit8u) s.b_state;
|
||||
buf[1] = (Bit8s) s.mouse_x;
|
||||
buf[2] = (Bit8s) s.mouse_y;
|
||||
s.b_state = 0;
|
||||
s.mouse_x = 0;
|
||||
s.mouse_y = 0;
|
||||
l = 3;
|
||||
if (len >= 4) {
|
||||
buf[3] = (Bit8s) s.mouse_z; // if wheel mouse
|
||||
s.mouse_z = 0;
|
||||
l = 4;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
void usb_hid_device_t::mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state)
|
||||
{
|
||||
// scale down the motion
|
||||
if ( (delta_x < -1) || (delta_x > 1) )
|
||||
delta_x /= 2;
|
||||
if ( (delta_y < -1) || (delta_y > 1) )
|
||||
delta_y /= 2;
|
||||
|
||||
if(delta_x>127) delta_x=127;
|
||||
if(delta_y>127) delta_y=127;
|
||||
if(delta_x<-128) delta_x=-128;
|
||||
if(delta_y<-128) delta_y=-128;
|
||||
|
||||
s.mouse_delayed_dx+=delta_x;
|
||||
s.mouse_delayed_dy-=delta_y;
|
||||
|
||||
if (s.mouse_delayed_dx > 127) {
|
||||
delta_x = 127;
|
||||
s.mouse_delayed_dx -= 127;
|
||||
} else if (s.mouse_delayed_dx < -128) {
|
||||
delta_x = -128;
|
||||
s.mouse_delayed_dx += 128;
|
||||
} else {
|
||||
delta_x = s.mouse_delayed_dx;
|
||||
s.mouse_delayed_dx = 0;
|
||||
}
|
||||
if (s.mouse_delayed_dy > 127) {
|
||||
delta_y = 127;
|
||||
s.mouse_delayed_dy -= 127;
|
||||
} else if (s.mouse_delayed_dy < -128) {
|
||||
delta_y = -128;
|
||||
s.mouse_delayed_dy += 128;
|
||||
} else {
|
||||
delta_y = s.mouse_delayed_dy;
|
||||
s.mouse_delayed_dy = 0;
|
||||
}
|
||||
|
||||
s.mouse_x = (Bit8s) delta_x;
|
||||
s.mouse_y = (Bit8s) delta_y;
|
||||
s.mouse_z = (Bit8s) delta_z;
|
||||
s.b_state = (Bit8u) button_state;
|
||||
}
|
||||
|
||||
#endif // BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB
|
51
bochs/iodev/usb_hid.h
Normal file
51
bochs/iodev/usb_hid.h
Normal file
@ -0,0 +1,51 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: usb_hid.h,v 1.1 2007-03-21 18:54:41 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2007 Volker Ruppert
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// USB HID emulation support ported from the Qemu project
|
||||
|
||||
#ifndef BX_IODEV_USB_HID_H
|
||||
#define BX_IODEV_USB_HID_H
|
||||
|
||||
|
||||
class usb_hid_device_t : public usb_device_t {
|
||||
public:
|
||||
usb_hid_device_t(usbdev_type type);
|
||||
virtual ~usb_hid_device_t(void);
|
||||
|
||||
virtual void handle_reset();
|
||||
virtual int handle_control(int request, int value, int index, int length, Bit8u *data);
|
||||
virtual int handle_data(USBPacket *p);
|
||||
void mouse_enq(int delta_x, int delta_y, int delta_z, unsigned button_state);
|
||||
protected:
|
||||
int mouse_poll(Bit8u *buf, int len);
|
||||
|
||||
private:
|
||||
struct {
|
||||
int mouse_delayed_dx;
|
||||
int mouse_delayed_dy;
|
||||
int mouse_delayed_dz;
|
||||
Bit8s mouse_x;
|
||||
Bit8s mouse_y;
|
||||
Bit8s mouse_z;
|
||||
Bit8u b_state;
|
||||
} s;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user