@@ -238,25 +238,19 @@ static inline cdch_interface_t* get_itf(uint8_t idx)
238
238
return (p_cdc -> daddr != 0 ) ? p_cdc : NULL ;
239
239
}
240
240
241
- TU_ATTR_ALWAYS_INLINE
242
- static inline uint8_t itf2idx (cdch_interface_t * p_cdc )
243
- {
244
- return (uint8_t ) (p_cdc - cdch_data );
245
- }
246
-
247
- static inline cdch_interface_t * get_itf_by_ep_addr (uint8_t daddr , uint8_t ep_addr )
241
+ static inline uint8_t get_idx_by_ep_addr (uint8_t daddr , uint8_t ep_addr )
248
242
{
249
243
for (uint8_t i = 0 ; i < CFG_TUH_CDC ; i ++ )
250
244
{
251
245
cdch_interface_t * p_cdc = & cdch_data [i ];
252
246
if ( (p_cdc -> daddr == daddr ) &&
253
247
(ep_addr == p_cdc -> ep_notif || ep_addr == p_cdc -> stream .rx .ep_addr || ep_addr == p_cdc -> stream .tx .ep_addr ))
254
248
{
255
- return p_cdc ;
249
+ return i ;
256
250
}
257
251
}
258
252
259
- return NULL ;
253
+ return TUSB_INDEX_INVALID ;
260
254
}
261
255
262
256
@@ -478,11 +472,15 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
478
472
// TODO handle stall response, retry failed transfer ...
479
473
TU_ASSERT (event == XFER_RESULT_SUCCESS );
480
474
481
- cdch_interface_t * p_cdc = get_itf_by_ep_addr (daddr , ep_addr );
475
+ uint8_t const idx = get_idx_by_ep_addr (daddr , ep_addr );
476
+ cdch_interface_t * p_cdc = get_itf (idx );
482
477
TU_ASSERT (p_cdc );
483
478
484
479
if ( ep_addr == p_cdc -> stream .tx .ep_addr )
485
480
{
481
+ // invoke tx complete callback to possibly refill tx fifo
482
+ if (tuh_cdc_tx_complete_cb ) tuh_cdc_tx_complete_cb (idx );
483
+
486
484
if ( 0 == tu_edpt_stream_write_xfer (daddr , & p_cdc -> stream .tx ) )
487
485
{
488
486
// If there is no data left, a ZLP should be sent if needed
@@ -496,7 +494,7 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
496
494
if (xferred_bytes ) tu_edpt_stream_read_xfer_complete (& p_cdc -> stream .rx , xferred_bytes );
497
495
498
496
// invoke receive callback
499
- if (tuh_cdc_rx_cb ) tuh_cdc_rx_cb (itf2idx ( p_cdc ) );
497
+ if (tuh_cdc_rx_cb ) tuh_cdc_rx_cb (idx );
500
498
501
499
// prepare for next transfer if needed
502
500
tu_edpt_stream_read_xfer (daddr , & p_cdc -> stream .rx );
0 commit comments