Merge branch 'master' into add_uvc
This commit is contained in:
@@ -215,7 +215,7 @@ static usbd_class_driver_t const _usbd_driver[] =
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_NET
|
||||
#if CFG_TUD_ECM_RNDIS || CFG_TUD_NCM
|
||||
{
|
||||
DRIVER_NAME("NET")
|
||||
.init = netd_init,
|
||||
@@ -892,7 +892,7 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
|
||||
// Parse configuration descriptor
|
||||
_usbd_dev.remote_wakeup_support = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP) ? 1 : 0;
|
||||
_usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED) ? 1 : 0;
|
||||
_usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED ) ? 1 : 0;
|
||||
|
||||
// Parse interface descriptor
|
||||
uint8_t const * p_desc = ((uint8_t const*) desc_cfg) + sizeof(tusb_desc_configuration_t);
|
||||
@@ -900,66 +900,75 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
|
||||
while( p_desc < desc_end )
|
||||
{
|
||||
tusb_desc_interface_assoc_t const * desc_iad = NULL;
|
||||
uint8_t assoc_itf_count = 1;
|
||||
|
||||
// Class will always starts with Interface Association (if any) and then Interface descriptor
|
||||
if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) )
|
||||
{
|
||||
desc_iad = (tusb_desc_interface_assoc_t const *) p_desc;
|
||||
tusb_desc_interface_assoc_t const * desc_iad = (tusb_desc_interface_assoc_t const *) p_desc;
|
||||
assoc_itf_count = desc_iad->bInterfaceCount;
|
||||
|
||||
p_desc = tu_desc_next(p_desc); // next to Interface
|
||||
|
||||
// IAD's first interface number and class should match with opened interface
|
||||
//TU_ASSERT(desc_iad->bFirstInterface == desc_itf->bInterfaceNumber &&
|
||||
// desc_iad->bFunctionClass == desc_itf->bInterfaceClass);
|
||||
}
|
||||
|
||||
TU_ASSERT( TUSB_DESC_INTERFACE == tu_desc_type(p_desc) );
|
||||
|
||||
tusb_desc_interface_t const * desc_itf = (tusb_desc_interface_t const*) p_desc;
|
||||
uint16_t const remaining_len = desc_end-p_desc;
|
||||
|
||||
// Interface number must not be used already
|
||||
TU_ASSERT(DRVID_INVALID == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber]);
|
||||
|
||||
// TODO usbd can calculate the total length used for driver --> driver open() does not need to calculate it
|
||||
// uint16_t const drv_len = tu_desc_get_interface_total_len(desc_itf, desc_iad ? desc_iad->bInterfaceCount : 1, desc_end-p_desc);
|
||||
|
||||
// Find driver for this interface
|
||||
uint16_t const remaining_len = desc_end-p_desc;
|
||||
uint8_t drv_id;
|
||||
for (drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++)
|
||||
{
|
||||
usbd_class_driver_t const *driver = get_driver(drv_id);
|
||||
uint16_t const drv_len = driver->open(rhport, desc_itf, remaining_len);
|
||||
|
||||
if ( drv_len > 0 )
|
||||
if ( (sizeof(tusb_desc_interface_t) <= drv_len) && (drv_len <= remaining_len) )
|
||||
{
|
||||
// Open successfully, check if length is correct
|
||||
TU_ASSERT( sizeof(tusb_desc_interface_t) <= drv_len && drv_len <= remaining_len);
|
||||
|
||||
// Open successfully
|
||||
TU_LOG2(" %s opened\r\n", driver->name);
|
||||
|
||||
// bind interface to found driver
|
||||
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id;
|
||||
|
||||
// If using IAD, bind all interfaces to the same driver
|
||||
if (desc_iad)
|
||||
// Some drivers use 2 or more interfaces but may not have IAD e.g MIDI (always) or
|
||||
// BTH (even CDC) with class in device descriptor (single interface)
|
||||
if ( assoc_itf_count == 1)
|
||||
{
|
||||
// IAD's first interface number and class should match with opened interface
|
||||
TU_ASSERT(desc_iad->bFirstInterface == desc_itf->bInterfaceNumber &&
|
||||
desc_iad->bFunctionClass == desc_itf->bInterfaceClass);
|
||||
#if CFG_TUD_CDC
|
||||
if ( driver->open == cdcd_open ) assoc_itf_count = 2;
|
||||
#endif
|
||||
|
||||
for(uint8_t i=1; i<desc_iad->bInterfaceCount; i++)
|
||||
{
|
||||
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber+i] = drv_id;
|
||||
}
|
||||
#if CFG_TUD_MIDI
|
||||
if ( driver->open == midid_open ) assoc_itf_count = 2;
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_BTH && CFG_TUD_BTH_ISO_ALT_COUNT
|
||||
if ( driver->open == btd_open ) assoc_itf_count = 2;
|
||||
#endif
|
||||
}
|
||||
|
||||
// bind (associated) interfaces to found driver
|
||||
for(uint8_t i=0; i<assoc_itf_count; i++)
|
||||
{
|
||||
uint8_t const itf_num = desc_itf->bInterfaceNumber+i;
|
||||
|
||||
// Interface number must not be used already
|
||||
TU_ASSERT(DRVID_INVALID == _usbd_dev.itf2drv[itf_num]);
|
||||
_usbd_dev.itf2drv[itf_num] = drv_id;
|
||||
}
|
||||
|
||||
// bind all endpoints to found driver
|
||||
tu_edpt_bind_driver(_usbd_dev.ep2drv, desc_itf, drv_len, drv_id);
|
||||
|
||||
p_desc += drv_len; // next interface
|
||||
// next Interface
|
||||
p_desc += drv_len;
|
||||
|
||||
break; // exit driver find loop
|
||||
}
|
||||
}
|
||||
|
||||
// Failed if cannot find supported driver
|
||||
// Failed if there is no supported drivers
|
||||
TU_ASSERT(drv_id < TOTAL_DRIVER_COUNT);
|
||||
}
|
||||
|
||||
|
||||
@@ -178,17 +178,18 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration & Interface Descriptor Templates
|
||||
// Configuration Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//------------- Configuration -------------//
|
||||
#define TUD_CONFIG_DESC_LEN (9)
|
||||
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
#define TUD_CONFIG_DESCRIPTOR(config_num, _itfcount, _stridx, _total_len, _attribute, _power_ma) \
|
||||
9, TUSB_DESC_CONFIGURATION, U16_TO_U8S_LE(_total_len), _itfcount, config_num, _stridx, TU_BIT(7) | _attribute, (_power_ma)/2
|
||||
|
||||
//------------- CDC -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// CDC Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Length of template descriptor: 66 bytes
|
||||
#define TUD_CDC_DESC_LEN (8+9+5+5+4+5+7+9+7+7)
|
||||
@@ -217,7 +218,9 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
//------------- MSC -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// MSC Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Length of template descriptor: 23 bytes
|
||||
#define TUD_MSC_DESC_LEN (9 + 7 + 7)
|
||||
@@ -231,7 +234,10 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
//------------- HID -------------//
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HID Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Length of template descriptor: 25 bytes
|
||||
#define TUD_HID_DESC_LEN (9 + 9 + 7)
|
||||
@@ -261,8 +267,10 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
|
||||
|
||||
//------------- MIDI -------------//
|
||||
// MIDI v1.0 is based on Audio v1.0
|
||||
//--------------------------------------------------------------------+
|
||||
// MIDI Descriptor Templates
|
||||
// Note: MIDI v1.0 is based on Audio v1.0
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define TUD_MIDI_DESC_HEAD_LEN (9 + 9 + 9 + 7)
|
||||
#define TUD_MIDI_DESC_HEAD(_itfnum, _stridx, _numcables) \
|
||||
@@ -319,7 +327,9 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
TUD_MIDI_DESC_EP(_epin, _epsize, 1),\
|
||||
TUD_MIDI_JACKID_OUT_EMB(1)
|
||||
|
||||
//------------- AUDIO -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// Audio v2.0 Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/* Standard Interface Association Descriptor (IAD) */
|
||||
#define TUD_AUDIO_DESC_IAD_LEN 8
|
||||
@@ -551,7 +561,10 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
((((_maxFrequency + ((CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED) ? 7999 : 999)) / ((CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED) ? 8000 : 1000)) + 1) * _nBytesPerSample * _nChannels)
|
||||
|
||||
|
||||
//------------- TUD_USBTMC/USB488 -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// USBTMC/USB488 Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define TUD_USBTMC_APP_CLASS (TUSB_CLASS_APPLICATION_SPECIFIC)
|
||||
#define TUD_USBTMC_APP_SUBCLASS 0x03u
|
||||
|
||||
@@ -581,8 +594,10 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
|
||||
#define TUD_USBTMC_INT_DESCRIPTOR_LEN (7u)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Vendor Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//------------- Vendor -------------//
|
||||
#define TUD_VENDOR_DESC_LEN (9+7+7)
|
||||
|
||||
// Interface number, string index, EP Out & IN address, EP size
|
||||
@@ -594,7 +609,10 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
//------------- DFU Runtime -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// DFU Runtime Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define TUD_DFU_APP_CLASS (TUSB_CLASS_APPLICATION_SPECIFIC)
|
||||
#define TUD_DFU_APP_SUBCLASS (APP_SUBCLASS_DFU_RUNTIME)
|
||||
|
||||
@@ -609,6 +627,10 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* Function */ \
|
||||
9, DFU_DESC_FUNCTIONAL, _attr, U16_TO_U8S_LE(_timeout), U16_TO_U8S_LE(_xfer_size), U16_TO_U8S_LE(0x0101)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DFU Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Length of template descriptor: 9 bytes + number of alternatives * 9
|
||||
#define TUD_DFU_DESC_LEN(_alt_count) (9 + (_alt_count) * 9)
|
||||
|
||||
@@ -654,8 +676,9 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
_TUD_DFU_ALT(_itfnum, _alt_count, _stridx), \
|
||||
_TUD_DFU_ALT_7(_itfnum, _alt_count+1, _stridx+1)
|
||||
|
||||
|
||||
//------------- CDC-ECM -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// CDC-ECM Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Length of template descriptor: 71 bytes
|
||||
#define TUD_CDC_ECM_DESC_LEN (8+9+5+5+13+7+9+9+7+7)
|
||||
@@ -684,8 +707,9 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* Endpoint Out */\
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
|
||||
//------------- RNDIS -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// RNDIS Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if 0
|
||||
/* Windows XP */
|
||||
@@ -726,7 +750,10 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
/* Endpoint Out */\
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
//------------- BT Radio -------------//
|
||||
//--------------------------------------------------------------------+
|
||||
// Bluetooth Radio Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#define TUD_BT_APP_CLASS (TUSB_CLASS_WIRELESS_CONTROLLER)
|
||||
#define TUD_BT_APP_SUBCLASS 0x01
|
||||
#define TUD_BT_PROTOCOL_PRIMARY_CONTROLLER 0x01
|
||||
@@ -777,10 +804,44 @@ TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb
|
||||
|
||||
// BT Primary controller descriptor
|
||||
// Interface number, string index, attributes, event endpoint, event endpoint size, interval, data in, data out, data endpoint size, iso endpoint sizes
|
||||
// TODO BTH should also use IAD like CDC for composite device
|
||||
#define TUD_BTH_DESCRIPTOR(_itfnum, _stridx, _ep_evt, _ep_evt_size, _ep_evt_interval, _ep_in, _ep_out, _ep_size,...) \
|
||||
TUD_BTH_PRI_ITF(_itfnum, _stridx, _ep_evt, _ep_evt_size, _ep_evt_interval, _ep_in, _ep_out, _ep_size) \
|
||||
TUD_BTH_ISO_ITFS(_itfnum + 1, _ep_in + 1, _ep_out + 1, __VA_ARGS__)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CDC-NCM Descriptor Templates
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Length of template descriptor
|
||||
#define TUD_CDC_NCM_DESC_LEN (8+9+5+5+13+6+7+9+9+7+7)
|
||||
|
||||
// CDC-ECM Descriptor Template
|
||||
// Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size.
|
||||
#define TUD_CDC_NCM_DESCRIPTOR(_itfnum, _desc_stridx, _mac_stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize, _maxsegmentsize) \
|
||||
/* Interface Association */\
|
||||
8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_NETWORK_CONTROL_MODEL, 0, 0,\
|
||||
/* CDC Control Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_NETWORK_CONTROL_MODEL, 0, _desc_stridx,\
|
||||
/* CDC-NCM Header */\
|
||||
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0110),\
|
||||
/* CDC-NCM Union */\
|
||||
5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
|
||||
/* CDC-NCM Functional Descriptor */\
|
||||
13, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ETHERNET_NETWORKING, _mac_stridx, 0, 0, 0, 0, U16_TO_U8S_LE(_maxsegmentsize), U16_TO_U8S_LE(0), 0, \
|
||||
/* CDC-NCM Functional Descriptor */\
|
||||
6, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_NCM, U16_TO_U8S_LE(0x0100), 0, \
|
||||
/* Endpoint Notification */\
|
||||
7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 50,\
|
||||
/* CDC Data Interface (default inactive) */\
|
||||
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 0, TUSB_CLASS_CDC_DATA, 0, NCM_DATA_PROTOCOL_NETWORK_TRANSFER_BLOCK, 0,\
|
||||
/* CDC Data Interface (alternative active) */\
|
||||
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 1, 2, TUSB_CLASS_CDC_DATA, 0, NCM_DATA_PROTOCOL_NETWORK_TRANSFER_BLOCK, 0,\
|
||||
/* Endpoint In */\
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
|
||||
/* Endpoint Out */\
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user