diff --git a/components/usb/include/usb/usb_host.h b/components/usb/include/usb/usb_host.h index b9a1c4dabb..c1159e42f7 100644 --- a/components/usb/include/usb/usb_host.h +++ b/components/usb/include/usb/usb_host.h @@ -101,13 +101,16 @@ typedef void (*usb_host_client_event_cb_t)(const usb_host_client_event_msg_t *ev * Configuration structure of the USB Host Library. Provided in the usb_host_install() function */ typedef struct { - bool skip_phy_setup; /**< If set, the USB Host Library will not configure the USB PHY thus allowing the user - to manually configure the USB PHY before calling usb_host_install(). Users should - set this if they want to use an external USB PHY. Otherwise, the USB Host Library - will automatically configure the internal USB PHY */ - int intr_flags; /**< Interrupt flags for the underlying ISR used by the USB Host stack */ - usb_host_enum_filter_cb_t enum_filter_cb; /**< Enumeration filter callback. Enable CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK - to use this feature. Set to NULL otherwise. */ + bool skip_phy_setup; /**< If set, the USB Host Library will not configure the USB PHY thus allowing + the user to manually configure the USB PHY before calling usb_host_install(). + Users should set this if they want to use an external USB PHY. Otherwise, + the USB Host Library will automatically configure the internal USB PHY */ + bool root_port_unpowered; /**< If set, the USB Host Library will not power on the root port on installation. + This allows users to power on the root port manually by calling + usb_host_lib_set_root_port_power(). */ + int intr_flags; /**< Interrupt flags for the underlying ISR used by the USB Host stack */ + usb_host_enum_filter_cb_t enum_filter_cb; /**< Enumeration filter callback. Enable CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK + to use this feature. Set to NULL otherwise. */ } usb_host_config_t; /** @@ -187,6 +190,21 @@ esp_err_t usb_host_lib_unblock(void); */ esp_err_t usb_host_lib_info(usb_host_lib_info_t *info_ret); +/** + * @brief Power the root port ON or OFF + * + * - Powering ON the root port will allow device connections to occur + * - Powering OFF the root port will disconnect all devices downstream off the root port and prevent + * any further device connections. + * + * @note If 'usb_host_config_t.root_port_unpowered' was set on USB Host Library installation, users must call this + * function to power ON the root port before any device connections can occur. + * + * @param enable True to power the root port ON, false to power OFF + * @return esp_err_t + */ +esp_err_t usb_host_lib_set_root_port_power(bool enable); + // ------------------------------------------------ Client Functions --------------------------------------------------- /** diff --git a/components/usb/usb_host.c b/components/usb/usb_host.c index 9d41be06af..39ac112114 100644 --- a/components/usb/usb_host.c +++ b/components/usb/usb_host.c @@ -540,8 +540,11 @@ esp_err_t usb_host_install(const usb_host_config_t *config) p_host_lib_obj = host_lib_obj; HOST_EXIT_CRITICAL(); - // Start the root hub - ESP_ERROR_CHECK(hub_root_start()); + if (!config->root_port_unpowered) { + // Start the root hub + ESP_ERROR_CHECK(hub_root_start()); + } + ret = ESP_OK; return ret; @@ -694,6 +697,18 @@ esp_err_t usb_host_lib_info(usb_host_lib_info_t *info_ret) return ESP_OK; } +esp_err_t usb_host_lib_set_root_port_power(bool enable) +{ + esp_err_t ret; + if (enable) { + ret = hub_root_start(); + } else { + ret = hub_root_stop(); + } + + return ret; +} + // ------------------------------------------------ Client Functions --------------------------------------------------- // ----------------------- Private -------------------------