rename cdc descriptor type

add tusbh_cdc_mounted_isr & tusbh_cdc_unmounted_isr
This commit is contained in:
hathach 2013-07-03 10:53:16 +07:00
parent 539c7cdbe1
commit b3f98bc15a
7 changed files with 58 additions and 45 deletions

View File

@ -58,19 +58,22 @@ static uint8_t buffer_in[64] TUSB_CFG_ATTR_USBRAM;
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
void tusbh_cdc_mounted_isr(uint8_t dev_addr)
{
// application set-up
osal_queue_flush(queue_hdl);
tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true); // first report
}
void tusbh_cdc_unmounted_isr(uint8_t dev_addr)
{
// application tear-down
}
void tusbh_cdc_isr(uint8_t dev_addr, tusb_event_t event)
{
switch(event)
{
case TUSB_EVENT_INTERFACE_OPEN: // application set-up
osal_queue_flush(queue_hdl);
tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true); // first report
break;
case TUSB_EVENT_INTERFACE_CLOSE: // application tear-down
break;
case TUSB_EVENT_XFER_COMPLETE:
// osal_queue_send(queue_hdl, &usb_keyboard_report);
tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true);

View File

@ -90,7 +90,7 @@ const cdc_configuration_desc_t cdc_config_descriptor =
.cdc_header =
{
.bLength = sizeof(tusb_cdc_func_header_t),
.bLength = sizeof(cdc_desc_func_header_t),
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubType = CDC_FUNC_DESC_HEADER,
.bcdCDC = 0x0120
@ -98,7 +98,7 @@ const cdc_configuration_desc_t cdc_config_descriptor =
.cdc_acm =
{
.bLength = sizeof(tusb_cdc_func_abstract_control_management_t),
.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
@ -109,7 +109,7 @@ const cdc_configuration_desc_t cdc_config_descriptor =
.cdc_union =
{
.bLength = sizeof(tusb_cdc_func_union_t), // plus number of
.bLength = sizeof(cdc_desc_func_union_t), // plus number of
.bDescriptorType = TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC,
.bDescriptorSubType = CDC_FUNC_DESC_UNION,
.bControlInterface = 1,

View File

@ -61,9 +61,9 @@ typedef struct
//CDC Control Interface
tusb_descriptor_interface_t cdc_comm_interface;
tusb_cdc_func_header_t cdc_header;
tusb_cdc_func_abstract_control_management_t cdc_acm;
tusb_cdc_func_union_t cdc_union;
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

View File

@ -117,8 +117,8 @@ void test_cdch_open_length_check(void)
{
const uint16_t expected_length =
//------------- Comm Interface -------------//
sizeof(tusb_descriptor_interface_t) + sizeof(tusb_cdc_func_header_t) +
sizeof(tusb_cdc_func_abstract_control_management_t) + sizeof(tusb_cdc_func_union_t) +
sizeof(tusb_descriptor_interface_t) + sizeof(cdc_desc_func_header_t) +
sizeof(cdc_desc_func_abstract_control_management_t) + sizeof(cdc_desc_func_union_t) +
sizeof(tusb_descriptor_endpoint_t) +
//------------- Data Interface -------------//
sizeof(tusb_descriptor_interface_t) + 2*sizeof(tusb_descriptor_endpoint_t);

View File

@ -184,7 +184,7 @@ typedef enum {
GET_ATM_VC_STATISTICS = 0x53,
MDLM_SEMANTIC_MODEL = 0x60,
}tusb_cdc_management_request_t;
}cdc_management_request_t;
//--------------------------------------------------------------------+
// MANAGEMENT ELEMENENT NOTIFICATION (NOTIFICATION ENDPOINT)
@ -202,7 +202,7 @@ typedef enum {
LINE_STATE_CHANGE = 0x29,
CONNECTION_SPEED_CHANGE = 0x2A,
MDLM_SEMANTIC_MODEL_NOTIFICATION = 0x40,
}tusb_cdc_notification_t;
}cdc_notification_request_t;
//--------------------------------------------------------------------+
// FUNCTIONAL DESCRIPTOR
@ -211,8 +211,8 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
uint16_t bcdCDC ; ///< CDC release number in Binary-Coded Decimal
}tusb_cdc_func_header_t;
uint16_t bcdCDC ; ///< CDC release number in Binary-Coded Decimal
}cdc_desc_func_header_t;
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
@ -220,9 +220,9 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
uint8_t bControlInterface ; ///< Interface number of Communication Interface
uint8_t bSubordinateInterface ; ///< Array of Interface number of Data Interface
}tusb_cdc_func_union_t;
}cdc_desc_func_union_t;
#define tusb_cdc_func_union_n_t(no_slave)\
#define cdc_desc_func_union_n_t(no_slave)\
ATTR_PACKED_STRUCT(struct) { \
uint8_t bLength ;\
uint8_t bDescriptorType ;\
@ -237,9 +237,9 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
uint8_t iCountryCodeRelDate ; ///< Index of a string giving the release date for the implemented ISO 3166 Country Codes.
uint16_t wCountryCode[] ; ///< Country code in the format as defined in [ISO3166], release date as specified inoffset 3 for the first supported country.
}tusb_cdc_func_country_selection_t;
}cdc_desc_func_country_selection_t;
#define tusb_cdc_func_country_selection_n_t(no_country) \
#define cdc_desc_func_country_selection_n_t(no_country) \
ATTR_PACKED_STRUCT(struct) {\
uint8_t bLength ;\
uint8_t bDescriptorType ;\
@ -263,7 +263,7 @@ typedef ATTR_PACKED_STRUCT(struct) {
} bmCapabilities;
uint8_t bDataInterface;
}tusb_cdc_func_call_management_t;
}cdc_desc_func_call_management_t;
typedef struct {
uint8_t support_comm_request : 1; ///< Device supports the request combination of Set_Comm_Feature, Clear_Comm_Feature, and Get_Comm_Feature.
@ -271,16 +271,16 @@ typedef struct {
uint8_t support_send_break : 1; ///< Device supports the request Send_Break
uint8_t support_notification_network_connection : 1; ///< Device supports the notification Network_Connection.
uint8_t : 0;
}cdc_fun_acm_capability_t;
}cdc_acm_capability_t;
STATIC_ASSERT(sizeof(cdc_fun_acm_capability_t) == 1, "mostly problem with compiler");
STATIC_ASSERT(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compiler");
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
cdc_fun_acm_capability_t bmCapabilities ;
}tusb_cdc_func_abstract_control_management_t;
cdc_acm_capability_t bmCapabilities ;
}cdc_desc_func_abstract_control_management_t;
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
@ -292,7 +292,7 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint8_t support_pulse_request : 1; ///< Device supports the request combination of Pulse_Setup, Send_Pulse, and Set_Pulse_Time.
uint8_t : 0;
} bmCapabilities;
}tusb_cdc_func_direct_line_management_t;
}cdc_desc_func_direct_line_management_t;
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
@ -300,7 +300,7 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
uint8_t bRingerVolSteps ;
uint8_t bNumRingerPatterns ;
}tusb_cdc_func_telephone_ringer_t;
}cdc_desc_func_telephone_ringer_t;
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
@ -312,7 +312,7 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint8_t computer_centric_mode : 1;
uint8_t : 0;
} bmCapabilities;
}tusb_cdc_func_telephone_operational_modes_t;
}cdc_desc_func_telephone_operational_modes_t;
typedef ATTR_PACKED_STRUCT(struct) {
uint8_t bLength ; ///< Size of this descriptor in bytes.
@ -327,10 +327,10 @@ typedef ATTR_PACKED_STRUCT(struct) {
uint32_t line_state_change : 1; ///< 0 : Does not support line state change notification. 1 : Does support line state change notification
uint32_t : 0;
} bmCapabilities;
}tusb_cdc_func_telephone_call_state_reporting_capabilities_t;
}cdc_desc_func_telephone_call_state_reporting_capabilities_t;
static inline uint8_t functional_desc_typeof(uint8_t const * p_desc) ATTR_PURE ATTR_ALWAYS_INLINE;
static inline uint8_t functional_desc_typeof(uint8_t const * p_desc)
static inline uint8_t cdc_functional_desc_typeof(uint8_t const * p_desc) ATTR_PURE ATTR_ALWAYS_INLINE;
static inline uint8_t cdc_functional_desc_typeof(uint8_t const * p_desc)
{
return p_desc[2];
}

