Merge pull request #3118 from ZakDanger/vendor_device_fix
vendor device open fix for descriptor parsing
This commit is contained in:
32
src/class/vendor/vendor_device.c
vendored
32
src/class/vendor/vendor_device.c
vendored
@@ -197,7 +197,7 @@ void vendord_reset(uint8_t rhport) {
|
|||||||
uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) {
|
uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) {
|
||||||
TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == desc_itf->bInterfaceClass, 0);
|
TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == desc_itf->bInterfaceClass, 0);
|
||||||
const uint8_t* p_desc = tu_desc_next(desc_itf);
|
const uint8_t* p_desc = tu_desc_next(desc_itf);
|
||||||
const uint8_t* desc_end = (uint8_t const*)desc_itf + max_len;
|
const uint8_t* desc_end = (const uint8_t*)desc_itf + max_len;
|
||||||
|
|
||||||
// Find available interface
|
// Find available interface
|
||||||
vendord_interface_t* p_vendor = NULL;
|
vendord_interface_t* p_vendor = NULL;
|
||||||
@@ -210,26 +210,18 @@ uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uin
|
|||||||
TU_VERIFY(p_vendor, 0);
|
TU_VERIFY(p_vendor, 0);
|
||||||
|
|
||||||
p_vendor->itf_num = desc_itf->bInterfaceNumber;
|
p_vendor->itf_num = desc_itf->bInterfaceNumber;
|
||||||
uint8_t found_ep = 0;
|
while (TUSB_DESC_INTERFACE != tu_desc_type(p_desc) && (desc_end - p_desc > 0)) {
|
||||||
while (found_ep < desc_itf->bNumEndpoints) {
|
if (TUSB_DESC_ENDPOINT == tu_desc_type(p_desc)) {
|
||||||
// skip non-endpoint descriptors
|
const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
|
||||||
while ( (TUSB_DESC_ENDPOINT != tu_desc_type(p_desc)) && (p_desc < desc_end) ) {
|
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
|
||||||
p_desc = tu_desc_next(p_desc);
|
|
||||||
}
|
|
||||||
if (p_desc >= desc_end) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
|
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
|
||||||
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
|
tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
|
||||||
found_ep++;
|
tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
|
||||||
|
} else {
|
||||||
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
|
tu_edpt_stream_open(&p_vendor->rx.stream, desc_ep);
|
||||||
tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
|
TU_ASSERT(tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream) > 0, 0); // prepare for incoming data
|
||||||
tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
|
}
|
||||||
} else {
|
|
||||||
tu_edpt_stream_open(&p_vendor->rx.stream, desc_ep);
|
|
||||||
TU_ASSERT(tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream) > 0, 0); // prepare for incoming data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p_desc = tu_desc_next(p_desc);
|
p_desc = tu_desc_next(p_desc);
|
||||||
|
Reference in New Issue
Block a user