From b802ee65a4e9cf5ae118b047d599e351a6a700d0 Mon Sep 17 00:00:00 2001 From: zhaokeke Date: Thu, 14 Sep 2023 14:09:28 +0800 Subject: [PATCH] feat(usb): add change NCM network status 1.When switching routers, the HOST can re-initiate DHCP by switching the network status. 2. Delete ECM/RNDIS config because NCM can support MAC, Linux and Windows11. --- usb/esp_tinyusb/Kconfig | 22 ++++++---------------- usb/esp_tinyusb/idf_component.yml | 2 +- usb/esp_tinyusb/include/tinyusb_net.h | 15 +++++++++++++++ usb/esp_tinyusb/include/tusb_config.h | 5 ----- usb/esp_tinyusb/tinyusb_net.c | 18 ++++++++++++++++++ usb/esp_tinyusb/usb_descriptors.c | 2 +- 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/usb/esp_tinyusb/Kconfig b/usb/esp_tinyusb/Kconfig index 7cdaa3e65a..64032907ae 100644 --- a/usb/esp_tinyusb/Kconfig +++ b/usb/esp_tinyusb/Kconfig @@ -241,21 +241,11 @@ menu "TinyUSB Stack" BTH ISO ALT COUNT. endmenu # "Bluetooth Host Device Class" - menu "Network driver (ECM/NCM/RNDIS)" - choice TINYUSB_NET_MODE - prompt "Network mode" - default TINYUSB_NET_MODE_NONE + menu "Network driver (NCM)" + config TINYUSB_NET_MODE_NCM + bool "Enable TinyUSB Network feature(NCM)" + default n help - Select network driver you want to use. - - config TINYUSB_NET_MODE_ECM_RNDIS - bool "ECM/RNDIS" - - config TINYUSB_NET_MODE_NCM - bool "NCM" - - config TINYUSB_NET_MODE_NONE - bool "None" - endchoice - endmenu # "Network driver (ECM/NCM/RNDIS)" + Enable TinyUSB NCM feature. NCM is already supported on Linux/MAC/Windows11 + endmenu # "Network driver (NCM)" endmenu # "TinyUSB Stack" diff --git a/usb/esp_tinyusb/idf_component.yml b/usb/esp_tinyusb/idf_component.yml index b1d459a84b..4e870df32b 100644 --- a/usb/esp_tinyusb/idf_component.yml +++ b/usb/esp_tinyusb/idf_component.yml @@ -5,7 +5,7 @@ url: https://github.com/espressif/idf-extra-components/tree/master/usb/esp_tinyu dependencies: idf: '>=5.0' # IDF 4.x contains TinyUSB as submodule tinyusb: - version: '>=0.14.2' + version: '>=0.15.0~3' public: true targets: - esp32s2 diff --git a/usb/esp_tinyusb/include/tinyusb_net.h b/usb/esp_tinyusb/include/tinyusb_net.h index 19e53c4da6..02a82ae7e9 100644 --- a/usb/esp_tinyusb/include/tinyusb_net.h +++ b/usb/esp_tinyusb/include/tinyusb_net.h @@ -92,6 +92,21 @@ esp_err_t tinyusb_net_send_sync(void *buffer, uint16_t len, void *buff_free_arg, */ esp_err_t tinyusb_net_send_async(void *buffer, uint16_t len, void *buff_free_arg); +/** + * @brief TinyUSB NET driver notify HOST that the device is connected to AP, + * @note This interface should be called when WiFi connected + * @return ESP_OK on success notify + * ESP_FAIL on fail notify + */ +esp_err_t tinyusb_net_connect(void); + +/** + * @brief TinyUSB NET driver notify HOST that the device is disconnected to AP, + * @note This interface should be called when WiFi disconnected + * @return esp_err_t + */ +esp_err_t tinyusb_net_disconnect(void); + #endif // (CONFIG_TINYUSB_NET_MODE_NONE != 1) #ifdef __cplusplus diff --git a/usb/esp_tinyusb/include/tusb_config.h b/usb/esp_tinyusb/include/tusb_config.h index ec96316320..4431812ee2 100644 --- a/usb/esp_tinyusb/include/tusb_config.h +++ b/usb/esp_tinyusb/include/tusb_config.h @@ -57,10 +57,6 @@ extern "C" { # define CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED 0 #endif -#ifndef CONFIG_TINYUSB_NET_MODE_ECM_RNDIS -# define CONFIG_TINYUSB_NET_MODE_ECM_RNDIS 0 -#endif - #ifndef CONFIG_TINYUSB_NET_MODE_NCM # define CONFIG_TINYUSB_NET_MODE_NCM 0 #endif @@ -137,7 +133,6 @@ extern "C" { #define CFG_TUD_HID CONFIG_TINYUSB_HID_COUNT #define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_COUNT #define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED -#define CFG_TUD_ECM_RNDIS CONFIG_TINYUSB_NET_MODE_ECM_RNDIS #define CFG_TUD_NCM CONFIG_TINYUSB_NET_MODE_NCM #define CFG_TUD_DFU CONFIG_TINYUSB_DFU_MODE_DFU #define CFG_TUD_DFU_RUNTIME CONFIG_TINYUSB_DFU_MODE_DFU_RUNTIME diff --git a/usb/esp_tinyusb/tinyusb_net.c b/usb/esp_tinyusb/tinyusb_net.c index f7390d7632..0d79d2ce7f 100644 --- a/usb/esp_tinyusb/tinyusb_net.c +++ b/usb/esp_tinyusb/tinyusb_net.c @@ -142,6 +142,24 @@ esp_err_t tinyusb_net_init(tinyusb_usbdev_t usb_dev, const tinyusb_net_config_t return ESP_OK; } +esp_err_t tinyusb_net_connect(void) +{ + if (tud_network_connect()) { + return ESP_OK; + } else { + return ESP_FAIL; + } +} + +esp_err_t tinyusb_net_disconnect(void) +{ + if (tud_network_disconnect()) { + return ESP_OK; + } else { + return ESP_FAIL; + } +} + //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ diff --git a/usb/esp_tinyusb/usb_descriptors.c b/usb/esp_tinyusb/usb_descriptors.c index 1c6e1ce577..3f3b50a66e 100644 --- a/usb/esp_tinyusb/usb_descriptors.c +++ b/usb/esp_tinyusb/usb_descriptors.c @@ -82,7 +82,7 @@ const char *descriptor_str_kconfig[] = { "", #endif -#if CONFIG_TINYUSB_NET_MODE_ECM_RNDIS || CONFIG_TINYUSB_NET_MODE_NCM +#if CONFIG_TINYUSB_NET_MODE_NCM "USB net", // 6. NET Interface "", // 7. MAC #endif