Skip to content

Commit 3df9029

Browse files
authored
Merge pull request #331 from adafruit/update-tinyusb-46f7cf4da2959b96d3af6b7f23d0d02ff7187f2f
update tinyusb to commit 46f7cf4da2959b96d3af6b7f23d0d02ff7187f2f
2 parents b16bbbf + 336f237 commit 3df9029

File tree

11 files changed

+1032
-113
lines changed

11 files changed

+1032
-113
lines changed

src/common/tusb_common.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,11 @@ TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, c
122122

123123

124124
//------------- Bytes -------------//
125-
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_u32(uint8_t b3, uint8_t b2, uint8_t b1, uint8_t b0)
126-
{
125+
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_u32(uint8_t b3, uint8_t b2, uint8_t b1, uint8_t b0) {
127126
return ( ((uint32_t) b3) << 24) | ( ((uint32_t) b2) << 16) | ( ((uint32_t) b1) << 8) | b0;
128127
}
129128

130-
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_u16(uint8_t high, uint8_t low)
131-
{
129+
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_u16(uint8_t high, uint8_t low) {
132130
return (uint16_t) ((((uint16_t) high) << 8) | low);
133131
}
134132

src/common/tusb_debug.h

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,14 @@ void tu_print_mem(void const *buf, uint32_t count, uint8_t indent);
5858
#define tu_printf printf
5959
#endif
6060

61-
static inline void tu_print_arr(uint8_t const* buf, uint32_t bufsize)
62-
{
61+
static inline void tu_print_buf(uint8_t const* buf, uint32_t bufsize) {
6362
for(uint32_t i=0; i<bufsize; i++) tu_printf("%02X ", buf[i]);
6463
}
6564

6665
// Log with Level
6766
#define TU_LOG(n, ...) TU_XSTRCAT(TU_LOG, n)(__VA_ARGS__)
6867
#define TU_LOG_MEM(n, ...) TU_XSTRCAT3(TU_LOG, n, _MEM)(__VA_ARGS__)
69-
#define TU_LOG_ARR(n, ...) TU_XSTRCAT3(TU_LOG, n, _ARR)(__VA_ARGS__)
70-
#define TU_LOG_PTR(n, ...) TU_XSTRCAT3(TU_LOG, n, _PTR)(__VA_ARGS__)
68+
#define TU_LOG_BUF(n, ...) TU_XSTRCAT3(TU_LOG, n, _BUF)(__VA_ARGS__)
7169
#define TU_LOG_INT(n, ...) TU_XSTRCAT3(TU_LOG, n, _INT)(__VA_ARGS__)
7270
#define TU_LOG_HEX(n, ...) TU_XSTRCAT3(TU_LOG, n, _HEX)(__VA_ARGS__)
7371
#define TU_LOG_LOCATION() tu_printf("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
@@ -76,17 +74,15 @@ static inline void tu_print_arr(uint8_t const* buf, uint32_t bufsize)
7674
// Log Level 1: Error
7775
#define TU_LOG1 tu_printf
7876
#define TU_LOG1_MEM tu_print_mem
79-
#define TU_LOG1_ARR(_x, _n) tu_print_arr((uint8_t const*)(_x), _n)
80-
#define TU_LOG1_PTR(_x) tu_print_arr((uint8_t const*)(_x), sizeof(*(_x)))
77+
#define TU_LOG1_BUF(_x, _n) tu_print_buf((uint8_t const*)(_x), _n)
8178
#define TU_LOG1_INT(_x) tu_printf(#_x " = %ld\r\n", (unsigned long) (_x) )
8279
#define TU_LOG1_HEX(_x) tu_printf(#_x " = %lX\r\n", (unsigned long) (_x) )
8380

8481
// Log Level 2: Warn
8582
#if CFG_TUSB_DEBUG >= 2
8683
#define TU_LOG2 TU_LOG1
8784
#define TU_LOG2_MEM TU_LOG1_MEM
88-
#define TU_LOG2_ARR TU_LOG1_ARR
89-
#define TU_LOG2_PTR TU_LOG1_PTR
85+
#define TU_LOG2_BUF TU_LOG1_BUF
9086
#define TU_LOG2_INT TU_LOG1_INT
9187
#define TU_LOG2_HEX TU_LOG1_HEX
9288
#endif
@@ -95,30 +91,25 @@ static inline void tu_print_arr(uint8_t const* buf, uint32_t bufsize)
9591
#if CFG_TUSB_DEBUG >= 3
9692
#define TU_LOG3 TU_LOG1
9793
#define TU_LOG3_MEM TU_LOG1_MEM
98-
#define TU_LOG3_ARR TU_LOG1_ARR
99-
#define TU_LOG3_PTR TU_LOG1_PTR
94+
#define TU_LOG3_BUF TU_LOG1_BUF
10095
#define TU_LOG3_INT TU_LOG1_INT
10196
#define TU_LOG3_HEX TU_LOG1_HEX
10297
#endif
10398

104-
typedef struct
105-
{
99+
typedef struct {
106100
uint32_t key;
107101
const char* data;
108102
} tu_lookup_entry_t;
109103

110-
typedef struct
111-
{
104+
typedef struct {
112105
uint16_t count;
113106
tu_lookup_entry_t const* items;
114107
} tu_lookup_table_t;
115108

116-
static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint32_t key)
117-
{
109+
static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint32_t key) {
118110
tu_static char not_found[11];
119111

120-
for(uint16_t i=0; i<p_table->count; i++)
121-
{
112+
for(uint16_t i=0; i<p_table->count; i++) {
122113
if (p_table->items[i].key == key) return p_table->items[i].data;
123114
}
124115

@@ -133,8 +124,7 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3
133124
#ifndef TU_LOG
134125
#define TU_LOG(n, ...)
135126
#define TU_LOG_MEM(n, ...)
136-
#define TU_LOG_ARR(n, ...)
137-
#define TU_LOG_PTR(n, ...)
127+
#define TU_LOG_BUF(n, ...)
138128
#define TU_LOG_INT(n, ...)
139129
#define TU_LOG_HEX(n, ...)
140130
#define TU_LOG_LOCATION()
@@ -145,34 +135,30 @@ static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint3
145135

146136
#define TU_LOG0(...)
147137
#define TU_LOG0_MEM(...)
148-
#define TU_LOG0_ARR(...)
149-
#define TU_LOG0_PTR(...)
138+
#define TU_LOG0_BUF(...)
150139
#define TU_LOG0_INT(...)
151140
#define TU_LOG0_HEX(...)
152141

153142
#ifndef TU_LOG1
154143
#define TU_LOG1(...)
155144
#define TU_LOG1_MEM(...)
156-
#define TU_LOG1_ARR(...)
157-
#define TU_LOG1_PTR(...)
145+
#define TU_LOG1_BUF(...)
158146
#define TU_LOG1_INT(...)
159147
#define TU_LOG1_HEX(...)
160148
#endif
161149

162150
#ifndef TU_LOG2
163151
#define TU_LOG2(...)
164152
#define TU_LOG2_MEM(...)
165-
#define TU_LOG2_ARR(...)
166-
#define TU_LOG2_PTR(...)
153+
#define TU_LOG2_BUF(...)
167154
#define TU_LOG2_INT(...)
168155
#define TU_LOG2_HEX(...)
169156
#endif
170157

171158
#ifndef TU_LOG3
172159
#define TU_LOG3(...)
173160
#define TU_LOG3_MEM(...)
174-
#define TU_LOG3_ARR(...)
175-
#define TU_LOG3_PTR(...)
161+
#define TU_LOG3_BUF(...)
176162
#define TU_LOG3_INT(...)
177163
#define TU_LOG3_HEX(...)
178164
#endif

src/common/tusb_mcu.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,18 @@
385385
#define TUP_RHPORT_HIGHSPEED 1
386386
#endif
387387

388+
389+
//--------------------------------------------------------------------+
390+
// External USB controller
391+
//--------------------------------------------------------------------+
392+
393+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
394+
#ifndef CFG_TUH_MAX3421_ENDPOINT_TOTAL
395+
#define CFG_TUH_MAX3421_ENDPOINT_TOTAL (8 + 4*(CFG_TUH_DEVICE_MAX-1))
396+
#endif
397+
#endif
398+
399+
388400
//--------------------------------------------------------------------+
389401
// Default Values
390402
//--------------------------------------------------------------------+

src/device/usbd.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,42 @@
3535
#include "device/usbd.h"
3636
#include "device/usbd_pvt.h"
3737

38+
#ifndef CFG_TUD_MEM_SECTION
39+
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
40+
#endif
41+
42+
#ifndef CFG_TUD_LOG_LEVEL
43+
#define CFG_TUD_LOG_LEVEL 2
44+
#endif
45+
46+
#ifndef TU_LOG_USBD
47+
#define TU_LOG_USBD(...) TU_LOG(CFG_TUD_LOG_LEVEL, __VA_ARGS__)
48+
#endif
49+
3850
//--------------------------------------------------------------------+
3951
// ESP32 out-of-sync
4052
//--------------------------------------------------------------------+
41-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
53+
#if defined(ARDUINO_ARCH_ESP32)
54+
55+
#ifndef tu_static
4256
#define tu_static static
4357
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
4458
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
4559
TU_ATTR_WEAK bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size);
4660
TU_ATTR_WEAK bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
4761
#endif
4862

49-
#ifndef CFG_TUD_MEM_SECTION
50-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
63+
#ifndef TU_LOG_BUF
64+
#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
65+
static inline void tu_print_buf(uint8_t const* buf, uint32_t bufsize) {
66+
for(uint32_t i=0; i<bufsize; i++) tu_printf("%02X ", buf[i]);
67+
}
68+
#define TU_LOG_BUF(lvl, _buf, _bufsize) tu_print_buf(_buf, _bufsize)
69+
#else
70+
#define TU_LOG_BUF(lvl, _buf, _bufsize)
5171
#endif
52-
53-
#ifndef CFG_TUD_LOG_LEVEL
54-
#define CFG_TUD_LOG_LEVEL 2
5572
#endif
5673

57-
#ifndef TU_LOG_USBD
58-
#define TU_LOG_USBD(...) TU_LOG(CFG_TUD_LOG_LEVEL, __VA_ARGS__)
5974
#endif
6075

6176
//--------------------------------------------------------------------+
@@ -529,11 +544,8 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr)
529544
break;
530545

531546
case DCD_EVENT_SETUP_RECEIVED:
532-
#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
533-
//TU_LOG_ARR(CFG_TUD_LOG_LEVEL, &event.setup_received, 8);
534-
tu_print_arr(&event.setup_received, 8);
547+
TU_LOG_BUF(CFG_TUD_LOG_LEVEL, &event.setup_received, 8);
535548
TU_LOG_USBD("\r\n");
536-
#endif
537549

538550
// Mark as connected after receiving 1st setup packet.
539551
// But it is easier to set it every time instead of wasting time to check then set

src/device/usbd.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr);
5050

5151
// Task function should be called in main/rtos loop
5252
TU_ATTR_ALWAYS_INLINE static inline
53-
void tud_task (void)
54-
{
53+
void tud_task (void) {
5554
tud_task_ext(UINT32_MAX, false);
5655
}
5756

@@ -80,8 +79,7 @@ bool tud_suspended(void);
8079

8180
// Check if device is ready to transfer
8281
TU_ATTR_ALWAYS_INLINE static inline
83-
bool tud_ready(void)
84-
{
82+
bool tud_ready(void) {
8583
return tud_mounted() && !tud_suspended();
8684
}
8785

src/device/usbd_pvt.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*
2424
* This file is part of the TinyUSB stack.
2525
*/
26-
#ifndef USBD_PVT_H_
27-
#define USBD_PVT_H_
26+
#ifndef _TUSB_USBD_PVT_H_
27+
#define _TUSB_USBD_PVT_H_
2828

2929
#include "osal/osal.h"
3030
#include "common/tusb_fifo.h"
@@ -44,8 +44,7 @@
4444
// Class Driver API
4545
//--------------------------------------------------------------------+
4646

47-
typedef struct
48-
{
47+
typedef struct {
4948
#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
5049
char const* name;
5150
#endif
@@ -111,8 +110,7 @@ bool usbd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endp
111110

112111
// Check if endpoint is ready (not busy and not stalled)
113112
TU_ATTR_ALWAYS_INLINE static inline
114-
bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr)
115-
{
113+
bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr) {
116114
return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr);
117115
}
118116

@@ -124,11 +122,10 @@ void usbd_sof_enable(uint8_t rhport, bool en);
124122
*------------------------------------------------------------------*/
125123

126124
bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in);
127-
void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr );
128-
125+
void usbd_defer_func(osal_task_func_t func, void *param, bool in_isr);
129126

130127
#ifdef __cplusplus
131128
}
132129
#endif
133130

134-
#endif /* USBD_PVT_H_ */
131+
#endif

src/host/hcd.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
// Configuration
4040
//--------------------------------------------------------------------+
4141

42-
// Max number of endpoints per device
42+
// Max number of endpoints pair per device
4343
// TODO optimize memory usage
4444
#ifndef CFG_TUH_ENDPOINT_MAX
4545
#define CFG_TUH_ENDPOINT_MAX 16
@@ -167,17 +167,17 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
167167
//--------------------------------------------------------------------+
168168

169169
// Open an endpoint
170-
bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc);
170+
bool hcd_edpt_open(uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const * ep_desc);
171171

172172
// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked
173-
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);
173+
bool hcd_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);
174174

