int usb_connect(int devId) { UsbDeviceDescriptor *dev; UsbConfigDescriptor *conf; dev = UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); conf = UsbGetDeviceStaticDescriptor(devId, dev, USB_DT_CONFIG); controlEndp = UsbOpenEndpoint(devId, NULL); int slot = 0; if (ds3_list[0].connected) slot = 1; ds3_list[slot].endp = controlEndp; ds3_list[slot].connected = 1; ds3_list[slot].devID = devId; UsbSetDevicePrivateData(devId, NULL); UsbSetDeviceConfiguration(controlEndp, conf->bConfigurationValue, config_set, (void*)slot); return 0; }
int ps2kbd_connect(int devId) { /* Assume we can only get here if we have already checked the device is kosher */ UsbDeviceDescriptor *dev; UsbConfigDescriptor *conf; UsbInterfaceDescriptor *intf; UsbEndpointDescriptor *endp; kbd_dev *currDev; int devLoop; //printf("PS2Kbd_connect devId %d\n", devId); dev = UsbGetDeviceStaticDescriptor(devId, NULL, USB_DT_DEVICE); /* Get device descriptor */ if(!dev) { printf("ERROR: Couldn't get device descriptor\n"); return 1; } conf = UsbGetDeviceStaticDescriptor(devId, dev, USB_DT_CONFIG); if(!conf) { printf("ERROR: Couldn't get configuration descriptor\n"); return 1; } intf = (UsbInterfaceDescriptor *) ((char *) conf + conf->bLength); /* Get first interface */ endp = (UsbEndpointDescriptor *) ((char *) intf + intf->bLength); endp = (UsbEndpointDescriptor *) ((char *) endp + endp->bLength); /* Go to the data endpoint */ for(devLoop = 0; devLoop < PS2KBD_MAXDEV; devLoop++) { if(devices[devLoop] == NULL) { break; } } if(devLoop == PS2KBD_MAXDEV) { /* How the f*** did we end up here ??? */ printf("ERROR: Device Weirdness!!\n"); return 1; } currDev = (kbd_dev *) AllocSysMemory(0, sizeof(kbd_dev), NULL); if(!currDev) { printf("ERROR: Couldn't allocate a device point for the kbd\n"); return 1; } devices[devLoop] = currDev; memset(currDev, 0, sizeof(kbd_dev)); currDev->configEndp = UsbOpenEndpoint(devId, NULL); currDev->dataEndp = UsbOpenEndpoint(devId, endp); currDev->packetSize = endp->wMaxPacketSizeLB | ((int) endp->wMaxPacketSizeHB << 8); currDev->eventmask = (1 << devLoop); if(currDev->packetSize > sizeof(kbd_data_recv)) { currDev->packetSize = sizeof(kbd_data_recv); } if(dev->iManufacturer != 0) { usb_getstring(currDev->configEndp, dev->iManufacturer, "Keyboard Manufacturer"); } if(dev->iProduct != 0) { usb_getstring(currDev->configEndp, dev->iProduct, "Keyboard Product"); } currDev->devId = devId; currDev->interfaceNo = intf->bInterfaceNumber; currDev->ledStatus = 0; UsbSetDevicePrivateData(devId, currDev); /* Set the index for the device data */ //printf("Configuration value %d\n", conf->bConfigurationValue); UsbSetDeviceConfiguration(currDev->configEndp, conf->bConfigurationValue, ps2kbd_config_set, currDev); dev_count++; /* Increment device count */ printf("PS2KBD: Connected device\n"); return 0; }