Skip to content

Commit 7aa566c

Browse files
authored
Merge pull request #256 from adafruit/update-tinyusb-0.15.0
update tinyusb core to 0.15.0
2 parents 202e700 + 386c14a commit 7aa566c

File tree

21 files changed

+732
-413
lines changed

21 files changed

+732
-413
lines changed

src/class/audio/audio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,13 @@ typedef struct TU_ATTR_PACKED
721721
uint8_t bLength ; ///< Size of this descriptor, in bytes: 17.
722722
uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
723723
uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_INPUT_TERMINAL.
724+
uint8_t bTerminalID ; ///< Constant uniquely identifying the Terminal within the audio function. This value is used in all requests to address this terminal.
724725
uint16_t wTerminalType ; ///< Constant characterizing the type of Terminal. See: audio_terminal_type_t for USB streaming and audio_terminal_input_type_t for other input types.
725726
uint8_t bAssocTerminal ; ///< ID of the Output Terminal to which this Input Terminal is associated.
726727
uint8_t bCSourceID ; ///< ID of the Clock Entity to which this Input Terminal is connected.
727728
uint8_t bNrChannels ; ///< Number of logical output channels in the Terminal’s output audio channel cluster.
728729
uint32_t bmChannelConfig ; ///< Describes the spatial location of the logical channels. See:audio_channel_config_t.
730+
uint8_t iChannelNames ; ///< Index of a string descriptor, describing the name of the first logical channel.
729731
uint16_t bmControls ; ///< See: audio_terminal_input_control_pos_t.
730732
uint8_t iTerminal ; ///< Index of a string descriptor, describing the Input Terminal.
731733
} audio_desc_input_terminal_t;

src/class/hid/hid_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
403403
{
404404
if (tud_hid_report_complete_cb)
405405
{
406-
tud_hid_report_complete_cb(instance, p_hid->epin_buf, (/*uint16_t*/ uint8_t) xferred_bytes);
406+
tud_hid_report_complete_cb(instance, p_hid->epin_buf, (uint16_t) xferred_bytes);
407407
}
408408
}
409409
// Received report

src/class/hid/hid_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate);
116116
// Invoked when sent REPORT successfully to host
117117
// Application can use this to send the next report
118118
// Note: For composite reports, report[0] is report ID
119-
TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, /*uint16_t*/ uint8_t len );
119+
TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint16_t len);
120120

121121

122122
//--------------------------------------------------------------------+

src/class/net/ncm_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ bool netd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
392392

393393
if (NCM_GET_NTB_PARAMETERS == request->bRequest)
394394
{
395-
tud_control_xfer(rhport, request, (void*)&ntb_parameters, sizeof(ntb_parameters));
395+
tud_control_xfer(rhport, request, (void*)(uintptr_t) &ntb_parameters, sizeof(ntb_parameters));
396396
}
397397

398398
break;

