8000 Update TinyUSB Lib · MartinUbl/arduino-esp32@ca7ed86 · GitHub
[go: up one dir, main page]

Skip to content

Commit ca7ed86

Browse files
committed
Update TinyUSB Lib
1 parent a1bd429 commit ca7ed86

File tree

21 files changed

+324
-113
lines changed

21 files changed

+324
-113
lines changed

tools/sdk/esp32s2/include/config/sdkconfig.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,12 @@
354354
#define CONFIG_SPIFFS_USE_MTIME 1
355355
#define CONFIG_USB_ENABLED 1
356356
#define CONFIG_USB_MAX_POWER_USAGE 500
357+
#define CONFIG_USB_DYNAMIC_DRIVER_LOADING 1
358+
#define CONFIG_USB_DYNAMIC_DRIVER_MAX 16
357359
#define CONFIG_USB_CDC_ENABLED 1
358360
#define CONFIG_USB_CDC_RX_BUFSIZE 1024
359361
#define CONFIG_USB_CDC_TX_BUFSIZE 1024
362+
#define CONFIG_USB_DFU_RT_ENABLED 1
360363
#define CONFIG_USB_MSC_ENABLED 1
361364
#define CONFIG_USB_MSC_BUFSIZE 512
362365
#define CONFIG_USB_HID_ENABLED 1
@@ -365,14 +368,14 @@
365368
#define CONFIG_USB_MIDI_RX_BUFSIZE 64
366369
#define CONFIG_USB_MIDI_TX_BUFSIZE 64
367370
#define CONFIG_USB_VENDOR_ENABLED 1
368-
#define CONFIG_USB_DFU_RT_ENABLED 1
369371
#define CONFIG_USB_DESC_USE_ESPRESSIF_VID 1
370372
#define CONFIG_USB_DESC_USE_DEFAULT_PID 1
371373
#define CONFIG_USB_DESC_BCDDEVICE 0x0100
372374
#define CONFIG_USB_DESC_MANUFACTURER_STRING "Espressif"
373375
#define CONFIG_USB_DESC_PRODUCT_STRING "Espressif Device"
374376
#define CONFIG_USB_DESC_SERIAL_STRING "123456"
375377
#define CONFIG_USB_DESC_CDC_STRING "Espressif CDC Device"
378+
#define CONFIG_USB_DESC_DFU_RT_STRING "Espressif DFU Device"
376379
#define CONFIG_USB_DESC_MSC_STRING "Espressif MSC Device"
377380
#define CONFIG_USB_DESC_MIDI_STRING "Espressif MIDI Device"
378381
#define CONFIG_USB_DESC_HID_STRING "Espressif HID Device"

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
#include "usb_descriptors.h"
1919

2020

21+
#if CONFIG_USB_USE_BUILTIN_DESCRIPTORS
2122
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
2223
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
2324
*
2425
* Auto ProductID layout's Bitmap:
2526
* [MSB] HID | MSC | CDC [LSB]
2627
*/
27-
#define EPNUM_MSC 0x01
28-
#define EPNUM_HID 0x02
29-
#define EPNUM_MIDI 0x04
30-
#define EPNUM_VENDOR 0x06
28+
#define EPNUM_MSC 0x02
29+
#define EPNUM_HID 0x03
30+
#define EPNUM_MIDI 0x06
31+
#define EPNUM_VENDOR 0x01
3132

3233
#ifdef __cplusplus
3334
extern "C" {
@@ -47,6 +48,10 @@ enum {
4748
ITF_NUM_CDC_DATA,
4849
# endif
4950

51+
# if CFG_TUD_DFU_RT
52+
ITF_NUM_DFU_RT,
53+
# endif
54+
5055
# if CFG_TUD_MSC
5156
ITF_NUM_MSC,
5257
# endif
@@ -68,7 +73,7 @@ enum {
6873
};
6974

7075
enum {
71-
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + CFG_TUD_MSC * TUD_MSC_DESC_LEN +
76+
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + CFG_TUD_DFU_RT * TUD_DFU_RT_DESC_LEN + CFG_TUD_MSC * TUD_MSC_DESC_LEN +
7277
CFG_TUD_HID * TUD_HID_DESC_LEN + CFG_TUD_VENDOR * TUD_VENDOR_DESC_LEN + CFG_TUD_MIDI * TUD_MIDI_DESC_LEN
7378
};
7479

@@ -81,3 +86,5 @@ void tusb_clear_descriptor(void);
8186
#ifdef __cplusplus
8287
}
8388
#endif
89+
90+
#endif /* CONFIG_USB_USE_BUILTIN_DESCRIPTORS */

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

Lines changed: 0 additions & 51 deletions
This file was deleted.

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

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

7676
typedef struct {
77-
tusb_desc_device_t *descriptor;
78-
char **string_descriptor;
7977
bool external_phy;
8078
} tinyusb_config_t;
8179

8280
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config);
8381
// TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474)
8482

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+
85150
#ifdef __cplusplus
86151
}
87152
#endif

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ 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+
6367

