int usbctrl_poll(usbctrl_softc_t * softc) { usbdev_t *dev = softc->dev; usbreq_t *ur; unsigned xdata_len = 0; uint8_t* buf = NULL; if (softc->is_wireless) { uint8_t xdata[0xC] = { 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };//Request headset status command, works as a poll xdata_len = 0xC; buf = usb_dma_alloc(0xC); if (buf == NULL) { printf("couldn't alloc buffer\n"); /* Could not allocate a buffer, fail. */ return -1; } memcpy(buf, &xdata, 0xC); } else { return -1; //Polling not needed for wired controllers, and if there is a command it is not known at this time } ur = usb_make_request(dev, softc->uhid_ipipe_tx, buf, xdata_len, UR_FLAG_OUT); ur->ur_callback = usbctrl_set_led_callback; usb_queue_request(ur); return 0; }
static void rtek_queue_rx( rtek_softc_t *softc ) { softc->rx_ur = usb_make_request(softc->dev, softc->bulk_inpipe, softc->rxbuf, sizeof(softc->rxbuf), (UR_FLAG_IN | UR_FLAG_SHORTOK)); usb_queue_request(softc->rx_ur); }
int usbctrl_set_leds(usbctrl_softc_t * softc, uint8_t clear) { usbdev_t *dev = softc->dev; usbreq_t *ur; //xenon_smc_set_led(1, (unsigned char) (0x80 >> 3)); //We need to figure out how to set ROL and still have the sync button work unsigned xdata_len = 0; int command; if(!clear) { command = 2 + (softc->index % 4); } else { command = 0; } uint8_t* buf = NULL; if (softc->is_wireless) { uint8_t xdata[0xC] = { 0x00, 0x00, 0x08, 0x40 + (command % 0x0e), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; xdata_len = 0xC; buf = usb_dma_alloc(0xC); if (buf == NULL) { printf("couldn't alloc buffer\n"); /* Could not allocate a buffer, fail. */ return -1; } memcpy(buf, &xdata, 0xC); } else { uint8_t xdata[3] = { 0x01, 0x03, command }; xdata_len = 3; buf = usb_dma_alloc(3); if (buf == NULL) { printf("couldn't alloc buffer\n"); /* Could not allocate a buffer, fail. */ return -1; } memcpy(buf, &xdata, 3); } ur = usb_make_request(dev, softc->uhid_ipipe_tx, buf, xdata_len, UR_FLAG_OUT); ur->ur_callback = usbctrl_set_led_callback; usb_queue_request(ur); return 0; }
static int usbhid_ireq_callback(usbreq_t *ur) { usbhid_softc_t *uhid = (ur->ur_dev->ud_private); /* * If the driver is unloaded, the request will be cancelled. */ if (ur->ur_status == 0xFF) { usb_free_request(ur); return 0; } /* * What we do now depends on the type of device. */ switch (uhid->uhid_devtype) { case HID_DEVTYPE_KBD: /* * Handle keyboard event */ usbhid_kbd_scan(uhid); /* * Save old event to compare for next time. */ memcpy(uhid->uhid_lastmsg,uhid->uhid_imsg,UBR_KBD_MAX); break; case HID_DEVTYPE_MOUSE: #if 0 /* * No need to handle mice, but here's the good stuff. */ printf("Mouse: [%s %s %s] X:%d Y:%d Wheel:%d\n", (ur->ur_buffer[0] & 1) ? "left" : "", (ur->ur_buffer[0] & 4) ? "middle" : "", (ur->ur_buffer[0] & 2) ? "right" : "", (int)(signed char)ur->ur_buffer[1], (int)(signed char)ur->ur_buffer[2], (int)(signed char)ur->ur_buffer[3]); #endif break; } /* * Re-queue request to get next keyboard event. */ usb_queue_request(ur); return 0; }
static void usbhub_queue_intreq(usbdev_t *dev,usbhub_softc_t *softc) { usbreq_t *ur; ur = usb_make_request(dev, softc->uhub_ipipe, softc->uhub_imsg,softc->uhub_ipipemps, UR_FLAG_IN | UR_FLAG_SHORTOK); ur->ur_callback = usbhub_ireq_callback; usb_queue_request(ur); }
static void usbctrl_queue_intreq(usbdev_t *dev,usbctrl_softc_t *softc) { usbreq_t *ur; ur = usb_make_request(dev, softc->uhid_ipipe, softc->uhid_imsg, softc->uhid_ipipemps, UR_FLAG_IN); ur->ur_callback = usbctrl_ireq_callback; ur->ur_ref = softc; //FIXME: Part of the hackish multi-wireless support usb_queue_request(ur); }
int usbctrl_set_rumble(int port, uint8_t l, uint8_t r) { usbctrl_softc_t * softc = getcontroller(port); if(softc == NULL) return -1; usbdev_t *dev = softc->dev; usbreq_t *ur; unsigned xdata_len; uint8_t* buf = NULL; if(softc->is_wireless) { buf = usb_dma_alloc(0xC); if (buf == NULL) { printf("couldn't alloc buffer\n"); /* Could not allocate a buffer, fail. */ return -1; } uint8_t xdata[0xC] = { 0x00, 0x01, 0x0f, 0xc0, 0x00, l, r, 0x00, 0x00, 0x00, 0x00, 0x00 }; xdata_len = 0xC; memcpy(buf, &xdata, 0xC); } else { buf = usb_dma_alloc(0x8); if (buf == NULL) { printf("couldn't alloc buffer\n"); /* Could not allocate a buffer, fail. */ return -1; } uint8_t xdata[0x8] = { 0x00, 0x08, 0x00, l, r, 0x00, 0x00, 0x00 }; xdata_len = 0x8; memcpy(buf, &xdata, 0x8); } ur = usb_make_request(dev, softc->uhid_ipipe_tx, buf, xdata_len, UR_FLAG_OUT); ur->ur_callback = usbctrl_set_led_callback; usb_queue_request(ur); return 0; }
static int usbctrl_ireq_callback(usbreq_t *ur) { usbctrl_softc_t *uhid = (ur->ur_ref); //FIXME: are we allowed to use ur_ref for this purpose? /* int i; for (i = 0; i < uhid->uhid_ipipemps; ++i) printf("%02x ", ur->ur_buffer[i]); printf("\n"); */ /* * If the driver is unloaded, the request will be cancelled. */ if (ur->ur_status == 0xFF) { usb_free_request(ur); return 0; } /* printf("Dump:\n"); int i; for (i = 0; i < uhid->uhid_ipipemps; ++i) printf("%02x ", ur->ur_buffer[i]); printf("\n\n\n"); */ struct controller_data_s c; unsigned char *b = ur->ur_buffer; if (uhid->is_wireless) { //FIXME: A polled, disconnected controller may cause uneeded spam of the controller status message if(uhid->index == -1) { //printf("Wireless controller %i has connected\n", uhid->wireless_index); int i; for (i = 0; controller_mask & (1<<i); ++i); //printf("attached controller %d\n", i); uhid->index = i; setcontroller(uhid, uhid->index); controller_mask |= 1<<i; usbctrl_set_leds(uhid, 0); } if (b[0] == 0x8 && b[1] == 0x0) { //printf("Wireless controller %i has disconnected\n", uhid->wireless_index); printf("detatched controller %d\n", uhid->index); setcontroller(NULL, uhid->index); controller_mask &= ~(1<<uhid->index); uhid->index = -1; goto ignore; } if (b[5] == 0x13) { #if 0 if (b[6] == 2) /* CHECKME: is this required for the Xbox racing wheel? */ b++; #endif b += 4; } else goto ignore; } c.s1_x = (b[7] << 8) | b[6]; c.s1_y = (b[9] << 8) | b[8]; c.s2_x = (b[11] << 8) | b[10]; c.s2_y = (b[13] << 8) | b[12]; c.s1_z = !!(b[2] & 0x40); c.s2_z = !!(b[2] & 0x80); c.lt = b[4]; c.rt = b[5]; c.lb = !!(b[3] & 1); c.rb = !!(b[3] & 2); c.a = !!(b[3] & 0x10); c.b = !!(b[3] & 0x20); c.x = !!(b[3] & 0x40); c.y = !!(b[3] & 0x80); c.start = !!(b[2] & 0x10); c.back = !!(b[2] & 0x20); c.up = !!(b[2] & 1); c.down = !!(b[2] & 2); c.left = !!(b[2] & 4); c.right = !!(b[2] & 8); c.logo = !!(b[3] & 0x4); set_controller_data(uhid->index, &c); ignore: usb_queue_request(ur); return 0; }