Skip to content

Commit ee35022

Browse files
authored
Merge pull request #265 from adafruit/update-tinyusb
Update tinyusb to commit 096b6ec462efe612613498b44ec596e4bac763a7
2 parents 40207d9 + d6c78d8 commit ee35022

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+955
-392
lines changed

src/arduino/cdc/Adafruit_USBH_CDC.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
#include "Adafruit_USBH_CDC.h"
3232

33-
Adafruit_USBH_CDC::Adafruit_USBH_CDC(void) { _idx = TUSB_INDEX_INVALID; }
33+
Adafruit_USBH_CDC::Adafruit_USBH_CDC(void) { _idx = TUSB_INDEX_INVALID_8; }
3434

3535
void Adafruit_USBH_CDC::begin(unsigned long baud) {
3636

3737
// default to index 0 when begin
38-
if (_idx == TUSB_INDEX_INVALID) {
38+
if (_idx == TUSB_INDEX_INVALID_8) {
3939
_idx = 0;
4040
}
4141

@@ -50,14 +50,14 @@ void Adafruit_USBH_CDC::begin(unsigned long baudrate, uint16_t config) {
5050
begin(baudrate);
5151
}
5252

53-
void Adafruit_USBH_CDC::end(void) { _idx = TUSB_INDEX_INVALID; }
53+
void Adafruit_USBH_CDC::end(void) { _idx = TUSB_INDEX_INVALID_8; }
5454

5555
bool Adafruit_USBH_CDC::connected(void) {
56-
return (_idx != TUSB_INDEX_INVALID) && tuh_cdc_connected(_idx);
56+
return (_idx != TUSB_INDEX_INVALID_8) && tuh_cdc_connected(_idx);
5757
}
5858

5959
bool Adafruit_USBH_CDC::mounted(void) {
60-
return (_idx != TUSB_INDEX_INVALID) && tuh_cdc_mounted(_idx);
60+
return (_idx != TUSB_INDEX_INVALID_8) && tuh_cdc_mounted(_idx);
6161
}
6262

6363
int Adafruit_USBH_CDC::available(void) {

src/class/audio/audio.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -824,10 +824,10 @@ typedef struct TU_ATTR_PACKED
824824
uint8_t type : 2; ///< Request type tusb_request_type_t.
825825
uint8_t direction : 1; ///< Direction type. tusb_dir_t
826826
} bmRequestType_bit;
827-
827+
828828
uint8_t bmRequestType;
829829
};
830-
830+
831831
uint8_t bRequest; ///< Request type audio_cs_req_t
832832
uint8_t bChannelNumber;
833833
uint8_t bControlSelector;

src/class/audio/audio_device.c

Lines changed: 281 additions & 165 deletions
Large diffs are not rendered by default.

src/class/audio/audio_device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2020 Ha Thach (tinyusb.org)
@@ -473,7 +473,7 @@ TU_ATTR_WEAK void tud_audio_fb_done_cb(uint8_t func_id);
473473
// 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
474474
// expects 16.16 format and handles the conversion to 10.14 on FS.
475475
//
476-
// 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
476+
// 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
477477
// driver can work with either format. So a good compromise is to keep format correction disabled and stick to 16.16 format.
478478

479479
// Feedback value can be determined from within the SOF ISR of the audio driver. This should reduce jitter. If the feature is used, the user can not set the feedback value.

src/class/bth/bth_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2020 Jerzy Kasenberg

src/class/cdc/cdc.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ typedef struct TU_ATTR_PACKED
377377
uint32_t incoming_distinctive : 1; ///< 0 : Reports only incoming ringing. 1 : Reports incoming distinctive ringing patterns.
378378
uint32_t dual_tone_multi_freq : 1; ///< 0 : Cannot report dual tone multi-frequency (DTMF) digits input remotely over the telephone line. 1 : Can report DTMF digits input remotely over the telephone line.
379379
uint32_t line_state_change : 1; ///< 0 : Does not support line state change notification. 1 : Does support line state change notification
380-
uint32_t TU_RESERVED : 26;
380+
uint32_t TU_RESERVED0 : 2;
381+
uint32_t TU_RESERVED1 : 16;
382+
uint32_t TU_RESERVED2 : 8;
381383
} bmCapabilities;
382384
}cdc_desc_func_telephone_call_state_reporting_capabilities_t;
383385

@@ -404,7 +406,8 @@ typedef struct TU_ATTR_PACKED
404406
{
405407
uint16_t dtr : 1;
406408
uint16_t rts : 1;
407-
uint16_t : 14;
409+
uint16_t : 6;
410+
uint16_t : 8;
408411
} cdc_line_control_state_t;
409412

