Skip to content

Commit 6fa324f

Browse files
committed
update tinyusb to hathach/tinyusb@fcca8bb
1 parent 88f0998 commit 6fa324f

File tree

22 files changed

+492
-206
lines changed

22 files changed

+492
-206
lines changed

src/class/audio/audio_device.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,24 +2247,28 @@ static void audiod_parse_for_AS_params(audiod_function_t* audio, uint8_t const *
22472247

22482248
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
22492249

2250-
// Input value feedback has to be in 16.16 format - the format will be converted according to speed settings automatically
22512250
bool tud_audio_n_fb_set(uint8_t func_id, uint32_t feedback)
22522251
{
22532252
TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
22542253

22552254
// Format the feedback value
2256-
#if !TUD_OPT_HIGH_SPEED
2257-
uint8_t * fb = (uint8_t *) &_audiod_fct[func_id].fb_val;
2258-
2259-
// For FS format is 10.14
2260-
*(fb++) = (feedback >> 2) & 0xFF;
2261-
*(fb++) = (feedback >> 10) & 0xFF;
2262-
*(fb++) = (feedback >> 18) & 0xFF;
2263-
// 4th byte is needed to work correctly with MS Windows
2264-
*fb = 0;
2255+
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_FORMAT_CORRECTION
2256+
if ( TUSB_SPEED_FULL == tud_speed_get() )
2257+
{
2258+
uint8_t * fb = (uint8_t *) &_audiod_fct[func_id].fb_val;
2259+
2260+
// For FS format is 10.14
2261+
*(fb++) = (feedback >> 2) & 0xFF;
2262+
*(fb++) = (feedback >> 10) & 0xFF;
2263+
*(fb++) = (feedback >> 18) & 0xFF;
2264+
// 4th byte is needed to work correctly with MS Windows
2265+
*fb = 0;
2266+
}else
22652267
#else
2266-
// For HS format is 16.16 as originally demanded
2267-
_audiod_fct[func_id].fb_val = feedback;
2268+
{
2269+
// Send value as-is, caller will choose the appropriate format
2270+
_audiod_fct[func_id].fb_val = feedback;
2271+
}
22682272
#endif
22692273

22702274
// Schedule a transmit with the new value if EP is not busy - this triggers repetitive scheduling of the feedback value

src/class/audio/audio_device.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@
186186
#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP 0 // Feedback - 0 or 1
187187
#endif
188188

189+
// Enable/disable conversion from 16.16 to 10.14 format on full-speed devices. See tud_audio_n_fb_set().
190+
#ifndef CFG_TUD_AUDIO_ENABLE_FEEDBACK_FORMAT_CORRECTION
191+
#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_FORMAT_CORRECTION 0 // 0 or 1
192+
#endif
193+
189194
// Audio interrupt control EP size - disabled if 0
190195
#ifndef CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
191196
#define CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN 0 // Audio interrupt control - if required - 6 Bytes according to UAC 2 specification (p. 74)
@@ -454,10 +459,15 @@ TU_ATTR_WEAK bool tud_audio_rx_done_post_read_cb(uint8_t rhport, uint16_t n_byte
454459

455460
#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
456461
TU_ATTR_WEAK bool tud_audio_fb_done_cb(uint8_t rhport);
457-
// User code should call this function with feedback value in 16.16 format for FS and HS.
458-
// Value will be corrected for FS to 10.14 format automatically.
459-
// (see Universal Serial Bus Specification Revision 2.0 5.12.4.2).
460-
// Feedback value will be sent at FB endpoint interval till it's changed.
462+
463+
// This function is used to provide data rate feedback from an asynchronous sink. Feedback value will be sent at FB endpoint interval till it's changed.
464+
//
465+
// The feedback format is specified to be 16.16 for HS and 10.14 for FS devices (see Universal Serial Bus Specification Revision 2.0 5.12.4.2). By default,
466+
// the choice of format is left to the caller and feedback argument is sent as-is. If CFG_TUD_AUDIO_ENABLE_FEEDBACK_FORMAT_CORRECTION is set, then tinyusb
467+
// expects 16.16 format and handles the conversion to 10.14 on FS.
468+
//
469+
// Note that due to a bug in its USB Audio 2.0 driver, Windows currently requires 16.16 format for _all_ USB 2.0 devices. On Linux and macOS it seems the
470+
// driver can work with either format. So a good compromise is to keep format correction disabled and stick to 16.16 format.
461471
bool tud_audio_n_fb_set(uint8_t func_id, uint32_t feedback);
462472
static inline bool tud_audio_fb_set(uint32_t feedback);
463473
#endif

src/class/hid/hid_device.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -310,46 +310,46 @@ static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y
310310
HID_COLLECTION_END \
311311

312312
// Gamepad Report Descriptor Template
313-
// with 16 buttons, 2 joysticks and 1 hat/dpad with following layout
314-
// | X | Y | Z | Rz | Rx | Ry (1 byte each) | hat/DPAD (1 byte) | Button Map (2 bytes) |
313+
// with 32 buttons, 2 joysticks and 1 hat/dpad with following layout
314+
// | X | Y | Z | Rz | Rx | Ry (1 byte each) | hat/DPAD (1 byte) | Button Map (4 bytes) |
315315
#define TUD_HID_REPORT_DESC_GAMEPAD(...) \
316316
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
317317
HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\
318318
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
319319
/* Report ID if any */\
320320
__VA_ARGS__ \
321321
/* 8 bit X, Y, Z, Rz, Rx, Ry (min -127, max 127 ) */ \
322-
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
323-
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
324-
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
325-
HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\
326-
HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\
327-
HID_USAGE ( HID_USAGE_DESKTOP_RX ) ,\
328-
HID_USAGE ( HID_USAGE_DESKTOP_RY ) ,\
329-
HID_LOGICAL_MIN ( 0x81 ) ,\
330-
HID_LOGICAL_MAX ( 0x7f ) ,\
331-
HID_REPORT_COUNT ( 6 ) ,\
332-
HID_REPORT_SIZE ( 8 ) ,\
333-
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
322+
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
323+
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
324+
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
325+
HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\
326+
HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\
327+
HID_USAGE ( HID_USAGE_DESKTOP_RX ) ,\
328+
HID_USAGE ( HID_USAGE_DESKTOP_RY ) ,\
329+
HID_LOGICAL_MIN ( 0x81 ) ,\
330+
HID_LOGICAL_MAX ( 0x7f ) ,\
331+
HID_REPORT_COUNT ( 6 ) ,\
332+
HID_REPORT_SIZE ( 8 ) ,\
333+
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
334334
/* 8 bit DPad/Hat Button Map */ \
335-
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
336-
HID_USAGE ( HID_USAGE_DESKTOP_HAT_SWITCH ) ,\
337-
HID_LOGICAL_MIN ( 1 ) ,\
338-
HID_LOGICAL_MAX ( 8 ) ,\
339-
HID_PHYSICAL_MIN ( 0 ) ,\
340-
HID_PHYSICAL_MAX_N ( 315, 2 ) ,\
341-
HID_REPORT_COUNT ( 1 ) ,\
342-
HID_REPORT_SIZE ( 8 ) ,\
343-
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
344-
/* 16 bit Button Map */ \
345-
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
346-
HID_USAGE_MIN ( 1 ) ,\
347-
HID_USAGE_MAX ( 32 ) ,\
348-
HID_LOGICAL_MIN ( 0 ) ,\
349-
HID_LOGICAL_MAX ( 1 ) ,\
350-
HID_REPORT_COUNT ( 32 ) ,\
351-
HID_REPORT_SIZE ( 1 ) ,\
352-
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
335+
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
336+
HID_USAGE ( HID_USAGE_DESKTOP_HAT_SWITCH ) ,\
337+
HID_LOGICAL_MIN ( 1 ) ,\
338+
HID_LOGICAL_MAX ( 8 ) ,\
339+
HID_PHYSICAL_MIN ( 0 ) ,\
340+
HID_PHYSICAL_MAX_N ( 315, 2 ) ,\
341+
HID_REPORT_COUNT ( 1 ) ,\
342+
HID_REPORT_SIZE ( 8 ) ,\
343+
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
344+
/* 32 bit Button Map */ \
345+
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
346+
HID_USAGE_MIN ( 1 ) ,\
347+
HID_USAGE_MAX ( 32 ) ,\
348+
HID_LOGICAL_MIN ( 0 ) ,\
349+
HID_LOGICAL_MAX ( 1 ) ,\
350+
HID_REPORT_COUNT ( 32 ) ,\
351+
HID_REPORT_SIZE ( 1 ) ,\
352+
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
353353
HID_COLLECTION_END \
354354

355355
// HID Generic Input & Output

src/class/msc/msc_device.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ TU_ATTR_UNUSED static tu_lookup_entry_t const _msc_scsi_cmd_lookup[] =
209209
{ .key = SCSI_CMD_MODE_SELECT_6 , .data = "Mode_Select 6" },
210210
{ .key = SCSI_CMD_MODE_SENSE_6 , .data = "Mode_Sense 6" },
211211
{ .key = SCSI_CMD_START_STOP_UNIT , .data = "Start Stop Unit" },
212-
{ .key = SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL , .data = "Prevent Allow Medium Removal" },
212+
{ .key = SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL , .data = "Prevent/Allow Medium Removal" },
213213
{ .key = SCSI_CMD_READ_CAPACITY_10 , .data = "Read Capacity10" },
214214
{ .key = SCSI_CMD_REQUEST_SENSE , .data = "Request Sense" },
215215
{ .key = SCSI_CMD_READ_FORMAT_CAPACITY , .data = "Read Format Capacity" },
@@ -239,7 +239,7 @@ bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, u
239239
return true;
240240
}
241241

242-
static inline void set_default_error_sense(uint8_t lun)
242+
static inline void set_sense_medium_not_present(uint8_t lun)
243243
{
244244
// default sense is NOT READY, MEDIUM NOT PRESENT
245245
tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3A, 0x00);
@@ -661,7 +661,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
661661
resplen = - 1;
662662

663663
// set default sense if not set by callback
664-
if ( p_msc->sense_key == 0 ) set_default_error_sense(lun);
664+
if ( p_msc->sense_key == 0 ) set_sense_medium_not_present(lun);
665665
}
666666
break;
667667

@@ -677,7 +677,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
677677
resplen = - 1;
678678

679679
// set default sense if not set by callback
680-
if ( p_msc->sense_key == 0 ) set_default_error_sense(lun);
680+
if ( p_msc->sense_key == 0 ) set_sense_medium_not_present(lun);
681681
}
682682
}
683683
break;
@@ -698,12 +698,12 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
698698
resplen = -1;
699699

