Skip to content

Allow retrieving the port a device is connected to #2357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
25 changes: 19 additions & 6 deletions src/host/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ static inline usbh_class_driver_t const *get_driver(uint8_t drv_id) {
return driver;
}

TU_ATTR_ALWAYS_INLINE
static inline bool is_hub_addr(uint8_t daddr)
{
return (CFG_TUH_HUB > 0) && (daddr > CFG_TUH_DEVICE_MAX);
}

//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -313,6 +319,19 @@ bool tuh_rhport_reset_bus(uint8_t rhport, bool active) {
return true;
}

uint8_t tuh_get_port(uint8_t dev_addr) {
usbh_device_t *dev = get_device(dev_addr);
TU_VERIFY(dev);
// rhport:hub_addr:hub_port
if (is_hub_addr(dev_addr)) {
return dev->hub_addr;
} else if (dev->hub_port != 0) {
return dev->hub_port;
}
return dev->rhport;
}


//--------------------------------------------------------------------+
// PUBLIC API (Parameter Verification is required)
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -1182,12 +1201,6 @@ uint8_t tuh_descriptor_get_serial_string_sync(uint8_t daddr, uint16_t language_i
// Detaching
//--------------------------------------------------------------------+

TU_ATTR_ALWAYS_INLINE
static inline bool is_hub_addr(uint8_t daddr)
{
return (CFG_TUH_HUB > 0) && (daddr > CFG_TUH_DEVICE_MAX);
}

//static void mark_removing_device_isr(uint8_t rhport, uint8_t hub_addr, uint8_t hub_port) {
// for (uint8_t dev_id = 0; dev_id < TOTAL_DEVICES; dev_id++) {
// usbh_device_t *dev = &_usbh_devices[dev_id];
Expand Down
3 changes: 3 additions & 0 deletions src/host/usbh.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ bool tuh_ready(uint8_t daddr) {
return tuh_mounted(daddr) && !tuh_suspended(daddr);
}

// Retrieve the port the device is connected to
uint8_t tuh_get_port(uint8_t daddr);

//--------------------------------------------------------------------+
// Transfer API
//--------------------------------------------------------------------+
Expand Down