@@ -327,51 +327,45 @@ static void connection_clear_conn_change_complete (tuh_xfer_t* xfer);
327
327
static void connection_port_reset_complete (tuh_xfer_t * xfer );
328
328
329
329
// callback as response of interrupt endpoint polling
330
- bool hub_xfer_cb (uint8_t dev_addr , uint8_t ep_addr , xfer_result_t result , uint32_t xferred_bytes )
331
- {
330
+ bool hub_xfer_cb (uint8_t dev_addr , uint8_t ep_addr , xfer_result_t result , uint32_t xferred_bytes ) {
332
331
(void ) xferred_bytes ; // TODO can be more than 1 for hub with lots of ports
333
332
(void ) ep_addr ;
334
333
TU_ASSERT (result == XFER_RESULT_SUCCESS );
335
334
336
335
hub_interface_t * p_hub = get_itf (dev_addr );
337
336
338
- TU_LOG2 (" Hub Status Change = 0x%02X\r\n" , p_hub -> status_change );
337
+ uint8_t const status_change = p_hub -> status_change ;
338
+ TU_LOG2 (" Hub Status Change = 0x%02X\r\n" , status_change );
339
339
340
- // Hub bit 0 is for the hub device events
341
- if (tu_bit_test (p_hub -> status_change , 0 ))
342
- {
343
- if (hub_port_get_status (dev_addr , 0 , & p_hub -> hub_status , hub_get_status_complete , 0 ) == false)
344
- {
340
+ if ( status_change == 0 ) {
341
+ // The status change event was neither for the hub, nor for any of its ports.
342
+ // This shouldn't happen, but it does with some devices.
343
+ // Initiate the next interrupt poll here.
344
+ hub_edpt_status_xfer (dev_addr );
345
+ return true;
346
+ }
347
+
348
+ if (tu_bit_test (status_change , 0 )) {
349
+ // Hub bit 0 is for the hub device events
350
+ if (hub_port_get_status (dev_addr , 0 , & p_hub -> hub_status , hub_get_status_complete , 0 ) == false) {
345
351
//Hub status control transfer failed, retry
346
352
hub_edpt_status_xfer (dev_addr );
347
353
}
348
354
}
349
- else
350
- {
355
+ else {
351
356
// Hub bits 1 to n are hub port events
352
- for (uint8_t port = 1 ; port <= p_hub -> port_count ; port ++ )
353
- {
354
- if ( tu_bit_test (p_hub -> status_change , port ) )
355
- {
356
- if (hub_port_get_status (dev_addr , port , & p_hub -> port_status , hub_port_get_status_complete , 0 ) == false)
357
- {
357
+ for (uint8_t port = 1 ; port <= p_hub -> port_count ; port ++ ) {
358
+ if ( tu_bit_test (status_change , port ) ) {
359
+ if (hub_port_get_status (dev_addr , port , & p_hub -> port_status , hub_port_get_status_complete , 0 ) == false) {
358
360
//Hub status control transfer failed, retry
359
361
hub_edpt_status_xfer (dev_addr );
360
362
}
361
363
break ;
362
364
}
363
365
}
364
-
365
- // The status change event was neither for the hub, nor for any of
366
- // its ports. (For example `p_hub->status_change == 0`.) This
367
- // shouldn't happen, but it does with some devices. Initiate the
368
- // next interrupt poll here, because we've scheduled no other work
369
- // whose completion can initiate it.
370
- hub_edpt_status_xfer (dev_addr );
371
366
}
372
367
373
368
// NOTE: next status transfer is queued by usbh.c after handling this request
374
-
375
369
return true;
376
370
}
377
371
0 commit comments