700700
// set default sense if not set by callback
701-
if ( p_msc->sense_key == 0 ) set_default_error_sense(lun);
701+
if ( p_msc->sense_key == 0 ) set_sense_medium_not_present(lun);
702702
}else
703703
{
704704
scsi_read_capacity10_resp_t read_capa10;
705705

706-
read_capa10.last_lba = tu_htonl(block_count-1);
706+
read_capa10.last_lba = tu_htonl(block_count-1);
707707
read_capa10.block_size = tu_htonl(block_size);
708708

709709
resplen = sizeof(read_capa10);
@@ -734,7 +734,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
734734
resplen = -1;
735735

736736
// set default sense if not set by callback
737-
if ( p_msc->sense_key == 0 ) set_default_error_sense(lun);
737+
if ( p_msc->sense_key == 0 ) set_sense_medium_not_present(lun);
738738
}else
739739
{
740740
read_fmt_capa.block_num = tu_htonl(block_count);
@@ -847,7 +847,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
847847
TU_LOG(MSC_DEBUG, " tud_msc_read10_cb() return -1\r\n");
848848

849849
// set sense
850-
set_default_error_sense(p_cbw->lun);
850+
set_sense_medium_not_present(p_cbw->lun);
851851

852852
fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_FAILED);
853853
}
@@ -912,7 +912,7 @@ static void proc_write10_new_data(uint8_t rhport, mscd_interface_t* p_msc, uint3
912912
p_msc->xferred_len += xferred_bytes;
913913

914914
// Set sense
915-
set_default_error_sense(p_cbw->lun);
915+
set_sense_medium_not_present(p_cbw->lun);
916916

917917
fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_FAILED);
918918
}else

