Skip to content
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

Allow retrieving the port a device is connected to #2357

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions src/host/usbh.c
Expand Up @@ -327,6 +327,15 @@ bool tuh_rhport_reset_bus(uint8_t rhport, bool active) {
return true;
}

void tuh_devtree_get_info(uint8_t dev_addr, tuh_devtree_info_t* devtree_info) {
hcd_devtree_info_t dt;
hcd_devtree_get_info(dev_addr, &dt);
devtree_info->rhport = dt.rhport;
devtree_info->hub_addr = dt.hub_addr;
devtree_info->hub_port = dt.hub_port;
devtree_info->speed = dt.speed;
}

//--------------------------------------------------------------------+
// PUBLIC API (Parameter Verification is required)
//--------------------------------------------------------------------+
Expand Down
12 changes: 12 additions & 0 deletions src/host/usbh.h
Expand Up @@ -78,6 +78,15 @@ enum {
TUH_CFGID_RPI_PIO_USB_CONFIGURATION = OPT_MCU_RP2040 << 8 // cfg_param: pio_usb_configuration_t
};

// Return data for tuh_devtree_get_info()
typedef struct
{
uint8_t rhport;
uint8_t hub_addr;
uint8_t hub_port;
uint8_t speed;
} tuh_devtree_info_t;

//--------------------------------------------------------------------+
// APPLICATION CALLBACK
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -148,6 +157,9 @@ bool tuh_rhport_is_active(uint8_t rhport);
// Assert/de-assert Bus Reset signal to roothub port. USB specs: it should last 10-50ms
bool tuh_rhport_reset_bus(uint8_t rhport, bool active);

// Retrieve devtree info like port of hub a device is connected to and speed.
void tuh_devtree_get_info(uint8_t dev_addr, tuh_devtree_info_t* devtree_info);

//--------------------------------------------------------------------+
// Device API
//--------------------------------------------------------------------+
Expand Down