⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 display.c

📁 微软DDK关于USB驱动编程的重要工具USBVIEW的源代码,通过该工具可以查看系统设备管理器中所有USB设备的信息,对于利用DDK编写USB驱动程序非常有帮助.
💻 C
📖 第 1 页 / 共 3 页
字号:
                    break;

                case USB_AUDIO_SUBCLASS_AUDIOSTREAMING:
                    pStr = " (Audio Streaming)\r\n";
                    break;

                case USB_AUDIO_SUBCLASS_MIDISTREAMING:
                    pStr = " (MIDI Streaming)\r\n";
                    break;

                default:
                    break;
            }
            break;

        default:
            break;
    }

    AppendTextBuffer(pStr);

    AppendTextBuffer("bInterfaceProtocol:   0x%02X\r\n",
                     InterfaceDesc->bInterfaceProtocol);

    AppendTextBuffer("iInterface:           0x%02X\r\n",
                     InterfaceDesc->iInterface);

    if (InterfaceDesc->iInterface)
    {
        DisplayStringDescriptor(InterfaceDesc->iInterface,
                                StringDescs);
    }

    if (InterfaceDesc->bLength == sizeof(USB_INTERFACE_DESCRIPTOR2))
    {
        PUSB_INTERFACE_DESCRIPTOR2 interfaceDesc2;

        interfaceDesc2 = (PUSB_INTERFACE_DESCRIPTOR2)InterfaceDesc;

        AppendTextBuffer("wNumClasses:        0x%04X\r\n",
                         interfaceDesc2->wNumClasses);
    }

}

//*****************************************************************************
//
// DisplayEndpointDescriptor()
//
//*****************************************************************************

VOID
DisplayEndpointDescriptor (
    PUSB_ENDPOINT_DESCRIPTOR    EndpointDesc
)
{

    AppendTextBuffer("\r\nEndpoint Descriptor:\r\n");

    AppendTextBuffer("bEndpointAddress:     0x%02X\r\n",
                     EndpointDesc->bEndpointAddress);

    switch (EndpointDesc->bmAttributes & 0x03)
    {
        case 0x00:
            AppendTextBuffer("Transfer Type:     Control\r\n");
            break;

        case 0x01:
            AppendTextBuffer("Transfer Type: Isochronous\r\n");
            break;

        case 0x02:
            AppendTextBuffer("Transfer Type:        Bulk\r\n");
            break;

        case 0x03:
            AppendTextBuffer("Transfer Type:   Interrupt\r\n");
            break;

    }

    AppendTextBuffer("wMaxPacketSize:     0x%04X (%d)\r\n",
                     EndpointDesc->wMaxPacketSize,
                     EndpointDesc->wMaxPacketSize);

    if (EndpointDesc->bLength == sizeof(USB_ENDPOINT_DESCRIPTOR))
    {
        AppendTextBuffer("bInterval:            0x%02X\r\n",
                         EndpointDesc->bInterval);
    }
    else
    {
        PUSB_ENDPOINT_DESCRIPTOR2 endpointDesc2;

        endpointDesc2 = (PUSB_ENDPOINT_DESCRIPTOR2)EndpointDesc;

        AppendTextBuffer("wInterval:          0x%04X\r\n",
                         endpointDesc2->wInterval);

        AppendTextBuffer("bSyncAddress:         0x%02X\r\n",
                         endpointDesc2->bSyncAddress);
    }

}


//*****************************************************************************
//
// DisplayHidDescriptor()
//
//*****************************************************************************

VOID
DisplayHidDescriptor (
    PUSB_HID_DESCRIPTOR         HidDesc
)
{
    UCHAR i;

    AppendTextBuffer("\r\nHID Descriptor:\r\n");

    AppendTextBuffer("bcdHID:             0x%04X\r\n",
    HidDesc->bcdHID);

    AppendTextBuffer("bCountryCode:         0x%02X\r\n",
                     HidDesc->bCountryCode);

    AppendTextBuffer("bNumDescriptors:      0x%02X\r\n",
                     HidDesc->bNumDescriptors);

    for (i=0; i<HidDesc->bNumDescriptors; i++)
    {
        AppendTextBuffer("bDescriptorType:      0x%02X\r\n",
                         HidDesc->OptionalDescriptors[i].bDescriptorType);

        AppendTextBuffer("wDescriptorLength:  0x%04X\r\n",
                         HidDesc->OptionalDescriptors[i].wDescriptorLength);
    }

}


#if 0
//*****************************************************************************
//
// DisplayPowerDescriptor()
//
//*****************************************************************************

PCHAR PowerUnits[] =
{
    "0.001 mW",
    "0.01 mW",
    "0.1 mW",
    "1 mW",
    "10 mW",
    "100 mW",
    "1 W"
};

