mirror of
https://github.com/hathach/tinyusb.git
synced 2026-02-06 16:55:53 +00:00
minor format
This commit is contained in:
@ -115,10 +115,6 @@ TU_ATTR_WEAK bool dcd_dcache_clean_invalidate(const void* addr, uint32_t data_si
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Data
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invalid driver ID in itf2drv[] ep2drv[][] mapping
|
||||
enum { DRVID_INVALID = 0xFFu };
|
||||
|
||||
typedef struct {
|
||||
struct TU_ATTR_PACKED {
|
||||
volatile uint8_t connected : 1;
|
||||
@ -343,7 +339,7 @@ enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(_usbd_driver) };
|
||||
static const usbd_class_driver_t *_app_driver = NULL;
|
||||
static uint8_t _app_driver_count = 0;
|
||||
|
||||
#define TOTAL_DRIVER_COUNT ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
|
||||
#define TOTAL_DRIVER_COUNT ((uint8_t) (_app_driver_count + BUILTIN_DRIVER_COUNT))
|
||||
|
||||
// virtually joins built-in and application drivers together.
|
||||
// Application is positioned first to allow overwriting built-in ones.
|
||||
@ -611,8 +607,8 @@ static void configuration_reset(uint8_t rhport) {
|
||||
}
|
||||
|
||||
tu_varclr(&_usbd_dev);
|
||||
(void) memset(_usbd_dev.itf2drv, DRVID_INVALID, sizeof(_usbd_dev.itf2drv)); // invalid mapping
|
||||
(void) memset(_usbd_dev.ep2drv, DRVID_INVALID, sizeof(_usbd_dev.ep2drv)); // invalid mapping
|
||||
(void)memset(_usbd_dev.itf2drv, TUSB_INDEX_INVALID_8, sizeof(_usbd_dev.itf2drv)); // invalid mapping
|
||||
(void)memset(_usbd_dev.ep2drv, TUSB_INDEX_INVALID_8, sizeof(_usbd_dev.ep2drv)); // invalid mapping
|
||||
}
|
||||
|
||||
static void usbd_reset(uint8_t rhport) {
|
||||
@ -1034,90 +1030,89 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
|
||||
// Process Set Configure Request
|
||||
// This function parse configuration descriptor & open drivers accordingly
|
||||
static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
{
|
||||
static bool process_set_config(uint8_t rhport, uint8_t cfg_num) {
|
||||
// index is cfg_num-1
|
||||
tusb_desc_configuration_t const * desc_cfg = (tusb_desc_configuration_t const *) tud_descriptor_configuration_cb(cfg_num-1);
|
||||
const tusb_desc_configuration_t *desc_cfg =
|
||||
(const tusb_desc_configuration_t *)tud_descriptor_configuration_cb(cfg_num - 1);
|
||||
TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
|
||||
|
||||
// Parse configuration descriptor
|
||||
_usbd_dev.remote_wakeup_support = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP) ? 1u : 0u;
|
||||
_usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED ) ? 1u : 0u;
|
||||
_usbd_dev.self_powered = (desc_cfg->bmAttributes & TUSB_DESC_CONFIG_ATT_SELF_POWERED) ? 1u : 0u;
|
||||
|
||||
// Parse interface descriptor
|
||||
uint8_t const * p_desc = ((uint8_t const*) desc_cfg) + sizeof(tusb_desc_configuration_t);
|
||||
uint8_t const * desc_end = ((uint8_t const*) desc_cfg) + tu_le16toh(desc_cfg->wTotalLength);
|
||||
const uint8_t *p_desc = ((const uint8_t *)desc_cfg) + sizeof(tusb_desc_configuration_t);
|
||||
const uint8_t *desc_end = ((const uint8_t *)desc_cfg) + tu_le16toh(desc_cfg->wTotalLength);
|
||||
|
||||
while( p_desc < desc_end )
|
||||
{
|
||||
while (p_desc < desc_end) {
|
||||
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) )
|
||||
{
|
||||
tusb_desc_interface_assoc_t const * desc_iad = (tusb_desc_interface_assoc_t const *) p_desc;
|
||||
assoc_itf_count = desc_iad->bInterfaceCount;
|
||||
if (TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc)) {
|
||||
const tusb_desc_interface_assoc_t *desc_iad = (const tusb_desc_interface_assoc_t *)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 &&
|
||||
// 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;
|
||||
TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc));
|
||||
const tusb_desc_interface_t *desc_itf = (const tusb_desc_interface_t *)p_desc;
|
||||
|
||||
// Find driver for this interface
|
||||
uint16_t const remaining_len = (uint16_t) (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);
|
||||
const uint16_t remaining_len = (uint16_t)(desc_end - p_desc);
|
||||
uint8_t drv_id;
|
||||
for (drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++) {
|
||||
const usbd_class_driver_t *driver = get_driver(drv_id);
|
||||
TU_ASSERT(driver);
|
||||
uint16_t const drv_len = driver->open(rhport, desc_itf, remaining_len);
|
||||
const uint16_t drv_len = driver->open(rhport, desc_itf, remaining_len);
|
||||
|
||||
if ( (sizeof(tusb_desc_interface_t) <= drv_len) && (drv_len <= remaining_len) )
|
||||
{
|
||||
if ((sizeof(tusb_desc_interface_t) <= drv_len) && (drv_len <= remaining_len)) {
|
||||
// Open successfully
|
||||
TU_LOG_USBD(" %s opened\r\n", driver->name);
|
||||
|
||||
// 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) {
|
||||
#if CFG_TUD_CDC
|
||||
if ( driver->open == cdcd_open ) {
|
||||
#if CFG_TUD_CDC
|
||||
if (driver->open == cdcd_open) {
|
||||
assoc_itf_count = 2;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MIDI
|
||||
#if CFG_TUD_MIDI
|
||||
if (driver->open == midid_open) {
|
||||
// If there is a class-compliant Audio Control Class, then 2 interfaces. Otherwise, only one
|
||||
if (TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass &&
|
||||
AUDIO_SUBCLASS_CONTROL == desc_itf->bInterfaceSubClass &&
|
||||
if (TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass &&
|
||||
AUDIO_SUBCLASS_CONTROL == desc_itf->bInterfaceSubClass &&
|
||||
AUDIO_FUNC_PROTOCOL_CODE_UNDEF == desc_itf->bInterfaceProtocol) {
|
||||
assoc_itf_count = 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_BTH && CFG_TUD_BTH_ISO_ALT_COUNT
|
||||
if ( driver->open == btd_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
|
||||
|
||||
#if CFG_TUD_AUDIO
|
||||
#if CFG_TUD_AUDIO
|
||||
if (driver->open == audiod_open) {
|
||||
// UAC1 device doesn't have IAD, needs to read AS interface count from CS AC descriptor
|
||||
if (TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass &&
|
||||
AUDIO_SUBCLASS_CONTROL == desc_itf->bInterfaceSubClass &&
|
||||
if (TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass &&
|
||||
AUDIO_SUBCLASS_CONTROL == desc_itf->bInterfaceSubClass &&
|
||||
AUDIO_FUNC_PROTOCOL_CODE_UNDEF == desc_itf->bInterfaceProtocol) {
|
||||
uint8_t const* p = tu_desc_next(p_desc);
|
||||
uint8_t const* const itf_end = p_desc + remaining_len;
|
||||
const uint8_t *p = tu_desc_next(p_desc);
|
||||
const uint8_t *const itf_end = p_desc + remaining_len;
|
||||
while (p < itf_end) {
|
||||
if (TUSB_DESC_CS_INTERFACE == tu_desc_type(p) &&
|
||||
AUDIO10_CS_AC_INTERFACE_HEADER == ((audio10_desc_cs_ac_interface_1_t const *) p)->bDescriptorSubType) {
|
||||
audio10_desc_cs_ac_interface_1_t const * p_header = (audio10_desc_cs_ac_interface_1_t const *) p;
|
||||
AUDIO10_CS_AC_INTERFACE_HEADER ==
|
||||
((const audio10_desc_cs_ac_interface_1_t *)p)->bDescriptorSubType) {
|
||||
const audio10_desc_cs_ac_interface_1_t *p_header = (const audio10_desc_cs_ac_interface_1_t *)p;
|
||||
// AC + AS interfaces
|
||||
assoc_itf_count = p_header->bInCollection + 1;
|
||||
break;
|
||||
@ -1126,16 +1121,15 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#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;
|
||||
for (uint8_t i = 0; i < assoc_itf_count; i++) {
|
||||
const uint8_t itf_num = desc_itf->bInterfaceNumber + i;
|
||||
|
||||
// Interface number must not be used already
|
||||
TU_ASSERT(DRVID_INVALID == _usbd_dev.itf2drv[itf_num]);
|
||||
TU_ASSERT(TUSB_INDEX_INVALID_8 == _usbd_dev.itf2drv[itf_num]);
|
||||
_usbd_dev.itf2drv[itf_num] = drv_id;
|
||||
}
|
||||
|
||||
@ -1363,20 +1357,17 @@ void usbd_spin_unlock(bool in_isr) {
|
||||
}
|
||||
|
||||
// Parse consecutive endpoint descriptors (IN & OUT)
|
||||
bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
|
||||
{
|
||||
for(int i=0; i<ep_count; i++)
|
||||
{
|
||||
tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
|
||||
bool usbd_open_edpt_pair(uint8_t rhport, const uint8_t *p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t *ep_out,
|
||||
uint8_t *ep_in) {
|
||||
for (int i = 0; i < ep_count; i++) {
|
||||
const tusb_desc_endpoint_t *desc_ep = (const tusb_desc_endpoint_t *)p_desc;
|
||||
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
|
||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
|
||||
|
||||
if ( tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN )
|
||||
{
|
||||
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
|
||||
(*ep_in) = desc_ep->bEndpointAddress;
|
||||
}else
|
||||
{
|
||||
} else {
|
||||
(*ep_out) = desc_ep->bEndpointAddress;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user