410413
TU_VERIFY_STATIC(sizeof(cdc_line_control_state_t) == 2, "size is not correct");

src/class/cdc/cdc_device.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -33,6 +33,11 @@
3333

3434
#include "cdc_device.h"
3535

36+
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
37+
#define tu_static static
38+
#endif
39+
40+
3641
//--------------------------------------------------------------------+
3742
// MACRO CONSTANT TYPEDEF
3843
//--------------------------------------------------------------------+
@@ -76,7 +81,7 @@ typedef struct
7681
//--------------------------------------------------------------------+
7782
// INTERNAL OBJECT & FUNCTION DECLARATION
7883
//--------------------------------------------------------------------+
79-
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
84+
CFG_TUSB_MEM_SECTION tu_static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
8085

8186
static bool _prep_out_transaction (cdcd_interface_t* p_cdc)
8287
{
@@ -386,7 +391,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
386391
bool const rts = tu_bit_test(request->wValue, 1);
387392

388393
p_cdc->line_state = (uint8_t) request->wValue;
389-
394+
390395
// Disable fifo overwriting if DTR bit is set
391396
tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr);
392397

@@ -433,7 +438,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
433438
if ( ep_addr == p_cdc->ep_out )
434439
{
435440
tu_fifo_write_n(&p_cdc->rx_ff, p_cdc->epout_buf, (uint16_t) xferred_bytes);
436-
441+
437442
// Check for wanted char and invoke callback if needed
438443
if ( tud_cdc_rx_wanted_cb && (((signed char) p_cdc->wanted_char) != -1) )
439444
{
@@ -445,14 +450,14 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
445450
}
446451
}
447452
}
448-
453+
449454
// invoke receive callback (if there is still data)
450455
if (tud_cdc_rx_cb && !tu_fifo_empty(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
451-
456+
452457
// prepare for OUT transaction
453458
_prep_out_transaction(p_cdc);
454459
}
455-
460+
456461
// Data sent to host, we continue to fetch from tx fifo to send.
457462
// Note: This will cause incorrect baudrate set in line coding.
458463
// Though maybe the baudrate is not really important !!!

src/class/cdc/cdc_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)

src/class/cdc/cdc_host.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -97,7 +97,7 @@ static inline uint8_t get_idx_by_ep_addr(uint8_t daddr, uint8_t ep_addr)
9797
}
9898
}
9999

100-
return TUSB_INDEX_INVALID;
100+
return TUSB_INDEX_INVALID_8;
101101
}
102102

103103

@@ -124,7 +124,7 @@ uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num)
124124
if (p_cdc->daddr == daddr && p_cdc->bInterfaceNumber == itf_num) return i;
125125
}
126126

127-
return TUSB_INDEX_INVALID;
127+
return TUSB_INDEX_INVALID_8;
128128
}
129129

130130
bool tuh_cdc_itf_get_info(uint8_t idx, tuh_cdc_itf_info_t* info)
@@ -533,7 +533,7 @@ static void process_cdc_config(tuh_xfer_t* xfer)
533533
uintptr_t const state = xfer->user_data;
534534
uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
535535
uint8_t const idx = tuh_cdc_itf_get_index(xfer->daddr, itf_num);
536-
TU_ASSERT(idx != TUSB_INDEX_INVALID, );
536+
TU_ASSERT(idx != TUSB_INDEX_INVALID_8, );
537537

538538
switch(state)
539539
{

src/class/cdc/cdc_host.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -80,7 +80,7 @@ typedef struct
8080
} tuh_cdc_itf_info_t;
8181

8282
// Get Interface index from device address + interface number
83-
// return TUSB_INDEX_INVALID (0xFF) if not found
83+
// return TUSB_INDEX_INVALID_8 (0xFF) if not found
8484
uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num);
8585

8686
// Get Interface information

src/class/dfu/dfu_device.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
// MACRO CONSTANT TYPEDEF
3838
//--------------------------------------------------------------------+
3939

40+
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
41+
#define tu_static static
42+
#endif
43+
4044
//--------------------------------------------------------------------+
4145
// INTERNAL OBJECT & FUNCTION DECLARATION
4246
//--------------------------------------------------------------------+
@@ -56,7 +60,7 @@ typedef struct
5660
} dfu_state_ctx_t;
5761