src/class/usbtmc/usbtmc_device.c

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ static bool handle_devMsgOut(uint8_t rhport, void *data, size_t len, size_t pack
157157
static uint8_t termChar;
158158
static uint8_t termCharRequested = false;
159159

160-
OSAL_MUTEX_DEF(usbtmcLockBuffer);
161-
static osal_mutex_t usbtmcLock;
160+
#if OSAL_MUTEX_REQUIRED
161+
static OSAL_MUTEX_DEF(usbtmcLockBuffer);
162+
#endif
163+
osal_mutex_t usbtmcLock;
162164

163165
// Our own private lock, mostly for the state variable.
164166
#define criticalEnter() do { (void) osal_mutex_lock(usbtmcLock,OSAL_TIMEOUT_WAIT_FOREVER); } while (0)
@@ -362,7 +364,7 @@ bool tud_usbtmc_start_bus_read()
362364
case STATE_RCV:
363365
break;
364366
default:
365-
TU_VERIFY(false);
367+
return false;
366368
}
367369
TU_VERIFY(usbd_edpt_xfer(usbtmc_state.rhport, usbtmc_state.ep_bulk_out, usbtmc_state.ep_bulk_out_buf, (uint16_t)usbtmc_state.ep_bulk_out_wMaxPacketSize));
368370
return true;
@@ -464,61 +466,60 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
464466
switch(usbtmc_state.state)
465467
{
466468
case STATE_IDLE:
467-
TU_VERIFY(xferred_bytes >= sizeof(usbtmc_msg_generic_t));
468-
msg = (usbtmc_msg_generic_t*)(usbtmc_state.ep_bulk_out_buf);
469-
uint8_t invInvTag = (uint8_t)~(msg->header.bTagInverse);
470-
TU_VERIFY(msg->header.bTag == invInvTag);
471-
TU_VERIFY(msg->header.bTag != 0x00);
472-
473-
switch(msg->header.MsgID) {
474-
case USBTMC_MSGID_DEV_DEP_MSG_OUT:
475-
if(!handle_devMsgOutStart(rhport, msg, xferred_bytes))
476-
{
477-
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
478-
TU_VERIFY(false);
479-
}
480-
break;
469+
{
470+
TU_VERIFY(xferred_bytes >= sizeof(usbtmc_msg_generic_t));
471+
msg = (usbtmc_msg_generic_t*)(usbtmc_state.ep_bulk_out_buf);
472+
uint8_t invInvTag = (uint8_t)~(msg->header.bTagInverse);
473+
TU_VERIFY(msg->header.bTag == invInvTag);
474+
TU_VERIFY(msg->header.bTag != 0x00);
475+
476+
switch(msg->header.MsgID) {
477+
case USBTMC_MSGID_DEV_DEP_MSG_OUT:
478+
if(!handle_devMsgOutStart(rhport, msg, xferred_bytes))
479+
{
480+
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
481+
return false;
482+
}
483+
break;
481484

482-
case USBTMC_MSGID_DEV_DEP_MSG_IN:
483-
TU_VERIFY(handle_devMsgIn(msg, xferred_bytes));
484-
break;
485+
case USBTMC_MSGID_DEV_DEP_MSG_IN:
486+
TU_VERIFY(handle_devMsgIn(msg, xferred_bytes));
487+
break;
485488

486489
#if (CFG_TUD_USBTMC_ENABLE_488)
487-
case USBTMC_MSGID_USB488_TRIGGER:
488-
// Spec says we halt the EP if we didn't declare we support it.
489-
TU_VERIFY(usbtmc_state.capabilities->bmIntfcCapabilities488.supportsTrigger);
490-
TU_VERIFY(tud_usbtmc_msg_trigger_cb(msg));
490+
case USBTMC_MSGID_USB488_TRIGGER:
491+
// Spec says we halt the EP if we didn't declare we support it.
492+
TU_VERIFY(usbtmc_state.capabilities->bmIntfcCapabilities488.supportsTrigger);
493+
TU_VERIFY(tud_usbtmc_msg_trigger_cb(msg));
491494

492-
break;
495+
break;
493496
#endif
494-
case USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT:
495-
case USBTMC_MSGID_VENDOR_SPECIFIC_IN:
496-
default:
497-
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
498-
TU_VERIFY(false);
499-
return false;
497+
case USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT:
498+
case USBTMC_MSGID_VENDOR_SPECIFIC_IN:
499+
default:
500+
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
501+
return false;
502+
}
503+
return true;
500504
}
501-
return true;
502-
503505
case STATE_RCV:
504506
if(!handle_devMsgOut(rhport, usbtmc_state.ep_bulk_out_buf, xferred_bytes, xferred_bytes))
505507
{
506508
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
507-
TU_VERIFY(false);
509+
return false;
508510
}
509511
return true;
510512

511513
case STATE_ABORTING_BULK_OUT:
512-
TU_VERIFY(false);
513-
return false; // Should be stalled by now, shouldn't have received a packet.
514+
return false;
514515

515516
case STATE_TX_REQUESTED:
516517
case STATE_TX_INITIATED:
517518
case STATE_ABORTING_BULK_IN:
518519
case STATE_ABORTING_BULK_IN_SHORTED:
519520
case STATE_ABORTING_BULK_IN_ABORTED:
520521
default:
521-
TU_VERIFY(false);
522+
return false;
522523
}
523524
}
524525
else if(ep_addr == usbtmc_state.ep_bulk_in)
@@ -567,7 +568,6 @@ bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
567568

