Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions host/usb/private_include/ext_hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,19 @@ void *ext_hub_get_client(void);
// -------------------------- External Hub API ---------------------------------

/**
* @brief Get External Hub device handle by USBH device handle
* @brief Get the External Hub device USB speed
*
* @param[in] dev_hdl USBH device handle
* @param[out] ext_hub_hdl External Hub device handle
* @note Device should be in list of devices
*
* @param[in] ext_hub_hdl External Hub device handle
* @param[out] speed USB speed
* @return
* - ESP_OK: External Hub device handle successfully obtained
* - ESP_ERR_INVALID_STATE: External Hub driver is not installed
* - ESP_ERR_NOT_FOUND: Device not found
* - ESP_ERR_NOT_ALLOWED if the External Hub driver is not installed
* - ESP_ERR_INVALID_ARG if the handle or speed is NULL
* - ESP_ERR_NOT_FOUND if the device is not found
* - ESP_OK if the speed was obtained
*/
esp_err_t ext_hub_get_handle(usb_device_handle_t dev_hdl, ext_hub_handle_t *ext_hub_hdl);
esp_err_t ext_hub_get_speed(ext_hub_handle_t ext_hub_hdl, usb_speed_t *speed);

/**
* @brief Add new device
Expand Down
8 changes: 4 additions & 4 deletions host/usb/private_include/hub.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ esp_err_t hub_node_active(unsigned int node_uid);
* @param[in] node_uid Device's node unique ID
*
* @return
* - ESP_OK: Port has been disabled without error
* - ESP_ERR_INVALID_STATE: Port can't be disabled in current state
* - ESP_ERR_NOT_SUPPORTED: This function is not supported by the selected port
* - ESP_ERR_NOT_FOUND: Device's node is not found
* - ESP_ERR_INVALID_STATE: If Hub driver is not installed
* - ESP_ERR_NOT_SUPPORTED: If the function is not support by the selected port
* - ESP_ERR_NOT_FOUND: If device's tree node is not found by uid
* - ESP_OK: If Port has been disabled without error
*/
esp_err_t hub_node_disable(unsigned int node_uid);

Expand Down
45 changes: 21 additions & 24 deletions host/usb/src/ext_hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,36 +779,27 @@ static void device_free(ext_hub_dev_t *ext_hub_dev)
heap_caps_free(ext_hub_dev);
}

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

EXT_HUB_ENTER_CRITICAL();
TAILQ_FOREACH(hub, &p_ext_hub_driver->dynamic.ext_hubs_pending_tailq, dynamic.tailq_entry) {
if (hub->constant.dev_hdl == dev_hdl) {
found_hub = hub;
if (hub == ext_hub_dev) {
is_in_list = true;
goto exit;
}
}

TAILQ_FOREACH(hub, &p_ext_hub_driver->dynamic.ext_hubs_tailq, dynamic.tailq_entry) {
if (hub->constant.dev_hdl == dev_hdl) {
found_hub = hub;
if (hub == ext_hub_dev) {
is_in_list = true;
goto exit;
}
}

exit:
if (found_hub == NULL) {
ret = ESP_ERR_NOT_FOUND;
}
EXT_HUB_EXIT_CRITICAL();

*ext_hub_hdl = found_hub;
return ret;
return is_in_list;
}

static esp_err_t get_dev_by_addr(uint8_t dev_addr, ext_hub_dev_t **ext_hub_hdl)
Expand Down Expand Up @@ -1215,14 +1206,6 @@ void *ext_hub_get_client(void)
// -------------------------- External Hub API ---------------------------------
// -----------------------------------------------------------------------------

esp_err_t ext_hub_get_handle(usb_device_handle_t dev_hdl, ext_hub_handle_t *ext_hub_hdl)
{
EXT_HUB_ENTER_CRITICAL();
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_INVALID_STATE);
EXT_HUB_EXIT_CRITICAL();
return get_dev_by_hdl(dev_hdl, ext_hub_hdl);
}

static esp_err_t find_first_intf_desc(const usb_config_desc_t *config_desc, device_config_t *hub_config)
{
bool iface_found = false;
Expand Down Expand Up @@ -1302,6 +1285,20 @@ static esp_err_t find_first_intf_desc(const usb_config_desc_t *config_desc, devi
return (iface_found) ? ESP_OK : ESP_ERR_NOT_FOUND;
}

esp_err_t ext_hub_get_speed(ext_hub_handle_t ext_hub_hdl, usb_speed_t *speed)
{
EXT_HUB_ENTER_CRITICAL();
EXT_HUB_CHECK_FROM_CRIT(p_ext_hub_driver != NULL, ESP_ERR_NOT_ALLOWED);
EXT_HUB_EXIT_CRITICAL();
EXT_HUB_CHECK(ext_hub_hdl != NULL && speed != NULL, ESP_ERR_INVALID_ARG);
EXT_HUB_CHECK(dev_is_in_list(ext_hub_hdl), ESP_ERR_NOT_FOUND);
ext_hub_dev_t *ext_hub_dev = (ext_hub_dev_t *)ext_hub_hdl;
usb_device_info_t dev_info;
ESP_ERROR_CHECK(usbh_dev_get_info(ext_hub_dev->constant.dev_hdl, &dev_info));
*speed = dev_info.speed;
return ESP_OK;
}

esp_err_t ext_hub_new_dev(uint8_t dev_addr)
{
EXT_HUB_ENTER_CRITICAL();
Expand Down
Loading
Loading