src/class/usbtmc/usbtmc_device.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,19 @@ void usbtmcd_init_cb(void)
235235
usbtmc_state.capabilities = tud_usbtmc_get_capabilities_cb();
236236
#ifndef NDEBUG
237237
# if CFG_TUD_USBTMC_ENABLE_488
238-
if(usbtmc_state.capabilities->bmIntfcCapabilities488.supportsTrigger)
239-
TU_ASSERT(&tud_usbtmc_msg_trigger_cb != NULL,);
240-
// Per USB488 spec: table 8
241-
TU_ASSERT(!usbtmc_state.capabilities->bmIntfcCapabilities.listenOnly,);
242-
TU_ASSERT(!usbtmc_state.capabilities->bmIntfcCapabilities.talkOnly,);
238+
if (usbtmc_state.capabilities->bmIntfcCapabilities488.supportsTrigger) {
239+
TU_ASSERT(&tud_usbtmc_msg_trigger_cb != NULL,);
240+
}
241+
// Per USB488 spec: table 8
242+
TU_ASSERT(!usbtmc_state.capabilities->bmIntfcCapabilities.listenOnly,);
243+
TU_ASSERT(!usbtmc_state.capabilities->bmIntfcCapabilities.talkOnly,);
243244
# endif
244-
if(usbtmc_state.capabilities->bmIntfcCapabilities.supportsIndicatorPulse)
245-
TU_ASSERT(&tud_usbtmc_indicator_pulse_cb != NULL,);
245+
if (usbtmc_state.capabilities->bmIntfcCapabilities.supportsIndicatorPulse) {
246+
TU_ASSERT(&tud_usbtmc_indicator_pulse_cb != NULL,);
247+
}
246248
#endif
247249

