@@ -197,7 +197,7 @@ void vendord_reset(uint8_t rhport) {
197
197
uint16_t vendord_open (uint8_t rhport , const tusb_desc_interface_t * desc_itf , uint16_t max_len ) {
198
198
TU_VERIFY (TUSB_CLASS_VENDOR_SPECIFIC == desc_itf -> bInterfaceClass , 0 );
199
199
const uint8_t * p_desc = tu_desc_next (desc_itf );
200
- const uint8_t * desc_end = (uint8_t const * )desc_itf + max_len ;
200
+ const uint8_t * desc_end = (const uint8_t * )desc_itf + max_len ;
201
201
202
202
// Find available interface
203
203
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
210
210
TU_VERIFY (p_vendor , 0 );
211
211
212
212
p_vendor -> itf_num = desc_itf -> bInterfaceNumber ;
213
- uint8_t found_ep = 0 ;
214
- while (found_ep < desc_itf -> bNumEndpoints ) {
215
- // skip non-endpoint descriptors
216
- while ( (TUSB_DESC_ENDPOINT != tu_desc_type (p_desc )) && (p_desc < desc_end ) ) {
217
- p_desc = tu_desc_next (p_desc );
218
- }
219
- if (p_desc >= desc_end ) {
220
- break ;
221
- }
222
-
223
- const tusb_desc_endpoint_t * desc_ep = (const tusb_desc_endpoint_t * ) p_desc ;
224
- TU_ASSERT (usbd_edpt_open (rhport , desc_ep ));
225
- found_ep ++ ;
226
-
227
- if (tu_edpt_dir (desc_ep -> bEndpointAddress ) == TUSB_DIR_IN ) {
228
- tu_edpt_stream_open (& p_vendor -> tx .stream , desc_ep );
229
- tud_vendor_n_write_flush ((uint8_t )(p_vendor - _vendord_itf ));
230
- } else {
231
- tu_edpt_stream_open (& p_vendor -> rx .stream , desc_ep );
232
- TU_ASSERT (tu_edpt_stream_read_xfer (rhport , & p_vendor -> rx .stream ) > 0 , 0 ); // prepare for incoming data
213
+ while (TUSB_DESC_INTERFACE != tu_desc_type (p_desc ) && (desc_end - p_desc > 0 )) {
214
+ if (TUSB_DESC_ENDPOINT == tu_desc_type (p_desc )) {
215
+ const tusb_desc_endpoint_t * desc_ep = (const tusb_desc_endpoint_t * ) p_desc ;
216
+ TU_ASSERT (usbd_edpt_open (rhport , desc_ep ));
217
+
218
+ if (tu_edpt_dir (desc_ep -> bEndpointAddress ) == TUSB_DIR_IN ) {
219
+ tu_edpt_stream_open (& p_vendor -> tx .stream , desc_ep );
220
+ tud_vendor_n_write_flush ((uint8_t )(p_vendor - _vendord_itf ));
221
+ } else {
222
+ tu_edpt_stream_open (& p_vendor -> rx .stream , desc_ep );
223
+ TU_ASSERT (tu_edpt_stream_read_xfer (rhport , & p_vendor -> rx .stream ) > 0 , 0 ); // prepare for incoming data
224
+ }
233
225
}
234
226
235
227
p_desc = tu_desc_next (p_desc );
0 commit comments