6468

6569
//--------------------------------------------------------------------
@@ -93,10 +97,6 @@ extern "C" {
9397
# define CONFIG_USB_DFU_RT_ENABLED 0
9498
#endif
9599

96-
#ifndef CONFIG_USB_NET_ENABLED
97-
# define CONFIG_USB_NET_ENABLED 0
98-
#endif
99-
100100
#ifndef CONFIG_USB_VENDOR_ENABLED
101101
# define CONFIG_USB_VENDOR_ENABLED 0
102102
#endif
@@ -106,11 +106,11 @@ extern "C" {
106106
#define CFG_TUD_MSC CONFIG_USB_MSC_ENABLED
107107
#define CFG_TUD_HID CONFIG_USB_HID_ENABLED
108108
#define CFG_TUD_DFU_RT CONFIG_USB_DFU_RT_ENABLED
109-
#define CFG_TUD_NET CONFIG_USB_NET_ENABLED
110109

111110
#define CFG_TUD_MIDI CONFIG_USB_MIDI_ENABLED
112111
#define CFG_TUD_CUSTOM_CLASS CONFIG_USB_CUSTOM_CLASS_ENABLED
113112

113+
114114
#define CFG_TUD_VENDOR CONFIG_USB_VENDOR_ENABLED
115115

116116
// CDC FIFO size of TX and RX
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2020 Jerzy Kasenberg
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#ifndef _TUSB_BTH_DEVICE_H_
28+
#define _TUSB_BTH_DEVICE_H_
29+
30+
#include <common/tusb_common.h>
31+
#include <device/usbd.h>
32+
33+
//--------------------------------------------------------------------+
34+
// Class Driver Configuration
35+
//--------------------------------------------------------------------+
36+
#ifndef CFG_TUD_BTH_EVENT_EPSIZE
37+
#define CFG_TUD_BTH_EVENT_EPSIZE 16
38+
#endif
39+
#ifndef CFG_TUD_BTH_DATA_EPSIZE
40+
#define CFG_TUD_BTH_DATA_EPSIZE 64
41+
#endif
42+
43+
typedef struct TU_ATTR_PACKED
44+
{
45+
uint16_t op_code;
46+
uint8_t param_length;
47+
uint8_t param[255];
48+
} bt_hci_cmd_t;
49+
50+
#ifdef __cplusplus
51+
extern "C" {
52+
#endif
53+
54+
//--------------------------------------------------------------------+
55+
// Application Callback API (weak is optional)
56+
//--------------------------------------------------------------------+
57+
58+
// Invoked when HCI command was received over USB from Bluetooth host.
59+
// Detailed format is described in Bluetooth core specification Vol 2,
60+
// Part E, 5.4.1.
61+
// Length of the command is from 3 bytes (2 bytes for OpCode,
62+
// 1 byte for parameter total length) to 258.
63+
TU_ATTR_WEAK void tud_bt_hci_cmd_cb(void *hci_cmd, size_t cmd_len);
64+
65+
// Invoked when ACL data was received over USB from Bluetooth host.
66+
// Detailed format is described in Bluetooth core specification Vol 2,
67+
// Part E, 5.4.2.
68+
// Length is from 4 bytes, (12 bits for Handle, 4 bits for flags
69+
// and 16 bits for data total length) to endpoint size.
70+
TU_ATTR_WEAK void tud_bt_acl_data_received_cb(void *acl_data, uint16_t data_len);
71+
72+
// Called when event sent with tud_bt_event_send() was delivered to BT stack.
73+
// Controller can release/reuse buffer with Event packet at this point.
74+
TU_ATTR_WEAK void tud_bt_event_sent_cb(uint16_t sent_bytes);
75+
76+
// Called when ACL data that was sent with tud_bt_acl_data_send()
77+
// was delivered to BT stack.
78+
// Controller can release/reuse buffer with ACL packet at this point.
79+
TU_ATTR_WEAK void tud_bt_acl_data_sent_cb(uint16_t sent_bytes);
80+
81+
// Bluetooth controller calls this function when it wants to send even packet
82+
// as described in Bluetooth core specification Vol 2, Part E, 5.4.4.
83+
// Event has at least 2 bytes, first is Event code second contains parameter
84+
// total length. Controller can release/reuse event memory after
85+
// tud_bt_event_sent_cb() is called.
86+
bool tud_bt_event_send(void *event, uint16_t event_len);
87+
88+
// Bluetooth controller calls this to send ACL data packet
89+
// as described in Bluetooth core specification Vol 2, Part E, 5.4.2
90+
// Minimum length is 4 bytes, (12 bits for Handle, 4 bits for flags
91+
// and 16 bits for data total length). Upper limit is not limited
92+
// to endpoint size since buffer is allocate by controller
93+
// and must not be reused till tud_bt_acl_data_sent_cb() is called.
94+
bool tud_bt_acl_data_send(void *acl_data, uint16_t data_len);
95+
96+
//--------------------------------------------------------------------+
97+
// Internal Class Driver API
98+
//--------------------------------------------------------------------+
99+
void btd_init (void);
100+
void btd_reset (uint8_t rhport);
101+
uint16_t btd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
102+
bool btd_control_request (uint8_t rhport, tusb_control_request_t const * request);
103+
bool btd_control_complete (uint8_t rhport, tusb_control_request_t const * request);
104+
bool btd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
105+
106+
#ifdef __cplusplus
107+
}
108+
#endif
109+
110+
#endif /* _TUSB_BTH_DEVICE_H_ */

tools/sdk/esp32s2/include/tinyusb/tinyusb/src/class/cdc/cdc_device.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ static inline uint32_t tud_cdc_write_available(void)
229229
//--------------------------------------------------------------------+
230230
// INTERNAL USBD-CLASS DRIVER API
231231
//--------------------------------------------------------------------+
232-
void cdcd_init (void);
233-
void cdcd_reset (uint8_t rhport);
234-
bool cdcd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
235-
bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * request);
236-
bool cdcd_control_complete (uint8_t rhport, tusb_control_request_t const * request);
237-
bool cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
232+
void cdcd_init (void);
233+
void cdcd_reset (uint8_t rhport);
234+
uint16_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
235+
bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * request);
236+
bool cdcd_control_complete (uint8_t rhport, tusb_control_request_t const * request);
237+
bool cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
238238

239239
#ifdef __cplusplus
240240
}

tools/sdk/esp32s2/include/tinyusb/tinyusb/src/class/dfu/dfu_rt_device.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ TU_ATTR_WEAK void tud_dfu_rt_reboot_to_dfu(void); // TODO rename to _cb conventi
6363
//--------------------------------------------------------------------+
6464
// Internal Class Driver API
6565
//--------------------------------------------------------------------+
66-
void dfu_rtd_init(void);
67-
void dfu_rtd_reset(uint8_t rhport);
68-
bool dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
69-
bool dfu_rtd_control_request(uint8_t rhport, tusb_control_request_t const * request);
70-
bool dfu_rtd_control_complete(uint8_t rhport, tusb_control_request_t const * request);
71-
bool dfu_rtd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
66+
void dfu_rtd_init(void);
67+
void dfu_rtd_reset(uint8_t rhport);
68+
uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
69+
bool dfu_rtd_control_request(uint8_t rhport, tusb_control_request_t const * request);
70+
bool dfu_rtd_control_complete(uint8_t rhport, tusb_control_request_t const * request);
71+
bool dfu_rtd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
7272

7373
#ifdef __cplusplus
7474
}

0 commit comments

Comments
 (0)
0