|
33 | 33 | #include "components/driver/include/driver/periph_ctrl.h"
|
34 | 34 | #include "components/driver/include/driver/gpio.h"
|
35 | 35 | #include "components/esp_rom/include/esp32s2/rom/gpio.h"
|
| 36 | +#include "components/esp_rom/include/esp_rom_gpio.h" |
| 37 | +#include "components/hal/esp32s2/include/hal/gpio_ll.h" |
36 | 38 |
|
37 | 39 | #include "freertos/FreeRTOS.h"
|
38 | 40 | #include "freertos/task.h"
|
@@ -68,17 +70,41 @@ void usb_device_task(void* param)
|
68 | 70 | }
|
69 | 71 | }
|
70 | 72 |
|
| 73 | +static void configure_pins (usb_hal_context_t *usb) |
| 74 | +{ |
| 75 | + /* usb_periph_iopins currently configures USB_OTG as USB Device. |
| 76 | + * Introduce additional parameters in usb_hal_context_t when adding support |
| 77 | + * for USB Host. |
| 78 | + */ |
| 79 | + for ( const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin ) { |
| 80 | + if ( (usb->use_external_phy) || (iopin->ext_phy_only == 0) ) { |
| 81 | + esp_rom_gpio_pad_select_gpio(iopin->pin); |
| 82 | + if ( iopin->is_output ) { |
| 83 | + esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false); |
| 84 | + } |
| 85 | + else { |
| 86 | + esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false); |
| 87 | + if ( (iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH) ) { |
| 88 | + gpio_ll_input_enable(&GPIO, iopin->pin); |
| 89 | + } |
| 90 | + } |
| 91 | + esp_rom_gpio_pad_unhold(iopin->pin); |
| 92 | + } |
| 93 | + } |
| 94 | + if ( !usb->use_external_phy ) { |
| 95 | + gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3); |
| 96 | + gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); |
| 97 | + } |
| 98 | +} |
| 99 | + |
71 | 100 | void init_usb_hardware(void) {
|
72 | 101 | periph_module_reset(PERIPH_USB_MODULE);
|
73 | 102 | periph_module_enable(PERIPH_USB_MODULE);
|
74 | 103 | usb_hal_context_t hal = {
|
75 | 104 | .use_external_phy = false // use built-in PHY
|
76 | 105 | };
|
77 | 106 | usb_hal_init(&hal);
|
78 |
| - |
79 |
| - // Initialize the pin drive strength. |
80 |
| - gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3); |
81 |
| - gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); |
| 107 | + configure_pins(&hal); |
82 | 108 |
|
83 | 109 | (void) xTaskCreateStatic(usb_device_task,
|
84 | 110 | "usbd",
|
|
0 commit comments