Merge branch 'feature/usb_host_hubs_support_msg' into 'master'

feat(hub): Added notification when hubs support is disabled

Closes IDF-11254

See merge request espressif/esp-idf!33703
This commit is contained in:
Roman Leonov 2024-10-15 09:16:27 +08:00
commit 7e0fc6a156
4 changed files with 41 additions and 10 deletions

View File

@ -528,7 +528,7 @@ static esp_err_t device_alloc(device_config_t *config, ext_hub_dev_t **ext_hub_d
usb_device_info_t dev_info;
ESP_ERROR_CHECK(usbh_dev_get_info(config->dev_hdl, &dev_info));
if (dev_info.parent.dev_hdl) {
ESP_LOGW(EXT_HUB_TAG, "Multiple Hubs not supported, use menuconfig to enable feature");
ESP_LOGW(EXT_HUB_TAG, "Multiple Hubs support disabled, Hub device was not initialized");
ret = ESP_ERR_NOT_SUPPORTED;
goto fail;
}

View File

@ -778,14 +778,35 @@ esp_err_t hub_port_disable(usb_device_handle_t parent_dev_hdl, uint8_t parent_po
return ret;
}
#if ENABLE_USB_HUBS
esp_err_t hub_notify_new_dev(uint8_t dev_addr)
{
HUB_DRIVER_ENTER_CRITICAL();
HUB_DRIVER_CHECK_FROM_CRIT(p_hub_driver_obj != NULL, ESP_ERR_INVALID_STATE);
HUB_DRIVER_EXIT_CRITICAL();
return ext_hub_new_dev(dev_addr);
esp_err_t ret;
#if ENABLE_USB_HUBS
ret = ext_hub_new_dev(dev_addr);
#else
// Verify the device descriptor and if the bDeviceClass is a Hub class,
// show the warning message, that Hub support feature is not enabled
usb_device_handle_t dev_hdl = NULL;
const usb_device_desc_t *device_desc = NULL;
// Open device
if (usbh_devs_open(dev_addr, &dev_hdl) == ESP_OK) {
// Get Device Descriptor
if (usbh_dev_get_desc(dev_hdl, &device_desc) == ESP_OK) {
if (device_desc->bDeviceClass == USB_CLASS_HUB) {
ESP_LOGW(HUB_DRIVER_TAG, "External Hubs support disabled, Hub device was not initialized");
}
}
// Close device
usbh_dev_close(dev_hdl);
}
// Logic should not stop the flow, so no error to return
ret = ESP_OK;
#endif // ENABLE_USB_HUBS
return ret;
}
esp_err_t hub_notify_dev_gone(uint8_t dev_addr)
@ -794,9 +815,17 @@ esp_err_t hub_notify_dev_gone(uint8_t dev_addr)
HUB_DRIVER_CHECK_FROM_CRIT(p_hub_driver_obj != NULL, ESP_ERR_INVALID_STATE);
HUB_DRIVER_EXIT_CRITICAL();
return ext_hub_dev_gone(dev_addr);
esp_err_t ret;
#if ENABLE_USB_HUBS
ret = ext_hub_dev_gone(dev_addr);
#else
// Nothing to do, while Hubs support is not enabled
ret = ESP_OK;
#endif // ENABLE_USB_HUBS
return ret;
}
#if (ENABLE_USB_HUBS)
esp_err_t hub_notify_all_free(void)
{
HUB_DRIVER_ENTER_CRITICAL();

View File

@ -191,13 +191,13 @@ esp_err_t hub_port_active(usb_device_handle_t parent_dev_hdl, uint8_t parent_por
*/
esp_err_t hub_port_disable(usb_device_handle_t parent_dev_hdl, uint8_t parent_port_num);
#if ENABLE_USB_HUBS
/**
* @brief Notify Hub driver that new device has been attached
*
* If device is has a HUB class, then it will be added as External Hub to Hub Driver.
*
* @note This function should only be called from the Host Library task
* @note If the Hub support feature is disabled and device has a Hub class, only the warning message will be shown.
*
* @param[in] dev_addr Device bus address
*
@ -213,6 +213,7 @@ esp_err_t hub_notify_new_dev(uint8_t dev_addr);
* If the device was an External Hub, then it will be removed from the Hub Driver.
*
* @note This function should only be called from the Host Library task
* @note If the Hub support feature is disabled, no additional logic requires here.
*
* @param[in] dev_addr Device bus address
*
@ -222,6 +223,7 @@ esp_err_t hub_notify_new_dev(uint8_t dev_addr);
*/
esp_err_t hub_notify_dev_gone(uint8_t dev_addr);
#if ENABLE_USB_HUBS
/**
* @brief Notify Hub driver that all devices should be freed
*

View File

@ -309,21 +309,21 @@ static void usbh_event_callback(usbh_event_data_t *event_data, void *arg)
break;
}
case USBH_EVENT_NEW_DEV: {
// Internal client
hub_notify_new_dev(event_data->new_dev_data.dev_addr);
// External clients
// Prepare a NEW_DEV client event message, the send it to all clients
usb_host_client_event_msg_t event_msg = {
.event = USB_HOST_CLIENT_EVENT_NEW_DEV,
.new_dev.address = event_data->new_dev_data.dev_addr,
};
send_event_msg_to_clients(&event_msg, true, 0);
#if ENABLE_USB_HUBS
hub_notify_new_dev(event_data->new_dev_data.dev_addr);
#endif // ENABLE_USB_HUBS
break;
}
case USBH_EVENT_DEV_GONE: {
#if ENABLE_USB_HUBS
// Internal client
hub_notify_dev_gone(event_data->new_dev_data.dev_addr);
#endif // ENABLE_USB_HUBS
// External clients
// Prepare event msg, send only to clients that have opened the device
usb_host_client_event_msg_t event_msg = {
.event = USB_HOST_CLIENT_EVENT_DEV_GONE,