refractor tusb_descriptor, adding support for cdc descriptor

This commit is contained in:
hathach 2013-11-07 12:28:10 +07:00
parent 8c9def8618
commit 3945869cc2
3 changed files with 80 additions and 50 deletions

View File

@ -75,7 +75,7 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// DEVICE CONFIGURATION // DEVICE CONFIGURATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define TUSB_CFG_DEVICE_FULLSPEED 0 // TODO refractor #define TUSB_CFG_DEVICE_FULLSPEED 1 // TODO refractor
#define TUSB_CFG_DEVICE_USE_ROM_DRIVER 0 #define TUSB_CFG_DEVICE_USE_ROM_DRIVER 0
@ -89,11 +89,11 @@
#define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE 64 #define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE 64
//------------- CLASS -------------// //------------- CLASS -------------//
#define TUSB_CFG_DEVICE_HID_KEYBOARD 1 #define TUSB_CFG_DEVICE_HID_KEYBOARD 0
#define TUSB_CFG_DEVICE_HID_MOUSE 1 #define TUSB_CFG_DEVICE_HID_MOUSE 0
#define TUSB_CFG_DEVICE_HID_GENERIC 0 #define TUSB_CFG_DEVICE_HID_GENERIC 0
#define TUSB_CFG_DEVICE_MSC 1 #define TUSB_CFG_DEVICE_MSC 0
#define TUSB_CFG_DEVICE_CDC 0 #define TUSB_CFG_DEVICE_CDC 1
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// COMMON CONFIGURATION // COMMON CONFIGURATION

View File

