Beispiel #1
0
        /// <summary>
        /// Gets the device string descriptor from the specified device.
        /// </summary>
        /// <param name="device">The device info of the device to get the descriptor from.</param>
        /// <returns>True if USB transfer completed successfully. Otherwise, false.</returns>
        public static StringInfo GetDeviceStringDescriptor(USBDeviceInfo device)
        {
#if USB_TRACE
            DBGMSG("USB: GET_DESCRIPTOR string");
#endif

            StringInfo result = null;
            StringDescriptor* descriptor = (StringDescriptor*)FOS_System.Heap.AllocZeroed((uint)sizeof(StringDescriptor), "USBManager : GetDeviceStringDescriptor");

            try
            {
                ushort size = (ushort)sizeof(StringDescriptor);
                USBTransfer transfer = new USBTransfer();
                device.hc.SetupTransfer(device, transfer, USBTransferType.Control, 0, 64);
                device.hc.SETUPTransaction(transfer, 8, 0x80, 6, 3, 0, 0, size);
                device.hc.INTransaction(transfer, false, descriptor, size);
                device.hc.OUTTransaction(transfer, true, null, 0);
                device.hc.IssueTransfer(transfer);
             
                if (transfer.success)
                {
                    if (descriptor->length > 0)
                    {
                        int totalLangs = 0;
                        for (int i = 0; i < 10; i++)
                        {
                            if (descriptor->languageID[i] >= 0x0400 && descriptor->languageID[i] <= 0x0465)
                            {
                                totalLangs++;
                            }
                        }

                        result = new StringInfo()
                        {
                            LanguageIds = new ushort[totalLangs]
                        };

                        totalLangs = 0;
                        for (int i = 0; i < 10; i++)
                        {
                            if (descriptor->languageID[i] >= 0x0400 && descriptor->languageID[i] <= 0x0465)
                            {
                                result.LanguageIds[totalLangs++] = descriptor->languageID[i];
                            }
                        }
                    }
                    else
                    {
                        result = new StringInfo()
                        {
                            LanguageIds = new ushort[0]
                        };
                    }

#if USB_TRACE
                    ShowString(result);
#endif
                }
            }
            finally
            {
                FOS_System.Heap.Free(descriptor);
            }

            return result;
        }
Beispiel #2
0
 private static void ShowString(StringInfo info)
 {
     DBGMSG("Languages: ");
     for (byte i = 0; i < info.LanguageIds.Length; i++)
     {
         DBGMSG(StringInfo.GetLanguageName(info.LanguageIds[i]));
     }
 }