Skip to content

Commit bfb631c

Browse files
committed
update tinyusb
1 parent 40207d9 commit bfb631c

Some content is hidden

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

64 files changed

+741
-390
lines changed

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: 253 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: 7 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)
@@ -76,7 +76,7 @@ typedef struct
7676
//--------------------------------------------------------------------+
7777
// INTERNAL OBJECT & FUNCTION DECLARATION
7878
//--------------------------------------------------------------------+
79-
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
79+
CFG_TUSB_MEM_SECTION tu_static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
8080

8181
static bool _prep_out_transaction (cdcd_interface_t* p_cdc)
8282
{
@@ -386,7 +386,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
386386
bool const rts = tu_bit_test(request->wValue, 1);
387387

388388
p_cdc->line_state = (uint8_t) request->wValue;
389-
389+
390390
// Disable fifo overwriting if DTR bit is set
391391
tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr);
392392

@@ -433,7 +433,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
433433
if ( ep_addr == p_cdc->ep_out )
434434
{
435435
tu_fifo_write_n(&p_cdc->rx_ff, p_cdc->epout_buf, (uint16_t) xferred_bytes);
436-
436+
437437
// Check for wanted char and invoke callback if needed
438438
if ( tud_cdc_rx_wanted_cb && (((signed char) p_cdc->wanted_char) != -1) )
439439
{
@@ -445,14 +445,14 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
445445
}
446446
}
447447
}
448-
448+
449449
// invoke receive callback (if there is still data)
450450
if (tud_cdc_rx_cb && !tu_fifo_empty(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
451-
451+
452452
// prepare for OUT transaction
453453
_prep_out_transaction(p_cdc);
454454
}
455-
455+
456456
// Data sent to host, we continue to fetch from tx fifo to send.
457457
// Note: This will cause incorrect baudrate set in line coding.
458458
// 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 TU_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 TU_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 != TU_INDEX_INVALID_8, );
537537

538538
switch(state)
539539
{

src/class/cdc/cdc_host.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/dfu/dfu_device.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef struct
5656
} dfu_state_ctx_t;
5757

5858
// Only a single dfu state is allowed
59-
CFG_TUSB_MEM_SECTION static dfu_state_ctx_t _dfu_ctx;
59+
CFG_TUSB_MEM_SECTION tu_static dfu_state_ctx_t _dfu_ctx;
6060

6161
static void reset_state(void)
6262
{
@@ -74,7 +74,7 @@ static bool process_manifest_get_status(uint8_t rhport, uint8_t stage, tusb_cont
7474
//--------------------------------------------------------------------+
7575
#if CFG_TUSB_DEBUG >= 2
7676

77-
static tu_lookup_entry_t const _dfu_request_lookup[] =
77+
tu_static tu_lookup_entry_t const _dfu_request_lookup[] =
7878
{
7979
{ .key = DFU_REQUEST_DETACH , .data = "DETACH" },
8080
{ .key = DFU_REQUEST_DNLOAD , .data = "DNLOAD" },
@@ -85,13 +85,13 @@ static tu_lookup_entry_t const _dfu_request_lookup[] =
8585
{ .key = DFU_REQUEST_ABORT , .data = "ABORT" },
8686
};
8787

88-
static tu_lookup_table_t const _dfu_request_table =
88+
tu_static tu_lookup_table_t const _dfu_request_table =
8989
{
9090
.count = TU_ARRAY_SIZE(_dfu_request_lookup),
9191
.items = _dfu_request_lookup
9292
};
9393

94-
static tu_lookup_entry_t const _dfu_state_lookup[] =
94+
tu_static tu_lookup_entry_t const _dfu_state_lookup[] =
9595
{
9696
{ .key = APP_IDLE , .data = "APP_IDLE" },
9797
{ .key = APP_DETACH , .data = "APP_DETACH" },
@@ -106,13 +106,13 @@ static tu_lookup_entry_t const _dfu_state_lookup[] =
106106
{ .key = DFU_ERROR , .data = "ERROR" },
107107
};
108108

109-
static tu_lookup_table_t const _dfu_state_table =
109+
tu_static tu_lookup_table_t const _dfu_state_table =
110110
{
111111
.count = TU_ARRAY_SIZE(_dfu_state_lookup),
112112
.items = _dfu_state_lookup
113113
};
114114

115-
static tu_lookup_entry_t const _dfu_status_lookup[] =
115+
tu_static tu_lookup_entry_t const _dfu_status_lookup[] =
116116
{
117117
{ .key = DFU_STATUS_OK , .data = "OK" },
118118
{ .key = DFU_STATUS_ERR_TARGET , .data = "errTARGET" },
@@ -132,7 +132,7 @@ static tu_lookup_entry_t const _dfu_status_lookup[] =
132132
{ .key = DFU_STATUS_ERR_STALLEDPKT , .data = "errSTALLEDPKT" },
133133
};
134134

135-
static tu_lookup_table_t const _dfu_status_table =
135+
tu_static tu_lookup_table_t const _dfu_status_table =
136136
{
137137
.count = TU_ARRAY_SIZE(_dfu_status_lookup),
138138
.items = _dfu_status_lookup

src/class/dfu/dfu_rt_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
110110
TU_LOG2(" DFU RT Request: GETSTATUS\r\n");
111111
dfu_status_response_t resp;
112112
// Status = OK, Poll timeout is ignored during RT, State = APP_IDLE, IString = 0
113-
memset(&resp, 0x00, sizeof(dfu_status_response_t));
113+
TU_VERIFY(tu_memset_s(&resp, sizeof(resp), 0x00, sizeof(resp))==0);
114114
tud_control_xfer(rhport, request, &resp, sizeof(dfu_status_response_t));
115115
}
116116
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)

src/class/hid/hid_device.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct
5858
tusb_hid_descriptor_hid_t const * hid_descriptor;
5959
} hidd_interface_t;
6060

61-
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID];
61+
CFG_TUSB_MEM_SECTION tu_static hidd_interface_t _hidd_itf[CFG_TUD_HID];
6262

