Skip to content

Commit f6fda74

Browse files
committed
IDF master 1cb31e509
1 parent 8e7fbe2 commit f6fda74

File tree

401 files changed

+7472
-1679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

401 files changed

+7472
-1679
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ set(includedirs
159159
set(srcs ${CORE_SRCS} ${LIBRARY_SRCS} ${BLE_SRCS})
160160
set(priv_includes cores/esp32/libb64)
161161
set(requires spi_flash mbedtls mdns esp_adc_cal)
162-
set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl bt tinyusb main)
162+
set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl bt arduino_tinyusb main)
163163

164164
if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_ArduinoOTA)
165165
list(APPEND priv_requires esp_https_ota)

cores/esp32/USB.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "esp32-hal.h"
1515
#include "esp32-hal-tinyusb.h"
1616
#include "USB.h"
17-
#if CONFIG_USB_ENABLED
17+
#if CONFIG_TINYUSB_ENABLED
1818

1919
#ifndef USB_VID
2020
#define USB_VID USB_ESPRESSIF_VID
@@ -32,10 +32,6 @@
3232
#define USB_SERIAL "0"
3333
#endif
3434

35-
extern "C" {
36-
#include "tinyusb.h"
37-
}
38-
3935
#if CFG_TUD_DFU_RUNTIME
4036
static uint16_t load_dfu_descriptor(uint8_t * dst, uint8_t * itf)
4137
{
@@ -335,4 +331,4 @@ const char * ESPUSB::webUSBURL(void){
335331

336332
ESPUSB USB;
337333

338-
#endif /* CONFIG_USB_ENABLED */
334+
#endif /* CONFIG_TINYUSB_ENABLED */

cores/esp32/USB.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#pragma once
1515

1616
#include "sdkconfig.h"
17-
#if CONFIG_USB_ENABLED
17+
#if CONFIG_TINYUSB_ENABLED
1818

1919
#include "Arduino.h"
2020
#include "USBCDC.h"
@@ -115,4 +115,4 @@ class ESPUSB {
115115

116116
extern ESPUSB USB;
117117

118-
#endif /* CONFIG_USB_ENABLED */
118+
#endif /* CONFIG_TINYUSB_ENABLED */

cores/esp32/USBCDC.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515
#include "esp32-hal-tinyusb.h"
1616
#include "USB.h"
1717
#include "USBCDC.h"
18-
#if CONFIG_USB_ENABLED
18+
#if CONFIG_TINYUSB_ENABLED
1919

2020
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_CDC_EVENTS);
2121
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait);
2222
esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg);
2323

24-
extern "C" {
25-
#include "tinyusb.h"
26-
}
27-
2824
#if CFG_TUD_CDC
2925
#define MAX_USB_CDC_DEVICES 2
3026
USBCDC * devices[MAX_USB_CDC_DEVICES] = {NULL, NULL};
@@ -216,8 +212,8 @@ void USBCDC::_onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _pari
216212
}
217213

