more dynamic controller for host
This commit is contained in:
		| @@ -125,6 +125,7 @@ typedef struct { | ||||
| // Invalid driver ID in itf2drv[] ep2drv[][] mapping | ||||
| enum { DRVID_INVALID = 0xFFu }; | ||||
| enum { ADDR_INVALID  = 0xFFu }; | ||||
| enum { CONTROLLER_INVALID = 0xFFu }; | ||||
|  | ||||
| #if CFG_TUSB_DEBUG >= 2 | ||||
|   #define DRIVER_NAME(_name)    .name = _name, | ||||
| @@ -203,7 +204,7 @@ enum { CONFIG_NUM = 1 }; // default to use configuration 1 | ||||
| // sum of end device + hub | ||||
| #define TOTAL_DEVICES   (CFG_TUH_DEVICE_MAX + CFG_TUH_HUB) | ||||
|  | ||||
| static bool _usbh_initialized = false; | ||||
| static uint8_t _usbh_controller = CONTROLLER_INVALID; | ||||
|  | ||||
| // Device with address = 0 for enumeration | ||||
| static usbh_dev0_t _dev0; | ||||
| @@ -280,8 +281,8 @@ void osal_task_delay(uint32_t msec) | ||||
| { | ||||
|   (void) msec; | ||||
|  | ||||
|   const uint32_t start = hcd_frame_number(TUH_OPT_RHPORT); | ||||
|   while ( ( hcd_frame_number(TUH_OPT_RHPORT) - start ) < msec ) {} | ||||
|   const uint32_t start = hcd_frame_number(_usbh_controller); | ||||
|   while ( ( hcd_frame_number(_usbh_controller) - start ) < msec ) {} | ||||
| } | ||||
| #endif | ||||
|  | ||||
| @@ -335,15 +336,15 @@ static void clear_device(usbh_device_t* dev) | ||||
|  | ||||
| bool tuh_inited(void) | ||||
| { | ||||
|   return _usbh_initialized; | ||||
|   return _usbh_controller != CONTROLLER_INVALID; | ||||
| } | ||||
|  | ||||
| bool tuh_init(uint8_t rhport) | ||||
| bool tuh_init(uint8_t controller_id) | ||||
| { | ||||
|   // skip if already initialized | ||||
|   if (_usbh_initialized) return _usbh_initialized; | ||||
|   if ( tuh_inited() ) return true; | ||||
|  | ||||
|   TU_LOG2("USBH init rhport %u\r\n", rhport); | ||||
|   TU_LOG2("USBH init on controller %u\r\n", controller_id); | ||||
|   TU_LOG2_INT(sizeof(usbh_device_t)); | ||||
|   TU_LOG2_INT(sizeof(hcd_event_t)); | ||||
|   TU_LOG2_INT(sizeof(_ctrl_xfer)); | ||||
| @@ -376,10 +377,11 @@ bool tuh_init(uint8_t rhport) | ||||
|     usbh_class_drivers[drv_id].init(); | ||||
|   } | ||||
|  | ||||
|   TU_ASSERT(hcd_init(rhport)); | ||||
|   hcd_int_enable(rhport); | ||||
|   _usbh_controller = controller_id;; | ||||
|  | ||||
|   TU_ASSERT(hcd_init(controller_id)); | ||||
|   hcd_int_enable(controller_id); | ||||
|  | ||||
|   _usbh_initialized = true; | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| @@ -721,13 +723,13 @@ uint8_t* usbh_get_enum_buf(void) | ||||
|  | ||||
| void usbh_int_set(bool enabled) | ||||
| { | ||||
|   // TODO all host controller | ||||
|   // TODO all host controller if multiple is used | ||||
|   if (enabled) | ||||
|   { | ||||
|     hcd_int_enable(TUH_OPT_RHPORT); | ||||
|     hcd_int_enable(_usbh_controller); | ||||
|   }else | ||||
|   { | ||||
|     hcd_int_disable(TUH_OPT_RHPORT); | ||||
|     hcd_int_disable(_usbh_controller); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @@ -1238,14 +1240,15 @@ static void process_enumeration(tuh_xfer_t* xfer) | ||||
|  | ||||
| #if 0 | ||||
|     case ENUM_RESET_2: | ||||
|       // XXX note used by now, but may be needed for some devices !? | ||||
|       // TODO not used by now, but may be needed for some devices !? | ||||
|       // Reset device again before Set Address | ||||
|       TU_LOG2("Port reset2 \r\n"); | ||||
|       if (_dev0.hub_addr == 0) | ||||
|       { | ||||
|         // connected directly to roothub | ||||
|         hcd_port_reset( _dev0.rhport ); | ||||
|         osal_task_delay(RESET_DELAY); | ||||
|         osal_task_delay(RESET_DELAY); // TODO may not work for no-OS on MCU that require reset_end() since | ||||
|                                       // sof of controller may not running while reseting | ||||
|         hcd_port_reset_end(_dev0.rhport); | ||||
|         // TODO: fall through to SET ADDRESS, refactor later | ||||
|       } | ||||
| @@ -1364,7 +1367,8 @@ static bool enum_new_device(hcd_event_t* event) | ||||
|     // connected/disconnected directly with roothub | ||||
|     // wait until device is stable TODO non blocking | ||||
|     hcd_port_reset(_dev0.rhport); | ||||
|     osal_task_delay(RESET_DELAY); | ||||
|     osal_task_delay(RESET_DELAY); // TODO may not work for no-OS on MCU that require reset_end() since | ||||
|                                   // sof of controller may not running while reseting | ||||
|     hcd_port_reset_end( _dev0.rhport); | ||||
|  | ||||
|     // device unplugged while delaying | ||||
|   | ||||
| @@ -95,10 +95,10 @@ TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr); | ||||
| // Should be called before tuh_init() | ||||
| // - cfg_id   : configure ID (TBD) | ||||
| // - cfg_param: configure data, structure depends on the ID | ||||
| bool tuh_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param); | ||||
| bool tuh_configure(uint8_t controller_id, uint32_t cfg_id, const void* cfg_param); | ||||
|  | ||||
| // Init host stack | ||||
| bool tuh_init(uint8_t rhport); | ||||
| bool tuh_init(uint8_t controller_id); | ||||
|  | ||||
| // Check if host stack is already initialized | ||||
| bool tuh_inited(void); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach