首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

wince的USB DEVICE固件驱动程序开发!解决方法

2012-03-18 
wince的USB DEVICE固件驱动程序开发!wince作为USB device时,已经支持Serial、Mass Storage、NDIS三种固件。我

wince的USB DEVICE固件驱动程序开发!
wince作为USB device时,已经支持Serial、Mass Storage、NDIS三种固件。

我现在想开发一个HID的固件。通过更改USBFN驱动,已经可以加载[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\FuncHID_Class]的驱动,注册表如下:

HTML code
[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\FuncHID_Class]    "Dll"="usbFuncHID.dll"    "InterfaceSubClass"=dword:03    "InterfaceProtocol"=dword:01    "DeviceName"="USBHIDKeyboard"    "FriendlyName"="USB Keyboard"    "idVendor"=dword:145E    "Manufacturer"="Samsung"    "idProduct"=dword:DFEF    "Product"="USB KeyBoard"    "bcdDevice"=dword:0    "Prefix"="FHD"    "Index"=dword:00000001

=========================分========割========线=============================
移植【PUBLIC\COMMON\OAK\DRIVERS\USBFN\CLASS\SERIAL】下的代码,更改了设备、接口、断点等描述符,在host端已经能够识别为HID 键盘输入设备了,描述符结构如下:
C/C++ code
//// D A T A / M A C R O S//#define MAX_INTERRUPT_ENDPOINT_PACKET_SIZE 8#define CB_CONFIG_DESCRIPTOR  (sizeof(USB_CONFIGURATION_DESCRIPTOR)+sizeof(USB_INTERFACE_DESCRIPTOR)+2*sizeof(USB_ENDPOINT_DESCRIPTOR))//  definitions#define COMMAND_PASSED                      0x00#define COMMAND_FAILED                      0x01#define PHASE_ERROR                         0x02#define EP0_PACKET_SIZE                     USB_FULL_HIGH_SPEED_CONTROL_MAX_PACKET_SIZE#define HIGH_SPEED_BULK_PACKET_SIZES        USB_HIGH_SPEED_BULK_MAX_PACKET_SIZE#define FULL_SPEED_BULK_PACKET_SIZES        USB_FULL_SPEED_BULK_MAX_PACKET_SIZE #define USB_VERSION                         0x200static USB_DEVICE_DESCRIPTOR                g_HighSpeedDeviceDesc = {    sizeof(USB_DEVICE_DESCRIPTOR),          // bLength    USB_DEVICE_DESCRIPTOR_TYPE,             // bDescriptorType    USB_VERSION,                            // bcdUSB    0x00,                                   // bDeviceClass    0x00,                                   // bDeviceSubClass    0x00,                                   // bDeviceProtocol    EP0_PACKET_SIZE,                        // bMaxPacketSize0    0,                                      // idVendor    0,                                      // idProduct    0x0000,                                 // bcdDevice    0x01,                                   // iManufacturer    0x02,                                   // iProduct    0x00,                                   // iSerialNumber    0x01                                    // bNumConfigurations};static USB_DEVICE_DESCRIPTOR                g_FullSpeedDeviceDesc = {    sizeof(USB_DEVICE_DESCRIPTOR),          // bLength    USB_DEVICE_DESCRIPTOR_TYPE,             // bDescriptorType    USB_VERSION,                            // bcdUSB    0x00,                                   // bDeviceClass    0x00,                                   // bDeviceSubClass    0x00,                                   // bDeviceProtocol    EP0_PACKET_SIZE,                        // bMaxPacketSize0    0,                                      // idVendor    0,                                      // idProduct    0x0000,                                 // bcdDevice    0x01,                                   // iManufacturer    0x02,                                   // iProduct    0x00,                                   // iSerialNumber    0x01                                    // bNumConfigurations};#define INTERRUPT_IN_ENDPOINT_ADDRESS  0x81#define INTERRUPT_OUT_ENDPOINT_ADDRESS 0x01#define INTERRUPT_IN_DESCRIPTOR_INDEX    0#define INTERRUPT_OUT_DESCRIPTOR_INDEX   1static UFN_ENDPOINT                         g_HighSpeedEndpoints[] = {    {        sizeof(UFN_ENDPOINT),        {            sizeof(USB_ENDPOINT_DESCRIPTOR),// bLength            USB_ENDPOINT_DESCRIPTOR_TYPE,   // bDescriptorType            INTERRUPT_IN_ENDPOINT_ADDRESS,       // bEndpointAddress (endpoint 1, in)            USB_ENDPOINT_TYPE_INTERRUPT,         // bmAttributes            MAX_INTERRUPT_ENDPOINT_PACKET_SIZE,    // wMaxPacketSize            0x0A                            // bInterval (interrupt only)        },        NULL    },    {        sizeof(UFN_ENDPOINT),        {            sizeof(USB_ENDPOINT_DESCRIPTOR),// bLength            USB_ENDPOINT_DESCRIPTOR_TYPE,   // bDescriptorType            INTERRUPT_OUT_ENDPOINT_ADDRESS,      // bEndpointAddress (endpoint 2, out)            USB_ENDPOINT_TYPE_INTERRUPT,         // bmAttributes            MAX_INTERRUPT_ENDPOINT_PACKET_SIZE,    // wMaxPacketSize            0x0A                            // bInterval (interrupt only)        },        NULL    }};static UFN_ENDPOINT                         g_FullSpeedEndpoints[] = {    {        sizeof(UFN_ENDPOINT),        {            sizeof(USB_ENDPOINT_DESCRIPTOR),// bLength            USB_ENDPOINT_DESCRIPTOR_TYPE,   // bDescriptorType            INTERRUPT_IN_ENDPOINT_ADDRESS,       // bEndpointAddress (endpoint 1, in)            USB_ENDPOINT_TYPE_INTERRUPT,         // bmAttributes            MAX_INTERRUPT_ENDPOINT_PACKET_SIZE,    // wMaxPacketSize            0x0A                            // bInterval (interrupt only)        },        NULL    },    {        sizeof(UFN_ENDPOINT),        {            sizeof(USB_ENDPOINT_DESCRIPTOR),// bLength            USB_ENDPOINT_DESCRIPTOR_TYPE,   // bDescriptorType            INTERRUPT_OUT_ENDPOINT_ADDRESS,      // bEndpointAddress (endpoint 2, out)            USB_ENDPOINT_TYPE_INTERRUPT,         // bmAttributes            MAX_INTERRUPT_ENDPOINT_PACKET_SIZE,    // wMaxPacketSize            0x0A                            // bInterval (interrupt only)        },        NULL    }};static UFN_INTERFACE                        g_HighSpeedInterface = {    sizeof(UFN_INTERFACE),    {        sizeof(USB_INTERFACE_DESCRIPTOR),   // bLength        USB_INTERFACE_DESCRIPTOR_TYPE,      // bDescriptorType        0x00,                               // bInterfaceNumber            0x00,                               // bAlternateSetting        dim(g_HighSpeedEndpoints),          // bNumEndpoints        0x03,                               // bInterfaceClass        0x01,                               // bInterfaceSubClass        0x01,                               // bInterfaceProtocol        0x00                                // iInterface        },    NULL,                                   // extended    0,    g_HighSpeedEndpoints                    // endpoint array};static UFN_INTERFACE                        g_FullSpeedInterface = {    sizeof(UFN_INTERFACE),    {        sizeof(USB_INTERFACE_DESCRIPTOR),   // bLength        USB_INTERFACE_DESCRIPTOR_TYPE,      // bDescriptorType        0x00,                               // bInterfaceNumber            0x00,                               // bAlternateSetting        dim(g_FullSpeedEndpoints),          // bNumEndpoints        0x03,                               // bInterfaceClass        0x01,                               // bInterfaceSubClass        0x01,                               // bInterfaceProtocol        0x00                                // iInterface     },    NULL,                                   // extended    0,    g_FullSpeedEndpoints                    // endpoint array};static UFN_CONFIGURATION                    g_HighSpeedConfig = {    sizeof(UFN_CONFIGURATION),    {        sizeof(USB_CONFIGURATION_DESCRIPTOR),// bLength        USB_CONFIGURATION_DESCRIPTOR_TYPE,  // bDescriptorType                CB_CONFIG_DESCRIPTOR,               // wTotalLength        0x01,                               // bNumInterfaces        0x01,                               // bConfigurationValue        0x00,                               // iConfiguration        USB_CONFIG_RESERVED_ATTRIBUTE | USB_CONFIG_SELF_POWERED,            // bmAttributes        0x50                                // MaxPower    },    NULL,    0x01,                                   // number of interfaces    &g_HighSpeedInterface                  // interface array};static UFN_CONFIGURATION                    g_FullSpeedConfig = {    sizeof(UFN_CONFIGURATION),    {        sizeof(USB_CONFIGURATION_DESCRIPTOR),// bLength        USB_CONFIGURATION_DESCRIPTOR_TYPE,  // bDescriptorType                CB_CONFIG_DESCRIPTOR,               // wTotalLength        0x01,                               // bNumInterfaces        0x01,                               // bConfigurationValue        0x00,                               // iConfiguration        USB_CONFIG_RESERVED_ATTRIBUTE | USB_CONFIG_SELF_POWERED,            // bmAttributes        0x50                                // MaxPower    },    NULL,    0x01,                                   // number of interfaces    &g_FullSpeedInterface                   // interface array};static UFN_CLIENT_REG_INFO g_RegInfo = { sizeof(UFN_CLIENT_REG_INFO) };static LPCWSTR g_rgpszStrings0409[] = {    g_RegInfo.szVendor, g_RegInfo.szProduct};static UFN_STRING_SET g_rgStringSets[] = {    0x0409, g_rgpszStrings0409, dim(g_rgpszStrings0409)}; 



=========================分========割========线=============================
但是PC(HOST)端实际获取到的信息是ENDPOINT数为0,我使用USB TRACE抓取到的接口信息如下:


[解决办法]
《圈圈教你玩USB》这本书里面有用单片机c语言实现的USB键盘的示例,也可以拿来参考下,能加深一下对于usb键盘,这个usb协议Device和PC通信的流程。帮顶。
[解决办法]
探讨

为什么获取到的设备、接口、短点描述符是错误的呢?

[解决办法]
1. 請問 "设备、接口、短点描述符" 的英文原文是什麼??

2. Serial 是靠 VendorID & ProductID 來辨認, HID 通常是用 Class ID 來辨認, 不知 LZ 是打算用哪一個??
探讨
0x00, // bDeviceClass
0x00, // bDeviceSubClass

[解决办法]
探讨

我在代码中加了一些调试信息,发现USB链接时,会调用DeviceNotifyStub ==》 DeviceNotify

在这之中会调用到UFN的API,LPUFN_OPEN_PIPE->lpOpenPipe,当调用这个函数时,出现异常,
我将这个函数指针值打印出来,也是正常的,参数也正确。

等待解决啊!

[解决办法]
探讨

应该不是指针异常,函数指针都不为空!

热点排行