📄 usb.c
字号:
while(1) { // // Wait until there is something to do. // while(!sUSB.ucHaveVendorMessage) { // // Put the EP7209 into HALT mode. // Halt(); } // // The USB_Vendor_Disconnect message is sent when the host application // is no longer using the Internet audio player. In this case, we // should exit from the loop. // if(sUSB.sControlOut.bRequest == USB_Vendor_Disconnect) { // // Respond to the host with an empty packet. // USBSendControl((unsigned char *)&ulResult, 4); // // We've handled the vendor specific message. // sUSB.ucHaveVendorMessage = 0; // // Break out of the loop. // break; } // // Handle the vendor specific message. // switch(sUSB.sControlOut.bRequest & 31) { // // A connect request. // case USB_Vendor_Connect: { // // Respond to the host with an empty packet. // USBSendControl((unsigned char *)&ulResult, 4); // // We're done handling this request. // break; } // // Return the value of one of our descriptors. // case USB_Vendor_GetDescriptor: { // // Figure out which descriptor was requested. // switch(sUSB.sControlOut.wIndex) { // // The unique device ID was requested. // case USB_Vendor_Descriptor_DeviceID: { // // We do not support a unique device ID, so return a // failure. // ulResult[0] = 0; ulResult[1] = 0; // // We're done handling this descriptor. // break; } // // The unique media ID was requested. // case USB_Vendor_Descriptor_MediaID: { // // Get the unique media ID of the requested drive. // ulResult[1] = 128 * 8; ulResult[0] = FSGetMediaID(sUSB.sControlOut.bRequest >> 5, pucData, &ulResult[1]); if(!ulResult[0]) { ulResult[1] = 0; } else { ulResult[1] = (ulResult[1] + 7) / 8; } // // We're done handling this descriptor. // break; } // // The name the media was requested. // case USB_Vendor_Descriptor_MediaName: { // // Get the name of the requested drive. // ulResult[0] = FSGetMediaName(sUSB.sControlOut.bRequest >> 5, (unsigned short *)pucData, &ulResult[1]); if(!ulResult[0]) { ulResult[1] = 0; } // // We're done handling this descriptor. // break; } // // The version of the firmware was requested. // case USB_Vendor_Descriptor_FirmwareVersion: { // // Write the firmware version into the scratch buffer. // This is firmware version '01.00.00.00'. // pucData[0] = 0x01; pucData[1] = 0x00; pucData[2] = 0x00; pucData[3] = 0x00; // // Set the return code to success. // ulResult[0] = 1; // // Set the length of the descriptor to four. // ulResult[1] = 4; // // We're done handling this descriptor. // break; } // // The ID and version of the hardware was requested. // case USB_Vendor_Descriptor_HardwareID: { // // Write the hardware ID into the scratch buffer. // pucData[0] = HardwareID & 0xff; pucData[1] = (HardwareID >> 8) & 0xff; pucData[2] = (HardwareID >> 16) & 0xff; pucData[3] = (HardwareID >> 24) & 0xff; // // Set the return code to success. // ulResult[0] = 1; // // Set the length of the descriptor to four. // ulResult[1] = 4; // // We're done handling this descriptor. // break; } // // One of the group IDs was requested. // case USB_Vendor_Descriptor_GroupID: { // // We do not support group IDs, so return a failure. // ulResult[0] = 0; ulResult[1] = 0; // // We're done handling this descriptor. // break; } // // The list of supported codecs was requested. // case USB_Vendor_Descriptor_CodecList: { // // We do not support the codec list, so return a // failure. // ulResult[0] = 0; ulResult[1] = 0; // // We're done handling this descriptor. // break; } // // The player's notion of the current time. // case USB_Vendor_Descriptor_CurrentTime: { unsigned long ulTime; // // Get the current system time. // ulTime = TimeGetSystemTime(); // // Write the current time into the scratch buffer. // pucData[0] = ulTime & 0xff; pucData[1] = (ulTime >> 8) & 0xff; pucData[2] = (ulTime >> 16) & 0xff; pucData[3] = (ulTime >> 24) & 0xff; // // Set the return code to success. // ulResult[0] = 1; // // Set the length of the descriptor to four. // ulResult[1] = 4; // // We're done handling this descriptor. // break; } // // The current remaining battery life. // case USB_Vendor_Descriptor_BatteryLife: { // // For now, set the battery life to 100%. // pucData[0] = 100; pucData[1] = 0; pucData[2] = 0; pucData[3] = 0; // // Set the return code to success. // ulResult[0] = 1; // // Set the length of the descriptor to four. // ulResult[1] = 4; // // We're done handling this descriptor. // break; } // // This is an unknown descriptor. // default: { // // Return a failure. // ulResult[0] = 0; ulResult[1] = 0; // // We're done handling this descriptor. // break; } } // // If there is descriptor data to be returned, then queue it. // if(ulResult[0] && ulResult[1]) { USBSendBulk(pucData, ulResult[1]); } // // Respond to the host with the data packet. // USBSendControl((unsigned char *)&ulResult, 8); // // We're done handling this request. // break; } // // Set the value of one of our descriptors. // case USB_Vendor_SetDescriptor: { // // Figure out which descriptor was requested. // switch(sUSB.sControlOut.wIndex) { // // One of the group IDs was requested. // case USB_Vendor_Descriptor_GroupID: { // // We do not support group IDs, so return a failure. // ulResult[0] = 0; // // We're done handling this descriptor. // break; } // // Set the current system time. // case USB_Vendor_Descriptor_CurrentTime: { unsigned long ulTime; // // Get the time from the scratch buffer. // ulTime = pucData[0] | (pucData[1] << 8) | (pucData[2] << 16) | (pucData[3] << 24); // // Set the system time. // TimeSetSystemTime(ulTime); // // Set the result to success. // ulResult[0] = 1; // // We're done handling this descriptor. // break; } // // We can not change any of the other descriptors. // default: { // // Return a failure. // ulResult[0] = 0; // // We're done handling this descriptor. // break; } } // // Re-queue the bulk out data buffer. // USBReceiveBulk(pucData, 16384); // // Respond to the host with the data packet. // USBSendControl((unsigned char *)&ulResult, 4); // // We're done handling this request. // break; } // // The number of drives in the system. // case USB_Vendor_NumDrives: { // // The return code is success. // ulResult[0] = 1; // // Return the number of drives. // ulResult[1] = FSNumDrives(); // // Respond to the host with the data packet. // USBSendControl((unsigned char *)&ulResult, 8); // // We're done handling this request. // break; } // // Open a file. // // XXXXXX We need to be able to fail this request if the file is // marked as no readback by the DRM flags. // case USB_Vendor_Open: { // // Make sure there is not already a file open. // if(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -