changing usbd driver open() return type, add max_len

only done with cdc and msc, push this interim for feedback first
This commit is contained in:
hathach
2020-05-27 19:01:59 +07:00
parent de88294e05
commit e340404968
5 changed files with 54 additions and 42 deletions

View File

@@ -85,13 +85,13 @@ typedef struct
char const* name;
#endif
void (* init ) (void);
void (* reset ) (uint8_t rhport);
bool (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length);
bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request);
bool (* control_complete ) (uint8_t rhport, tusb_control_request_t const * request);
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
void (* sof ) (uint8_t rhport); /* optional */
void (* init ) (void);
void (* reset ) (uint8_t rhport);
uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request);
bool (* control_complete ) (uint8_t rhport, tusb_control_request_t const * request);
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
void (* sof ) (uint8_t rhport); /* optional */
} usbd_class_driver_t;
static usbd_class_driver_t const _usbd_driver[] =
@@ -713,6 +713,8 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
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;
uint8_t drv_id;
uint16_t drv_len;
@@ -720,13 +722,17 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
{
usbd_class_driver_t const *driver = &_usbd_driver[drv_id];
drv_len = 0;
if ( driver->open(rhport, desc_itf, &drv_len) )
drv_len = driver->open(rhport, desc_itf, remaining_len);
if ( drv_len > 0 )
{
// 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", _usbd_driver[drv_id].name);
TU_LOG2(" %s opened\r\n", driver->name);
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id;
// If IAD exist, assign all interfaces to the same driver
@@ -748,8 +754,8 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
}
}
// Assert if cannot find supported driver
TU_ASSERT( drv_id < USBD_CLASS_DRIVER_COUNT && drv_len >= sizeof(tusb_desc_interface_t) );
// Failed if cannot find supported driver
TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT);
mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, drv_len, drv_id); // TODO refactor