summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-03-07 11:01:23 +0700
committerhathach <[email protected]>2018-03-07 11:01:23 +0700
commit321324a485190a9dce2c49ef7019fc0eda83299b (patch)
tree26273c02d1aa5585b842c9e69a55c0ec54e272ab
parent7928eaf58a7ef4bd34ac14a2f82102d41484e817 (diff)
enhance cdc implementation
-rw-r--r--examples/device/src/tusb_descriptors.c20
-rw-r--r--examples/device/src/tusb_descriptors.h3
-rw-r--r--tinyusb/class/cdc/cdc_device.c26
-rw-r--r--tinyusb/device/usbd.c2
4 files changed, 42 insertions, 9 deletions
diff --git a/examples/device/src/tusb_descriptors.c b/examples/device/src/tusb_descriptors.c
index 4a58161f1..82d9d1fbe 100644
--- a/examples/device/src/tusb_descriptors.c
+++ b/examples/device/src/tusb_descriptors.c
@@ -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 -------------//
diff --git a/examples/device/src/tusb_descriptors.h b/examples/device/src/tusb_descriptors.h
index e6a9c01a2..322af0392 100644
--- a/examples/device/src/tusb_descriptors.h
+++ b/examples/device/src/tusb_descriptors.h
@@ -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;
diff --git a/tinyusb/class/cdc/cdc_device.c b/tinyusb/class/cdc/cdc_device.c
index 9867b9e6c..f15255e4a 100644
--- a/tinyusb/class/cdc/cdc_device.c
+++ b/tinyusb/class/cdc/cdc_device.c
@@ -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;
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c
index 4b3620abf..936fd78f1 100644
--- a/tinyusb/device/usbd.c
+++ b/tinyusb/device/usbd.c
@@ -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 )
{