summaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
Diffstat (limited to 'src/device')
-rw-r--r--src/device/usbd.c86
1 files changed, 20 insertions, 66 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 8b4f4e7e3..e12dafcfd 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -274,7 +274,6 @@ static osal_mutex_t _usbd_mutex;
//--------------------------------------------------------------------+
// Prototypes
//--------------------------------------------------------------------+
-static void mark_interface_endpoint(uint8_t ep2drv[][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id);
static bool process_control_request(uint8_t rhport, tusb_control_request_t const * p_request);
static bool process_set_config(uint8_t rhport, uint8_t cfg_num);
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request);
@@ -857,12 +856,12 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
while( p_desc < desc_end )
{
- tusb_desc_interface_assoc_t const * desc_itf_assoc = NULL;
+ tusb_desc_interface_assoc_t const * desc_iad = NULL;
// Class will always starts with Interface Association (if any) and then Interface descriptor
if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) )
{
- desc_itf_assoc = (tusb_desc_interface_assoc_t const *) p_desc;
+ desc_iad = (tusb_desc_interface_assoc_t const *) p_desc;
p_desc = tu_desc_next(p_desc); // next to Interface
}
@@ -871,6 +870,13 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
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
uint8_t drv_id;
for (drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++)
{
@@ -882,30 +888,30 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
// Open successfully, check if length is correct
TU_ASSERT( sizeof(tusb_desc_interface_t) <= drv_len && drv_len <= remaining_len);
- // Interface number must not be used already
- TU_ASSERT(DRVID_INVALID == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber]);
-
TU_LOG2(" %s opened\r\n", driver->name);
+
+ // bind interface to found driver
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id;
- // If IAD exist, assign all interfaces to the same driver
- if (desc_itf_assoc)
+ // If using IAD, bind all interfaces to the same driver
+ if (desc_iad)
{
// IAD's first interface number and class should match with opened interface
- TU_ASSERT(desc_itf_assoc->bFirstInterface == desc_itf->bInterfaceNumber &&
- desc_itf_assoc->bFunctionClass == desc_itf->bInterfaceClass);
+ TU_ASSERT(desc_iad->bFirstInterface == desc_itf->bInterfaceNumber &&
+ desc_iad->bFunctionClass == desc_itf->bInterfaceClass);
- for(uint8_t i=1; i<desc_itf_assoc->bInterfaceCount; i++)
+ for(uint8_t i=1; i<desc_iad->bInterfaceCount; i++)
{
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber+i] = drv_id;
}
}
- mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, drv_len, drv_id); // TODO refactor
+ // 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
- break;
+ break; // exit driver find loop
}
}
@@ -919,25 +925,6 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
return true;
}
-// Helper marking endpoint of interface belongs to class driver
-static void mark_interface_endpoint(uint8_t ep2drv[][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id)
-{
- uint16_t len = 0;
-
- while( len < desc_len )
- {
- if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
- {
- uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress;
-
- ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = driver_id;
- }
-
- len = (uint16_t)(len + tu_desc_len(p_desc));
- p_desc = tu_desc_next(p_desc);
- }
-}
-
// return descriptor's buffer and update desc_len
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request)
{
@@ -1177,41 +1164,8 @@ void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr)
bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep)
{
- uint16_t const max_packet_size = tu_le16toh(desc_ep->wMaxPacketSize.size);
-
- TU_LOG2(" Open EP %02X with Size = %u\r\n", desc_ep->bEndpointAddress, max_packet_size);
TU_ASSERT(tu_edpt_number(desc_ep->bEndpointAddress) < CFG_TUD_ENDPPOINT_MAX);
-
- switch (desc_ep->bmAttributes.xfer)
- {
- case TUSB_XFER_ISOCHRONOUS:
- {
- uint16_t const spec_size = (_usbd_dev.speed == TUSB_SPEED_HIGH ? 1024 : 1023);
- TU_ASSERT(max_packet_size <= spec_size);
- }
- break;
-
- case TUSB_XFER_BULK:
- if (_usbd_dev.speed == TUSB_SPEED_HIGH)
- {
- // Bulk highspeed must be EXACTLY 512
- TU_ASSERT(max_packet_size == 512);
- }else
- {
- // TODO Bulk fullspeed can only be 8, 16, 32, 64
- TU_ASSERT(max_packet_size <= 64);
- }
- break;
-
- case TUSB_XFER_INTERRUPT:
- {
- uint16_t const spec_size = (_usbd_dev.speed == TUSB_SPEED_HIGH ? 1024 : 64);
- TU_ASSERT(max_packet_size <= spec_size);
- }
- break;
-
- default: return false;
- }
+ TU_ASSERT(tu_edpt_validate(desc_ep, (tusb_speed_t) _usbd_dev.speed));
return dcd_edpt_open(rhport, desc_ep);
}