mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-16 15:04:22 +00:00
Merge branch 'feat/usb_host_set_device_config_v5.2' into 'release/v5.2'
USB Host: Add enumeration callback filter (backport v5.2) See merge request espressif/esp-idf!28550
This commit is contained in:
@@ -3,3 +3,5 @@ idf_component_register(
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES usb
|
||||
)
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-missing-field-initializers")
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -14,10 +14,43 @@
|
||||
#define DAEMON_TASK_PRIORITY 2
|
||||
#define CLASS_TASK_PRIORITY 3
|
||||
|
||||
#ifdef CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK
|
||||
#define ENABLE_ENUM_FILTER_CALLBACK
|
||||
#endif // CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK
|
||||
|
||||
extern void class_driver_task(void *arg);
|
||||
|
||||
static const char *TAG = "DAEMON";
|
||||
|
||||
/**
|
||||
* @brief Set configuration callback
|
||||
*
|
||||
* Set the USB device configuration during the enumeration process, must be enabled in the menuconfig
|
||||
|
||||
* @note bConfigurationValue starts at index 1
|
||||
*
|
||||
* @param[in] dev_desc device descriptor of the USB device currently being enumerated
|
||||
* @param[out] bConfigurationValue configuration descriptor index, that will be user for enumeration
|
||||
*
|
||||
* @return bool
|
||||
* - true: USB device will be enumerated
|
||||
* - false: USB device will not be enumerated
|
||||
*/
|
||||
#ifdef ENABLE_ENUM_FILTER_CALLBACK
|
||||
static bool set_config_cb(const usb_device_desc_t *dev_desc, uint8_t *bConfigurationValue)
|
||||
{
|
||||
// If the USB device has more than one configuration, set the second configuration
|
||||
if (dev_desc->bNumConfigurations > 1) {
|
||||
*bConfigurationValue = 2;
|
||||
} else {
|
||||
*bConfigurationValue = 1;
|
||||
}
|
||||
|
||||
// Return true to enumerate the USB device
|
||||
return true;
|
||||
}
|
||||
#endif // ENABLE_ENUM_FILTER_CALLBACK
|
||||
|
||||
static void host_lib_daemon_task(void *arg)
|
||||
{
|
||||
SemaphoreHandle_t signaling_sem = (SemaphoreHandle_t)arg;
|
||||
@@ -26,6 +59,9 @@ static void host_lib_daemon_task(void *arg)
|
||||
usb_host_config_t host_config = {
|
||||
.skip_phy_setup = false,
|
||||
.intr_flags = ESP_INTR_FLAG_LEVEL1,
|
||||
#ifdef ENABLE_ENUM_FILTER_CALLBACK
|
||||
.enum_filter_cb = set_config_cb,
|
||||
#endif // ENABLE_ENUM_FILTER_CALLBACK
|
||||
};
|
||||
ESP_ERROR_CHECK(usb_host_install(&host_config));
|
||||
|
||||
|
Reference in New Issue
Block a user