Skip to content

Commit b8fcea9

Browse files
committed
Update TinyUSB
1 parent 46bde99 commit b8fcea9

File tree

8 files changed

+86
-87
lines changed

8 files changed

+86
-87
lines changed

cores/esp32/esp32-hal-tinyusb.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "esp32-hal.h"
3030

3131
#include "esp32-hal-tinyusb.h"
32+
#include "usb_persist.h"
3233

3334
typedef char tusb_str_t[127];
3435

@@ -285,6 +286,24 @@ bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_request_t const
285286
return true;
286287
}
287288

289+
/*
290+
* Required Callbacks
291+
* */
292+
#if CFG_TUD_HID
293+
__attribute__ ((weak)) const uint8_t * tud_hid_descriptor_report_cb(void){return NULL;}
294+
__attribute__ ((weak)) uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen){return 0;}
295+
__attribute__ ((weak)) void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, const uint8_t * buffer, uint16_t bufsize){}
296+
#endif
297+
#if CFG_TUD_MSC
298+
__attribute__ ((weak)) bool tud_msc_test_unit_ready_cb(uint8_t lun){return false;}
299+
__attribute__ ((weak)) void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]){}
300+
__attribute__ ((weak)) void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size){}
301+
__attribute__ ((weak)) int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize){return -1;}
302+
__attribute__ ((weak)) int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize){return -1;}
303+
__attribute__ ((weak)) int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize){return -1;}
304+
#endif
305+
306+
288307
/*
289308
* Private API
290309
* */
@@ -510,7 +529,7 @@ esp_err_t tinyusb_enable_interface(tinyusb_interface_t interface)
510529
descriptor_len = CFG_TUD_DFU_RT * TUD_DFU_RT_DESC_LEN;
511530
break;
512531
case USB_INTERFACE_HID:
513-
descriptor_len = CFG_TUD_HID * TUD_HID_DESC_LEN;
532+
descriptor_len = CFG_TUD_HID * TUD_HID_INOUT_DESC_LEN;
514533
break;
515534
case USB_INTERFACE_MSC:
516535
descriptor_len = CFG_TUD_MSC * TUD_MSC_DESC_LEN;

libraries/USB/src/USBCDC.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "USB.h"
1717
#include "USBCDC.h"
1818
#if CONFIG_USB_ENABLED
19+
#include "usb_persist.h"
1920