VOID
DisplayPowerDescriptor (
    PUSB_POWER_DESCRIPTOR       PowerDesc
)
{
    UCHAR i;

    AppendTextBuffer("\r\nPower Descriptor:\r\n");

    AppendTextBuffer("bCapabilitiesFlags:   0x%02X (",
                     PowerDesc->bCapabilitiesFlags);

    if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D2_WAKEUP)
    {
        AppendTextBuffer("WakeD2 ");
    }
    if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D1_WAKEUP)
    {
        AppendTextBuffer("WakeD1 ");
    }
    if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D3_COMMAND)
    {
        AppendTextBuffer("D3 ");
    }
    if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D2_COMMAND)
    {
        AppendTextBuffer("D2 ");
    }
    if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D1_COMMAND)
    {
        AppendTextBuffer("D1 ");
    }
    if (PowerDesc->bCapabilitiesFlags & USB_SUPPORT_D0_COMMAND)
    {
        AppendTextBuffer("D0 ");
    }
    AppendTextBuffer(")\r\n");

    AppendTextBuffer("EventNotification:  0x%04X\r\n",
                     PowerDesc->EventNotification);

    AppendTextBuffer("D1LatencyTime:      0x%04X\r\n",
                     PowerDesc->D1LatencyTime);

    AppendTextBuffer("D2LatencyTime:      0x%04X\r\n",
                     PowerDesc->D2LatencyTime);

    AppendTextBuffer("D3LatencyTime:      0x%04X\r\n",
                     PowerDesc->D3LatencyTime);

    AppendTextBuffer("PowerUnit:            0x%02X (%s)\r\n",
                     PowerDesc->PowerUnit,
                     PowerDesc->PowerUnit < sizeof(PowerUnits)/sizeof(PowerUnits[0])
                     ? PowerUnits[PowerDesc->PowerUnit]
                     : "?");

    AppendTextBuffer("D0PowerConsumption: 0x%04X (%5d)\r\n",
                     PowerDesc->D0PowerConsumption,
                     PowerDesc->D0PowerConsumption);

    AppendTextBuffer("D1PowerConsumption: 0x%04X (%5d)\r\n",
                     PowerDesc->D1PowerConsumption,
                     PowerDesc->D1PowerConsumption);

    AppendTextBuffer("D2PowerConsumption: 0x%04X (%5d)\r\n",
                     PowerDesc->D2PowerConsumption,
                     PowerDesc->D2PowerConsumption);

}
#endif

//*****************************************************************************
//
// DisplayStringDescriptor()
//
//*****************************************************************************

#if 1

VOID
DisplayStringDescriptor (
    UCHAR                       Index,
    PSTRING_DESCRIPTOR_NODE     StringDescs
)
{
    ULONG nBytes;

    while (StringDescs)
    {
        if (StringDescs->DescriptorIndex == Index)
        {
            AppendTextBuffer("0x%04X: \"",
                             StringDescs->LanguageID);

            nBytes = WideCharToMultiByte(
                         CP_ACP,     // CodePage
                         0,          // CodePage
                         StringDescs->StringDescriptor->bString,
                         (StringDescs->StringDescriptor->bLength - 2) / 2,
                         TextBuffer + TextBufferPos,
                         TextBufferLen - TextBufferPos,
                         NULL,       // lpDefaultChar
                         NULL);      // pUsedDefaultChar

            TextBufferPos += nBytes;

            AppendTextBuffer("\"\r\n");
        }

        StringDescs = StringDescs->Next;
    }

}

#else

VOID
DisplayStringDescriptor (
    UCHAR                       Index,
    PSTRING_DESCRIPTOR_NODE     StringDescs
)
{
    UCHAR i;

    while (StringDescs)
    {
        if (StringDescs->DescriptorIndex == Index)
        {
            AppendTextBuffer("String Descriptor:\r\n");

            AppendTextBuffer("LanguageID:         0x%04X\r\n",
                             StringDescs->LanguageID);

            AppendTextBuffer("bLength:              0x%02X\r\n",
                             StringDescs->StringDescriptor->bLength);

            for (i = 0; i < StringDescs->StringDescriptor->bLength-2; i++)
            {
                AppendTextBuffer("%02X ",
                                 ((PUCHAR)StringDescs->StringDescriptor->bString)[i]);

                if (i % 16 == 15)
                {
                    AppendTextBuffer("\r\n");
                }
            }

            if (i % 16 != 0)
            {
                AppendTextBuffer("\r\n");
            }
        }

        StringDescs = StringDescs->Next;
    }

}

#endif

//*****************************************************************************
//
// DisplayUnknownDescriptor()
//
//*****************************************************************************

VOID
DisplayUnknownDescriptor (
    PUSB_COMMON_DESCRIPTOR      CommonDesc
)
{
    UCHAR   i;

    AppendTextBuffer("\r\nUnknown Descriptor:\r\n");

    AppendTextBuffer("bDescriptorType:      0x%02X\r\n",
                     CommonDesc->bDescriptorType);

    AppendTextBuffer("bLength:              0x%02X\r\n",
                     CommonDesc->bLength);

    for (i = 0; i < CommonDesc->bLength; i++)
    {
        AppendTextBuffer("%02X ",
                         ((PUCHAR)CommonDesc)[i]);

        if (i % 16 == 15)
        {
            AppendTextBuffer("\r\n");
        }
    }

    if (i % 16 != 0)
    {
        AppendTextBuffer("\r\n");
    }

}

//*****************************************************************************
//
// GetVendorString()
//
// idVendor - USB Vendor ID
//
// Return Value - Vendor name string associated with idVendor, or NULL if
// no vendor name string is found which is associated with idVendor.
//
//*****************************************************************************

PCHAR
GetVendorString (
    USHORT     idVendor
)
{
    PUSBVENDORID vendorID;

    if (idVendor != 0x0000)
    {
        vendorID = USBVendorIDs;

        while (vendorID->usVendorID != 0x0000)
        {
            if (vendorID->usVendorID == idVendor)
            {
                return (vendorID->szVendor);
            }
            vendorID++;
        }
    }

    return NULL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -