Exemplo n.º 1
0
static int usbctrl_detach(usbdev_t *dev)
{
	if(dev->ud_private)
	{

	usbctrl_softc_t *uhid = dev->ud_private;
	
	printf("detached controller %d\n", uhid->index);
	setcontroller(NULL, uhid->index);
	controller_mask &= ~(1<<uhid->index);
	return 0;

	}
	else
	{
		printf("Wirless module detatched, not yet handled\n");


		return 0;

	}

}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
static int usbctrl_attach(usbdev_t *dev,usb_driver_t *drv)
{
	usb_config_descr_t *cfgdscr = dev->ud_cfgdescr;
	//printf("Number of interfaces: %i\n", cfgdscr->bNumInterfaces);



	dev->ud_drv = drv;

	usbctrl_softc_t *softc;

	



	//printf("Number of endpoints: %i\n", ifdscr->bNumEndpoints);

	usb_endpoint_descr_t *epdscr;
	usb_interface_descr_t *ifdscr;

	int wireless = (GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x291) || 
			(GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x2aa) ||
			(GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x2a9);

	if(wireless)
	{

		dev->ud_private = NULL;


		int i;
		for(i = 0; i < 4; i++)
		{
			softc = KMALLOC(sizeof(usbctrl_softc_t),0);
			softc->dev = dev;
			softc->is_wireless = (wireless);
			epdscr = usb_find_cfg_descr(dev,USB_ENDPOINT_DESCRIPTOR_TYPE,i * 4);
			ifdscr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,i * 2);

			if (!epdscr || !ifdscr) {
				printf("couldn't find descriptor for controller %i!\n", i);
				return 0;
			}
		

			//printf("Initializing wireless controller %d\n", i);
			softc->index = -1;
			softc->wireless_index = i;
			//controller_mask |= 1<<i; //Dont set this right now, let wired controllers use the slots

			/*
			 * Allocate a DMA buffer
			 */

			softc->uhid_imsg = usb_dma_alloc(UBR_KBD_MAX);
			if (softc->uhid_imsg == NULL) {
				printf("couldn't alloc buffer\n");
				/* Could not allocate a buffer, fail. */
				return -1;
			}
	
			/*
			 * Choose the standard configuration.
	 		*/

			usb_set_configuration(dev,cfgdscr->bConfigurationValue);

			/*
	 		* Open the interrupt pipe.
	 		*/

			softc->uhid_ipipe = usb_open_pipe(dev,epdscr);
			
			usb_endpoint_descr_t *txdscr = usb_find_cfg_descr(dev, USB_ENDPOINT_DESCRIPTOR_TYPE, (i * 4) + 1);
			//if (USB_ENDPOINT_DIR_OUT(txdscr->bEndpointAddress))
			//	printf("Opened an outgoing endpoint\n");

			softc->uhid_ipipe_tx = usb_open_pipe(dev, txdscr);

			

			softc->uhid_ipipemps = GETUSBFIELD(epdscr,wMaxPacketSize);
			softc->uhid_ipipemps_tx = GETUSBFIELD(epdscr,wMaxPacketSize);

			usbctrl_set_leds(softc, 1); //Clear leds, FIXME: Implement controller shutdown somewhere
			usbctrl_poll(softc);

			/*
			 * Queue a transfer on the interrupt endpoint to catch
			 * our first characters.
	 		*/

			usbctrl_queue_intreq(dev,softc);

			

		}


	}
	else
	{

	softc = KMALLOC(sizeof(usbctrl_softc_t),0);
	memset(softc,0,sizeof(usbctrl_softc_t));
	softc->dev = dev;
	dev->ud_private = softc;

	softc->is_wireless = (wireless);

	epdscr = usb_find_cfg_descr(dev,USB_ENDPOINT_DESCRIPTOR_TYPE,0);
	ifdscr = usb_find_cfg_descr(dev,USB_INTERFACE_DESCRIPTOR_TYPE,0);

	usb_endpoint_descr_t *txdscr = usb_find_cfg_descr(dev, USB_ENDPOINT_DESCRIPTOR_TYPE,1);

	
	//if (USB_ENDPOINT_DIR_OUT(txdscr->bEndpointAddress))
	//	printf("Opened an outgoing endpoint\n");

	softc->uhid_ipipe_tx = usb_open_pipe(dev, txdscr);

	if (!epdscr || !ifdscr) {
		printf("couldn't find descriptor!\n");
		return 0;
	}
	

	
	int i;
	for (i = 0; controller_mask & (1<<i); ++i);
	printf("attached controller %d\n", i);
	softc->index = i;
	setcontroller(softc, i);
	controller_mask |= 1<<i;

	/*
	 * Allocate a DMA buffer
	 */

	softc->uhid_imsg = usb_dma_alloc(UBR_KBD_MAX);
	if (softc->uhid_imsg == NULL) {
		printf("couldn't alloc buffer\n");
		/* Could not allocate a buffer, fail. */
		return -1;
	}
	
	/*
	 * Choose the standard configuration.
	 */

	usb_set_configuration(dev,cfgdscr->bConfigurationValue);

	/*
	 * Open the interrupt pipe.
	 */

	softc->uhid_ipipe = usb_open_pipe(dev,epdscr);
	softc->uhid_ipipemps = GETUSBFIELD(epdscr,wMaxPacketSize);

	/*
	 * Queue a transfer on the interrupt endpoint to catch
	 * our first characters.
	 */
	usbctrl_set_leds(softc, 0);
	usbctrl_queue_intreq(dev,softc);


	}

	return 0;


}
Exemplo n.º 4
0
/*
 * Controllers 
 */
void Master::SetController(unsigned char chan,unsigned int type,int par){
    dump.dumpcontroller(chan,type,par);
    
    setcontroller(chan,type,par);
};