From 14be0630f3dcb18f40b6f84220afb2a9863fb371 Mon Sep 17 00:00:00 2001 From: Roman Leonov Date: Tue, 14 Jan 2025 11:20:50 +0100 Subject: [PATCH] refactor(esp_tinyusb): Changed the PHY to periph (as we select the periph) and added run-time selection option --- device/esp_tinyusb/Kconfig | 25 ++++++++++++++++++------- device/esp_tinyusb/tinyusb.c | 3 +++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/device/esp_tinyusb/Kconfig b/device/esp_tinyusb/Kconfig index c1cd4ea6..741f9895 100644 --- a/device/esp_tinyusb/Kconfig +++ b/device/esp_tinyusb/Kconfig @@ -6,19 +6,30 @@ menu "TinyUSB Stack" help Specify verbosity of TinyUSB log output. - choice TINYUSB_RHPORT + config TINYUSB_DYNAMIC_RHPORT_CONFIG depends on IDF_TARGET_ESP32P4 - prompt "TinyUSB PHY" + bool "TinyUSB Peripheral dynamic selection" + default n + help + Allows to select and configure the Peripheral for TinyUSB in run-time. + + - Disable to select peripheral via CFG_TUSB_RHPORTx_MODE (legacy way). + - Enable to use run-time port selection via TinyUSB configuration parameter. + + choice TINYUSB_RHPORT + depends on !TINYUSB_DYNAMIC_RHPORT_CONFIG + prompt "USB Peripheral" default TINYUSB_RHPORT_HS help - Allows set the USB PHY Controller for TinyUSB: - - HS (USB OTG2.0 PHY for HighSpeed) - - FS (USB OTG1.1 PHY for FullSpeed) + Allows set the USB Peripheral Controller for TinyUSB. + + - High-speed (USB OTG2.0 Peripheral for High-, Full- and Low-speed) + - Full-speed (USB OTG1.1 Peripheral for Full- and Low-speed) config TINYUSB_RHPORT_HS - bool "HS" + bool "OTG2.0" config TINYUSB_RHPORT_FS - bool "FS" + bool "OTG1.1" endchoice menu "TinyUSB DCD" diff --git a/device/esp_tinyusb/tinyusb.c b/device/esp_tinyusb/tinyusb.c index a2dc67dc..7511c679 100644 --- a/device/esp_tinyusb/tinyusb.c +++ b/device/esp_tinyusb/tinyusb.c @@ -11,6 +11,7 @@ #include "esp_private/periph_ctrl.h" #include "esp_private/usb_phy.h" #include "soc/usb_pins.h" +#include "soc/usb_dwc_cfg.h" // To get awailable OTG interfaces #include "tinyusb.h" #include "descriptors_control.h" #include "tusb.h" @@ -32,7 +33,9 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) usb_phy_config_t phy_conf = { .controller = USB_PHY_CTRL_OTG, .otg_mode = USB_OTG_MODE_DEVICE, +#if OTG20_HSPHY_INTERFACE .otg_speed = (TUD_OPT_HIGH_SPEED) ? USB_PHY_SPEED_HIGH : USB_PHY_SPEED_FULL, +#endif // OTG20_HSPHY_INTERFACE }; // External PHY IOs config