From dc705312a3fc04e15d11257661271c491ce01bbe Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Thu, 6 Oct 2022 09:04:53 +0200 Subject: [PATCH] usb: Allow settings of all signals in usb_phy Until now, only usb_phy signals for external PHY were defined. This is now extended with all OTG signals. --- components/soc/esp32s2/CMakeLists.txt | 2 +- components/soc/esp32s2/usb_otg_periph.c | 34 ++++++++++ components/soc/esp32s2/usb_phy_periph.c | 23 ------- components/soc/esp32s3/CMakeLists.txt | 2 +- components/soc/esp32s3/usb_otg_periph.c | 34 ++++++++++ components/soc/esp32s3/usb_phy_periph.c | 23 ------- .../{usb_phy_periph.h => usb_otg_periph.h} | 13 +++- components/tinyusb/additions/src/tinyusb.c | 4 +- components/usb/include/esp_private/usb_phy.h | 50 ++++++++++++-- components/usb/test/common/test_usb_common.c | 3 +- components/usb/usb_host.c | 3 +- components/usb/usb_phy.c | 66 +++++++++++++------ 12 files changed, 177 insertions(+), 80 deletions(-) create mode 100644 components/soc/esp32s2/usb_otg_periph.c delete mode 100644 components/soc/esp32s2/usb_phy_periph.c create mode 100644 components/soc/esp32s3/usb_otg_periph.c delete mode 100644 components/soc/esp32s3/usb_phy_periph.c rename components/soc/include/soc/{usb_phy_periph.h => usb_otg_periph.h} (60%) diff --git a/components/soc/esp32s2/CMakeLists.txt b/components/soc/esp32s2/CMakeLists.txt index 591ab340d1..5f51433981 100644 --- a/components/soc/esp32s2/CMakeLists.txt +++ b/components/soc/esp32s2/CMakeLists.txt @@ -18,7 +18,7 @@ set(srcs "uart_periph.c" "usb_periph.c" "temperature_sensor_periph.c" - "usb_phy_periph.c") + "usb_otg_periph.c") add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}") diff --git a/components/soc/esp32s2/usb_otg_periph.c b/components/soc/esp32s2/usb_otg_periph.c new file mode 100644 index 0000000000..e2f96e23b6 --- /dev/null +++ b/components/soc/esp32s2/usb_otg_periph.c @@ -0,0 +1,34 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "soc/usb_otg_periph.h" +#include "soc/gpio_sig_map.h" + +/* + Bunch of constants for USB peripheral: GPIO signals +*/ +const usb_phy_signal_conn_t usb_otg_periph_signal = { + .extphy_vp_in = USB_EXTPHY_VP_IDX, + .extphy_vm_in = USB_EXTPHY_VM_IDX, + .extphy_rcv_in = USB_EXTPHY_RCV_IDX, + .extphy_oen_out = USB_EXTPHY_OEN_IDX, + .extphy_vpo_out = USB_EXTPHY_VPO_IDX, + .extphy_vmo_out = USB_EXTPHY_VMO_IDX, + .extphy_suspend_in = USB_EXTPHY_SUSPND_IDX, + .extphy_speed_in = USB_EXTPHY_SPEED_IDX, + .srp_bvalid_in = USB_SRP_BVALID_IN_IDX, + .srp_sessend_in = USB_SRP_SESSEND_IN_IDX, + .srp_chrgvbus_out = USB_SRP_CHRGVBUS_IDX, + .srp_dischrgvbus_out = USB_SRP_DISCHRGVBUS_IDX, + .otg_iddig_in = USB_OTG_IDDIG_IN_IDX, + .otg_avalid_in = USB_OTG_AVALID_IN_IDX, + .otg_vbusvalid_in = USB_OTG_VBUSVALID_IN_IDX, + .otg_idpullup_out = USB_OTG_IDPULLUP_IDX, + .otg_dppulldown_out = USB_OTG_DPPULLDOWN_IDX, + .otg_dmpulldown_out = USB_OTG_DMPULLDOWN_IDX, + .otg_drvvbus_out = USB_OTG_DRVVBUS_IDX, + .module = PERIPH_USB_MODULE +}; diff --git a/components/soc/esp32s2/usb_phy_periph.c b/components/soc/esp32s2/usb_phy_periph.c deleted file mode 100644 index 596db0417c..0000000000 --- a/components/soc/esp32s2/usb_phy_periph.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "soc/usb_phy_periph.h" -#include "soc/gpio_sig_map.h" - -/* - Bunch of constants for USB peripheral: GPIO signals -*/ -const usb_phy_signal_conn_t usb_phy_periph_signal = { - .extphy_vp_in = USB_EXTPHY_VP_IDX, - .extphy_vm_in = USB_EXTPHY_VM_IDX, - .extphy_rcv_in = USB_EXTPHY_RCV_IDX, - .extphy_oen_out = USB_EXTPHY_OEN_IDX, - .extphy_vpo_out = USB_EXTPHY_VPO_IDX, - .extphy_vmo_out = USB_EXTPHY_VMO_IDX, - .extphy_suspend_in = USB_EXTPHY_SUSPND_IDX, - .extphy_speed_in = USB_EXTPHY_SPEED_IDX, - .module = PERIPH_USB_MODULE -}; diff --git a/components/soc/esp32s3/CMakeLists.txt b/components/soc/esp32s3/CMakeLists.txt index ada8caba2e..e2d20fb00b 100644 --- a/components/soc/esp32s3/CMakeLists.txt +++ b/components/soc/esp32s3/CMakeLists.txt @@ -21,7 +21,7 @@ set(srcs "temperature_sensor_periph.c" "uart_periph.c" "usb_periph.c" - "usb_phy_periph.c") + "usb_otg_periph.c") add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}") diff --git a/components/soc/esp32s3/usb_otg_periph.c b/components/soc/esp32s3/usb_otg_periph.c new file mode 100644 index 0000000000..e2f96e23b6 --- /dev/null +++ b/components/soc/esp32s3/usb_otg_periph.c @@ -0,0 +1,34 @@ +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "soc/usb_otg_periph.h" +#include "soc/gpio_sig_map.h" + +/* + Bunch of constants for USB peripheral: GPIO signals +*/ +const usb_phy_signal_conn_t usb_otg_periph_signal = { + .extphy_vp_in = USB_EXTPHY_VP_IDX, + .extphy_vm_in = USB_EXTPHY_VM_IDX, + .extphy_rcv_in = USB_EXTPHY_RCV_IDX, + .extphy_oen_out = USB_EXTPHY_OEN_IDX, + .extphy_vpo_out = USB_EXTPHY_VPO_IDX, + .extphy_vmo_out = USB_EXTPHY_VMO_IDX, + .extphy_suspend_in = USB_EXTPHY_SUSPND_IDX, + .extphy_speed_in = USB_EXTPHY_SPEED_IDX, + .srp_bvalid_in = USB_SRP_BVALID_IN_IDX, + .srp_sessend_in = USB_SRP_SESSEND_IN_IDX, + .srp_chrgvbus_out = USB_SRP_CHRGVBUS_IDX, + .srp_dischrgvbus_out = USB_SRP_DISCHRGVBUS_IDX, + .otg_iddig_in = USB_OTG_IDDIG_IN_IDX, + .otg_avalid_in = USB_OTG_AVALID_IN_IDX, + .otg_vbusvalid_in = USB_OTG_VBUSVALID_IN_IDX, + .otg_idpullup_out = USB_OTG_IDPULLUP_IDX, + .otg_dppulldown_out = USB_OTG_DPPULLDOWN_IDX, + .otg_dmpulldown_out = USB_OTG_DMPULLDOWN_IDX, + .otg_drvvbus_out = USB_OTG_DRVVBUS_IDX, + .module = PERIPH_USB_MODULE +}; diff --git a/components/soc/esp32s3/usb_phy_periph.c b/components/soc/esp32s3/usb_phy_periph.c deleted file mode 100644 index 596db0417c..0000000000 --- a/components/soc/esp32s3/usb_phy_periph.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "soc/usb_phy_periph.h" -#include "soc/gpio_sig_map.h" - -/* - Bunch of constants for USB peripheral: GPIO signals -*/ -const usb_phy_signal_conn_t usb_phy_periph_signal = { - .extphy_vp_in = USB_EXTPHY_VP_IDX, - .extphy_vm_in = USB_EXTPHY_VM_IDX, - .extphy_rcv_in = USB_EXTPHY_RCV_IDX, - .extphy_oen_out = USB_EXTPHY_OEN_IDX, - .extphy_vpo_out = USB_EXTPHY_VPO_IDX, - .extphy_vmo_out = USB_EXTPHY_VMO_IDX, - .extphy_suspend_in = USB_EXTPHY_SUSPND_IDX, - .extphy_speed_in = USB_EXTPHY_SPEED_IDX, - .module = PERIPH_USB_MODULE -}; diff --git a/components/soc/include/soc/usb_phy_periph.h b/components/soc/include/soc/usb_otg_periph.h similarity index 60% rename from components/soc/include/soc/usb_phy_periph.h rename to components/soc/include/soc/usb_otg_periph.h index 802d1720ce..d13286aa1d 100644 --- a/components/soc/include/soc/usb_phy_periph.h +++ b/components/soc/include/soc/usb_otg_periph.h @@ -25,10 +25,21 @@ typedef struct { const uint8_t extphy_vmo_out; const uint8_t extphy_suspend_in; const uint8_t extphy_speed_in; + const uint8_t srp_bvalid_in; + const uint8_t srp_sessend_in; + const uint8_t srp_chrgvbus_out; + const uint8_t srp_dischrgvbus_out; + const uint8_t otg_iddig_in; + const uint8_t otg_avalid_in; + const uint8_t otg_vbusvalid_in; + const uint8_t otg_idpullup_out; + const uint8_t otg_dppulldown_out; + const uint8_t otg_dmpulldown_out; + const uint8_t otg_drvvbus_out; const periph_module_t module; } usb_phy_signal_conn_t; -extern const usb_phy_signal_conn_t usb_phy_periph_signal; +extern const usb_phy_signal_conn_t usb_otg_periph_signal; #ifdef __cplusplus } diff --git a/components/tinyusb/additions/src/tinyusb.c b/components/tinyusb/additions/src/tinyusb.c index 3045ec0aef..8e6473554d 100644 --- a/components/tinyusb/additions/src/tinyusb.c +++ b/components/tinyusb/additions/src/tinyusb.c @@ -32,7 +32,7 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) .controller = USB_PHY_CTRL_OTG, .otg_mode = USB_OTG_MODE_DEVICE, }; - usb_phy_gpio_conf_t gpio_conf = { + usb_phy_ext_io_conf_t ext_io_conf = { .vp_io_num = USBPHY_VP_NUM, .vm_io_num = USBPHY_VM_NUM, .rcv_io_num = USBPHY_RCV_NUM, @@ -42,7 +42,7 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) }; if (config->external_phy) { phy_conf.target = USB_PHY_TARGET_EXT; - phy_conf.gpio_conf = &gpio_conf; + phy_conf.ext_io_conf = &ext_io_conf; } else { phy_conf.target = USB_PHY_TARGET_INT; } diff --git a/components/usb/include/esp_private/usb_phy.h b/components/usb/include/esp_private/usb_phy.h index 5260e0589e..7848e7cdba 100644 --- a/components/usb/include/esp_private/usb_phy.h +++ b/components/usb/include/esp_private/usb_phy.h @@ -15,6 +15,24 @@ extern "C" { #endif +/** + * @brief Initialization for usb_phy_otg_io_conf_t: Self-powered device + */ +#define USB_PHY_SELF_POWERED_DEVICE(vbus_monitor_io) \ + { \ + .iddig_io_num = -1, \ + .avalid_io_num = -1, \ + .vbusvalid_io_num = -1, \ + .idpullup_io_num = -1, \ + .dppulldown_io_num = -1, \ + .dmpulldown_io_num = -1, \ + .drvvbus_io_num = -1, \ + .bvalid_io_num = vbus_monitor_io, \ + .sessend_io_num = -1, \ + .chrgvbus_io_num = -1, \ + .dischrgvbus_io_num = -1, \ + }; + /** * @brief USB PHY status */ @@ -33,7 +51,7 @@ typedef enum { } usb_phy_action_t; /** - * @brief USB external PHY iopins configure struct + * @brief USB external PHY IO pins configuration structure */ typedef struct { int vp_io_num; /**< GPIO pin to USB_EXTPHY_VP_IDX */ @@ -42,7 +60,24 @@ typedef struct { int oen_io_num; /**< GPIO pin to USB_EXTPHY_OEN_IDX */ int vpo_io_num; /**< GPIO pin to USB_EXTPHY_VPO_IDX */ int vmo_io_num; /**< GPIO pin to USB_EXTPHY_VMO_IDX */ -} usb_phy_gpio_conf_t; +} usb_phy_ext_io_conf_t; + +/** + * @brief USB OTG IO pins configuration structure + */ +typedef struct { + int iddig_io_num; /**< GPIO pin to USB_OTG_IDDIG_IN_IDX */ + int avalid_io_num; /**< GPIO pin to USB_OTG_AVALID_IN_IDX */ + int vbusvalid_io_num; /**< GPIO pin to USB_OTG_VBUSVALID_IN_IDX */ + int idpullup_io_num; /**< GPIO pin to USB_OTG_IDPULLUP_IDX */ + int dppulldown_io_num; /**< GPIO pin to USB_OTG_DPPULLDOWN_IDX */ + int dmpulldown_io_num; /**< GPIO pin to USB_OTG_DMPULLDOWN_IDX */ + int drvvbus_io_num; /**< GPIO pin to USB_OTG_DRVVBUS_IDX */ + int bvalid_io_num; /**< GPIO pin to USB_SRP_BVALID_IN_IDX */ + int sessend_io_num; /**< GPIO pin to USB_SRP_SESSEND_IN_IDX */ + int chrgvbus_io_num; /**< GPIO pin to USB_SRP_CHRGVBUS_IDX */ + int dischrgvbus_io_num; /**< GPIO pin to USB_SRP_DISCHRGVBUS_IDX */ +} usb_phy_otg_io_conf_t; /** * @brief USB PHY configure struct @@ -50,11 +85,12 @@ typedef struct { * At minimum the PHY controller and PHY target must be initialized. */ typedef struct { - usb_phy_controller_t controller; /**< USB PHY controller */ - usb_phy_target_t target; /**< USB PHY target INT/EXT */ - usb_otg_mode_t otg_mode; /**< USB OTG mode */ - usb_phy_speed_t otg_speed; /**< USB OTG speed */ - usb_phy_gpio_conf_t *gpio_conf; /**< USB external PHY iopins configure */ + usb_phy_controller_t controller; /**< USB PHY controller */ + usb_phy_target_t target; /**< USB PHY target INT/EXT */ + usb_otg_mode_t otg_mode; /**< USB OTG mode */ + usb_phy_speed_t otg_speed; /**< USB OTG speed */ + const usb_phy_ext_io_conf_t *ext_io_conf; /**< USB external PHY IO pins configuration */ + const usb_phy_otg_io_conf_t *otg_io_conf; /**< USB OTG IO pins configuration */ } usb_phy_config_t; typedef struct phy_context_t *usb_phy_handle_t; /**< USB PHY context handle */ diff --git a/components/usb/test/common/test_usb_common.c b/components/usb/test/common/test_usb_common.c index c9855ace11..bc9e32d3c9 100644 --- a/components/usb/test/common/test_usb_common.c +++ b/components/usb/test/common/test_usb_common.c @@ -22,7 +22,8 @@ void test_usb_init_phy(void) .target = USB_PHY_TARGET_INT, .otg_mode = USB_OTG_MODE_HOST, .otg_speed = USB_PHY_SPEED_UNDEFINED, //In Host mode, the speed is determined by the connected device - .gpio_conf = NULL, + .ext_io_conf = NULL, + .otg_io_conf = NULL, }; ESP_ERROR_CHECK(usb_new_phy(&phy_config, &phy_hdl)); } diff --git a/components/usb/usb_host.c b/components/usb/usb_host.c index b4ced72a54..2c8531e7c2 100644 --- a/components/usb/usb_host.c +++ b/components/usb/usb_host.c @@ -384,7 +384,8 @@ esp_err_t usb_host_install(const usb_host_config_t *config) .target = USB_PHY_TARGET_INT, .otg_mode = USB_OTG_MODE_HOST, .otg_speed = USB_PHY_SPEED_UNDEFINED, //In Host mode, the speed is determined by the connected device - .gpio_conf = NULL, + .ext_io_conf = NULL, + .otg_io_conf = NULL, }; ret = usb_new_phy(&phy_config, &host_lib_obj->constant.phy_handle); if (ret != ESP_OK) { diff --git a/components/usb/usb_phy.c b/components/usb/usb_phy.c index 0df895e977..a16a7dde9c 100644 --- a/components/usb/usb_phy.c +++ b/components/usb/usb_phy.c @@ -11,7 +11,7 @@ #include "esp_check.h" #include "esp_private/periph_ctrl.h" #include "esp_private/usb_phy.h" -#include "soc/usb_phy_periph.h" +#include "soc/usb_otg_periph.h" #include "hal/usb_phy_hal.h" #include "hal/usb_phy_ll.h" #include "esp_rom_gpio.h" @@ -31,7 +31,7 @@ struct phy_context_t { usb_phy_status_t status; /**< PHY status */ usb_otg_mode_t otg_mode; /**< USB OTG mode */ usb_phy_speed_t otg_speed; /**< USB speed */ - usb_phy_gpio_conf_t *iopins; /**< external PHY I/O pins */ + usb_phy_ext_io_conf_t *iopins; /**< external PHY I/O pins */ usb_phy_hal_context_t hal_context; /**< USB_PHY hal context */ }; @@ -53,20 +53,11 @@ typedef struct { static phy_ctrl_obj_t *p_phy_ctrl_obj = NULL; static portMUX_TYPE phy_spinlock = portMUX_INITIALIZER_UNLOCKED; -static esp_err_t phy_external_iopins_configure(usb_phy_gpio_conf_t *gpio_conf) +static esp_err_t phy_iopins_configure(const usb_iopin_dsc_t *usb_periph_iopins, int iopins_num) { - const usb_iopin_dsc_t usb_periph_iopins[] = { - {gpio_conf->vp_io_num, usb_phy_periph_signal.extphy_vp_in, 0}, - {gpio_conf->vm_io_num, usb_phy_periph_signal.extphy_vm_in, 0}, - {gpio_conf->rcv_io_num, usb_phy_periph_signal.extphy_rcv_in, 0}, - {gpio_conf->oen_io_num, usb_phy_periph_signal.extphy_oen_out, 1}, - {gpio_conf->vpo_io_num, usb_phy_periph_signal.extphy_vpo_out, 1}, - {gpio_conf->vmo_io_num, usb_phy_periph_signal.extphy_vmo_out, 1}, - }; - - for (int i = 0; i < sizeof(usb_periph_iopins)/sizeof(usb_iopin_dsc_t); i++) { + for (int i = 0; i < iopins_num; i++) { const usb_iopin_dsc_t iopin = usb_periph_iopins[i]; - if (iopin.pin != -1) { + if (iopin.pin != GPIO_NUM_NC) { ESP_RETURN_ON_FALSE((iopin.is_output && GPIO_IS_VALID_OUTPUT_GPIO(iopin.pin)) || (!iopin.is_output && GPIO_IS_VALID_GPIO(iopin.pin)), ESP_ERR_INVALID_ARG, USBPHY_TAG, "io_num argument is invalid"); @@ -83,6 +74,38 @@ static esp_err_t phy_external_iopins_configure(usb_phy_gpio_conf_t *gpio_conf) return ESP_OK; } +static esp_err_t phy_external_iopins_configure(const usb_phy_ext_io_conf_t *ext_io_conf) +{ + const usb_iopin_dsc_t usb_periph_iopins[] = { + {ext_io_conf->vp_io_num, usb_otg_periph_signal.extphy_vp_in, false}, + {ext_io_conf->vm_io_num, usb_otg_periph_signal.extphy_vm_in, false}, + {ext_io_conf->rcv_io_num, usb_otg_periph_signal.extphy_rcv_in, false}, + {ext_io_conf->oen_io_num, usb_otg_periph_signal.extphy_oen_out, true}, + {ext_io_conf->vpo_io_num, usb_otg_periph_signal.extphy_vpo_out, true}, + {ext_io_conf->vmo_io_num, usb_otg_periph_signal.extphy_vmo_out, true}, + }; + + return phy_iopins_configure(usb_periph_iopins, sizeof(usb_periph_iopins)/sizeof(usb_iopin_dsc_t)); +} + +static esp_err_t phy_otg_iopins_configure(const usb_phy_otg_io_conf_t *otg_io_conf) +{ + const usb_iopin_dsc_t usb_periph_iopins[] = { + {otg_io_conf->iddig_io_num, usb_otg_periph_signal.otg_iddig_in, false}, + {otg_io_conf->avalid_io_num, usb_otg_periph_signal.otg_avalid_in, false}, + {otg_io_conf->vbusvalid_io_num, usb_otg_periph_signal.otg_vbusvalid_in, false}, + {otg_io_conf->idpullup_io_num, usb_otg_periph_signal.otg_idpullup_out, true}, + {otg_io_conf->dppulldown_io_num, usb_otg_periph_signal.otg_dppulldown_out, true}, + {otg_io_conf->dmpulldown_io_num, usb_otg_periph_signal.otg_dmpulldown_out, true}, + {otg_io_conf->drvvbus_io_num, usb_otg_periph_signal.otg_drvvbus_out, true}, + {otg_io_conf->bvalid_io_num, usb_otg_periph_signal.srp_bvalid_in, false}, + {otg_io_conf->sessend_io_num, usb_otg_periph_signal.srp_sessend_in, false}, + {otg_io_conf->chrgvbus_io_num, usb_otg_periph_signal.srp_chrgvbus_out, true}, + {otg_io_conf->dischrgvbus_io_num, usb_otg_periph_signal.srp_dischrgvbus_out, true}, + }; + return phy_iopins_configure(usb_periph_iopins, sizeof(usb_periph_iopins)/sizeof(usb_iopin_dsc_t)); +} + esp_err_t usb_phy_otg_set_mode(usb_phy_handle_t handle, usb_otg_mode_t mode) { ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, USBPHY_TAG, "handle argument is invalid"); @@ -197,8 +220,8 @@ static esp_err_t usb_phy_install(void) goto cleanup; } portEXIT_CRITICAL(&phy_spinlock); - periph_module_enable(usb_phy_periph_signal.module); - periph_module_reset(usb_phy_periph_signal.module); + periph_module_enable(usb_otg_periph_signal.module); + periph_module_reset(usb_otg_periph_signal.module); return ESP_OK; cleanup: @@ -254,10 +277,10 @@ esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_r } *handle_ret = (usb_phy_handle_t) phy_context; - if (config->gpio_conf && config->target == USB_PHY_TARGET_EXT) { - phy_context->iopins = (usb_phy_gpio_conf_t *) calloc(1, sizeof(usb_phy_gpio_conf_t)); + if (config->ext_io_conf && config->target == USB_PHY_TARGET_EXT) { + phy_context->iopins = (usb_phy_ext_io_conf_t *) calloc(1, sizeof(usb_phy_ext_io_conf_t)); ESP_GOTO_ON_FALSE(phy_context->iopins, ESP_ERR_NO_MEM, cleanup, USBPHY_TAG, "no mem for storing I/O pins"); - memcpy(phy_context->iopins, config->gpio_conf, sizeof(usb_phy_gpio_conf_t)); + memcpy(phy_context->iopins, config->ext_io_conf, sizeof(usb_phy_ext_io_conf_t)); ESP_ERROR_CHECK(phy_external_iopins_configure(phy_context->iopins)); } if (config->otg_mode != USB_PHY_MODE_DEFAULT) { @@ -266,6 +289,9 @@ esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_r if (config->otg_speed != USB_PHY_SPEED_UNDEFINED) { ESP_ERROR_CHECK(usb_phy_otg_dev_set_speed(*handle_ret, config->otg_speed)); } + if (config->otg_io_conf && (phy_context->controller == USB_PHY_CTRL_OTG)) { + ESP_ERROR_CHECK(phy_otg_iopins_configure(config->otg_io_conf)); + } return ESP_OK; cleanup: @@ -286,7 +312,7 @@ static void phy_uninstall(void) p_phy_ctrl_obj_free = p_phy_ctrl_obj; p_phy_ctrl_obj = NULL; // Disable USB peripheral - periph_module_disable(usb_phy_periph_signal.module); + periph_module_disable(usb_otg_periph_signal.module); } portEXIT_CRITICAL(&phy_spinlock); free(p_phy_ctrl_obj_free);