Skip to content

Commit 160c6ee

Browse files
committed
update tinyusb to hathach/tinyusb@79de831
1 parent 43147e9 commit 160c6ee

File tree

10 files changed

+226
-152
lines changed

10 files changed

+226
-152
lines changed

src/class/audio/audio_device.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
CFG_TUSB_MCU == OPT_MCU_GD32VF103 || \
103103
CFG_TUSB_MCU == OPT_MCU_LPC18XX || \
104104
CFG_TUSB_MCU == OPT_MCU_LPC43XX || \
105-
CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
105+
CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
106+
CFG_TUSB_MCU == OPT_MCU_MSP432E4
106107
#if TUD_AUDIO_PREFER_RING_BUFFER
107108
#define USE_LINEAR_BUFFER 0
108109
#else

src/class/bth/bth_device.c

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -112,74 +112,78 @@ uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_
112112
TUD_BT_APP_SUBCLASS == itf_desc->bInterfaceSubClass &&
113113
TUD_BT_PROTOCOL_PRIMARY_CONTROLLER == itf_desc->bInterfaceProtocol, 0);
114114

115-
// Distinguish interface by number of endpoints, as both interface have same class, subclass and protocol
116-
if (itf_desc->bNumEndpoints == 3 && max_len >= hci_itf_size)
117-
{
118-
_btd_itf.itf_num = itf_desc->bInterfaceNumber;
115+
TU_ASSERT(itf_desc->bNumEndpoints == 3 && max_len >= hci_itf_size);
119116

120-
desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
117+
_btd_itf.itf_num = itf_desc->bInterfaceNumber;
121118

122-
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
123-
TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
124-
_btd_itf.ep_ev = desc_ep->bEndpointAddress;
119+
desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
125120

126-
// Open endpoint pair
127-
TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(desc_ep), 2, TUSB_XFER_BULK, &_btd_itf.ep_acl_out,
128-
&_btd_itf.ep_acl_in), 0);
121+
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
122+
TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
123+
_btd_itf.ep_ev = desc_ep->bEndpointAddress;
129124

130-
// Prepare for incoming data from host
131-
TU_ASSERT(usbd_edpt_xfer(rhport, _btd_itf.ep_acl_out, _btd_itf.epout_buf, CFG_TUD_BTH_DATA_EPSIZE), 0);
125+
// Open endpoint pair
126+
TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(desc_ep), 2, TUSB_XFER_BULK, &_btd_itf.ep_acl_out,
127+
&_btd_itf.ep_acl_in), 0);
132128

133-
drv_len = hci_itf_size;
134-
}
135-
else if (itf_desc->bNumEndpoints == 2 && max_len >= iso_alt_itf_size)
136-
{
137-
uint8_t dir;
129+
itf_desc = (tusb_desc_interface_t const *)tu_desc_next(tu_desc_next(tu_desc_next(desc_ep)));
138130

139-
desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(itf_desc);
131+
// Prepare for incoming data from host
132+
TU_ASSERT(usbd_edpt_xfer(rhport, _btd_itf.ep_acl_out, _btd_itf.epout_buf, CFG_TUD_BTH_DATA_EPSIZE), 0);
133+
134+
drv_len = hci_itf_size;
135+
136+
// Ensure this is still BT Primary Controller
137+
TU_ASSERT(TUSB_CLASS_WIRELESS_CONTROLLER == itf_desc->bInterfaceClass &&
138+
TUD_BT_APP_SUBCLASS == itf_desc->bInterfaceSubClass &&
139+
TUD_BT_PROTOCOL_PRIMARY_CONTROLLER == itf_desc->bInterfaceProtocol, 0);
140+
TU_ASSERT(itf_desc->bNumEndpoints == 2 && max_len >= iso_alt_itf_size + drv_len);
141+
142+
uint8_t dir;
143+
144+
desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(itf_desc);
145+
TU_ASSERT(itf_desc->bAlternateSetting < CFG_TUD_BTH_ISO_ALT_COUNT, 0);
146+
TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT, 0);
147+
dir = tu_edpt_dir(desc_ep->bEndpointAddress);
148+
_btd_itf.ep_voice[dir] = desc_ep->bEndpointAddress;
149+
// Store endpoint size for alternative
150+
_btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t) tu_edpt_packet_size(desc_ep);
151+
152+
desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(desc_ep);
153+
TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT, 0);
154+
dir = tu_edpt_dir(desc_ep->bEndpointAddress);
155+
_btd_itf.ep_voice[dir] = desc_ep->bEndpointAddress;
156+
// Store endpoint size for alternative
157+
_btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t) tu_edpt_packet_size(desc_ep);
158+
drv_len += iso_alt_itf_size;
159+
160+
for (int i = 1; i < CFG_TUD_BTH_ISO_ALT_COUNT && drv_len + iso_alt_itf_size <= max_len; ++i) {
161+
// Make sure rest of alternatives matches
162+
itf_desc = (tusb_desc_interface_t const *)tu_desc_next(desc_ep);
163+
if (itf_desc->bDescriptorType != TUSB_DESC_INTERFACE ||
164+
TUSB_CLASS_WIRELESS_CONTROLLER != itf_desc->bInterfaceClass ||
165+
TUD_BT_APP_SUBCLASS != itf_desc->bInterfaceSubClass ||
166+
TUD_BT_PROTOCOL_PRIMARY_CONTROLLER != itf_desc->bInterfaceProtocol)
167+
{
168+
// Not an Iso interface instance
169+
break;
170+
}
140171
TU_ASSERT(itf_desc->bAlternateSetting < CFG_TUD_BTH_ISO_ALT_COUNT, 0);
141-
TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT, 0);
172+
173+
desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(itf_desc);
142174
dir = tu_edpt_dir(desc_ep->bEndpointAddress);
143-
_btd_itf.ep_voice[dir] = desc_ep->bEndpointAddress;
144-
// Store endpoint size for alternative
175+
// Verify that alternative endpoint are same as first ones
176+
TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT &&
177+
_btd_itf.ep_voice[dir] == desc_ep->bEndpointAddress, 0);
145178
_btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t) tu_edpt_packet_size(desc_ep);
146179

