Exemplo n.º 1
0
        void SetEndPoints()
        {
            if (_configs == 0) return;
            if (_interfaces == 0) return;

            EndPoints = USBCfgs[_cfgNum].Interfaces[_intfcIndex].EndPoints;
            int eptCount = EndPointCount;

            IsocInEndPt = null;
            IsocOutEndPt = null;
            BulkInEndPt = null;
            BulkOutEndPt = null;
            InterruptInEndPt = null;
            InterruptOutEndPt = null;

            for (int i = 1; i < eptCount; i++)
            {
                bool bIn = (EndPoints[i].Address & 0x80) > 0;
                byte attrib = EndPoints[i].Attributes;

                if (EndPoints[i] != null) EndPoints[i].XferMode = XMODE.DIRECT;

                if ((IsocInEndPt == null) && (attrib == 1) && bIn) IsocInEndPt = EndPoints[i] as CyIsocEndPoint;
                if ((BulkInEndPt == null) && (attrib == 2) && bIn) BulkInEndPt = EndPoints[i] as CyBulkEndPoint;
                if ((InterruptInEndPt == null) && (attrib == 3) && bIn) InterruptInEndPt = EndPoints[i] as CyInterruptEndPoint;

                if ((IsocOutEndPt == null) && (attrib == 1) && !bIn) IsocOutEndPt = EndPoints[i] as CyIsocEndPoint;
                if ((BulkOutEndPt == null) && (attrib == 2) && !bIn) BulkOutEndPt = EndPoints[i] as CyBulkEndPoint;
                if ((InterruptOutEndPt == null) && (attrib == 3) && !bIn) InterruptOutEndPt = EndPoints[i] as CyInterruptEndPoint;
            }
        }
Exemplo n.º 2
0
        ushort _wTotalLength; // Needed in case Intfc has additional (non-endpt) descriptors

        #endregion Fields

        #region Constructors

        internal unsafe CyUSBInterface(IntPtr handle, byte* DescrData, CyControlEndPoint ctlEndPt)
        {
            USB_INTERFACE_DESCRIPTOR* pIntfcDescriptor = (USB_INTERFACE_DESCRIPTOR*)DescrData;

            _bLength = pIntfcDescriptor->bLength;
            _bDescriptorType = pIntfcDescriptor->bDescriptorType;
            _bInterfaceNumber = pIntfcDescriptor->bInterfaceNumber;
            _bAlternateSetting = pIntfcDescriptor->bAlternateSetting;
            _bNumEndpoints = pIntfcDescriptor->bNumEndpoints;
            _bInterfaceClass = pIntfcDescriptor->bInterfaceClass;
            _bInterfaceSubClass = pIntfcDescriptor->bInterfaceSubClass;
            _bInterfaceProtocol = pIntfcDescriptor->bInterfaceProtocol;
            _iInterface = pIntfcDescriptor->iInterface;

            _bAltSettings = 0;
            _wTotalLength = bLength;

            byte* desc = (byte*)(DescrData + pIntfcDescriptor->bLength);

            int i;
            int unexpected = 0;

            EndPoints = new CyUSBEndPoint[bNumEndpoints + 1];
            EndPoints[0] = ctlEndPt;

            for (i = 1; i <= bNumEndpoints; i++)
            {

                USB_ENDPOINT_DESCRIPTOR* endPtDesc = (USB_ENDPOINT_DESCRIPTOR*)desc;
                _wTotalLength += endPtDesc->bLength;

                if (endPtDesc->bDescriptorType == CyConst.USB_ENDPOINT_DESCRIPTOR_TYPE)
                {
                    switch (endPtDesc->bmAttributes)
                    {
                        case 0:
                            EndPoints[i] = ctlEndPt;
                            break;
                        case 1:
                            EndPoints[i] = new CyIsocEndPoint(handle, endPtDesc);
                            break;
                        case 2:
                            EndPoints[i] = new CyBulkEndPoint(handle, endPtDesc);
                            break;
                        case 3:
                            EndPoints[i] = new CyInterruptEndPoint(handle, endPtDesc);
                            break;
                    }

                    desc += endPtDesc->bLength;
                }
                else
                {
                    unexpected++;
                    if (unexpected < 12)
                    {  // Sanity check - prevent infinite loop

                        // This may have been a class-specific descriptor (like HID).  Skip it.
                        desc += endPtDesc->bLength;

                        // Stay in the loop, grabbing the next descriptor
                        i--;
                    }

                }

            }
        }