基于ST官方的JoyStickMouse修改的程序,原程序是用EP1发送4个字节数据,我想把它改成使用EP2或者发送EP3发送。
但是发现:
usb_desc.h:把JOYSTICK_SIZ_CONFIG_DESC改成48,即34+7+7
usb_desc.c:
const uint8_t Joystick_ConfigDescriptor[JOYSTICK_SIZ_CONFIG_DESC] =
{
0x09, /* bLength: Configuration Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
JOYSTICK_SIZ_CONFIG_DESC,
/* wTotalLength: Bytes returned */
0x00,
0x01, /*bNumInterfaces: 1 interface*/
0x01, /*bConfigurationValue: Configuration value*/
0x00, /*iConfiguration: Index of string descriptor describing
the configuration*/
0xE0, /*bmAttributes: bus powered */
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
/************** Descriptor of Joystick Mouse interface ****************/
/* 09 */
0x09, /*bLength: Interface Descriptor size*/
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
0x00, /*bInterfaceNumber: Number of Interface*/
0x00, /*bAlternateSetting: Alternate setting*/
0x03, /*bNumEndpoints*/
0x03, /*bInterfaceClass: HID*/
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
0, /*iInterface: Index of string descriptor*/
/******************** Descriptor of Joystick Mouse HID ********************/
/* 18 */
0x09, /*bLength: HID Descriptor size*/
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
0x00, /*bcdHID: HID Class Spec release number*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
0x22, /*bDescriptorType*/
JOYSTICK_SIZ_REPORT_DESC,/*wItemLength: Total length of Report descriptor*/
0x00,
/******************** Descriptor of Joystick Mouse endpoint ********************/
/* 27 */
0x07, /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
0x83, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
0x04, /*wMaxPacketSize: 4 Byte max */
0x00,
0x20, /*bInterval: Polling Interval (32 ms)*/
/* 34 */
0x07, /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
0x82, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
0x04, /*wMaxPacketSize: 4 Byte max */
0x00,
0x20, /*bInterval: Polling Interval (32 ms)*/
/*41*/
0x07, /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
0x81, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
0x04, /*wMaxPacketSize: 4 Byte max */
0x00,
0x20, /*bInterval: Polling Interval (32 ms)*/
/*48*/
}
usb_conf.h中:
把#define EP_NUM (2) 改成 #define EP_NUM (4)
#define ENDP0_RXADDR (0x50)
#define ENDP0_TXADDR (0x90)
#define ENDP1_TXADDR (0xC0)
#define ENDP1_RXADDR (0xD0)
#define ENDP2_TXADDR (0x100)
#define ENDP2_RXADDR (0x140)
#define ENDP3_TXADDR (0x180)
#define ENDP3_RXADDR (0x1C0)
hw_config.c中:
USB_SIL_Write(EP3_IN, Mouse_Buffer, 4);
SetEPTxValid(ENDP3);
这样,端点3可以正常IN。但是,如果我把hw_config.c中的EP3换成EP2或EP1,则工作不正常。
而且,如果交换usb_desc.c中三个端点描述的顺序,则总是第一个被描述的端点能正常IN,而其他两个都不行。
这是什么原因呢?
|
|