62#define ALIGN(n,align) (((n)+((align)-1)) & ~((align)-1))
64#define usb_dma_alloc(n) (KMALLOC(ALIGN((n),CACHE_ALIGN),BUFF_ALIGN))
65#define usb_dma_free(p) (KFREE(p))
69static int usbctrl_detach(
usbdev_t *dev);
73static int controller_mask = 0;
95 controllers[id] = ctrl;
100 return controllers[id];
105 "Xbox 360 Controller",
110static int usbctrl_set_led_callback(
usbreq_t *ur) {
130 unsigned xdata_len = 0;
146 uint8_t xdata[0xC] = { 0x00, 0x00, 0x08, 0x40 + (
command % 0x0e), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
151 printf(
"couldn't alloc buffer\n");
156 memcpy(buf, &xdata, 0xC);
166 printf(
"couldn't alloc buffer\n");
171 memcpy(buf, &xdata, 3);
184 unsigned xdata_len = 0;
191 uint8_t xdata[0xC] = { 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
196 printf(
"couldn't alloc buffer\n");
200 memcpy(buf, &xdata, 0xC);
229 printf(
"couldn't alloc buffer\n");
234 uint8_t xdata[0xC] = { 0x00, 0x01, 0x0f, 0xc0, 0x00, l, r, 0x00, 0x00, 0x00, 0x00, 0x00 };
236 memcpy(buf, &xdata, 0xC);
243 printf(
"couldn't alloc buffer\n");
248 uint8_t xdata[0x8] = { 0x00, 0x08, 0x00, l, r, 0x00, 0x00, 0x00 };
250 memcpy(buf, &xdata, 0x8);
292static int usbctrl_ireq_callback(
usbreq_t *ur)
325 if(uhid->
index == -1)
329 for (i = 0; controller_mask & (1<<i); ++i);
332 setcontroller(uhid, uhid->
index);
333 controller_mask |= 1<<i;
340 if (
b[0] == 0x8 &&
b[1] == 0x0)
343 printf(
"detached controller %d\n", uhid->
index);
345 controller_mask &= ~(1<<uhid->
index);
369 c.s1_x = (
b[7] << 8) |
b[6];
370 c.s1_y = (
b[9] << 8) |
b[8];
371 c.s2_x = (
b[11] << 8) |
b[10];
372 c.s2_y = (
b[13] << 8) |
b[12];
373 c.s1_z = !!(
b[2] & 0x40);
374 c.s2_z = !!(
b[2] & 0x80);
380 c.a = !!(
b[3] & 0x10);
381 c.b = !!(
b[3] & 0x20);
382 c.x = !!(
b[3] & 0x40);
383 c.y = !!(
b[3] & 0x80);
385 c.start = !!(
b[2] & 0x10);
386 c.back = !!(
b[2] & 0x20);
389 c.down = !!(
b[2] & 2);
390 c.left = !!(
b[2] & 4);
391 c.right = !!(
b[2] & 8);
393 c.logo = !!(
b[3] & 0x4);
483 for(i = 0; i < 4; i++)
491 if (!epdscr || !ifdscr) {
492 printf(
"couldn't find descriptor for controller %i!\n", i);
508 printf(
"couldn't alloc buffer\n");
544 usbctrl_queue_intreq(dev,softc);
575 if (!epdscr || !ifdscr) {
576 printf(
"couldn't find descriptor!\n");
583 for (i = 0; controller_mask & (1<<i); ++i);
584 printf(
"attached controller %d\n", i);
586 setcontroller(softc, i);
587 controller_mask |= 1<<i;
597 printf(
"couldn't alloc buffer\n");
620 usbctrl_queue_intreq(dev,softc);
645static int usbctrl_detach(
usbdev_t *dev)
652 printf(
"detached controller %d\n", uhid->
index);
654 controller_mask &= ~(1<<uhid->
index);
663 printf(
"Wirless module detatched, not yet handled\n");
#define KMALLOC(size, align)
uint8_t bConfigurationValue
uint8_t uhid_lastmsg[UBR_KBD_MAX]
usb_config_descr_t * ud_cfgdescr
usb_device_descr_t ud_devdescr
int(* ur_callback)(struct usbreq_s *req)
#define GETUSBFIELD(s, f)
#define USB_ENDPOINT_DESCRIPTOR_TYPE
#define USB_INTERFACE_DESCRIPTOR_TYPE
int usbctrl_set_rol(uint controllerMask)
int usbctrl_poll(usbctrl_softc_t *softc)
struct usbctrl_softc_s usbctrl_softc_t
int usbctrl_set_leds(usbctrl_softc_t *softc, uint8_t clear)
int usbctrl_set_rumble(int port, uint8_t l, uint8_t r)
usb_driver_t usbctrl_driver
void * usb_find_cfg_descr(usbdev_t *dev, int dtype, int idx)
int usb_simple_request(usbdev_t *dev, uint8_t reqtype, int bRequest, int wValue, int wIndex)
usbreq_t * usb_make_request(usbdev_t *dev, int epaddr, uint8_t *buf, int length, int flags)
void usb_free_request(usbreq_t *ur)
int usb_queue_request(usbreq_t *ur)
int usb_set_configuration(usbdev_t *dev, int config)
int usb_open_pipe(usbdev_t *dev, usb_endpoint_descr_t *epdesc)