public USBConfiguration WithInterface(USBClassCode classCode          = USBClassCode.NotSpecified,
                                              byte subClassCode               = 0,
                                              byte protocol                   = 0,
                                              string description              = null,
                                              Action <USBInterface> configure = null)
        {
            var newInterface = new USBInterface(device, (byte)interfaces.Count, classCode, subClassCode, protocol, description);

            configure?.Invoke(newInterface);
            return(WithInterface(newInterface));
        }
        public USBInterface(IUSBDevice device,
                            byte identifier,
                            USBClassCode classCode = USBClassCode.NotSpecified,
                            byte subClassCode      = 0,
                            byte protocol          = 0,
                            string description     = null) : base(9, (byte)DescriptorType.Interface)
        {
            this.device = device;
            endpoints   = new List <USBEndpoint>();

            Identifier  = identifier;
            Class       = classCode;
            SubClass    = subClassCode;
            Protocol    = protocol;
            Description = description;

            RegisterSubdescriptors(endpoints);
        }
        public USBDeviceCore(IUSBDevice device,
                             USBClassCode classCode         = USBClassCode.NotSpecified,
                             byte subClassCode              = 0,
                             byte protocol                  = 0,
                             USBProtocol usbProtocolVersion = USBProtocol.USB_2_0,
                             short deviceReleaseNumber      = 0,
                             PacketSize maximalPacketSize   = PacketSize.Size64,
                             string manufacturerName        = null,
                             string productName             = null,
                             string serialNumber            = null,
                             ushort vendorId                = 0,
                             ushort productId               = 0,
                             Action <SetupPacket, byte[], Action <byte[]> > customSetupPacketHandler = null) : base(18, (byte)DescriptorType.Device)
        {
            if (maximalPacketSize != PacketSize.Size8 &&
                maximalPacketSize != PacketSize.Size16 &&
                maximalPacketSize != PacketSize.Size32 &&
                maximalPacketSize != PacketSize.Size64)
            {
                throw new ConstructionException("Unsupported maximal packet size.");
            }

            this.customSetupPacketHandler = customSetupPacketHandler;
            this.device    = device;
            configurations = new List <USBConfiguration>();

            CompatibleProtocolVersion = usbProtocolVersion;
            Class               = classCode;
            SubClass            = subClassCode;
            Protocol            = protocol;
            DeviceReleaseNumber = deviceReleaseNumber;
            MaximalPacketSize   = maximalPacketSize;
            ManufacturerName    = manufacturerName;
            ProductName         = productName;
            SerialNumber        = serialNumber;
            VendorId            = vendorId;
            ProductId           = productId;

            RegisterSubdescriptors(configurations);
        }