tinyusb/src/host/usbh.c
static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port)
{
  bool is_found = false;
  //------------- find the all devices (star-network) under port that is unplugged -------------//
  for (uint8_t dev_addr = 0; dev_addr <= CFG_TUSB_HOST_DEVICE_MAX; dev_addr ++)
  {
    if (_usbh_devices[dev_addr].core_id  == hostid   &&
        (hub_addr == 0 || _usbh_devices[dev_addr].hub_addr == hub_addr) && // hub_addr == 0 & hub_port == 0 means roothub
        (hub_port == 0 || _usbh_devices[dev_addr].hub_port == hub_port) &&
        _usbh_devices[dev_addr].state    != TUSB_DEVICE_STATE_UNPLUG)
    {
      // TODO Hub multiple level
      for (uint8_t class_index = 1; class_index < USBH_CLASS_DRIVER_COUNT; class_index++)
      {
        if ((_usbh_devices[dev_addr].flag_supported_class & BIT_(class_index)) &&
            usbh_class_drivers[class_index].close)
        {
          usbh_class_drivers[class_index].close(dev_addr);
        }
      }

      // TODO refractor
      // set to REMOVING to allow HCD to clean up its cached data for this device
      // HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done
      _usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_REMOVING;
      _usbh_devices[dev_addr].flag_supported_class = 0;

      usbh_pipe_control_close(dev_addr);


      is_found = true;
    }
  }

  if (is_found) hcd_port_unplug(_usbh_devices[0].core_id); // TODO hack

}
// a device unplugged on hostid, hub_addr, hub_port
// return true if found and unmounted device, false if cannot find

a device unplugged on hostid, hub_addr, hub_port
return true if found and unmounted device, false if cannot find
a device unplugged on hostid hub_addr hub_port return true if found and unmounted device false if cannot find
static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port)
{
  bool is_found = false;
  for (uint8_t dev_addr = 0; dev_addr <= CFG_TUSB_HOST_DEVICE_MAX; dev_addr ++)
  {
    if (_usbh_devices[dev_addr].core_id  == hostid   &&
        (hub_addr == 0 || _usbh_devices[dev_addr].hub_addr == hub_addr) && 
        (hub_port == 0 || _usbh_devices[dev_addr].hub_port == hub_port) &&
        _usbh_devices[dev_addr].state    != TUSB_DEVICE_STATE_UNPLUG)
    {
      for (uint8_t class_index = 1; class_index < USBH_CLASS_DRIVER_COUNT; class_index++)
      {
        if ((_usbh_devices[dev_addr].flag_supported_class & BIT_(class_index)) &&
            usbh_class_drivers[class_index].close)
        {
          usbh_class_drivers[class_index].close(dev_addr);
        }
      }
      _usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_REMOVING;
      _usbh_devices[dev_addr].flag_supported_class = 0;
      usbh_pipe_control_close(dev_addr);
      is_found = true;
    }
  }
  if (is_found) hcd_port_unplug(_usbh_devices[0].core_id); 
}
static void usbh_device_unplugged ( uint8_t hostid , uint8_t hub_addr , uint8_t hub_port ) { bool is_found = false ; for ( uint8_t dev_addr = 0 ; dev_addr <= CFG_TUSB_HOST_DEVICE_MAX ; dev_addr ++ ) { if ( _usbh_devices [ dev_addr ] . core_id == hostid && ( hub_addr == 0 || _usbh_devices [ dev_addr ] . hub_addr == hub_addr ) && ( hub_port == 0 || _usbh_devices [ dev_addr ] . hub_port == hub_port ) && _usbh_devices [ dev_addr ] . state != TUSB_DEVICE_STATE_UNPLUG ) { for ( uint8_t class_index = 1 ; class_index < USBH_CLASS_DRIVER_COUNT ; class_index ++ ) { if ( ( _usbh_devices [ dev_addr ] . flag_supported_class & BIT_ ( class_index ) ) && usbh_class_drivers [ class_index ] . close ) { usbh_class_drivers [ class_index ] . close ( dev_addr ) ; } } _usbh_devices [ dev_addr ] . state = TUSB_DEVICE_STATE_REMOVING ; _usbh_devices [ dev_addr ] . flag_supported_class = 0 ; usbh_pipe_control_close ( dev_addr ) ; is_found = true ; } } if ( is_found ) hcd_port_unplug ( _usbh_devices [ 0 ] . core_id ) ; }
a device unplugged on hostid, hub_addr, hub_port
return true if found and unmounted device, false if cannot find
a device unplugged on hostid hub_addr hub_port return true if found and unmounted device false if cannot find
//------------- find the all devices (star-network) under port that is unplugged -------------//
 // hub_addr == 0 & hub_port == 0 means roothub
 // TODO Hub multiple level
 // TODO refractor
 // set to REMOVING to allow HCD to clean up its cached data for this device
 // HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done
 // TODO hack
