1. 修改usb_conf.h 文件
#define EP_NUM (3) 改为3个端点
#define ENDP2_RXADDR (0x128) 分配端点2输出ram偏移
/* #define EP1_IN_Callback NOP_Process*/
#define EP2_IN_Callback NOP_Process
#define EP3_IN_Callback NOP_Process
#define EP4_IN_Callback NOP_Process
#define EP5_IN_Callback NOP_Process
#define EP6_IN_Callback NOP_Process
#define EP7_IN_Callback NOP_Process
#define EP1_OUT_Callback NOP_Process
//#define EP2_OUT_Callback NOP_Process
#define EP3_OUT_Callback NOP_Process
#define EP4_OUT_Callback NOP_Process
#define EP5_OUT_Callback NOP_Process
#define EP6_OUT_Callback NOP_Process
#define EP7_OUT_Callback NOP_Process
允许端点1输入回调,允许端点2输出回调处理
2. 在main.c文件或usb_endp.c中定义回调函数
voidEP2_OUT_Callback(void)
{
USB_ReceiveFlg = TRUE;
PMAToUserBufferCopy(Receive_Buffer,ENDP2_RXADDR,16);
MsgCmd =Receive_Buffer[0];
switch(MsgCmd)
{
case 1:
LED1_ON;
break;
case 2:
LED2_ON;
break;
default:
LED1_OFF; LED2_OFF;
}
SetEPRxStatus(ENDP2,EP_RX_VALID);
}
3. 修改VID和PID 方便区别
constuint8_t Joystick_DeviceDescriptor[JOYSTICK_SIZ_DEVICE_DESC] =
{
0x12, /*bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
0x00, /*bcdUSB*/
0x02,
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
0x40, /*bMaxPacketSize 64*/
0x16, /*idVendor (0x0483)*/
0x20,
0x09, /*idProduct = 0x5710*/
0x05,
0x00, /*bcdDevice rel. 2.00*/
0x02,
1, /*Index of string descriptor describing
manufacturer */
2, /*Index of string descriptor describing
product*/
3, /*Index of string descriptor describing the
device serial number */
0x01 /*bNumConfigurations*/
}
4. 修改配置描述符
constuint8_t Joystick_ConfigDescriptor[JOYSTICK_SIZ_CONFIG_DESC] =
{
0x09, /* bLength: Configuration Descriptorsize */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /*bDescriptorType: Configuration */
JOYSTICK_SIZ_CONFIG_DESC,
/* wTotalLength: Bytes returned */
0x00,
0x01, /*bNumInterfaces: 1 interface*/
0x01, /*bConfigurationValue: Configurationvalue*/
0x00, /*iConfiguration: Index of stringdescriptor describing
theconfiguration*/
0xE0, /*bmAttributes: Self powered */
0x32, /*MaxPower 100 mA: this current isused for detecting Vbus*/
/************** Descriptor of JoystickMouse interface ****************/
/* 09 */
0x09, /*bLength: Interface Descriptor size*/
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptortype*/
0x00, /*bInterfaceNumber: Number ofInterface*/
0x00, /*bAlternateSetting: Alternatesetting*/
0x02, /*bNumEndpoints*/ //变为两个端口 ep1 IN ep2 OUT
0x03, /*bInterfaceClass: HID*/
0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/ //自定义hid
0x00, /*nInterfaceProtocol : 0=none, 1=keyboard,2=mouse*/ //自定义hid
0, /*iInterface: Index of stringdescriptor*/
/*********** Descriptor of Joystick MouseHID ********************/
/* 18 */
0x09, /*bLength: HID Descriptor size*/
HID_DESCRIPTOR_TYPE, /*bDescriptorType:HID*/
0x00, /*bcdHID: HID Class Spec releasenumber*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of HID classdescriptors to follow*/
0x22, /*bDescriptorType*/
JOYSTICK_SIZ_REPORT_DESC,/*wItemLength:Total length of Report descriptor*/
0x00,
/************* Descriptor of Joystick Mouseendpoint ********************/
/* 27 */
0x07, /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE,/*bDescriptorType:*/
0x81, /*bEndpointAddress: Endpoint Address(IN)*/
// bit 3...0 : the endpoint number
// bit 6...4 : reserved
// bit 7 : 0(OUT), 1(IN)
0x03, /*bmAttributes: Interrupt endpoint*/
0x04, /*wMaxPacketSize: 4 Byte max */ //包长为4byte
0x00,
0x20, /*bInterval: Polling Interval (32ms)*/
/* 34 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType: */
/* Endpoint descriptor type */
0x02, /* bEndpointAddress: */ //追加一个端点2作为输出
/* Endpoint Address (OUT) */
0x03, /* bmAttributes: Interrupt endpoint */
0x08,//0x02, /* wMaxPacketSize: 20 Bytes max */ //包长为8byte
0x00,
0x10, /* bInterval: Polling Interval (32 ms)*/
/* 41 */
}
; /* MOUSE_ConfigDescriptor */
别忘了修改JOYSTICK_SIZ_CONFIG_DESC数组的大小为41。
5. 最后修改报告描述符,同样JOYSTICK_SIZ_REPORT_DESC修改为27
constuint8_t Joystick_ReportDescriptor[JOYSTICK_SIZ_REPORT_DESC] =
{
0x05,0x01, // USAGE_PAGE (Generic Desktop)
0x09,0x00, // USAGE (0)
0xa1,0x01, // COLLECTION (Application)
0x15,0x00, // LOGICAL_MINIMUM (0)
0x25,0xff, // LOGICAL_MAXIMUM (255)
0x19,0x01, // USAGE_MINIMUM (1)
0x29,0x08, // USAGE_MAXIMUM (8)
0x95,0x08, // REPORT_COUNT (8)
0x75,0x08, // REPORT_SIZE (8)
0x81,0x02, // INPUT (Data,Var,Abs)
//--------------------------------输出---------------------
0x19,0x01,
0x29,0x08,
0x91,0x02,
0xc0 // END_COLLECTION
}; /* CustomHID_ReportDescriptor */