@@ -125,6 +125,7 @@ typedef struct {
125125// Invalid driver ID in itf2drv[] ep2drv[][] mapping
126126enum { DRVID_INVALID = 0xFFu };
127127enum { ADDR_INVALID = 0xFFu };
128+ enum { CONTROLLER_INVALID = 0xFFu };
128129
129130#if CFG_TUSB_DEBUG >= 2
130131 #define DRIVER_NAME (_name ) .name = _name,
@@ -203,7 +204,7 @@ enum { CONFIG_NUM = 1 }; // default to use configuration 1
203204// sum of end device + hub
204205#define TOTAL_DEVICES (CFG_TUH_DEVICE_MAX + CFG_TUH_HUB)
205206
206- static bool _usbh_initialized = false ;
207+ static uint8_t _usbh_controller = CONTROLLER_INVALID ;
207208
208209// Device with address = 0 for enumeration
209210static usbh_dev0_t _dev0 ;
@@ -280,8 +281,8 @@ void osal_task_delay(uint32_t msec)
280281{
281282 (void ) msec ;
282283
283- const uint32_t start = hcd_frame_number (TUH_OPT_RHPORT );
284- while ( ( hcd_frame_number (TUH_OPT_RHPORT ) - start ) < msec ) {}
284+ const uint32_t start = hcd_frame_number (_usbh_controller );
285+ while ( ( hcd_frame_number (_usbh_controller ) - start ) < msec ) {}
285286}
286287#endif
287288
@@ -335,15 +336,15 @@ static void clear_device(usbh_device_t* dev)
335336
336337bool tuh_inited (void )
337338{
338- return _usbh_initialized ;
339+ return _usbh_controller != CONTROLLER_INVALID ;
339340}
340341
341- bool tuh_init (uint8_t rhport )
342+ bool tuh_init (uint8_t controller_id )
342343{
343344 // skip if already initialized
344- if (_usbh_initialized ) return _usbh_initialized ;
345+ if ( tuh_inited () ) return true ;
345346
346- TU_LOG2 ("USBH init rhport %u\r\n" , rhport );
347+ TU_LOG2 ("USBH init on controller %u\r\n" , controller_id );
347348 TU_LOG2_INT (sizeof (usbh_device_t ));
348349 TU_LOG2_INT (sizeof (hcd_event_t ));
349350 TU_LOG2_INT (sizeof (_ctrl_xfer ));
@@ -376,10 +377,11 @@ bool tuh_init(uint8_t rhport)
376377 usbh_class_drivers [drv_id ].init ();
377378 }
378379
379- TU_ASSERT (hcd_init (rhport ));
380- hcd_int_enable (rhport );
380+ _usbh_controller = controller_id ;;
381+
382+ TU_ASSERT (hcd_init (controller_id ));
383+ hcd_int_enable (controller_id );
381384
382- _usbh_initialized = true;
383385 return true;
384386}
385387
@@ -721,13 +723,13 @@ uint8_t* usbh_get_enum_buf(void)
721723
722724void usbh_int_set (bool enabled )
723725{
724- // TODO all host controller
726+ // TODO all host controller if multiple is used
725727 if (enabled )
726728 {
727- hcd_int_enable (TUH_OPT_RHPORT );
729+ hcd_int_enable (_usbh_controller );
728730 }else
729731 {
730- hcd_int_disable (TUH_OPT_RHPORT );
732+ hcd_int_disable (_usbh_controller );
731733 }
732734}
733735
@@ -1238,14 +1240,15 @@ static void process_enumeration(tuh_xfer_t* xfer)
12381240
12391241#if 0
12401242 case ENUM_RESET_2 :
1241- // XXX note used by now, but may be needed for some devices !?
1243+ // TODO not used by now, but may be needed for some devices !?
12421244 // Reset device again before Set Address
12431245 TU_LOG2 ("Port reset2 \r\n" );
12441246 if (_dev0 .hub_addr == 0 )
12451247 {
12461248 // connected directly to roothub
12471249 hcd_port_reset ( _dev0 .rhport );
1248- osal_task_delay (RESET_DELAY );
1250+ osal_task_delay (RESET_DELAY ); // TODO may not work for no-OS on MCU that require reset_end() since
1251+ // sof of controller may not running while reseting
12491252 hcd_port_reset_end (_dev0 .rhport );
12501253 // TODO: fall through to SET ADDRESS, refactor later
12511254 }
@@ -1364,7 +1367,8 @@ static bool enum_new_device(hcd_event_t* event)
13641367 // connected/disconnected directly with roothub
13651368 // wait until device is stable TODO non blocking
13661369 hcd_port_reset (_dev0 .rhport );
1367- osal_task_delay (RESET_DELAY );
1370+ osal_task_delay (RESET_DELAY ); // TODO may not work for no-OS on MCU that require reset_end() since
1371+ // sof of controller may not running while reseting
13681372 hcd_port_reset_end ( _dev0 .rhport );
13691373
13701374 // device unplugged while delaying
0 commit comments