175175
// Abort a queued transfer. Note: it can only abort transfer that has not been started
176176
// Return true if a queued transfer is aborted, false if there is no transfer to abort
177177
bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr);
178178

179179
// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked
180-
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]);
180+
bool hcd_setup_send(uint8_t rhport, uint8_t daddr, uint8_t const setup_packet[8]);
181181

182182
// clear stall, data toggle is also reset to DATA0
183183
bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr);
@@ -198,8 +198,7 @@ extern void hcd_event_handler(hcd_event_t const* event, bool in_isr);
198198

199199
// Helper to send device attach event
200200
TU_ATTR_ALWAYS_INLINE static inline
201-
void hcd_event_device_attach(uint8_t rhport, bool in_isr)
202-
{
201+
void hcd_event_device_attach(uint8_t rhport, bool in_isr) {
203202
hcd_event_t event;
204203
event.rhport = rhport;
205204
event.event_id = HCD_EVENT_DEVICE_ATTACH;
@@ -211,8 +210,7 @@ void hcd_event_device_attach(uint8_t rhport, bool in_isr)
211210

212211
// Helper to send device removal event
213212
TU_ATTR_ALWAYS_INLINE static inline
214-
void hcd_event_device_remove(uint8_t rhport, bool in_isr)
215-
{
213+
void hcd_event_device_remove(uint8_t rhport, bool in_isr) {
216214
hcd_event_t event;
217215
event.rhport = rhport;
218216
event.event_id = HCD_EVENT_DEVICE_REMOVE;
@@ -224,10 +222,8 @@ void hcd_event_device_remove(uint8_t rhport, bool in_isr)
224222

225223
// Helper to send USB transfer event
226224
TU_ATTR_ALWAYS_INLINE static inline
227-
void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint32_t xferred_bytes, xfer_result_t result, bool in_isr)
228-
{
229-
hcd_event_t event =
230-
{
225+
void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint32_t xferred_bytes, xfer_result_t result, bool in_isr) {
226+
hcd_event_t event = {
231227
.rhport = 0, // TODO correct rhport
232228
.event_id = HCD_EVENT_XFER_COMPLETE,
233229
.dev_addr = dev_addr,

0 commit comments

Comments
 (0)