568569
default:
569570
TU_ASSERT(false);
570-
return false;
571571
}
572572
}
573573
else if (ep_addr == usbtmc_state.ep_int_in) {
@@ -871,16 +871,13 @@ bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
871871
case USB488_bREQUEST_LOCAL_LOCKOUT:
872872
{
873873
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
874-
TU_VERIFY(false);
875874
return false;
876875
}
877876
#endif
878877

879878
default:
880-
TU_VERIFY(false);
881879
return false;
882880
}
883-
TU_VERIFY(false);
884881
}
885882

886883
#endif /* CFG_TUD_TSMC */

src/class/video/video_device.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ typedef struct TU_ATTR_PACKED {
108108

109109
/* video control interface */
110110
typedef struct TU_ATTR_PACKED {
111-
void const *beg; /* The head of the first video control interface descriptor */
111+
uint8_t const *beg; /* The head of the first video control interface descriptor */
112112
uint16_t len; /* Byte length of the descriptors */
113113
uint16_t cur; /* offset for current video control interface */
114114
uint8_t stm[CFG_TUD_VIDEO_STREAMING]; /* Indices of streaming interface */
@@ -174,7 +174,7 @@ static tusb_desc_vc_itf_t const* _get_desc_vc(videod_interface_t const *self)
174174
static tusb_desc_vs_itf_t const* _get_desc_vs(videod_streaming_interface_t const *self)
175175
{
176176
if (!self->desc.cur) return NULL;
177-
void const *desc = _videod_itf[self->index_vc].beg;
177+
uint8_t const *desc = _videod_itf[self->index_vc].beg;
178178
return (tusb_desc_vs_itf_t const*)(desc + self->desc.cur);
179179
}
180180

@@ -247,9 +247,9 @@ static void const* _next_desc_itf(void const *beg, void const *end)
247247
*
248248
* @return The pointer for interface descriptor.
249249
* @retval end did not found interface descriptor */
250-
static inline void const* _find_desc_itf(void const *beg, void const *end, uint_fast8_t itfnum, uint_fast8_t altnum)
250+
static inline uint8_t const* _find_desc_itf(void const *beg, void const *end, uint_fast8_t itfnum, uint_fast8_t altnum)
251251
{
252-
return _find_desc_3(beg, end, TUSB_DESC_INTERFACE, itfnum, altnum);
252+
return (uint8_t const*) _find_desc_3(beg, end, TUSB_DESC_INTERFACE, itfnum, altnum);
253253
}
254254

255255
/** Find the first endpoint descriptor belonging to the current interface descriptor.
@@ -275,7 +275,7 @@ static void const* _find_desc_ep(void const *beg, void const *end)
275275
static inline void const* _end_of_control_descriptor(void const *desc)
276276
{
277277
tusb_desc_vc_itf_t const *vc = (tusb_desc_vc_itf_t const *)desc;
278-
return desc + vc->std.bLength + vc->ctl.wTotalLength;
278+
return ((uint8_t const*) desc) + vc->std.bLength + tu_le16toh(vc->ctl.wTotalLength);
279279
}
280280

281281
/** Find the first entity descriptor with the entity ID
@@ -305,7 +305,7 @@ static void const* _find_desc_entity(void const *desc, uint_fast8_t entityid)
305305
static inline void const* _end_of_streaming_descriptor(void const *desc)
306306
{
307307
tusb_desc_vs_itf_t const *vs = (tusb_desc_vs_itf_t const *)desc;
308-
return desc + vs->std.bLength + vs->stm.wTotalLength;
308+
return ((uint8_t const*) desc) + vs->std.bLength + tu_le16toh(vs->stm.wTotalLength);
309309
}
310310

311311
/** Find the first format descriptor with the specified format number. */
@@ -581,8 +581,10 @@ static bool _negotiate_streaming_parameters(videod_streaming_interface_t const *
581581
static bool _close_vc_itf(uint8_t rhport, videod_interface_t *self)
582582
{
583583
tusb_desc_vc_itf_t const *vc = _get_desc_vc(self);
584+
584585
/* The next descriptor after the class-specific VC interface header descriptor. */
585-
void const *cur = (void const*)vc + vc->std.bLength + vc->ctl.bLength;
586+
void const *cur = (uint8_t const*)vc + vc->std.bLength + vc->ctl.bLength;
587+
586588
/* The end of the video control interface descriptor. */
587589
void const *end = _end_of_control_descriptor(vc);
588590
if (vc->std.bNumEndpoints) {
@@ -603,10 +605,11 @@ static bool _close_vc_itf(uint8_t rhport, videod_interface_t *self)
603605
static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t altnum)
604606
{
605607
TU_LOG2(" open VC %d\n", altnum);
606-
void const *beg = self->beg;
607-
void const *end = beg + self->len;
608+
uint8_t const *beg = self->beg;
609+
uint8_t const *end = beg + self->len;
610+
608611
/* The first descriptor is a video control interface descriptor. */
609-
void const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum);
612+
uint8_t const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum);
610613
TU_LOG2(" cur %d\n", cur - beg);
611614
TU_VERIFY(cur < end);
612615

@@ -616,7 +619,8 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t
616619
TU_ASSERT(vc->ctl.bInCollection <= CFG_TUD_VIDEO_STREAMING);
617620

618621
/* Update to point the end of the video control interface descriptor. */
619-
end = _end_of_control_descriptor(cur);
622+
end = _end_of_control_descriptor(cur);
623+
620624
/* Advance to the next descriptor after the class-specific VC interface header descriptor. */
621625
cur += vc->std.bLength + vc->ctl.bLength;
622626
TU_LOG2(" bNumEndpoints %d\n", vc->std.bNumEndpoints);
@@ -631,7 +635,7 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t
631635
/* Open the notification endpoint */
632636
TU_ASSERT(usbd_edpt_open(rhport, notif));
633637
}
634-
self->cur = (uint16_t) ((void const*)vc - beg);
638+
self->cur = (uint16_t) ((uint8_t const*)vc - beg);
635639
return true;
636640
}
637641

@@ -643,7 +647,7 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
643647
{
644648
uint_fast8_t i;
645649
TU_LOG2(" reopen VS %d\n", altnum);
646-
void const *desc = _videod_itf[stm->index_vc].beg;
650+
uint8_t const *desc = _videod_itf[stm->index_vc].beg;
647651

648652
/* Close endpoints of previous settings. */
649653
for (i = 0; i < TU_ARRAY_SIZE(stm->desc.ep); ++i) {
@@ -654,16 +658,18 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
654658
stm->desc.ep[i] = 0;
655659
TU_LOG2(" close EP%02x\n", ep_adr);
656660
}
661+
657662
/* clear transfer management information */
658663
stm->buffer = NULL;
659664
stm->bufsize = 0;
660665
stm->offset = 0;
661666

662667
/* Find a alternate interface */
663-
void const *beg = desc + stm->desc.beg;
664-
void const *end = desc + stm->desc.end;
665-
void const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum);
668+
uint8_t const *beg = desc + stm->desc.beg;
669+
uint8_t const *end = desc + stm->desc.end;
670+
uint8_t const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum);
666671
TU_VERIFY(cur < end);
672+
667673
uint_fast8_t numeps = ((tusb_desc_interface_t const *)cur)->bNumEndpoints;
668674
TU_ASSERT(numeps <= TU_ARRAY_SIZE(stm->desc.ep));
669675
stm->desc.cur = (uint16_t) (cur - desc); /* Save the offset of the new settings */
@@ -917,7 +923,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
917923
switch (request->bRequest) {
918924
case VIDEO_REQUEST_SET_CUR:
919925
if (stage == CONTROL_STAGE_SETUP) {
920-
TU_VERIFY(sizeof(video_probe_and_commit_control_t) == request->wLength, VIDEO_ERROR_UNKNOWN);
926+
TU_VERIFY(sizeof(video_probe_and_commit_control_t) >= request->wLength, VIDEO_ERROR_UNKNOWN);
921927
TU_VERIFY(tud_control_xfer(rhport, request, self->ep_buf, sizeof(video_probe_and_commit_control_t)),
922928
VIDEO_ERROR_UNKNOWN);
923929
} else if (stage == CONTROL_STAGE_DATA) {
@@ -973,7 +979,7 @@ static int handle_video_stm_cs_req(uint8_t rhport, uint8_t stage,
973979
switch (request->bRequest) {
974980
case VIDEO_REQUEST_SET_CUR:
975981
if (stage == CONTROL_STAGE_SETUP) {
976-
TU_VERIFY(sizeof(video_probe_and_commit_control_t) == request->wLength, VIDEO_ERROR_UNKNOWN);
982+
TU_VERIFY(sizeof(video_probe_and_commit_control_t) >= request->wLength, VIDEO_ERROR_UNKNOWN);
977983
TU_VERIFY(tud_control_xfer(rhport, request, self->ep_buf, sizeof(video_probe_and_commit_control_t)), VIDEO_ERROR_UNKNOWN);
978984
} else if (stage == CONTROL_STAGE_DATA) {
979985
TU_VERIFY(_update_streaming_parameters(self, (video_probe_and_commit_control_t*)self->ep_buf), VIDEO_ERROR_INVALID_VALUE_WITHIN_RANGE);
@@ -1043,7 +1049,6 @@ static int handle_video_stm_req(uint8_t rhport, uint8_t stage,
10431049

10441050
default: return VIDEO_ERROR_INVALID_REQUEST;
10451051
}
1046-
return VIDEO_ERROR_UNKNOWN;
10471052
}
10481053

10491054
//--------------------------------------------------------------------+
@@ -1076,7 +1081,7 @@ bool tud_video_n_frame_xfer(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void *bu
10761081
if (!stm || !stm->desc.ep[0] || stm->buffer) return false;
10771082

10781083
/* Find EP address */
1079-
void const *desc = _videod_itf[stm->index_vc].beg;
1084+
uint8_t const *desc = _videod_itf[stm->index_vc].beg;
10801085
uint8_t ep_addr = 0;
10811086
for (uint_fast8_t i = 0; i < CFG_TUD_VIDEO_STREAMING; ++i) {
10821087
uint_fast16_t ofs_ep = stm->desc.ep[i];
@@ -1143,13 +1148,15 @@ uint16_t videod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
11431148
}
11441149
TU_ASSERT(ctl_idx < CFG_TUD_VIDEO, 0);
11451150

1146-
void const *end = (void const*)itf_desc + max_len;
1147-
self->beg = itf_desc;
1151+
uint8_t const *end = (uint8_t const*)itf_desc + max_len;
1152+
self->beg = (uint8_t const*) itf_desc;
11481153
self->len = max_len;
1154+
11491155
/*------------- Video Control Interface -------------*/
11501156
TU_VERIFY(_open_vc_itf(rhport, self, 0), 0);
11511157
tusb_desc_vc_itf_t const *vc = _get_desc_vc(self);
11521158
uint_fast8_t bInCollection = vc->ctl.bInCollection;
1159+
11531160
/* Find the end of the video interface descriptor */
11541161
void const *cur = _next_desc_itf(itf_desc, end);
11551162
for (uint8_t stm_idx = 0; stm_idx < bInCollection; ++stm_idx) {
@@ -1200,7 +1207,7 @@ bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_
12001207
for (itf = 0; itf < CFG_TUD_VIDEO_STREAMING; ++itf) {
12011208
videod_streaming_interface_t *stm = &_videod_streaming_itf[itf];
12021209
if (!stm->desc.beg) continue;
1203-
void const *desc = _videod_itf[stm->index_vc].beg;
1210+
uint8_t const *desc = _videod_itf[stm->index_vc].beg;
12041211
if (itfnum == _desc_itfnum(desc + stm->desc.beg)) break;
12051212
}
12061213

@@ -1226,7 +1233,7 @@ bool videod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint3
12261233
uint_fast16_t const ep_ofs = stm->desc.ep[0];
12271234
if (!ep_ofs) continue;
12281235
ctl = &_videod_itf[stm->index_vc];
1229-
void const *desc = ctl->beg;
1236+
uint8_t const *desc = ctl->beg;
12301237
if (ep_addr == _desc_ep_addr(desc + ep_ofs)) break;
12311238
}
12321239

src/common/tusb_compiler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
* - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma)
7777
*------------------------------------------------------------------*/
7878
#if !defined(__CCRX__)
79-
#define TU_ARGS_NUM(...) _TU_NARG(_0, ##__VA_ARGS__,_RSEQ_N())
79+
#define TU_ARGS_NUM(...) _TU_NARG(_0, ##__VA_ARGS__, _RSEQ_N())
8080
#else
81-
#define TU_ARGS_NUM(...) _TU_NARG(_0, __VA_ARGS__,_RSEQ_N())
81+
#define TU_ARGS_NUM(...) _TU_NARG(_0, __VA_ARGS__, _RSEQ_N())
8282
#endif
8383

8484
#define _TU_NARG(...) _GET_NTH_ARG(__VA_ARGS__)

0 commit comments

Comments
 (0)