2021
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_CDC_EVENTS);
2122
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);
@@ -27,17 +28,13 @@ extern "C" {
2728
#if CFG_TUD_DFU_RT
2829
uint16_t tusb_dfu_load_descriptor(uint8_t * dst, uint8_t * itf)
2930
{
30-
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB DFU_RT");
31-
#if CFG_TUSB_DYNAMIC_DRIVER_LOAD
32-
LOAD_DEFAULT_TUSB_DRIVER(dfu_rt);
33-
#endif
34-
3531
#define DFU_ATTR_CAN_DOWNLOAD 1
3632
#define DFU_ATTR_CAN_UPLOAD 2
3733
#define DFU_ATTR_MANIFESTATION_TOLERANT 4
3834
#define DFU_ATTR_WILL_DETACH 8
3935
#define DFU_ATTRS (DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_CAN_UPLOAD | DFU_ATTR_MANIFESTATION_TOLERANT)
40-
36+
37+
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB DFU_RT");
4138
uint8_t descriptor[TUD_DFU_RT_DESC_LEN] = {
4239
// Interface number, string index, attributes, detach timeout, transfer size */
4340
TUD_DFU_RT_DESCRIPTOR(*itf, str_index, DFU_ATTRS, 700, 64)
@@ -52,9 +49,6 @@ uint16_t tusb_dfu_load_descriptor(uint8_t * dst, uint8_t * itf)
5249
uint16_t tusb_cdc_load_descriptor(uint8_t * dst, uint8_t * itf)
5350
{
5451
uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB CDC");
55-
#if CFG_TUSB_DYNAMIC_DRIVER_LOAD
56-
LOAD_DEFAULT_TUSB_DRIVER(cdc);
57-
#endif
5852
// Interface number, string index, attributes, detach timeout, transfer size */
5953
uint8_t descriptor[TUD_CDC_DESC_LEN] = {
6054
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.

tools/sdk/esp32s2/include/tinyusb/port/common/include/descriptors_control.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <string.h>
1818
#include "usb_descriptors.h"
1919

20-
2120
#if CONFIG_USB_USE_BUILTIN_DESCRIPTORS
2221
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
2322
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.

tools/sdk/esp32s2/include/tinyusb/port/common/include/usb_descriptors.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
#pragma once
1415

1516
#ifdef __cplusplus
1617
extern "C" {
1718
#endif
1819

19-
#pragma once
20-
2120
#include "tusb.h"
2221

23-
#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
24-
2522
#define USB_ESPRESSIF_VID 0x303A
2623

24+
#if CONFIG_USB_USE_BUILTIN_DESCRIPTORS
25+
26+
#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
27+
2728
#define USB_STRING_DESCRIPTOR_ARRAY_SIZE 10
2829
typedef char *tusb_desc_strarray_device_t[USB_STRING_DESCRIPTOR_ARRAY_SIZE];
2930

@@ -32,6 +33,7 @@ extern tusb_desc_strarray_device_t descriptor_str_tinyusb;
3233

3334
extern tusb_desc_device_t descriptor_kconfig;
3435
extern tusb_desc_strarray_device_t descriptor_str_kconfig;
36+
#endif /* CONFIG_USB_USE_BUILTIN_DESCRIPTORS */
3537

3638
#ifdef __cplusplus
3739
}

tools/sdk/esp32s2/include/tinyusb/port/esp32s2/include/tinyusb.h

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -74,79 +74,16 @@ extern "C" {
7474
#endif
7575

7676
typedef struct {
77+
#if CONFIG_USB_USE_BUILTIN_DESCRIPTORS
78+
tusb_desc_device_t *descriptor;
79+
char **string_descriptor;
80+
#endif /* CONFIG_USB_USE_BUILTIN_DESCRIPTORS */
7781
bool external_phy;
7882
} tinyusb_config_t;
7983

8084
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);
8185
// TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474)
8286

83-
/*
84-
* USB Persistence API
85-
* */
86-
typedef enum {
87-
REBOOT_NO_PERSIST,
88-
REBOOT_PERSIST,
89-
REBOOT_BOOTLOADER,
90-
REBOOT_BOOTLOADER_DFU
91-
} reboot_type_t;
92-
93-
/*
94-
* Enable Persist reboot
95-
*
96-
* Note: Persistence should be enabled when ONLY CDC and DFU are being used
97-
* */
98-
void tinyusb_persist_set_enable(bool enable);
99-
100-
/*
101-
* Set Persist reboot mode, if available, before calling esp_reboot();
102-
* */
103-
void tinyusb_persist_set_mode(reboot_type_t mode);
104-
105-
/*
106-
* TinyUSB Dynamic Driver Loading
107-
*
108-
* When enabled, usb drivers can be loaded at runtime, before calling tinyusb_driver_install()
109-
* */
110-
#if CFG_TUSB_DYNAMIC_DRIVER_LOAD
111-
#if CFG_TUSB_DEBUG >= 2
112-
#define DRIVER_NAME(_name) .name = _name,
113-
#else
114-
#define DRIVER_NAME(_name)
115-
#endif
116-
117-
typedef struct
118-
{
119-
#if CFG_TUSB_DEBUG >= 2
120-
char const* name;
121-
#endif
122-
123-
void (* init ) (void);
124-
void (* reset ) (uint8_t rhport);
125-
uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
126-
bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request);
127-
bool (* control_complete ) (uint8_t rhport, tusb_control_request_t const * request);
128-
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
129-
void (* sof ) (uint8_t rhport); /* optional */
130-
} usbd_class_driver_t;
131-
132-
bool usbd_device_driver_load(const usbd_class_driver_t * driver);
133-
134-
#define STRINGIFY(x) #x
135-
#define TOSTRING(x) STRINGIFY(x)
136-
#define LOAD_DEFAULT_TUSB_DRIVER(name) \
137-
static usbd_class_driver_t name ## d_driver = { \
138-
DRIVER_NAME(TOSTRING(name)) \
139-
.init = name ## d_init, \
140-
.reset = name ## d_reset, \
141-
.open = name ## d_open, \
142-
.control_request = name ## d_control_request, \
143-
.control_complete = name ## d_control_complete, \
144-
.xfer_cb = name ## d_xfer_cb, \
145-
.sof = NULL \
146-
}; \
147-
TU_VERIFY (usbd_device_driver_load(&name ## d_driver));
148-
#endif /* CFG_TUSB_DYNAMIC_DRIVER_LOAD */
149-
15087
#ifdef __cplusplus
15188
}
15289
#endif

tools/sdk/esp32s2/include/tinyusb/port/esp32s2/include/tusb_config.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ extern "C" {
6060
# define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
6161
#endif
6262

63-
//Allow loading additional drivers
64-
#define CFG_TUSB_DYNAMIC_DRIVER_LOAD CONFIG_USB_DYNAMIC_DRIVER_LOADING
65-
#define CFG_TUSB_DYNAMIC_DRIVER_MAX CONFIG_USB_DYNAMIC_DRIVER_MAX
66-
67-
6863

6964
//--------------------------------------------------------------------
7065
// DEVICE CONFIGURATION
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <stdbool.h>
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
/*
24+
* USB Persistence API
25+
* */
26+
typedef enum {
27+
REBOOT_NO_PERSIST,
28+
REBOOT_PERSIST,
29+
REBOOT_BOOTLOADER,
30+
REBOOT_BOOTLOADER_DFU,
31+
REBOOT_TYPE_MAX
32+
} reboot_type_t;
33+
34+
/*
35+
* Init Persistence reboot system
36+
* */
37+
void tinyusb_persist_init(void);
38+
39+
/*
40+
* Enable Persistence reboot
41+
*
42+
* Note: Persistence should be enabled when ONLY CDC and DFU are being used
43+
* */
44+
void tinyusb_persist_set_enable(bool enable);
45+
46+
/*
47+
* Set Reboot mode. Call before esp_reboot();
48+
* */
49+
void tinyusb_persist_set_mode(reboot_type_t mode);
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif

tools/sdk/esp32s2/lib/libtinyusb.a

33.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)