Skip to content

Commit fafc824

Browse files
committed
update tinyusb to hathach/tinyusb@1a783b3
1 parent 6b772c0 commit fafc824

35 files changed

+2554
-1485
lines changed

src/class/audio/audio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ typedef struct TU_ATTR_PACKED
661661
uint16_t wTotalLength ; ///< Total number of bytes returned for the class-specific AudioControl interface descriptor. Includes the combined length of this descriptor header and all Clock Source, Unit and Terminal descriptors.
662662
uint8_t bmControls ; ///< See: audio_cs_ac_interface_control_pos_t.
663663
} audio_desc_cs_ac_interface_t;
664+
TU_VERIFY_STATIC(sizeof(audio_desc_cs_ac_interface_t) == 9, "size is not correct");
664665

665666
/// AUDIO Clock Source Descriptor (4.7.2.1)
666667
typedef struct TU_ATTR_PACKED

src/class/audio/audio_device.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ tu_static CFG_TUD_MEM_SECTION struct {
208208
#endif// CFG_TUD_AUDIO_ENABLE_EP_OUT && (USE_LINEAR_BUFFER || CFG_TUD_AUDIO_ENABLE_DECODING)
209209

210210
// Control buffers
211-
tu_static uint8_t ctrl_buf_1[CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ];
212-
213-
#if CFG_TUD_AUDIO > 1
214-
tu_static uint8_t ctrl_buf_2[CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ];
215-
#endif
216-
217-
#if CFG_TUD_AUDIO > 2
218-
tu_static uint8_t ctrl_buf_3[CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ];
219-
#endif
211+
tu_static CFG_TUD_MEM_SECTION struct {
212+
TUD_EPBUF_DEF(buf1, CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ);
213+
#if CFG_TUD_AUDIO > 1
214+
TUD_EPBUF_DEF(buf2, CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ);
215+
#endif
216+
#if CFG_TUD_AUDIO > 2
217+
TUD_EPBUF_DEF(buf3, CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ);
218+
#endif
219+
} ctrl_buf;
220220

221221
// Active alternate setting of interfaces
222222
tu_static uint8_t alt_setting_1[CFG_TUD_AUDIO_FUNC_1_N_AS_INT];
@@ -628,10 +628,6 @@ static uint8_t audiod_get_audio_fct_idx(audiod_function_t *audio);
628628

629629
#if (CFG_TUD_AUDIO_ENABLE_EP_IN && (CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL || CFG_TUD_AUDIO_ENABLE_ENCODING)) || (CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING)
630630
static void audiod_parse_for_AS_params(audiod_function_t *audio, uint8_t const *p_desc, uint8_t const *p_desc_end, uint8_t const as_itf);
631-
632-
static inline uint8_t tu_desc_subtype(void const *desc) {
633-
return ((uint8_t const *) desc)[2];
634-
}
635631
#endif
636632

637633
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL
@@ -1227,18 +1223,18 @@ void audiod_init(void) {
12271223
// Initialize control buffers
12281224
switch (i) {
12291225
case 0:
1230-
audio->ctrl_buf = ctrl_buf_1;
1226+
audio->ctrl_buf = ctrl_buf.buf1;
12311227
audio->ctrl_buf_sz = CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ;
12321228
break;
12331229
#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ > 0
12341230
case 1:
1235-
audio->ctrl_buf = ctrl_buf_2;
1231+
audio->ctrl_buf = ctrl_buf.buf2;
12361232
audio->ctrl_buf_sz = CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ;
12371233
break;
12381234
#endif
12391235
#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ > 0
12401236
case 2:
1241-
audio->ctrl_buf = ctrl_buf_3;
1237+
audio->ctrl_buf = ctrl_buf.buf3;
12421238
audio->ctrl_buf_sz = CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ;
12431239
break;
12441240
#endif

src/class/cdc/cdc_device.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef struct {
8282
static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
8383
CFG_TUD_MEM_SECTION static cdcd_epbuf_t _cdcd_epbuf[CFG_TUD_CDC];
8484

85-
static tud_cdc_configure_fifo_t _cdcd_fifo_cfg;
85+
static tud_cdc_configure_t _cdcd_cfg = TUD_CDC_CONFIGURE_DEFAULT();
8686

8787
static bool _prep_out_transaction(uint8_t itf) {
8888
const uint8_t rhport = 0;
@@ -119,9 +119,9 @@ static bool _prep_out_transaction(uint8_t itf) {
119119
// APPLICATION API
120120
//--------------------------------------------------------------------+
121121

122-
bool tud_cdc_configure_fifo(const tud_cdc_configure_fifo_t* cfg) {
123-
TU_VERIFY(cfg);
124-
_cdcd_fifo_cfg = (*cfg);
122+
bool tud_cdc_configure(const tud_cdc_configure_t* driver_cfg) {
123+
TU_VERIFY(driver_cfg);
124+
_cdcd_cfg = *driver_cfg;
125125
return true;
126126
}
127127

@@ -175,7 +175,7 @@ void tud_cdc_n_read_flush(uint8_t itf) {
175175
//--------------------------------------------------------------------+
176176
uint32_t tud_cdc_n_write(uint8_t itf, const void* buffer, uint32_t bufsize) {
177177
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
178-
uint16_t ret = tu_fifo_write_n(&p_cdc->tx_ff, buffer, (uint16_t) TU_MIN(bufsize, UINT16_MAX));
178+
uint16_t wr_count = tu_fifo_write_n(&p_cdc->tx_ff, buffer, (uint16_t) TU_MIN(bufsize, UINT16_MAX));
179179

180180
// flush if queue more than packet size
181181
if (tu_fifo_count(&p_cdc->tx_ff) >= BULK_PACKET_SIZE
@@ -186,7 +186,7 @@ uint32_t tud_cdc_n_write(uint8_t itf, const void* buffer, uint32_t bufsize) {
186186
tud_cdc_n_write_flush(itf);
187187
}
188188

189-
return ret;
189+
return wr_count;
190190
}
191191

192192
uint32_t tud_cdc_n_write_flush(uint8_t itf) {
@@ -233,8 +233,6 @@ bool tud_cdc_n_write_clear(uint8_t itf) {
233233
//--------------------------------------------------------------------+
234234
void cdcd_init(void) {
235235
tu_memclr(_cdcd_itf, sizeof(_cdcd_itf));
236-
tu_memclr(&_cdcd_fifo_cfg, sizeof(_cdcd_fifo_cfg));
237-
238236
for (uint8_t i = 0; i < CFG_TUD_CDC; i++) {
239237
cdcd_interface_t* p_cdc = &_cdcd_itf[i];
240238

@@ -249,10 +247,10 @@ void cdcd_init(void) {
249247
// Config RX fifo
250248
tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, TU_ARRAY_SIZE(p_cdc->rx_ff_buf), 1, false);
251249

252-
// Config TX fifo as overwritable at initialization and will be changed to non-overwritable
253-
// if terminal supports DTR bit. Without DTR we do not know if data is actually polled by terminal.
254-
// In this way, the most current data is prioritized.
255-
tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1, true);
250+
// TX fifo can be configured to change to overwritable if not connected (DTR bit not set). Without DTR we do not
251+
// know if data is actually polled by terminal. This way the most current data is prioritized.
252+
// Default: is overwritable
253+
tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1, _cdcd_cfg.tx_overwritabe_if_not_connected);
256254

257255
#if OSAL_MUTEX_REQUIRED
258256
osal_mutex_t mutex_rd = osal_mutex_create(&p_cdc->rx_ff_mutex);
@@ -294,13 +292,13 @@ void cdcd_reset(uint8_t rhport) {
294292
cdcd_interface_t* p_cdc = &_cdcd_itf[i];
295293

296294
tu_memclr(p_cdc, ITF_MEM_RESET_SIZE);
297-
if (!_cdcd_fifo_cfg.rx_persistent) {
295+
if (!_cdcd_cfg.rx_persistent) {
298296
tu_fifo_clear(&p_cdc->rx_ff);
299297
}
300-
if (!_cdcd_fifo_cfg.tx_persistent) {
298+
if (!_cdcd_cfg.tx_persistent) {
301299
tu_fifo_clear(&p_cdc->tx_ff);
302300
}
303-
tu_fifo_set_overwritable(&p_cdc->tx_ff, true);
301+
tu_fifo_set_overwritable(&p_cdc->tx_ff, _cdcd_cfg.tx_overwritabe_if_not_connected);
304302
}
305303
}
306304

@@ -414,8 +412,12 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_requ
414412

415413
p_cdc->line_state = (uint8_t) request->wValue;
416414

417-
// Disable fifo overwriting if DTR bit is set
418-
tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr);
415+
// If enabled: fifo overwriting is disabled if DTR bit is set and vice versa
416+
if (_cdcd_cfg.tx_overwritabe_if_not_connected) {
417+
tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr);
418+
} else {
419+
tu_fifo_set_overwritable(&p_cdc->tx_ff, false);
420+
}
419421

420422
TU_LOG_DRV(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
421423

@@ -496,7 +498,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
496498
// xferred_bytes is multiple of EP Packet size and not zero
497499
if (!tu_fifo_count(&p_cdc->tx_ff) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE - 1)))) {
498500
if (usbd_edpt_claim(rhport, p_cdc->ep_in)) {
499-
usbd_edpt_xfer(rhport, p_cdc->ep_in, NULL, 0);
501+
TU_ASSERT(usbd_edpt_xfer(rhport, p_cdc->ep_in, NULL, 0));
500502
}
501503
}
502504
}

src/class/cdc/cdc_device.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@
4848
//--------------------------------------------------------------------+
4949
// Driver Configuration
5050
//--------------------------------------------------------------------+
51-
5251
typedef struct TU_ATTR_PACKED {
53-
uint8_t rx_persistent : 1; // keep rx fifo on bus reset or disconnect
54-
uint8_t tx_persistent : 1; // keep tx fifo on bus reset or disconnect
55-
} tud_cdc_configure_fifo_t;
52+
uint8_t rx_persistent : 1; // keep rx fifo data even with bus reset or disconnect
53+
uint8_t tx_persistent : 1; // keep tx fifo data even with reset or disconnect
54+
uint8_t tx_overwritabe_if_not_connected : 1; // if not connected, tx fifo can be overwritten
55+
} tud_cdc_configure_t;
56+
57+
#define TUD_CDC_CONFIGURE_DEFAULT() { \
58+
.rx_persistent = 0, \
59+
.tx_persistent = 0, \
60+
.tx_overwritabe_if_not_connected = 1, \
61+
}
62+
63+
// Configure CDC driver behavior
64+
bool tud_cdc_configure(const tud_cdc_configure_t* driver_cfg);
5665

57-
// Configure CDC FIFOs behavior
58-
bool tud_cdc_configure_fifo(tud_cdc_configure_fifo_t const* cfg);
66+
// Backward compatible
67+
#define tud_cdc_configure_fifo_t tud_cdc_configure_t
68+
#define tud_cdc_configure_fifo tud_cdc_configure
5969

6070
//--------------------------------------------------------------------+
6171
// Application API (Multiple Ports) i.e. CFG_TUD_CDC > 1

src/class/cdc/cdc_host.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,10 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
691691
}
692692
} else if ( ep_addr == p_cdc->stream.rx.ep_addr ) {
693693
#if CFG_TUH_CDC_FTDI
694-
if (p_cdc->serial_drid == SERIAL_DRIVER_FTDI) {
694+
if (p_cdc->serial_drid == SERIAL_DRIVER_FTDI && xferred_bytes > 2) {
695695
// FTDI reserve 2 bytes for status
696696
// uint8_t status[2] = {p_cdc->stream.rx.ep_buf[0], p_cdc->stream.rx.ep_buf[1]};
697-
tu_edpt_stream_read_xfer_complete_offset(&p_cdc->stream.rx, xferred_bytes, 2);
697+
tu_edpt_stream_read_xfer_complete_with_buf(&p_cdc->stream.rx, p_cdc->stream.rx.ep_buf+2, xferred_bytes-2);
698698
}else
699699
#endif
700700
{

src/class/cdc/cdc_host.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@
4949

5050
// RX FIFO size
5151
#ifndef CFG_TUH_CDC_RX_BUFSIZE
52-
#define CFG_TUH_CDC_RX_BUFSIZE USBH_EPSIZE_BULK_MAX
52+
#define CFG_TUH_CDC_RX_BUFSIZE TUH_EPSIZE_BULK_MPS
5353
#endif
5454

5555
// RX Endpoint size
5656
#ifndef CFG_TUH_CDC_RX_EPSIZE
57-
#define CFG_TUH_CDC_RX_EPSIZE USBH_EPSIZE_BULK_MAX
57+
#define CFG_TUH_CDC_RX_EPSIZE TUH_EPSIZE_BULK_MPS
5858
#endif
5959

6060
// TX FIFO size
6161
#ifndef CFG_TUH_CDC_TX_BUFSIZE
62-
#define CFG_TUH_CDC_TX_BUFSIZE USBH_EPSIZE_BULK_MAX
62+
#define CFG_TUH_CDC_TX_BUFSIZE TUH_EPSIZE_BULK_MPS
6363
#endif
6464

6565
// TX Endpoint size
6666
#ifndef CFG_TUH_CDC_TX_EPSIZE
67-
#define CFG_TUH_CDC_TX_EPSIZE USBH_EPSIZE_BULK_MAX
67+
#define CFG_TUH_CDC_TX_EPSIZE TUH_EPSIZE_BULK_MPS
6868
#endif
6969

7070
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)