6363
/*------------- Helpers -------------*/
6464
static inline uint8_t get_index_by_itfnum(uint8_t itf_num)
@@ -92,16 +92,12 @@ bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, u
9292
// prepare data
9393
if (report_id)
9494
{
95-
len = tu_min16(len, CFG_TUD_HID_EP_BUFSIZE-1);
96-
9795
p_hid->epin_buf[0] = report_id;
98-
memcpy(p_hid->epin_buf+1, report, len);
96+
TU_VERIFY(0 == tu_memcpy_s(p_hid->epin_buf+1, CFG_TUD_HID_EP_BUFSIZE-1, report, len));
9997
len++;
10098
}else
10199
{
102-
// If report id = 0, skip ID field
103-
len = tu_min16(len, CFG_TUD_HID_EP_BUFSIZE);
104-
memcpy(p_hid->epin_buf, report, len);
100+
TU_VERIFY(0 == tu_memcpy_s(p_hid->epin_buf, CFG_TUD_HID_EP_BUFSIZE, report, len));
105101
}
106102

107103
return usbd_edpt_xfer(rhport, p_hid->ep_in, p_hid->epin_buf, len);
@@ -126,7 +122,7 @@ bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modi
126122

127123
if ( keycode )
128124
{
129-
memcpy(report.keycode, keycode, 6);
125+
memcpy(report.keycode, keycode, sizeof(report.keycode));
130126
}else
131127
{
132128
tu_memclr(report.keycode, 6);
@@ -151,8 +147,7 @@ bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id,
151147
}
152148

153149
bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id,
154-
int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons)
155-
{
150+
int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons) {
156151
hid_gamepad_report_t report =
157152
{
158153
.x = x,
@@ -183,11 +178,12 @@ void hidd_reset(uint8_t rhport)
183178
}
184179

185180
uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t max_len)
186-
{
181+
{
187182
TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass, 0);
188183

189184
// len = interface + hid + n*endpoints
190-
uint16_t const drv_len = (uint16_t) (sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) +
185+
uint16_t const drv_len =
186+
(uint16_t) (sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) +
191187
desc_itf->bNumEndpoints * sizeof(tusb_desc_endpoint_t));
192188
TU_ASSERT(max_len >= drv_len, 0);
193189

src/class/hid/hid_host.c

Lines changed: 45 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)
@@ -274,7 +274,49 @@ bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance)
274274
// return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
275275
//}
276276

277-
//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
277+
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, const void* report, uint16_t len)
278+
{
279+
TU_LOG2("HID Send Report %d\r\n", report_id);
280+
281+
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
282+
283+
if (hid_itf->ep_out == 0)
284+
{
285+
// This HID does not have an out endpoint (other than control)
286+
return false;
287+
}
288+
else if (len > CFG_TUH_HID_EPOUT_BUFSIZE
289+
|| (report_id != 0 && len > (CFG_TUH_HID_EPOUT_BUFSIZE - 1)))
290+
{
291+
// ep_out buffer is not large enough to hold contents
292+
return false;
293+
}
294+
295+
// claim endpoint
296+
TU_VERIFY( usbh_edpt_claim(dev_addr, hid_itf->ep_out) );
297+
298+
if (report_id == 0)
299+
{
300+
// No report ID in transmission
301+
memcpy(&hid_itf->epout_buf[0], report, len);
302+
}
303+
else
304+
{
305+
hid_itf->epout_buf[0] = report_id;
306+
memcpy(&hid_itf->epout_buf[1], report, len);
307+
++len; // 1 more byte for report_id
308+
}
309+
310+
TU_LOG3_MEM(hid_itf->epout_buf, len, 2);
311+
312+
if ( !usbh_edpt_xfer(dev_addr, hid_itf->ep_out, hid_itf->epout_buf, len) )
313+
{
314+
usbh_edpt_release(dev_addr, hid_itf->ep_out);
315+
return false;
316+
}
317+
318+
return true;
319+
}
278320

279321
//--------------------------------------------------------------------+
280322
// USBH API
@@ -349,7 +391,7 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
349391
hidh_device_t* hid_dev = get_dev(dev_addr);
350392
TU_ASSERT(hid_dev->inst_count < CFG_TUH_HID, 0);
351393

352-
hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->inst_count);
394+
hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->inst_count);
353395

354396
//------------- Endpoint Descriptors -------------//
355397
p_desc = tu_desc_next(p_desc);

src/class/hid/hid_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)
@@ -106,7 +106,7 @@ bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance);
106106

107107
// Send report using interrupt endpoint
108108
// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
109-
//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
109+
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, const void* report, uint16_t len);
110110

111111
//--------------------------------------------------------------------+
112112
// Callbacks (Weak is optional)

src/class/midi/midi.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)