Beispiel #1
0
        unsafe internal CyUSBConfig(IntPtr handle, byte[] DescrData, CyControlEndPoint ctlEndPt)
        {// This contructore is to initialize usb2.0 device
            fixed(byte *buf = DescrData)
            {
                USB_CONFIGURATION_DESCRIPTOR *ConfigDescr = (USB_CONFIGURATION_DESCRIPTOR *)buf;

                _bLength             = ConfigDescr->bLength;
                _bDescriptorType     = ConfigDescr->bDescriptorType;
                _wTotalLength        = ConfigDescr->wTotalLength;
                _bNumInterfaces      = ConfigDescr->bNumInterfaces;
                _AltInterfaces       = 0;
                _bConfigurationValue = ConfigDescr->bConfigurationValue;
                _iConfiguration      = ConfigDescr->iConfiguration;
                _bmAttributes        = ConfigDescr->bmAttributes;
                _MaxPower            = ConfigDescr->MaxPower;

                int tLen = ConfigDescr->wTotalLength;

                byte *desc          = (byte *)(buf + ConfigDescr->bLength);
                int   bytesConsumed = ConfigDescr->bLength;

                Interfaces = new CyUSBInterface[CyConst.MAX_INTERFACES];

                int i = 0;

                do
                {
                    USB_INTERFACE_DESCRIPTOR *interfaceDesc = (USB_INTERFACE_DESCRIPTOR *)desc;

                    if (interfaceDesc->bDescriptorType == CyConst.USB_INTERFACE_DESCRIPTOR_TYPE)
                    {
                        Interfaces[i] = new CyUSBInterface(handle, desc, ctlEndPt);
                        i++;
                        _AltInterfaces++;  // Actually the total number of interfaces for the config
                        bytesConsumed += Interfaces[i - 1].wTotalLength;
                    }
                    else
                    {
                        // Unexpected descriptor type
                        // Just skip it and go on  - could have thrown an exception instead
                        // since this indicates that the descriptor structure is invalid.
                        bytesConsumed += interfaceDesc->bLength;
                    }


                    desc = (byte *)(buf + bytesConsumed);
                } while ((bytesConsumed < tLen) && (i < CyConst.MAX_INTERFACES));
                // Count the alt interfaces for each interface number
                for (i = 0; i < _AltInterfaces; i++)
                {
                    Interfaces[i]._bAltSettings = 0;

                    for (int j = 0; j < AltInterfaces; j++) // Walk the list looking for identical bInterfaceNumbers
                    {
                        if (Interfaces[i].bInterfaceNumber == Interfaces[j].bInterfaceNumber)
                        {
                            Interfaces[i]._bAltSettings++;
                        }
                    }
                }

                // Create the Interface Container (this is done only for Tree view purpose).
                IntfcContainer = new CyUSBInterfaceContainer[bNumInterfaces];

                Dictionary <int, bool> altDict = new Dictionary <int, bool>();
                int intfcCount = 0;

                for (i = 0; i < _AltInterfaces; i++)
                {
                    if (altDict.ContainsKey(Interfaces[i].bInterfaceNumber) == false)
                    {
                        int altIntfcCount = 0;
                        IntfcContainer[intfcCount] = new CyUSBInterfaceContainer(Interfaces[i].bInterfaceNumber, Interfaces[i].bAltSettings);

                        for (int j = i; j < AltInterfaces; j++)
                        {
                            if (Interfaces[i].bInterfaceNumber == Interfaces[j].bInterfaceNumber)
                            {
                                IntfcContainer[intfcCount].Interfaces[altIntfcCount] = Interfaces[j];
                                altIntfcCount++;
                            }
                        }
                        intfcCount++;
                        altDict.Add(Interfaces[i].bInterfaceNumber, true);
                    }
                }
            } /* end of fixed loop */
        }
Beispiel #2
0
        internal unsafe CyUSBConfig(IntPtr handle, byte[] DescrData, CyControlEndPoint ctlEndPt)
        {
            // This contructore is to initialize usb2.0 device
            fixed (byte* buf = DescrData)
            {
                USB_CONFIGURATION_DESCRIPTOR* ConfigDescr = (USB_CONFIGURATION_DESCRIPTOR*)buf;

                _bLength = ConfigDescr->bLength;
                _bDescriptorType = ConfigDescr->bDescriptorType;
                _wTotalLength = ConfigDescr->wTotalLength;
                _bNumInterfaces = ConfigDescr->bNumInterfaces;
                _AltInterfaces = 0;
                _bConfigurationValue = ConfigDescr->bConfigurationValue;
                _iConfiguration = ConfigDescr->iConfiguration;
                _bmAttributes = ConfigDescr->bmAttributes;
                _MaxPower = ConfigDescr->MaxPower;

                int tLen = ConfigDescr->wTotalLength;

                byte* desc = (byte*)(buf + ConfigDescr->bLength);
                int bytesConsumed = ConfigDescr->bLength;

                Interfaces = new CyUSBInterface[CyConst.MAX_INTERFACES];

                int i = 0;
                do
                {
                    USB_INTERFACE_DESCRIPTOR* interfaceDesc = (USB_INTERFACE_DESCRIPTOR*)desc;

                    if (interfaceDesc->bDescriptorType == CyConst.USB_INTERFACE_DESCRIPTOR_TYPE)
                    {
                        Interfaces[i] = new CyUSBInterface(handle, desc, ctlEndPt);
                        i++;
                        _AltInterfaces++;  // Actually the total number of interfaces for the config
                        bytesConsumed += Interfaces[i - 1].wTotalLength;
                    }
                    else
                    {
                        // Unexpected descriptor type
                        // Just skip it and go on  - could have thrown an exception instead
                        // since this indicates that the descriptor structure is invalid.
                        bytesConsumed += interfaceDesc->bLength;
                    }

                    desc = (byte*)(buf + bytesConsumed);

                } while ((bytesConsumed < tLen) && (i < CyConst.MAX_INTERFACES));
                // Count the alt interfaces for each interface number
                for (i = 0; i < _AltInterfaces; i++)
                {
                    Interfaces[i]._bAltSettings = 0;

                    for (int j = 0; j < AltInterfaces; j++) // Walk the list looking for identical bInterfaceNumbers
                        if (Interfaces[i].bInterfaceNumber == Interfaces[j].bInterfaceNumber)
                            Interfaces[i]._bAltSettings++;

                }

                // Create the Interface Container (this is done only for Tree view purpose).
                IntfcContainer = new CyUSBInterfaceContainer[bNumInterfaces];

                Dictionary<int, bool> altDict = new Dictionary<int, bool>();
                int intfcCount = 0;

                for (i = 0; i < _AltInterfaces; i++)
                {
                    if (altDict.ContainsKey(Interfaces[i].bInterfaceNumber) == false)
                    {
                        int altIntfcCount = 0;
                        IntfcContainer[intfcCount] = new CyUSBInterfaceContainer(Interfaces[i].bInterfaceNumber, Interfaces[i].bAltSettings);

                        for (int j = i; j < AltInterfaces; j++)
                        {
                            if (Interfaces[i].bInterfaceNumber == Interfaces[j].bInterfaceNumber)
                            {
                                IntfcContainer[intfcCount].Interfaces[altIntfcCount] = Interfaces[j];
                                altIntfcCount++;
                            }
                        }
                        intfcCount++;
                        altDict.Add(Interfaces[i].bInterfaceNumber, true);
                    }

                }
            } /* end of fixed loop */
        }