218214
void USBCDC::_onRX(){
219-
uint8_t buf[CONFIG_USB_CDC_RX_BUFSIZE+1];
220-
uint32_t count = tud_cdc_n_read(itf, buf, CONFIG_USB_CDC_RX_BUFSIZE);
215+
uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE+1];
216+
uint32_t count = tud_cdc_n_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE);
221217
for(uint32_t i=0; i<count; i++){
222218
if(rx_queue == NULL || !xQueueSend(rx_queue, buf+i, 0)){
223219
return;
@@ -333,6 +329,6 @@ USBCDC::operator bool() const
333329
USBCDC Serial(0);
334330
#endif
335331

336-
#endif /* CONFIG_USB_CDC_ENABLED */
332+
#endif /* CONFIG_TINYUSB_CDC_ENABLED */
337333

338-
#endif /* CONFIG_USB_ENABLED */
334+
#endif /* CONFIG_TINYUSB_ENABLED */

cores/esp32/USBCDC.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "Stream.h"
1919
#include "esp32-hal.h"
20-
#if CONFIG_USB_CDC_ENABLED
20+
#if CONFIG_TINYUSB_CDC_ENABLED
2121

2222
#include "esp_event.h"
2323

@@ -130,4 +130,4 @@ class USBCDC: public Stream
130130
extern USBCDC Serial;
131131
#endif
132132

133-
#endif /* CONFIG_USB_CDC_ENABLED */
133+
#endif /* CONFIG_TINYUSB_CDC_ENABLED */

cores/esp32/esp32-hal-tinyusb.c

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
#include "sdkconfig.h"
3-
#if CONFIG_USB_ENABLED
3+
#if CONFIG_TINYUSB_ENABLED
44
#include <stdlib.h>
5+
#include <stdbool.h>
56

67
#include "esp_log.h"
78

@@ -12,10 +13,14 @@
1213
#include "soc/usb_reg.h"
1314
#include "soc/usb_wrap_reg.h"
1415
#include "soc/usb_wrap_struct.h"
16+
#include "soc/usb_periph.h"
1517
#include "soc/periph_defs.h"
1618
#include "soc/timer_group_struct.h"
1719
#include "soc/system_reg.h"
1820

21+
#include "hal/usb_hal.h"
22+
#include "hal/gpio_ll.h"
23+
1924
#include "freertos/FreeRTOS.h"
2025
#include "freertos/task.h"
2126

@@ -24,15 +29,78 @@
2429

2530
#include "esp_efuse.h"
2631
#include "esp_efuse_table.h"
32+
#include "esp_rom_gpio.h"
2733

28-
#include "tinyusb.h"
2934
#include "esp32-hal.h"
3035

3136
#include "esp32-hal-tinyusb.h"
3237
#include "esp32s2/rom/usb/usb_persist.h"
3338
#include "esp32s2/rom/usb/usb_dc.h"
3439
#include "esp32s2/rom/usb/chip_usb_dw_wrapper.h"
3540

41+
typedef enum{
42+
TINYUSB_USBDEV_0,
43+
} tinyusb_usbdev_t;
44+
45+
typedef char *tusb_desc_strarray_device_t[USB_STRING_DESCRIPTOR_ARRAY_SIZE];
46+
47+
typedef struct {
48+
bool external_phy;
49+
} tinyusb_config_t;
50+
51+
static TaskHandle_t s_tusb_tskh;
52+
53+
static void configure_pins(usb_hal_context_t *usb)
54+
{
55+
for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) {
56+
if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) {
57+
esp_rom_gpio_pad_select_gpio(iopin->pin);
58+
if (iopin->is_output) {
59+
esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false);
60+
} else {
61+
esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false);
62+
if ((iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH)) {
63+
gpio_ll_input_enable(&GPIO, iopin->pin);
64+
}
65+
}
66+
esp_rom_gpio_pad_unhold(iopin->pin);
67+
}
68+
}
69+
if (!usb->use_external_phy) {
70+
gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
71+
gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
72+
}
73+
}
74+
75+
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config)
76+
{
77+
int res;
78+
log_i("Driver installation...");
79+
80+
// Hal init
81+
usb_hal_context_t hal = {
82+
.use_external_phy = config->external_phy
83+
};
84+
usb_hal_init(&hal);
85+
configure_pins(&hal);
86+
87+
if (!tusb_init()) {
88+
log_e("Can't initialize the TinyUSB stack.");
89+
return ESP_FAIL;
90+
}
91+
log_i("Driver installed");
92+
return ESP_OK;
93+
}
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
36104
typedef char tusb_str_t[127];
37105

38106
static bool WEBUSB_ENABLED = false;
@@ -694,4 +762,4 @@ void usb_dw_reg_dump(void)
694762
}
695763
}
696764
*/
697-
#endif /* CONFIG_USB_ENABLED */
765+
#endif /* CONFIG_TINYUSB_ENABLED */

cores/esp32/esp32-hal-tinyusb.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616
#include "esp32-hal.h"
1717

1818
#if CONFIG_IDF_TARGET_ESP32S2
19-
#if CONFIG_USB_ENABLED
19+
#if CONFIG_TINYUSB_ENABLED
2020

2121
#ifdef __cplusplus
2222
extern "C" {
2323
#endif
2424

25-
#include "tinyusb.h"
25+
#include "tusb.h"
26+
#include "tusb_option.h"
27+
#include "tusb_config.h"
28+
29+
#define USB_ESPRESSIF_VID 0x303A
30+
#define USB_STRING_DESCRIPTOR_ARRAY_SIZE 10
2631

2732
typedef struct {
2833
uint16_t vid;
@@ -46,10 +51,10 @@ typedef struct {
4651
#define TINYUSB_CONFIG_DEFAULT() { \
4752
.vid = USB_ESPRESSIF_VID, \
4853
.pid = 0x0002, \
49-
.product_name = CONFIG_USB_DESC_PRODUCT_STRING, \
50-
.manufacturer_name = CONFIG_USB_DESC_MANUFACTURER_STRING, \
51-
.serial_number = CONFIG_USB_DESC_SERIAL_STRING, \
52-
.fw_version = CONFIG_USB_DESC_BCDDEVICE, \
54+
.product_name = CONFIG_TINYUSB_DESC_PRODUCT_STRING, \
55+
.manufacturer_name = CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, \
56+
.serial_number = CONFIG_TINYUSB_DESC_SERIAL_STRING, \
57+
.fw_version = CONFIG_TINYUSB_DESC_BCDDEVICE, \
5358
.usb_version = 0x0200, \
5459
.usb_class = TUSB_CLASS_MISC, \
5560
.usb_subclass = MISC_SUBCLASS_COMMON, \
@@ -99,5 +104,5 @@ uint8_t tinyusb_get_free_out_endpoint(void);
99104
}
100105
#endif
101106

102-
#endif /* CONFIG_USB_ENABLED */
107+
#endif /* CONFIG_TINYUSB_ENABLED */
103108
#endif /* CONFIG_IDF_TARGET_ESP32S2 */

0 commit comments

Comments
 (0)