Skip to content

Commit 55150bf

Browse files
committed
refactor(ext_hub): Added device speed getter to stop using parent_dev_hdl
1 parent 608b157 commit 55150bf

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

host/usb/private_include/ext_hub.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ void *ext_hub_get_client(void);
8282

8383
// -------------------------- External Hub API ---------------------------------
8484

85+
/**
86+
* @brief Get the External Hub device USB speed
87+
*
88+
* @note Device should be in list of devices
89+
*
90+
* @param[in] ext_hub_hdl External Hub device handle
91+
* @param[out] speed USB speed
92+
* @return
93+
* - ESP_ERR_NOT_ALLOWED if the External Hub driver is not installed
94+
* - ESP_ERR_INVALID_ARG if the handle or speed is NULL
95+
* - ESP_ERR_NOT_FOUND if the device is not found
96+
* - ESP_OK if the speed was obtained
97+
*/
98+
esp_err_t ext_hub_get_speed(ext_hub_handle_t ext_hub_hdl, usb_speed_t *speed);
99+
85100
/**
86101
* @brief Add new device
87102
*

host/usb/src/ext_hub.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -779,36 +779,27 @@ static void device_free(ext_hub_dev_t *ext_hub_dev)
779779
heap_caps_free(ext_hub_dev);
780780
}
781781

782-
static esp_err_t get_dev_by_hdl(usb_device_handle_t dev_hdl, ext_hub_dev_t **ext_hub_hdl)
782+
static bool dev_is_in_list(ext_hub_dev_t *ext_hub_dev)
783783
{
784-
esp_err_t ret = ESP_OK;
785-
// Go through the Hubs lists to find the hub with the specified device address
786-
ext_hub_dev_t *found_hub = NULL;
784+
bool is_in_list = false;
787785
ext_hub_dev_t *hub = NULL;
788786

789787
EXT_HUB_ENTER_CRITICAL();
790788
TAILQ_FOREACH(hub, &p_ext_hub_driver->dynamic.ext_hubs_pending_tailq, dynamic.tailq_entry) {
791-
if (hub->constant.dev_hdl == dev_hdl) {
792-
found_hub = hub;
789+
if (hub == ext_hub_dev) {
790+
is_in_list = true;
793791
goto exit;
794792
}
795793
}
796-
797794
TAILQ_FOREACH(hub, &p_ext_hub_driver->dynamic.ext_hubs_tailq, dynamic.tailq_entry) {
798-
if (hub->constant.dev_hdl == dev_hdl) {
799-
found_hub = hub;
795+
if (hub == ext_hub_dev) {
796+
is_in_list = true;
800797
goto exit;
801798
}
802799
}
803-
804800
exit:
805-
if (found_hub == NULL) {
806-
ret = ESP_ERR_NOT_FOUND;
807-
}
808801
EXT_HUB_EXIT_CRITICAL();
809-
810-
*ext_hub_hdl = found_hub;
811-
return ret;
802+
return is_in_list;
812803
}
813804

814805
static esp_err_t get_dev_by_addr(uint8_t dev_addr, ext_hub_dev_t **ext_hub_hdl)
@@ -1294,6 +1285,20 @@ static esp_err_t find_first_intf_desc(const usb_config_desc_t *config_desc, devi
12941285
return (iface_found) ? ESP_OK : ESP_ERR_NOT_FOUND;
12951286
}
12961287

1288+
esp_err_t ext_hub_get_speed(ext_hub_handle_t ext_hub_hdl, usb_speed_t *speed)
1289+
{
1290+
EXT_HUB_ENTER_CRITICAL();
1291+
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_NOT_ALLOWED);
1292+
EXT_HUB_EXIT_CRITICAL();
1293+
EXT_HUB_CHECK(ext_hub_hdl != NULL && speed != NULL, ESP_ERR_INVALID_ARG);
1294+
EXT_HUB_CHECK(dev_is_in_list(ext_hub_hdl), ESP_ERR_NOT_FOUND);
1295+
ext_hub_dev_t *ext_hub_dev = (ext_hub_dev_t *)ext_hub_hdl;
1296+
usb_device_info_t dev_info;
1297+
ESP_ERROR_CHECK(usbh_dev_get_info(ext_hub_dev->constant.dev_hdl, &dev_info));
1298+
*speed = dev_info.speed;
1299+
return ESP_OK;
1300+
}
1301+
12971302
esp_err_t ext_hub_new_dev(uint8_t dev_addr)
12981303
{
12991304
EXT_HUB_ENTER_CRITICAL();

host/usb/src/hub.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,10 @@ static void ext_port_event_callback(ext_port_hdl_t port_hdl, ext_port_event_data
352352
goto new_ds_dev_err;
353353
}
354354

355-
// TODO: IDF-10023 Move responsibility of parent-child tree building to Hub Driver instead of USBH
356-
usb_device_info_t parent_dev_info;
357-
ESP_ERROR_CHECK(usbh_dev_get_info(event_data->connected.parent_dev_hdl, &parent_dev_info));
358-
if (parent_dev_info.speed == USB_SPEED_HIGH) {
359-
if (port_speed != parent_dev_info.speed) {
355+
usb_speed_t parent_speed;
356+
ESP_ERROR_CHECK(ext_hub_get_speed(ext_hub_hdl, &parent_speed));
357+
if (parent_speed == USB_SPEED_HIGH) {
358+
if (port_speed != parent_speed) {
360359
ESP_LOGE(HUB_DRIVER_TAG, "Connected device is %s, transaction translator (TT) is not supported",
361360
(char *[]) {
362361
"LS", "FS", "HS"

0 commit comments

Comments
 (0)