mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-16 23:43:23 +00:00
enhance cdc implementation
This commit is contained in:
parent
7928eaf58a
commit
321324a485
@ -181,7 +181,7 @@ app_descriptor_configuration_t const desc_configuration =
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0x00,
|
||||
.bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER,
|
||||
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100)
|
||||
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(500)
|
||||
},
|
||||
|
||||
#if TUSB_CFG_DEVICE_CDC
|
||||
@ -222,14 +222,22 @@ app_descriptor_configuration_t const desc_configuration =
|
||||
.bcdCDC = 0x0120
|
||||
},
|
||||
|
||||
.cdc_call =
|
||||
{
|
||||
.bLength = sizeof(cdc_desc_func_call_management_t),
|
||||
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
|
||||
.bDescriptorSubType = CDC_FUNC_DESC_CALL_MANAGEMENT,
|
||||
.bmCapabilities = { 0 },
|
||||
.bDataInterface = INTERFACE_NO_CDC+1,
|
||||
},
|
||||
|
||||
.cdc_acm =
|
||||
{
|
||||
.bLength = sizeof(cdc_desc_func_abstract_control_management_t),
|
||||
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
|
||||
.bDescriptorSubType = CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT,
|
||||
.bmCapabilities = { // 0x06
|
||||
.bmCapabilities = { // 0x02
|
||||
.support_line_request = 1,
|
||||
.support_send_break = 1
|
||||
}
|
||||
},
|
||||
|
||||
@ -238,8 +246,8 @@ app_descriptor_configuration_t const desc_configuration =
|
||||
.bLength = sizeof(cdc_desc_func_union_t), // plus number of
|
||||
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
|
||||
.bDescriptorSubType = CDC_FUNC_DESC_UNION,
|
||||
.bControlInterface = 0,
|
||||
.bSubordinateInterface = 1,
|
||||
.bControlInterface = INTERFACE_NO_CDC,
|
||||
.bSubordinateInterface = INTERFACE_NO_CDC+1,
|
||||
},
|
||||
|
||||
.cdc_endpoint_notification =
|
||||
@ -249,7 +257,7 @@ app_descriptor_configuration_t const desc_configuration =
|
||||
.bEndpointAddress = CDC_EDPT_NOTIFICATION_ADDR,
|
||||
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
|
||||
.wMaxPacketSize = { .size = 0x08 },
|
||||
.bInterval = 0x0a
|
||||
.bInterval = 0x10
|
||||
},
|
||||
|
||||
//------------- CDC Data Interface -------------//
|
||||
|
@ -130,7 +130,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// CONFIGURATION DESCRIPTOR
|
||||
//--------------------------------------------------------------------+
|
||||
typedef ATTR_PACKED_STRUCT(struct)
|
||||
typedef struct ATTR_PACKED
|
||||
{
|
||||
tusb_descriptor_configuration_t configuration;
|
||||
|
||||
@ -141,6 +141,7 @@ typedef ATTR_PACKED_STRUCT(struct)
|
||||
//CDC Control Interface
|
||||
tusb_descriptor_interface_t cdc_comm_interface;
|
||||
cdc_desc_func_header_t cdc_header;
|
||||
cdc_desc_func_call_management_t cdc_call;
|
||||
cdc_desc_func_abstract_control_management_t cdc_acm;
|
||||
cdc_desc_func_union_t cdc_union;
|
||||
tusb_descriptor_endpoint_t cdc_endpoint_notification;
|
||||
|
@ -103,7 +103,13 @@ void cdcd_init(void)
|
||||
|
||||
// default line coding is : stop bit = 1, parity = none, data bits = 8
|
||||
memclr_(cdcd_line_coding, sizeof(cdc_line_coding_t)*CONTROLLER_DEVICE_NUMBER);
|
||||
for(uint8_t i=0; i<CONTROLLER_DEVICE_NUMBER; i++) cdcd_line_coding[i].data_bits = 8;
|
||||
for(uint8_t i=0; i<CONTROLLER_DEVICE_NUMBER; i++)
|
||||
{
|
||||
cdcd_line_coding[i].bit_rate = 115200;
|
||||
cdcd_line_coding[i].stop_bits = 0;
|
||||
cdcd_line_coding[i].parity = 0;
|
||||
cdcd_line_coding[i].data_bits = 8;
|
||||
}
|
||||
}
|
||||
|
||||
tusb_error_t cdcd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
|
||||
@ -195,6 +201,24 @@ tusb_error_t cdcd_control_request_subtask(uint8_t coreid, tusb_control_request_t
|
||||
break;
|
||||
|
||||
case CDC_REQUEST_SET_CONTROL_LINE_STATE: // TODO extract DTE present
|
||||
{
|
||||
enum {
|
||||
ACTIVE_DTE_PRESENT = 0x0003,
|
||||
ACTIVE_DTE_NOT_PRESENT = 0x0002
|
||||
};
|
||||
|
||||
if (p_request->wValue == ACTIVE_DTE_PRESENT)
|
||||
{
|
||||
// terminal connected
|
||||
}
|
||||
else if (p_request->wValue == ACTIVE_DTE_NOT_PRESENT)
|
||||
{
|
||||
// terminal disconnected
|
||||
}else
|
||||
{
|
||||
// De-active --> disconnected
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
|
||||
|
@ -244,7 +244,7 @@ tusb_error_t usbd_control_request_subtask(uint8_t coreid, tusb_control_request_t
|
||||
tusb_error_t error;
|
||||
error = TUSB_ERROR_NONE;
|
||||
|
||||
//------------- Standard Control such as those in enumeration -------------//
|
||||
//------------- Standard Control e.g in enumeration -------------//
|
||||
if( TUSB_REQUEST_RECIPIENT_DEVICE == p_request->bmRequestType_bit.recipient &&
|
||||
TUSB_REQUEST_TYPE_STANDARD == p_request->bmRequestType_bit.type )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user