From eb83afdcf1e887787b6f832fc8386520a86fe9d0 Mon Sep 17 00:00:00 2001 From: zedamota Date: Fri, 24 Feb 2012 16:22:52 +0000 Subject: [PATCH] Working compliant VCP+HID descriptors for Windows. --- flight/PiOS/Common/pios_usb_desc_hid_cdc.c | 166 ++++++++++----------- flight/PiOS/STM32F10x/pios_usbhook.c | 10 +- 2 files changed, 88 insertions(+), 88 deletions(-) diff --git a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c index 13fd988f2..1d4f0a9b2 100644 --- a/flight/PiOS/Common/pios_usb_desc_hid_cdc.c +++ b/flight/PiOS/Common/pios_usb_desc_hid_cdc.c @@ -38,9 +38,9 @@ static const struct usb_device_desc device_desc = { .bLength = sizeof(struct usb_device_desc), .bDescriptorType = USB_DESC_TYPE_DEVICE, .bcdUSB = htousbs(0x0200), - .bDeviceClass = 0x02, - .bDeviceSubClass = 0x00, - .bDeviceProtocol = 0x00, + .bDeviceClass = 0xef, + .bDeviceSubClass = 0x02, + .bDeviceProtocol = 0x01, .bMaxPacketSize0 = 64, /* Must be 64 for high-speed devices */ .idVendor = htousbs(USB_VENDOR_ID_OPENPILOT), .idProduct = htousbs(PIOS_USB_BOARD_PRODUCT_ID), @@ -98,10 +98,6 @@ static const uint8_t hid_report_desc[36] = { struct usb_config_hid_cdc { struct usb_configuration_desc config; struct usb_interface_association_desc iad; - struct usb_interface_desc hid_if; - struct usb_hid_desc hid; - struct usb_endpoint_desc hid_in; - struct usb_endpoint_desc hid_out; struct usb_interface_desc cdc_control_if; struct usb_cdc_header_func_desc cdc_header; struct usb_cdc_callmgmt_func_desc cdc_callmgmt; @@ -111,6 +107,10 @@ struct usb_config_hid_cdc { struct usb_interface_desc cdc_data_if; struct usb_endpoint_desc cdc_in; struct usb_endpoint_desc cdc_out; + struct usb_interface_desc hid_if; + struct usb_hid_desc hid; + struct usb_endpoint_desc hid_in; + struct usb_endpoint_desc hid_out; } __attribute__((packed)); static const struct usb_config_hid_cdc config_hid_cdc = { @@ -129,15 +129,87 @@ static const struct usb_config_hid_cdc config_hid_cdc = { .bDescriptorType = USB_DESC_TYPE_IAD, .bFirstInterface = 0, .bInterfaceCount = 2, - .bFunctionClass = 2, /* Communication */ - .bFunctionSubClass = 2, /* Abstract Control Model */ - .bFunctionProtocol = 0, /* V.25ter, Common AT commands */ + .bFunctionClass = USB_INTERFACE_CLASS_CDC, /* Communication */ + .bFunctionSubClass = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, /* Abstract Control Model */ + .bFunctionProtocol = 1, /* V.25ter, Common AT commands */ .iInterface = 0, }, + .cdc_control_if = { + .bLength = sizeof(struct usb_interface_desc), + .bDescriptorType = USB_DESC_TYPE_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 1, + .bInterfaceClass = USB_INTERFACE_CLASS_CDC, + .bInterfaceSubClass = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, /* Abstract Control Model */ + .nInterfaceProtocol = 1, /* V.25ter, Common AT commands */ + .iInterface = 0, + }, + .cdc_header = { + .bLength = sizeof(struct usb_cdc_header_func_desc), + .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, + .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_HEADER, + .bcdCDC = htousbs(0x0110), + }, + .cdc_callmgmt = { + .bLength = sizeof(struct usb_cdc_callmgmt_func_desc), + .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, + .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_CALLMGMT, + .bmCapabilities = 0x00, /* No call handling */ + .bDataInterface = 1, + }, + .cdc_acm = { + .bLength = sizeof(struct usb_cdc_acm_func_desc), + .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, + .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, + .bmCapabilities = 0x00, + }, + .cdc_union = { + .bLength = sizeof(struct usb_cdc_union_func_desc), + .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, + .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_UNION, + .bMasterInterface = 0, + .bSlaveInterface = 1, + }, + .cdc_mgmt_in = { + .bLength = sizeof(struct usb_endpoint_desc), + .bDescriptorType = USB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = USB_EP_IN(2), + .bmAttributes = USB_EP_ATTR_TT_INTERRUPT, + .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_MGMT_LENGTH), + .bInterval = 4, /* ms */ + }, + .cdc_data_if = { + .bLength = sizeof(struct usb_interface_desc), + .bDescriptorType = USB_DESC_TYPE_INTERFACE, + .bInterfaceNumber = 1, + .bAlternateSetting = 0, + .bNumEndpoints = 2, + .bInterfaceClass = USB_INTERFACE_CLASS_DATA, + .bInterfaceSubClass = 0, + .nInterfaceProtocol = 0, /* No class specific protocol */ + .iInterface = 0, + }, + .cdc_in = { + .bLength = sizeof(struct usb_endpoint_desc), + .bDescriptorType = USB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = USB_EP_IN(3), + .bmAttributes = USB_EP_ATTR_TT_BULK, + .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH), + .bInterval = 0, /* ms */ + }, + .cdc_out = { + .bLength = sizeof(struct usb_endpoint_desc), + .bDescriptorType = USB_DESC_TYPE_ENDPOINT, + .bEndpointAddress = USB_EP_OUT(3), + .bmAttributes = USB_EP_ATTR_TT_BULK, /* Bulk */ + .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH), + .bInterval = 0, /* ms */ + }, .hid_if = { .bLength = sizeof(struct usb_interface_desc), .bDescriptorType = USB_DESC_TYPE_INTERFACE, - .bInterfaceNumber = 0, + .bInterfaceNumber = 2, .bAlternateSetting = 0, .bNumEndpoints = 2, .bInterfaceClass = USB_INTERFACE_CLASS_HID, @@ -170,78 +242,6 @@ static const struct usb_config_hid_cdc config_hid_cdc = { .wMaxPacketSize = htousbs(PIOS_USB_BOARD_HID_DATA_LENGTH), .bInterval = 4, /* ms */ }, - .cdc_control_if = { - .bLength = sizeof(struct usb_interface_desc), - .bDescriptorType = USB_DESC_TYPE_INTERFACE, - .bInterfaceNumber = 1, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_INTERFACE_CLASS_CDC, - .bInterfaceSubClass = 2, /* Abstract Control Model */ - .nInterfaceProtocol = 1, /* V.25ter, Common AT commands */ - .iInterface = 0, - }, - .cdc_header = { - .bLength = sizeof(struct usb_cdc_header_func_desc), - .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, - .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_HEADER, - .bcdCDC = htousbs(0x0110), - }, - .cdc_callmgmt = { - .bLength = sizeof(struct usb_cdc_callmgmt_func_desc), - .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, - .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_CALLMGMT, - .bmCapabilities = 0x00, /* No call handling */ - .bDataInterface = 2, - }, - .cdc_acm = { - .bLength = sizeof(struct usb_cdc_acm_func_desc), - .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, - .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_ABSTRACT_CTRL, - .bmCapabilities = 0, - }, - .cdc_union = { - .bLength = sizeof(struct usb_cdc_union_func_desc), - .bDescriptorType = USB_DESC_TYPE_CLASS_SPECIFIC, - .bDescriptorSubType = USB_CDC_DESC_SUBTYPE_UNION, - .bMasterInterface = 1, - .bSlaveInterface = 2, - }, - .cdc_mgmt_in = { - .bLength = sizeof(struct usb_endpoint_desc), - .bDescriptorType = USB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = USB_EP_IN(2), - .bmAttributes = USB_EP_ATTR_TT_INTERRUPT, - .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_MGMT_LENGTH), - .bInterval = 4, /* ms */ - }, - .cdc_data_if = { - .bLength = sizeof(struct usb_interface_desc), - .bDescriptorType = USB_DESC_TYPE_INTERFACE, - .bInterfaceNumber = 2, - .bAlternateSetting = 0, - .bNumEndpoints = 2, - .bInterfaceClass = USB_INTERFACE_CLASS_DATA, - .bInterfaceSubClass = 0, - .nInterfaceProtocol = 0, /* No class specific protocol */ - .iInterface = 0, - }, - .cdc_in = { - .bLength = sizeof(struct usb_endpoint_desc), - .bDescriptorType = USB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = USB_EP_IN(3), - .bmAttributes = USB_EP_ATTR_TT_BULK, - .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH), - .bInterval = 0, /* ms */ - }, - .cdc_out = { - .bLength = sizeof(struct usb_endpoint_desc), - .bDescriptorType = USB_DESC_TYPE_ENDPOINT, - .bEndpointAddress = USB_EP_OUT(3), - .bmAttributes = USB_EP_ATTR_TT_BULK, /* Bulk */ - .wMaxPacketSize = htousbs(PIOS_USB_BOARD_CDC_DATA_LENGTH), - .bInterval = 0, /* ms */ - }, }; int32_t PIOS_USB_DESC_HID_CDC_Init(void) diff --git a/flight/PiOS/STM32F10x/pios_usbhook.c b/flight/PiOS/STM32F10x/pios_usbhook.c index c6a952498..be94fef4d 100644 --- a/flight/PiOS/STM32F10x/pios_usbhook.c +++ b/flight/PiOS/STM32F10x/pios_usbhook.c @@ -304,7 +304,7 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo) switch (Type_Recipient) { case (STANDARD_REQUEST | INTERFACE_RECIPIENT): switch (pInformation->USBwIndex0) { - case 0: /* HID Interface */ + case 2: /* HID Interface */ switch (RequestNo) { case GET_DESCRIPTOR: switch (pInformation->USBwValue1) { @@ -321,7 +321,7 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo) case (CLASS_REQUEST | INTERFACE_RECIPIENT): switch (pInformation->USBwIndex0) { - case 0: /* HID Interface */ + case 2: /* HID Interface */ switch (RequestNo) { case USB_HID_REQ_GET_PROTOCOL: CopyRoutine = PIOS_USBHOOK_GetProtocolValue; @@ -330,16 +330,16 @@ static RESULT PIOS_USBHOOK_Data_Setup(uint8_t RequestNo) break; #if defined(PIOS_INCLUDE_USB_CDC) - case 1: /* CDC Call Control Interface */ + case 0: /* CDC Call Control Interface */ switch (RequestNo) { case USB_CDC_REQ_GET_LINE_CODING: - CopyRoutine = PIOS_USB_CDC_GetLineCoding; + //CopyRoutine = PIOS_USB_CDC_GetLineCoding; break; } break; - case 2: /* CDC Data Interface */ + case 1: /* CDC Data Interface */ switch (RequestNo) { case 0: break;