mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
a602befe1b
This commit updates how the USBH handles device creation and enumeration so that upper layers (such as the Hub driver) can use the USBH API for enumeration instead of calling the HCD. USBH Updates: USBH now creates unenumerated devices set to address 0 with no device/config descriptor. A newly created device can be opened and communicated with immediately (using control transfers). This allows the Hub driver to call the USBH instead of the HCD. Summary of USBH changes: - Added new APIs to add/remove a device. Devices are now created as unenumerated and can be immediately opened and communicated with. - Added new APIs to enumerate a device (see 'usbh_dev_set_...()' functions). Device must be locked (see 'usbh_dev_enum_lock()') before enumeration functions can be called. - Added UID for each device. This allows the particular USBH without needing to use the device's handle (which implies opening the device). Hub Driver Updates: Hub driver now calls the USBH for enumeration. Summary of USBH changes: - Replace all 'hcd_pipe_...()' calls with 'usbh_dev_...()' calls - Refactored port event handling to fit with new USBH API - Updated to use UID to uniquely identify devices without opening them USB Host Updates: - Reroute USBH control transfers to clients and hub driver
106 lines
2.5 KiB
C
106 lines
2.5 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include "sdkconfig.h"
|
|
#include "esp_err.h"
|
|
#include "usb_private.h"
|
|
#include "usbh.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// ------------------------------------------------------ Types --------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Hub driver configuration
|
|
*/
|
|
typedef struct {
|
|
usb_proc_req_cb_t proc_req_cb; /**< Processing request callback */
|
|
void *proc_req_cb_arg; /**< Processing request callback argument */
|
|
#ifdef CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK
|
|
usb_host_enum_filter_cb_t enum_filter_cb; /**< Set device configuration callback */
|
|
#endif // CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK
|
|
} hub_config_t;
|
|
|
|
// ---------------------------------------------- Hub Driver Functions -------------------------------------------------
|
|
|
|
/**
|
|
* @brief Install Hub driver
|
|
*
|
|
* Entry:
|
|
* - USBH must already be installed
|
|
* Exit:
|
|
* - Install Hub driver memory resources
|
|
* - Initializes the HCD root port
|
|
*
|
|
* @param[in] hub_config Hub driver configuration
|
|
* @param[out] client_ret Unique pointer to identify the Hub as a USB Host client
|
|
* @return esp_err_t
|
|
*/
|
|
esp_err_t hub_install(hub_config_t *hub_config, void **client_ret);
|
|
|
|
/**
|
|
* @brief Uninstall Hub driver
|
|
*
|
|
* This must be called before uninstalling the USBH
|
|
* Entry:
|
|
* - Must have stopped the root port
|
|
* Exit:
|
|
* - HCD root port deinitialized
|
|
*
|
|
* @return esp_err_t
|
|
*/
|
|
esp_err_t hub_uninstall(void);
|
|
|
|
/**
|
|
* @brief Start the Hub driver's root port
|
|
*
|
|
* This will power the root port ON
|
|
*
|
|
* @return esp_err_t
|
|
*/
|
|
esp_err_t hub_root_start(void);
|
|
|
|
/**
|
|
* @brief Stops the Hub driver's root port
|
|
*
|
|
* This will power OFF the root port
|
|
*
|
|
* @return esp_err_t
|
|
*/
|
|
esp_err_t hub_root_stop(void);
|
|
|
|
/**
|
|
* @brief Indicate to the Hub driver that a device's port can be recycled
|
|
*
|
|
* The device connected to the port has been freed. The Hub driver can now
|
|
* recycled the port.
|
|
*
|
|
* @param dev_uid Device's unique ID
|
|
* @return
|
|
* - ESP_OK: Success
|
|
*/
|
|
esp_err_t hub_port_recycle(unsigned int dev_uid);
|
|
|
|
/**
|
|
* @brief Hub driver's processing function
|
|
*
|
|
* Hub driver handling function that must be called repeatdly to process the Hub driver's events. If blocking, the
|
|
* caller can block on the notification callback of source USB_PROC_REQ_SOURCE_HUB to run this function.
|
|
*
|
|
* @return esp_err_t
|
|
*/
|
|
esp_err_t hub_process(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|