Skip to content

Commit

Permalink
Allow retrieving the port a device is connected to
Browse files Browse the repository at this point in the history
  • Loading branch information
Yveaux committed Nov 29, 2023
1 parent 0877a48 commit 64692ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 18 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,18 @@ 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);
// 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 +1200,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

0 comments on commit 64692ba

Please sign in to comment.