147180
desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(desc_ep);
148-
TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT, 0);
149181
dir = tu_edpt_dir(desc_ep->bEndpointAddress);
150-
_btd_itf.ep_voice[dir] = desc_ep->bEndpointAddress;
151-
// Store endpoint size for alternative
182+
// Verify that alternative endpoint are same as first ones
183+
TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT &&
184+
_btd_itf.ep_voice[dir] == desc_ep->bEndpointAddress, 0);
152185
_btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t) tu_edpt_packet_size(desc_ep);
153186
drv_len += iso_alt_itf_size;
154-
155-
for (int i = 1; i < CFG_TUD_BTH_ISO_ALT_COUNT && drv_len + iso_alt_itf_size <= max_len; ++i) {
156-
// Make sure rest of alternatives matches
157-
itf_desc = (tusb_desc_interface_t const *)tu_desc_next(desc_ep);
158-
if (itf_desc->bDescriptorType != TUSB_DESC_INTERFACE ||
159-
TUSB_CLASS_WIRELESS_CONTROLLER != itf_desc->bInterfaceClass ||
160-
TUD_BT_APP_SUBCLASS != itf_desc->bInterfaceSubClass ||
161-
TUD_BT_PROTOCOL_PRIMARY_CONTROLLER != itf_desc->bInterfaceProtocol)
162-
{
163-
// Not an Iso interface instance
164-
break;
165-
}
166-
TU_ASSERT(itf_desc->bAlternateSetting < CFG_TUD_BTH_ISO_ALT_COUNT, 0);
167-
168-
desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(itf_desc);
169-
dir = tu_edpt_dir(desc_ep->bEndpointAddress);
170-
// Verify that alternative endpoint are same as first ones
171-
TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT &&
172-
_btd_itf.ep_voice[dir] == desc_ep->bEndpointAddress, 0);
173-
_btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t) tu_edpt_packet_size(desc_ep);
174-
175-
desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(desc_ep);
176-
dir = tu_edpt_dir(desc_ep->bEndpointAddress);
177-
// Verify that alternative endpoint are same as first ones
178-
TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT &&
179-
_btd_itf.ep_voice[dir] == desc_ep->bEndpointAddress, 0);
180-
_btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t) tu_edpt_packet_size(desc_ep);
181-
drv_len += iso_alt_itf_size;
182-
}
183187
}
184188

185189
return drv_len;

src/class/msc/msc_device.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
481481
if (p_cbw->total_bytes)
482482
{
483483
// 6.7 The 13 Cases: case 4 (Hi > Dn)
484-
TU_LOG(MSC_DEBUG, " SCSI case 4 (Hi > Dn): %lu\r\n", p_cbw->total_bytes);
484+
// TU_LOG(MSC_DEBUG, " SCSI case 4 (Hi > Dn): %lu\r\n", p_cbw->total_bytes);
485485
fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_FAILED);
486486
}else
487487
{
@@ -494,7 +494,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
494494
if ( p_cbw->total_bytes == 0 )
495495
{
496496
// 6.7 The 13 Cases: case 2 (Hn < Di)
497-
TU_LOG(MSC_DEBUG, " SCSI case 2 (Hn < Di): %lu\r\n", p_cbw->total_bytes);
497+
// TU_LOG(MSC_DEBUG, " SCSI case 2 (Hn < Di): %lu\r\n", p_cbw->total_bytes);
498498
fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_FAILED);
499499
}else
500500
{
@@ -609,15 +609,15 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
609609
if ( (p_cbw->total_bytes > p_msc->xferred_len) && is_data_in(p_cbw->dir) )
610610
{
611611
// 6.7 The 13 Cases: case 5 (Hi > Di): STALL before status
612-
TU_LOG(MSC_DEBUG, " SCSI case 5 (Hi > Di): %lu > %lu\r\n", p_cbw->total_bytes, p_msc->xferred_len);
612+
// TU_LOG(MSC_DEBUG, " SCSI case 5 (Hi > Di): %lu > %lu\r\n", p_cbw->total_bytes, p_msc->xferred_len);
613613
usbd_edpt_stall(rhport, p_msc->ep_in);
614614
}else
615615
{
616616
TU_ASSERT( send_csw(rhport, p_msc) );
617617
}
618618
}
619619

620-
#if TU_CHECK_MCU(CXD56)
620+
#if TU_CHECK_MCU(OPT_MCU_CXD56)
621621
// WORKAROUND: cxd56 has its own nuttx usb stack which does not forward Set/ClearFeature(Endpoint) to DCD.
622622
// There is no way for us to know when EP is un-stall, therefore we will unconditionally un-stall here and
623623
// hope everything will work

src/common/tusb_common.h

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u32_byte2(uint32_t ui32) { return
111111
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u32_byte1(uint32_t ui32) { return TU_U32_BYTE1(ui32); }
112112
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u32_byte0(uint32_t ui32) { return TU_U32_BYTE0(ui32); }
113113

114+
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_u32_high16(uint32_t ui32) { return (uint16_t) (ui32 >> 16); }
115+
TU_ATTR_ALWAYS_INLINE static inline uint16_t tu_u32_low16 (uint32_t ui32) { return (uint16_t) (ui32 & 0x0000ffffu); }
116+
114117
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_high(uint16_t ui16) { return TU_U16_HIGH(ui16); }
115118
TU_ATTR_ALWAYS_INLINE static inline uint8_t tu_u16_low (uint16_t ui16) { return TU_U16_LOW(ui16); }
116119

@@ -235,37 +238,6 @@ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16 (void* mem, ui
235238

236239
#endif
237240

238-
/*------------------------------------------------------------------*/
239-
/* Count number of arguments of __VA_ARGS__
240-
* - reference https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
241-
* - _GET_NTH_ARG() takes args >= N (64) but only expand to Nth one (64th)
242-
* - _RSEQ_N() is reverse sequential to N to add padding to have
243-
* Nth position is the same as the number of arguments
244-
* - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma)
245-
*------------------------------------------------------------------*/
246-
#ifndef TU_ARGS_NUM
247-
248-
#define TU_ARGS_NUM(...) _TU_NARG(_0, ##__VA_ARGS__,_RSEQ_N())
249-
250-
#define _TU_NARG(...) _GET_NTH_ARG(__VA_ARGS__)
251-
#define _GET_NTH_ARG( \
252-
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
253-
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
254-
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
255-
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
256-
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
257-
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
258-
_61,_62,_63,N,...) N
259-
#define _RSEQ_N() \
260-
62,61,60, \
261-
59,58,57,56,55,54,53,52,51,50, \
262-
49,48,47,46,45,44,43,42,41,40, \
263-
39,38,37,36,35,34,33,32,31,30, \
264-
29,28,27,26,25,24,23,22,21,20, \
265-
19,18,17,16,15,14,13,12,11,10, \
266-
9,8,7,6,5,4,3,2,1,0
267-
#endif
268-
269241
// To be removed
270242
//------------- Binary constant -------------//
271243
#if defined(__GNUC__) && !defined(__CC_ARM)
@@ -334,8 +306,8 @@ void tu_print_var(uint8_t const* buf, uint32_t bufsize)
334306
#define TU_LOG1 tu_printf
335307
#define TU_LOG1_MEM tu_print_mem
336308
#define TU_LOG1_VAR(_x) tu_print_var((uint8_t const*)(_x), sizeof(*(_x)))
337-
#define TU_LOG1_INT(_x) tu_printf(#_x " = %ld\r\n", (uint32_t) (_x) )
338-
#define TU_LOG1_HEX(_x) tu_printf(#_x " = %lX\r\n", (uint32_t) (_x) )
309+
#define TU_LOG1_INT(_x) tu_printf(#_x " = %ld\r\n", (unsigned long) (_x) )
310+
#define TU_LOG1_HEX(_x) tu_printf(#_x " = %lX\r\n", (unsigned long) (_x) )
339311

340312
// Log Level 2: Warn
341313
#if CFG_TUSB_DEBUG >= 2

src/common/tusb_compiler.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,46 @@
6767
#define TU_LITTLE_ENDIAN (0x12u)
6868
#define TU_BIG_ENDIAN (0x21u)
6969

70+
/*------------------------------------------------------------------*/
71+
/* Count number of arguments of __VA_ARGS__
72+
* - reference https://stackoverflow.com/questions/2124339/c-preprocessor-va-args-number-of-arguments
73+
* - _GET_NTH_ARG() takes args >= N (64) but only expand to Nth one (64th)
74+
* - _RSEQ_N() is reverse sequential to N to add padding to have
75+
* Nth position is the same as the number of arguments
76+
* - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma)
77+
*------------------------------------------------------------------*/
78+
#define TU_ARGS_NUM(...) _TU_NARG(_0, ##__VA_ARGS__,_RSEQ_N())
79+
80+
#define _TU_NARG(...) _GET_NTH_ARG(__VA_ARGS__)
81+
#define _GET_NTH_ARG( \
82+
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
83+
_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
84+
_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
85+
_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
86+
_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
87+
_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
88+
_61,_62,_63,N,...) N
89+
#define _RSEQ_N() \
90+
62,61,60, \
91+
59,58,57,56,55,54,53,52,51,50, \
92+
49,48,47,46,45,44,43,42,41,40, \
93+
39,38,37,36,35,34,33,32,31,30, \
94+
29,28,27,26,25,24,23,22,21,20, \
95+
19,18,17,16,15,14,13,12,11,10, \
96+
9,8,7,6,5,4,3,2,1,0
97+
98+
// Apply an macro X to each of the arguments with an separated of choice
99+
#define TU_ARGS_APPLY(_X, _s, ...) TU_XSTRCAT(_TU_ARGS_APPLY_, TU_ARGS_NUM(__VA_ARGS__))(_X, _s, __VA_ARGS__)
100+
101+
#define _TU_ARGS_APPLY_1(_X, _s, _a1) _X(_a1)
102+
#define _TU_ARGS_APPLY_2(_X, _s, _a1, _a2) _X(_a1) _s _X(_a2)
103+
#define _TU_ARGS_APPLY_3(_X, _s, _a1, _a2, _a3) _X(_a1) _s _TU_ARGS_APPLY_2(_X, _s, _a2, _a3)
104+
#define _TU_ARGS_APPLY_4(_X, _s, _a1, _a2, _a3, _a4) _X(_a1) _s _TU_ARGS_APPLY_3(_X, _s, _a2, _a3, _a4)
105+
#define _TU_ARGS_APPLY_5(_X, _s, _a1, _a2, _a3, _a4, _a5) _X(_a1) _s _TU_ARGS_APPLY_4(_X, _s, _a2, _a3, _a4, _a5)
106+
#define _TU_ARGS_APPLY_6(_X, _s, _a1, _a2, _a3, _a4, _a5, _a6) _X(_a1) _s _TU_ARGS_APPLY_5(_X, _s, _a2, _a3, _a4, _a5, _a6)
107+
#define _TU_ARGS_APPLY_7(_X, _s, _a1, _a2, _a3, _a4, _a5, _a6, _a7) _X(_a1) _s _TU_ARGS_APPLY_6(_X, _s, _a2, _a3, _a4, _a5, _a6, _a7)
108+
#define _TU_ARGS_APPLY_8(_X, _s, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8) _X(_a1) _s _TU_ARGS_APPLY_7(_X, _s, _a2, _a3, _a4, _a5, _a6, _a7, _a8)
109+
70110
//--------------------------------------------------------------------+
71111
// Compiler porting with Attribute and Endian
72112
//--------------------------------------------------------------------+

src/common/tusb_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
typedef enum
4848
{
4949
TUSB_SPEED_FULL = 0,
50-
TUSB_SPEED_LOW ,
51-
TUSB_SPEED_HIGH,
50+
TUSB_SPEED_LOW = 1,
51+
TUSB_SPEED_HIGH = 2,
5252
TUSB_SPEED_INVALID = 0xff,
5353
}tusb_speed_t;
5454

0 commit comments

Comments
 (0)