248-
usbtmcLock = osal_mutex_create(&usbtmcLockBuffer);
250+
usbtmcLock = osal_mutex_create(&usbtmcLockBuffer);
249251
}
250252

251253
uint16_t usbtmcd_open_cb(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)

src/common/tusb_compiler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@
137137
#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
138138
#define TU_BSWAP32(u32) (__builtin_bswap32(u32))
139139

140+
#ifndef __ARMCC_VERSION
140141
// List of obsolete callback function that is renamed and should not be defined.
141142
// Put it here since only gcc support this pragma
142-
#pragma GCC poison tud_vendor_control_request_cb
143+
#pragma GCC poison tud_vendor_control_request_cb
144+
#endif
143145

144146
#elif defined(__TI_COMPILER_VERSION__)
145147
#define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))

src/common/tusb_fifo.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ bool tu_fifo_peek(tu_fifo_t* f, void * p_buffer)
716716
uint16_t tu_fifo_peek_n(tu_fifo_t* f, void * p_buffer, uint16_t n)
717717
{
718718
_ff_lock(f->mutex_rd);
719-
bool ret = _tu_fifo_peek_n(f, p_buffer, n, f->wr_idx, f->rd_idx, TU_FIFO_COPY_INC);
719+
uint16_t ret = _tu_fifo_peek_n(f, p_buffer, n, f->wr_idx, f->rd_idx, TU_FIFO_COPY_INC);
720720
_ff_unlock(f->mutex_rd);
721721
return ret;
722722
}
@@ -741,21 +741,28 @@ bool tu_fifo_write(tu_fifo_t* f, const void * data)
741741
{
742742
_ff_lock(f->mutex_wr);
743743

744-
uint16_t w = f->wr_idx;
744+
bool ret;
745+
uint16_t const w = f->wr_idx;
745746

746-
if ( _tu_fifo_full(f, w, f->rd_idx) && !f->overwritable ) return false;
747+
if ( _tu_fifo_full(f, w, f->rd_idx) && !f->overwritable )
748+
{
749+
ret = false;
750+
}else
751+
{
752+
uint16_t wRel = get_relative_pointer(f, w);
747753

748-
uint16_t wRel = get_relative_pointer(f, w);
754+
// Write data
755+
_ff_push(f, data, wRel);
749756

750-
// Write data
751-
_ff_push(f, data, wRel);
757+
// Advance pointer
758+
f->wr_idx = advance_pointer(f, w, 1);
752759

753-
// Advance pointer
754-
f->wr_idx = advance_pointer(f, w, 1);
760+
ret = true;
761+
}
755762

756763
_ff_unlock(f->mutex_wr);
757764

758-
return true;
765+
return ret;
759766
}
760767

