wince的USB DEVICE固件驱动程序开发!
wince作为USB device时,已经支持Serial、Mass Storage、NDIS三种固件。
我现在想开发一个HID的固件。通过更改USBFN驱动,已经可以加载[HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\FuncHID_Class]的驱动,注册表如下:
[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
//// 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)};