static void usb_set_interface(mass_dev* dev, int interface, int altSetting) { int ret; usb_callback_data cb_data; cb_data.semh = dev->ioSema; XPRINTF("USBHDFSD: setting interface controlEp=%i, interface=%i altSetting=%i\n", dev->controlEp, interface, altSetting); ret = UsbSetInterface(dev->controlEp, interface, altSetting, usb_callback, (void*)&cb_data); if (ret == USB_RC_OK) { WaitSema(cb_data.semh); ret = cb_data.returnCode; } if (ret != USB_RC_OK) { XPRINTF("USBHDFSD: Error - sending set_interface %d\n", ret); } }
void usb_set_interface(mass_dev* dev, int interface, int altSetting) { int ret; usb_callback_data cb_data; iop_sema_t s; s.initial = 0; s.max = 1; s.option = 0; s.attr = 0; cb_data.semh = CreateSema(&s); XPRINTF("USBHDFSD: setting interface controlEp=%i, interface=%i altSetting=%i\n", dev->controlEp, interface, altSetting); ret = UsbSetInterface(dev->controlEp, interface, altSetting, usb_callback, (void*)&cb_data); if (ret != USB_RC_OK) { printf("USBHDFSD: Error - sending set_interface %d\n", ret); } else { WaitSema(cb_data.semh); } DeleteSema(cb_data.semh); }
/************************************************************************* * Function Name: USB_SetupHandler * Parameters: void * * Return: none * * Description: Setup packet handler * *************************************************************************/ void USB_SetupHandler (void) { switch(UsbEp0SetupPacket.mRequestType.Type) { // Standard case UsbTypeStandart: // Decoding standard request switch (UsbEp0SetupPacket.bRequest) { case GET_STATUS: UsbGetStatus(); break; case CLEAR_FEATURE: UsbClearFeature(); break; case SET_FEATURE: UsbSetFeature(); break; case SET_ADDRESS: UsbSetAddress(); break; case GET_DESCRIPTOR: if(UsbEp0SetupPacket.mRequestType.Recipient == UsbRecipientDevice) { UsbGetDescriptor(); } // Only get descriptor for device is standard request else if ((UsbEp0SetupPacket.mRequestType.Dir == UsbDevice2Host) && (USB_GET_DESCRIPTOR_HOOK(&UsbEp0SetupPacket) == UsbPass)) { } else { USB_T9_ERROR_REQUEST(); } break; case SET_DESCRIPTOR: // Optional (only for configuration and string descriptors) UsbSetDescriptor(); break; case GET_CONFIGURATION: UsbGetConfiguration(); break; case SET_CONFIGURATION: UsbSetConfiguration(); break; case GET_INTERFACE: UsbGetInterface(); break; case SET_INTERFACE: UsbSetInterface(); break; case SYNCH_FRAME: UsbSynchFrame(); break; default: USB_T9_ERROR_REQUEST(); } break; // Class case UsbTypeClass: if(USB_CLASS_REQUEST_HOOK(&UsbEp0SetupPacket) != UsbPass) { USB_T9_ERROR_REQUEST(); } else { } break; // Vendor case UsbTypeVendor: if( USB_VENDOR_REQUEST_HOOK(&UsbEp0SetupPacket) != UsbPass) { USB_T9_ERROR_REQUEST(); } else { } break; // Other default: USB_T9_ERROR_REQUEST(); } }