View File

@ -134,9 +134,9 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
while( TUSB_DESC_TYPE_INTERFACE_CLASS_SPECIFIC == p_desc[DESCRIPTOR_OFFSET_TYPE] )
{ // Communication Functional Descriptors
if ( CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT == functional_desc_typeof(p_desc) )
if ( CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT == cdc_functional_desc_typeof(p_desc) )
{ // save ACM bmCapabilities
p_cdc->acm_capability = ((tusb_cdc_func_abstract_control_management_t const *) p_desc)->bmCapabilities;
p_cdc->acm_capability = ((cdc_desc_func_abstract_control_management_t const *) p_desc)->bmCapabilities;
}
(*p_length) += p_desc[DESCRIPTOR_OFFSET_LENGTH];
@ -178,9 +178,9 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
}
// FIXME mounted class flag is not set yet
if (tusbh_cdc_isr)
if (tusbh_cdc_mounted_isr)
{
tusbh_cdc_isr(dev_addr, TUSB_EVENT_INTERFACE_OPEN);
tusbh_cdc_mounted_isr(dev_addr);
}
return TUSB_ERROR_NONE;
@ -217,9 +217,9 @@ void cdch_close(uint8_t dev_addr)
memclr_(p_cdc, sizeof(cdch_data_t));
if (tusbh_cdc_isr)
if (tusbh_cdc_unmounted_isr)
{
tusbh_cdc_isr(dev_addr, TUSB_EVENT_INTERFACE_CLOSE);
tusbh_cdc_unmounted_isr(dev_addr);
}
ASSERT(err1 == TUSB_ERROR_NONE &&

View File

@ -54,15 +54,25 @@
extern "C" {
#endif
typedef enum {
CDC_PIPE_NOTIFICATION = 1,
CDC_PIPE_DATA_IN,
CDC_PIPE_DATA_OUT
}cdc_pipeid_t;
//--------------------------------------------------------------------+
// APPLICATION PUBLIC API
//--------------------------------------------------------------------+
bool tusbh_cdc_serial_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
bool tusbh_cdc_rndis_is_mounted(uint8_t dev_addr) ATTR_PURE ATTR_WARN_UNUSED_RESULT;
void tusbh_cdc_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK;
tusb_error_t tusbh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify);
tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify);
//------------- Application Callback -------------//
void tusbh_cdc_mounted_isr(uint8_t dev_addr) ATTR_WEAK;
void tusbh_cdc_unmounted_isr(uint8_t dev_addr) ATTR_WEAK;
void tusbh_cdc_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK;
void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK;
//--------------------------------------------------------------------+
// USBH-CLASS API
//--------------------------------------------------------------------+
@ -71,7 +81,7 @@ tusb_error_t tusbh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t lengt
typedef struct {
uint8_t interface_number;
uint8_t interface_protocol;
cdc_fun_acm_capability_t acm_capability;
cdc_acm_capability_t acm_capability;
pipe_handle_t pipe_notification, pipe_out, pipe_in;