Merge branch 'refactor/tinyusb_uses_usb_phy' into 'master'

tinyusb: Update tinyusb.c to use the usb_phy API to configure PHY

See merge request espressif/esp-idf!15337
This commit is contained in:
Darian 2022-01-18 19:31:28 +00:00
commit 65666af5ed

View File

@ -5,63 +5,46 @@
*/ */
#include "sdkconfig.h" #include "sdkconfig.h"
#include "driver/gpio.h"
#include "esp_private/periph_ctrl.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_check.h" #include "esp_check.h"
#include "esp_rom_gpio.h" #include "esp_err.h"
#include "hal/gpio_ll.h" #include "esp_private/periph_ctrl.h"
#include "hal/usb_hal.h" #include "esp_private/usb_phy.h"
#include "soc/gpio_periph.h" #include "soc/usb_pins.h"
#include "soc/usb_periph.h"
#include "soc/gpio_pins.h"
#include "tinyusb.h" #include "tinyusb.h"
#include "descriptors_control.h" #include "descriptors_control.h"
#include "tusb.h" #include "tusb.h"
#include "tusb_tasks.h" #include "tusb_tasks.h"
const static char *TAG = "TinyUSB"; const static char *TAG = "TinyUSB";
static usb_phy_handle_t phy_hdl;
static void configure_pins(usb_hal_context_t *usb)
{
/* usb_periph_iopins currently configures USB_OTG as USB Device.
* Introduce additional parameters in usb_hal_context_t when adding support
* for USB Host.
*/
for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) {
if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) {
esp_rom_gpio_pad_select_gpio(iopin->pin);
if (iopin->is_output) {
esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false);
} else {
esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false);
if ((iopin->pin != GPIO_MATRIX_CONST_ZERO_INPUT) && (iopin->pin != GPIO_MATRIX_CONST_ONE_INPUT)) {
gpio_ll_input_enable(&GPIO, iopin->pin);
}
}
esp_rom_gpio_pad_unhold(iopin->pin);
}
}
if (!usb->use_external_phy) {
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
}
}
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) esp_err_t tinyusb_driver_install(const tinyusb_config_t *config)
{ {
tusb_desc_device_t *dev_descriptor; tusb_desc_device_t *dev_descriptor;
const char **string_descriptor; const char **string_descriptor;
ESP_RETURN_ON_FALSE(config, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); ESP_RETURN_ON_FALSE(config, ESP_ERR_INVALID_ARG, TAG, "invalid argument");
// Enable APB CLK to USB peripheral
periph_module_enable(PERIPH_USB_MODULE); // Configure USB PHY
periph_module_reset(PERIPH_USB_MODULE); usb_phy_config_t phy_conf = {
// Initialize HAL layer .controller = USB_PHY_CTRL_OTG,
usb_hal_context_t hal = { .otg_mode = USB_OTG_MODE_DEVICE,
.use_external_phy = config->external_phy
}; };
usb_hal_init(&hal); if (config->external_phy) {
configure_pins(&hal); phy_conf.target = USB_PHY_TARGET_EXT;
usb_phy_gpio_conf_t gpio_conf = {
.vp_io_num = USBPHY_VP_NUM,
.vm_io_num = USBPHY_VM_NUM,
.rcv_io_num = USBPHY_RCV_NUM,
.oen_io_num = USBPHY_OEN_NUM,
.vpo_io_num = USBPHY_VPO_NUM,
.vmo_io_num = USBPHY_VMO_NUM,
};
phy_conf.gpio_conf = &gpio_conf;
} else {
phy_conf.target = USB_PHY_TARGET_INT;
}
ESP_RETURN_ON_ERROR(usb_new_phy(&phy_conf, &phy_hdl), TAG, "Install USB PHY failed");
dev_descriptor = config->descriptor ? config->descriptor : &descriptor_kconfig; dev_descriptor = config->descriptor ? config->descriptor : &descriptor_kconfig;
string_descriptor = config->string_descriptor ? config->string_descriptor : descriptor_str_kconfig; string_descriptor = config->string_descriptor ? config->string_descriptor : descriptor_str_kconfig;