5862
// Only a single dfu state is allowed
59-
CFG_TUSB_MEM_SECTION static dfu_state_ctx_t _dfu_ctx;
63+
CFG_TUSB_MEM_SECTION tu_static dfu_state_ctx_t _dfu_ctx;
6064

6165
static void reset_state(void)
6266
{
@@ -74,7 +78,7 @@ static bool process_manifest_get_status(uint8_t rhport, uint8_t stage, tusb_cont
7478
//--------------------------------------------------------------------+
7579
#if CFG_TUSB_DEBUG >= 2
7680

77-
static tu_lookup_entry_t const _dfu_request_lookup[] =
81+
tu_static tu_lookup_entry_t const _dfu_request_lookup[] =
7882
{
7983
{ .key = DFU_REQUEST_DETACH , .data = "DETACH" },
8084
{ .key = DFU_REQUEST_DNLOAD , .data = "DNLOAD" },
@@ -85,13 +89,13 @@ static tu_lookup_entry_t const _dfu_request_lookup[] =
8589
{ .key = DFU_REQUEST_ABORT , .data = "ABORT" },
8690
};
8791

88-
static tu_lookup_table_t const _dfu_request_table =
92+
tu_static tu_lookup_table_t const _dfu_request_table =
8993
{
9094
.count = TU_ARRAY_SIZE(_dfu_request_lookup),
9195
.items = _dfu_request_lookup
9296
};
9397

94-
static tu_lookup_entry_t const _dfu_state_lookup[] =
98+
tu_static tu_lookup_entry_t const _dfu_state_lookup[] =
9599
{
96100
{ .key = APP_IDLE , .data = "APP_IDLE" },
97101
{ .key = APP_DETACH , .data = "APP_DETACH" },
@@ -106,13 +110,13 @@ static tu_lookup_entry_t const _dfu_state_lookup[] =
106110
{ .key = DFU_ERROR , .data = "ERROR" },
107111
};
108112

109-
static tu_lookup_table_t const _dfu_state_table =
113+
tu_static tu_lookup_table_t const _dfu_state_table =
110114
{
111115
.count = TU_ARRAY_SIZE(_dfu_state_lookup),
112116
.items = _dfu_state_lookup
113117
};
114118

115-
static tu_lookup_entry_t const _dfu_status_lookup[] =
119+
tu_static tu_lookup_entry_t const _dfu_status_lookup[] =
116120
{
117121
{ .key = DFU_STATUS_OK , .data = "OK" },
118122
{ .key = DFU_STATUS_ERR_TARGET , .data = "errTARGET" },
@@ -132,7 +136,7 @@ static tu_lookup_entry_t const _dfu_status_lookup[] =
132136
{ .key = DFU_STATUS_ERR_STALLEDPKT , .data = "errSTALLEDPKT" },
133137
};
134138

135-
static tu_lookup_table_t const _dfu_status_table =
139+
tu_static tu_lookup_table_t const _dfu_status_table =
136140
{
137141
.count = TU_ARRAY_SIZE(_dfu_status_lookup),
138142
.items = _dfu_status_lookup

src/class/dfu/dfu_rt_device.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@
3333

3434
#include "dfu_rt_device.h"
3535

36+
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
37+
#define tu_static static
38+
39+
// This is a backport of memset_s from c11
40+
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
41+
{
42+
// TODO may check if desst and src is not NULL
43+
if (count > destsz) {
44+
return -1;
45+
}
46+
memset(dest, ch, count);
47+
return 0;
48+
}
49+
50+
// This is a backport of memcpy_s from c11
51+
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
52+
{
53+
// TODO may check if desst and src is not NULL
54+
if (count > destsz) {
55+
return -1;
56+
}
57+
memcpy(dest, src, count);
58+
return 0;
59+
}
60+
#endif
61+
3662
//--------------------------------------------------------------------+
3763
// MACRO CONSTANT TYPEDEF
3864
//--------------------------------------------------------------------+
@@ -110,7 +136,7 @@ bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
110136
TU_LOG2(" DFU RT Request: GETSTATUS\r\n");
111137
dfu_status_response_t resp;
112138
// Status = OK, Poll timeout is ignored during RT, State = APP_IDLE, IString = 0
113-
memset(&resp, 0x00, sizeof(dfu_status_response_t));
139+
TU_VERIFY(tu_memset_s(&resp, sizeof(resp), 0x00, sizeof(resp))==0);
114140
tud_control_xfer(rhport, request, &resp, sizeof(dfu_status_response_t));
115141
}
116142
break;

src/class/hid/hid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)

0 commit comments

Comments
 (0)