@@ -327,34 +327,35 @@ 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
+ return hub_edpt_status_xfer (dev_addr );
345
+ }
346
+
347
+ if (tu_bit_test (status_change , 0 )) {
348
+ // Hub bit 0 is for the hub device events
349
+ if (hub_port_get_status (dev_addr , 0 , & p_hub -> hub_status , hub_get_status_complete , 0 ) == false) {
345
350
//Hub status control transfer failed, retry
346
351
hub_edpt_status_xfer (dev_addr );
347
352
}
348
353
}
349
- else
350
- {
354
+ else {
351
355
// 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
- {
356
+ for (uint8_t port = 1 ; port <= p_hub -> port_count ; port ++ ) {
357
+ if ( tu_bit_test (status_change , port ) ) {
358
+ if (hub_port_get_status (dev_addr , port , & p_hub -> port_status , hub_port_get_status_complete , 0 ) == false) {
358
359
//Hub status control transfer failed, retry
359
360
hub_edpt_status_xfer (dev_addr );
360
361
}
@@ -364,7 +365,6 @@ bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32
364
365
}
365
366
366
367
// NOTE: next status transfer is queued by usbh.c after handling this request
367
-
368
368
return true;
369
369
}
370
370
0 commit comments