mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 12:53:29 +00:00
soc/usb: use new headers in LL, move some code out of LL
* Keep only USB related register operations in the LL. * Move pad-related logic into the driver. * Driver is now responsible for enabling the peripheral.
This commit is contained in:
@@ -14,6 +14,35 @@
|
||||
|
||||
#include "tinyusb.h"
|
||||
#include "hal/usb_hal.h"
|
||||
#include "soc/usb_periph.h"
|
||||
#include "driver/periph_ctrl.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp32s2/rom/gpio.h"
|
||||
|
||||
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)) {
|
||||
gpio_pad_select_gpio(iopin->pin);
|
||||
if (iopin->is_output) {
|
||||
gpio_matrix_out(iopin->pin, iopin->func, false, false);
|
||||
} else {
|
||||
gpio_matrix_in(iopin->pin, iopin->func, false);
|
||||
gpio_pad_input_enable(iopin->pin);
|
||||
}
|
||||
gpio_pad_unhold(iopin->pin);
|
||||
}
|
||||
}
|
||||
if (!usb->use_external_phy) {
|
||||
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
|
||||
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializes the tinyUSB driver.
|
||||
@@ -31,11 +60,15 @@ esp_err_t tinyusb_driver_install(const tinyusb_config_t *config)
|
||||
tusb_desc_device_t *descriptor;
|
||||
char **string_descriptor;
|
||||
|
||||
periph_module_reset(PERIPH_USB_MODULE);
|
||||
periph_module_enable(PERIPH_USB_MODULE);
|
||||
|
||||
// Hal init
|
||||
usb_hal_context_t hal = {
|
||||
.use_external_phy = config->external_phy
|
||||
};
|
||||
usb_hal_init(&hal);
|
||||
configure_pins(&hal);
|
||||
|
||||
if (config->descriptor == NULL) {
|
||||
descriptor = &descriptor_kconfig;
|
||||
|
Reference in New Issue
Block a user