761768
/******************************************************************************/

src/common/tusb_verify.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,31 @@
3737
* manipulation that you are told to stay away.
3838
*
3939
* This contains macros for both VERIFY and ASSERT:
40-
*
40+
*
4141
* VERIFY: Used when there is an error condition which is not the
4242
* fault of the MCU. For example, bounds checking on data
4343
* sent to the micro over USB should use this function.
4444
* Another example is checking for buffer overflows, where
4545
* returning from the active function causes a NAK.
46-
*
46+
*
4747
* ASSERT: Used for error conditions that are caused by MCU firmware
4848
* bugs. This is used to discover bugs in the code more
4949
* quickly. One example would be adding assertions in library
5050
* function calls to confirm a function's (untainted)
5151
* parameters are valid.
52-
*
52+
*
5353
* The difference in behavior is that ASSERT triggers a breakpoint while
5454
* verify does not.
5555
*
5656
* #define TU_VERIFY(cond) if(cond) return false;
5757
* #define TU_VERIFY(cond,ret) if(cond) return ret;
58-
*
58+
*
5959
* #define TU_VERIFY_HDLR(cond,handler) if(cond) {handler; return false;}
6060
* #define TU_VERIFY_HDLR(cond,ret,handler) if(cond) {handler; return ret;}
6161
*
6262
* #define TU_ASSERT(cond) if(cond) {_MESS_FAILED(); TU_BREAKPOINT(), return false;}
6363
* #define TU_ASSERT(cond,ret) if(cond) {_MESS_FAILED(); TU_BREAKPOINT(), return ret;}
64-
*
64+
*
6565
*------------------------------------------------------------------*/
6666

6767
#ifdef __cplusplus
@@ -81,8 +81,8 @@
8181
#define _MESS_FAILED() do {} while (0)
8282
#endif
8383

84-
// Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7
85-
#if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__)
84+
// Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7, M33
85+
#if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__) || defined(__ARM_ARCH_8M_MAIN__)
8686
#define TU_BREAKPOINT() do \
8787
{ \
8888
volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */ \

src/device/dcd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ typedef struct TU_ATTR_ALIGNED(4)
106106
void dcd_init (uint8_t rhport);
107107

108108
// Interrupt Handler
109-
#if __GNUC__
109+
#if __GNUC__ && !defined(__ARMCC_VERSION)
110110
#pragma GCC diagnostic push
111111
#pragma GCC diagnostic ignored "-Wredundant-decls"
112112
#endif
113113
void dcd_int_handler(uint8_t rhport);
114-
#if __GNUC__
114+
#if __GNUC__ && !defined(__ARMCC_VERSION)
115115
#pragma GCC diagnostic pop
116116
#endif
117117

0 commit comments

Comments
 (0)