@ -134,9 +134,20 @@ tusb_descriptor_device_t app_tusb_desc_device =
.bLength = sizeof(tusb_descriptor_device_t), .bLength = sizeof(tusb_descriptor_device_t),
.bDescriptorType = TUSB_DESC_TYPE_DEVICE, .bDescriptorType = TUSB_DESC_TYPE_DEVICE,
.bcdUSB = 0x0200, .bcdUSB = 0x0200,
.bDeviceClass = 0x00, #if IAD_DESC_REQUIRED
.bDeviceSubClass = 0x00, /* Multiple Interfaces Using Interface Association Descriptor (IAD) */
.bDeviceProtocol = 0x00, .bDeviceClass = USB_DEVICE_CLASS_IAD,
.bDeviceSubClass = USB_DEVICE_SUBCLASS_IAD,
.bDeviceProtocol = USB_DEVICE_PROTOCOL_IAD,
#elif defined CFG_USB_CDC
.bDeviceClass = CDC_COMMUNICATION_INTERFACE_CLASS,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
#else
.bDeviceClass = 0x00,
.bDeviceSubClass = 0x00,
.bDeviceProtocol = 0x00,
#endif
.bMaxPacketSize0 = TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE, .bMaxPacketSize0 = TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE,
@ -170,17 +181,17 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
#if IAD_DESC_REQUIRED #if IAD_DESC_REQUIRED
// IAD points to CDC Interfaces // IAD points to CDC Interfaces
.CDC_IAD = .cdc_iad =
{ {
.bLength = sizeof(tusb_descriptor_interface_association_t), .bLength = sizeof(tusb_descriptor_interface_association_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_ASSOCIATION, .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_ASSOCIATION,
.bFirstInterface = 0, .bFirstInterface = 1,
.bInterfaceCount = 2, .bInterfaceCount = 2,
.bFunctionClass = CDC_COMMUNICATION_INTERFACE_CLASS, .bFunctionClass = TUSB_CLASS_CDC,
.bFunctionSubClass = CDC_ABSTRACT_CONTROL_MODEL, .bFunctionSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL,
.bFunctionProtocol = CDC_PROTOCOL_COMMON_AT_COMMANDS, .bFunctionProtocol = CDC_COMM_PROTOCOL_ATCOMMAND,
.iFunction = 0 .iFunction = 0
}, },
@ -188,89 +199,89 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
#if TUSB_CFG_DEVICE_CDC #if TUSB_CFG_DEVICE_CDC
// USB CDC Serial Interface // USB CDC Serial Interface
// CDC Control Interface //------------- CDC Communication Interface -------------//
.CDC_CCI_Interface = .cdc_comm_interface =
{ {
.bLength = sizeof(tusb_descriptor_interface_t), .bLength = sizeof(tusb_descriptor_interface_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE, .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = INTERFACE_INDEX_CDC, .bInterfaceNumber = INTERFACE_INDEX_CDC,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 1, .bNumEndpoints = 1,
.bInterfaceClass = CDC_COMMUNICATION_INTERFACE_CLASS, .bInterfaceClass = TUSB_CLASS_CDC,
.bInterfaceSubClass = CDC_ABSTRACT_CONTROL_MODEL, .bInterfaceSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL,
.bInterfaceProtocol = CDC_PROTOCOL_COMMON_AT_COMMANDS, .bInterfaceProtocol = CDC_COMM_PROTOCOL_ATCOMMAND,
.iInterface = 0x00 .iInterface = 0x00
}, },
.CDC_Header = .cdc_header =
{ {
.bFunctionLength = sizeof(CDC_HEADER_DESCRIPTOR), .bLength = sizeof(cdc_desc_func_header_t),
.bDescriptorType = CDC_CS_INTERFACE, .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubtype = CDC_HEADER, .bDescriptorSubType = CDC_FUNC_DESC_HEADER,
.bcdCDC = 0x0120 .bcdCDC = 0x0120
}, },
.CDC_ACM = .cdc_acm =
{ {
.bFunctionLength = sizeof(CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR), .bLength = sizeof(cdc_desc_func_abstract_control_management_t),
.bDescriptorType = CDC_CS_INTERFACE, .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubtype = CDC_ABSTRACT_CONTROL_MANAGEMENT, .bDescriptorSubType = CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT,
.bmCapabilities = 0x06 // Support Send_Break and Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State .bmCapabilities = { // 0x06
.support_line_request = 1,
.support_send_break = 1
}
}, },
.CDC_Union = .cdc_union =
{ {
.sUnion = .bLength = sizeof(cdc_desc_func_union_t), // plus number of
{ .bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bFunctionLength = sizeof(CDC_UNION_1SLAVE_DESCRIPTOR), .bDescriptorSubType = CDC_FUNC_DESC_UNION,
.bDescriptorType = CDC_CS_INTERFACE, .bControlInterface = 0,
.bDescriptorSubtype = CDC_UNION, .bSubordinateInterface = 1,
.bMasterInterface = 0
},
.bSlaveInterfaces[0] = 1
}, },
.CDC_NotificationEndpoint = .cdc_endpoint_notification =
{ {
.bLength = sizeof(tusb_descriptor_endpoint_t), .bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = CDC_NOTIFICATION_EP, .bEndpointAddress = CDC_NOTIFICATION_EP,
.bmAttributes = USB_ENDPOINT_TYPE_INTERRUPT, .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
.wMaxPacketSize = CDC_NOTIFICATION_EP_MAXPACKETSIZE, .wMaxPacketSize = { .size = 0x08 },
.bInterval = 0xff // lowest polling rate .bInterval = 0x0a
}, },
// CDC Data Interface //------------- CDC Data Interface -------------//
.CDC_DCI_Interface = .cdc_data_interface =
{ {
.bLength = sizeof(tusb_descriptor_interface_t), .bLength = sizeof(tusb_descriptor_interface_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE, .bDescriptorType = TUSB_DESC_TYPE_INTERFACE,
.bInterfaceNumber = INTERFACE_INDEX_CDC+1, .bInterfaceNumber = INTERFACE_INDEX_CDC+1,
.bAlternateSetting = 0x00, .bAlternateSetting = 0x00,
.bNumEndpoints = 2, .bNumEndpoints = 2,
.bInterfaceClass = CDC_DATA_INTERFACE_CLASS, .bInterfaceClass = TUSB_CLASS_CDC_DATA,
.bInterfaceSubClass = 0, .bInterfaceSubClass = 0,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
.iInterface = 0x00 .iInterface = 0x00
}, },
.CDC_DataOutEndpoint = .cdc_endpoint_out =
{ {
.bLength = sizeof(tusb_descriptor_endpoint_t), .bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = CDC_DATA_EP_OUT, .bEndpointAddress = CDC_DATA_EP_OUT,
.bmAttributes = USB_ENDPOINT_TYPE_BULK, .bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = CDC_DATA_EP_MAXPACKET_SIZE, .wMaxPacketSize = { .size = CDC_DATA_EP_MAXPACKET_SIZE },
.bInterval = 0 .bInterval = 0
}, },
.CDC_DataInEndpoint = .cdc_endpoint_in =
{ {
.bLength = sizeof(tusb_descriptor_endpoint_t), .bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = CDC_DATA_EP_IN, .bEndpointAddress = CDC_DATA_EP_IN,
.bmAttributes = USB_ENDPOINT_TYPE_BULK, .bmAttributes = { .xfer = TUSB_XFER_BULK },
.wMaxPacketSize = CDC_DATA_EP_MAXPACKET_SIZE, .wMaxPacketSize = { .size = CDC_DATA_EP_MAXPACKET_SIZE },
.bInterval = 0 .bInterval = 0
}, },
#endif #endif
@ -305,7 +316,7 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
{ {
.bLength = sizeof(tusb_descriptor_endpoint_t), .bLength = sizeof(tusb_descriptor_endpoint_t),
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT, .bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
.bEndpointAddress = HID_KEYBOARD_EP_IN, //todo HID_KEYBOARD_EP_IN, .bEndpointAddress = HID_KEYBOARD_EP_IN, //TODO HID_KEYBOARD_EP_IN,
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
.wMaxPacketSize = { .size = 0x08 }, .wMaxPacketSize = { .size = 0x08 },
.bInterval = 0x0A .bInterval = 0x0A

View File

@ -76,6 +76,25 @@ typedef ATTR_PACKED_STRUCT(struct)
{ {
tusb_descriptor_configuration_t configuration; tusb_descriptor_configuration_t configuration;
//------------- CDC -------------//
#if TUSB_CFG_DEVICE_CDC
#if IAD_DESC_REQUIRED
tusb_descriptor_interface_association_t cdc_iad;
#endif
//CDC Control Interface
tusb_descriptor_interface_t cdc_comm_interface;
cdc_desc_func_header_t cdc_header;
cdc_desc_func_abstract_control_management_t cdc_acm;
cdc_desc_func_union_t cdc_union;
tusb_descriptor_endpoint_t cdc_endpoint_notification;
//CDC Data Interface
tusb_descriptor_interface_t cdc_data_interface;
tusb_descriptor_endpoint_t cdc_endpoint_out;
tusb_descriptor_endpoint_t cdc_endpoint_in;
#endif
//------------- HID Keyboard -------------// //------------- HID Keyboard -------------//
#if TUSB_CFG_DEVICE_HID_KEYBOARD #if TUSB_CFG_DEVICE_HID_KEYBOARD
tusb_descriptor_interface_t keyboard_interface; tusb_descriptor_interface_t keyboard_interface;