Skip to content

Commit ffdc100

Browse files
committed
rename ep_num to ep_idx, minor clean up
1 parent 8db462b commit ffdc100

File tree

4 files changed

+223
-206
lines changed

4 files changed

+223
-206
lines changed

src/class/audio/audio_device.c

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,17 +1495,19 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
14951495
}
14961496

14971497
#if USE_ISO_EP_ALLOCATION
1498-
#if CFG_TUD_AUDIO_ENABLE_EP_IN
1498+
#if CFG_TUD_AUDIO_ENABLE_EP_IN
14991499
uint8_t ep_in = 0;
15001500
uint16_t ep_in_size = 0;
1501-
#endif
1502-
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
1501+
#endif
1502+
1503+
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
15031504
uint8_t ep_out = 0;
15041505
uint16_t ep_out_size = 0;
1505-
#endif
1506-
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
1506+
#endif
1507+
1508+
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
15071509
uint8_t ep_fb = 0;
1508-
#endif
1510+
#endif
15091511

15101512
uint8_t const *p_desc = _audiod_fct[i].p_desc;
15111513
uint8_t const *p_desc_end = p_desc + _audiod_fct[i].desc_length - TUD_AUDIO_DESC_IAD_LEN;
@@ -1516,28 +1518,28 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
15161518
tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *) p_desc;
15171519
if (desc_ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS)
15181520
{
1519-
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
1521+
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
15201522
// Explicit feedback EP
15211523
if (desc_ep->bmAttributes.usage == 1)
15221524
{
15231525
ep_fb = desc_ep->bEndpointAddress;
15241526
}
1525-
#endif
1527+
#endif
15261528
// Data EP
15271529
if (desc_ep->bmAttributes.usage == 0)
15281530
{
15291531
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN)
15301532
{
1531-
#if CFG_TUD_AUDIO_ENABLE_EP_IN
1533+
#if CFG_TUD_AUDIO_ENABLE_EP_IN
15321534
ep_in = desc_ep->bEndpointAddress;
15331535
ep_in_size = TU_MAX(tu_edpt_packet_size(desc_ep), ep_in_size);
1534-
#endif
1536+
#endif
15351537
} else
15361538
{
1537-
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
1539+
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
15381540
ep_out = desc_ep->bEndpointAddress;
15391541
ep_out_size = TU_MAX(tu_edpt_packet_size(desc_ep), ep_out_size);
1540-
#endif
1542+
#endif
15411543
}
15421544
}
15431545

@@ -1546,26 +1548,28 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
15461548
p_desc = tu_desc_next(p_desc);
15471549
}
15481550

1549-
#if CFG_TUD_AUDIO_ENABLE_EP_IN
1551+
#if CFG_TUD_AUDIO_ENABLE_EP_IN
15501552
if (ep_in)
15511553
{
15521554
usbd_edpt_iso_alloc(rhport, ep_in, ep_in_size);
15531555
}
1554-
#endif
1555-
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
1556+
#endif
1557+
1558+
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
15561559
if (ep_out)
15571560
{
15581561
usbd_edpt_iso_alloc(rhport, ep_out, ep_out_size);
15591562
}
1560-
#endif
1561-
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
1563+
#endif
1564+
1565+
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
15621566
if (ep_fb)
15631567
{
15641568
usbd_edpt_iso_alloc(rhport, ep_fb, 4);
15651569
}
1566-
#endif
1570+
#endif
15671571

1568-
#endif
1572+
#endif // USE_ISO_EP_ALLOCATION
15691573

15701574
break;
15711575
}
@@ -1628,59 +1632,61 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
16281632
if (audio->ep_in_as_intf_num == itf)
16291633
{
16301634
audio->ep_in_as_intf_num = 0;
1631-
#if !USE_ISO_EP_ALLOCATION
1635+
#if !USE_ISO_EP_ALLOCATION
16321636
usbd_edpt_close(rhport, audio->ep_in);
1633-
#endif
1637+
#endif
1638+
16341639
// Clear FIFOs, since data is no longer valid
1635-
#if !CFG_TUD_AUDIO_ENABLE_ENCODING
1640+
#if !CFG_TUD_AUDIO_ENABLE_ENCODING
16361641
tu_fifo_clear(&audio->ep_in_ff);
1637-
#else
1642+
#else
16381643
for (uint8_t cnt = 0; cnt < audio->n_tx_supp_ff; cnt++)
16391644
{
16401645
tu_fifo_clear(&audio->tx_supp_ff[cnt]);
16411646
}
1642-
#endif
1647+
#endif
16431648

16441649
// Invoke callback - can be used to stop data sampling
16451650
if (tud_audio_set_itf_close_EP_cb) TU_VERIFY(tud_audio_set_itf_close_EP_cb(rhport, p_request));
16461651

16471652
audio->ep_in = 0; // Necessary?
16481653

16491654
}
1650-
#endif
1655+
#endif // CFG_TUD_AUDIO_ENABLE_EP_IN
16511656

16521657
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
16531658
if (audio->ep_out_as_intf_num == itf)
16541659
{
16551660
audio->ep_out_as_intf_num = 0;
1656-
#if !USE_ISO_EP_ALLOCATION
1661+
#if !USE_ISO_EP_ALLOCATION
16571662
usbd_edpt_close(rhport, audio->ep_out);
1658-
#endif
1663+
#endif
1664+
16591665
// Clear FIFOs, since data is no longer valid
1660-
#if !CFG_TUD_AUDIO_ENABLE_DECODING
1666+
#if !CFG_TUD_AUDIO_ENABLE_DECODING
16611667
tu_fifo_clear(&audio->ep_out_ff);
1662-
#else
1668+
#else
16631669
for (uint8_t cnt = 0; cnt < audio->n_rx_supp_ff; cnt++)
16641670
{
16651671
tu_fifo_clear(&audio->rx_supp_ff[cnt]);
16661672
}
1667-
#endif
1673+
#endif
16681674

16691675
// Invoke callback - can be used to stop data sampling
16701676
if (tud_audio_set_itf_close_EP_cb) TU_VERIFY(tud_audio_set_itf_close_EP_cb(rhport, p_request));
16711677

16721678
audio->ep_out = 0; // Necessary?
16731679

16741680
// Close corresponding feedback EP
1675-
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
1676-
#if !USE_ISO_EP_ALLOCATION
1681+
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
1682+
#if !USE_ISO_EP_ALLOCATION
16771683
usbd_edpt_close(rhport, audio->ep_fb);
1678-
#endif
1684+
#endif
16791685
audio->ep_fb = 0;
16801686
tu_memclr(&audio->feedback, sizeof(audio->feedback));
1681-
#endif
1687+
#endif
16821688
}
1683-
#endif
1689+
#endif // CFG_TUD_AUDIO_ENABLE_EP_OUT
16841690

16851691
// Save current alternative interface setting
16861692
audio->alt_setting[idxItf] = alt;
@@ -1724,21 +1730,20 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
17241730
audio->ep_in_sz = tu_edpt_packet_size(desc_ep);
17251731

17261732
// If software encoding is enabled, parse for the corresponding parameters - doing this here means only AS interfaces with EPs get scanned for parameters
1727-
#if CFG_TUD_AUDIO_ENABLE_ENCODING
1733+
#if CFG_TUD_AUDIO_ENABLE_ENCODING
17281734
audiod_parse_for_AS_params(audio, p_desc_parse_for_params, p_desc_end, itf);
17291735

17301736
// Reconfigure size of support FIFOs - this is necessary to avoid samples to get split in case of a wrap
1731-
#if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
1737+
#if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
17321738
const uint16_t active_fifo_depth = (uint16_t) ((audio->tx_supp_ff_sz_max / audio->n_bytes_per_sampe_tx) * audio->n_bytes_per_sampe_tx);
17331739
for (uint8_t cnt = 0; cnt < audio->n_tx_supp_ff; cnt++)
17341740
{
17351741
tu_fifo_config(&audio->tx_supp_ff[cnt], audio->tx_supp_ff[cnt].buffer, active_fifo_depth, 1, true);
17361742
}
17371743
audio->n_ff_used_tx = audio->n_channels_tx / audio->n_channels_per_ff_tx;
17381744
TU_ASSERT( audio->n_ff_used_tx <= audio->n_tx_supp_ff );
1739-
#endif
1740-
1741-
#endif
1745+
#endif
1746+
#endif
17421747

17431748
// Schedule first transmit if alternate interface is not zero i.e. streaming is disabled - in case no sample data is available a ZLP is loaded
17441749
// It is necessary to trigger this here since the refill is done with an RX FIFO empty interrupt which can only trigger if something was in there
@@ -1755,30 +1760,30 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
17551760
audio->ep_out_as_intf_num = itf;
17561761
audio->ep_out_sz = tu_edpt_packet_size(desc_ep);
17571762

1758-
#if CFG_TUD_AUDIO_ENABLE_DECODING
1763+
#if CFG_TUD_AUDIO_ENABLE_DECODING
17591764
audiod_parse_for_AS_params(audio, p_desc_parse_for_params, p_desc_end, itf);
17601765

17611766
// Reconfigure size of support FIFOs - this is necessary to avoid samples to get split in case of a wrap
1762-
#if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
1767+
#if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
17631768
const uint16_t active_fifo_depth = (audio->rx_supp_ff_sz_max / audio->n_bytes_per_sampe_rx) * audio->n_bytes_per_sampe_rx;
17641769
for (uint8_t cnt = 0; cnt < audio->n_rx_supp_ff; cnt++)
17651770
{
17661771
tu_fifo_config(&audio->rx_supp_ff[cnt], audio->rx_supp_ff[cnt].buffer, active_fifo_depth, 1, true);
17671772
}
17681773
audio->n_ff_used_rx = audio->n_channels_rx / audio->n_channels_per_ff_rx;
17691774
TU_ASSERT( audio->n_ff_used_rx <= audio->n_rx_supp_ff );
1770-
#endif
1771-
#endif
1775+
#endif
1776+
#endif
17721777

17731778
// Prepare for incoming data
1774-
#if USE_LINEAR_BUFFER_RX
1779+
#if USE_LINEAR_BUFFER_RX
17751780
TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz), false);
1776-
#else
1781+
#else
17771782
TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false);
1778-
#endif
1783+
#endif
17791784
}
17801785

1781-
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
1786+
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
17821787
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN && desc_ep->bmAttributes.usage == 1) // Check if usage is explicit data feedback
17831788
{
17841789
audio->ep_fb = ep_addr;
@@ -1787,7 +1792,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
17871792
// Enable SOF interrupt if callback is implemented
17881793
if (tud_audio_feedback_interval_isr) usbd_sof_enable(rhport, true);
17891794
}
1790-
#endif
1795+
#endif
17911796
#endif // CFG_TUD_AUDIO_ENABLE_EP_OUT
17921797

17931798
foundEPs += 1;
@@ -1838,7 +1843,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
18381843
default: break;
18391844
}
18401845
}
1841-
#endif
1846+
#endif // CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
18421847

18431848
// We are done - abort loop
18441849
break;

src/device/usbd.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,12 +1384,10 @@ bool usbd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packe
13841384
{
13851385
rhport = _usbd_rhport;
13861386

1387+
TU_ASSERT(dcd_edpt_iso_alloc);
13871388
TU_ASSERT(tu_edpt_number(ep_addr) < CFG_TUD_ENDPPOINT_MAX);
13881389

1389-
if (dcd_edpt_iso_alloc)
1390-
return dcd_edpt_iso_alloc(rhport, ep_addr, largest_packet_size);
1391-
else
1392-
return false;
1390+
return dcd_edpt_iso_alloc(rhport, ep_addr, largest_packet_size);
13931391
}
13941392

13951393
bool usbd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep)
@@ -1399,18 +1397,14 @@ bool usbd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep
13991397
uint8_t const epnum = tu_edpt_number(desc_ep->bEndpointAddress);
14001398
uint8_t const dir = tu_edpt_dir(desc_ep->bEndpointAddress);
14011399

1400+
TU_ASSERT(dcd_edpt_iso_activate);
14021401
TU_ASSERT(epnum < CFG_TUD_ENDPPOINT_MAX);
14031402
TU_ASSERT(tu_edpt_validate(desc_ep, (tusb_speed_t) _usbd_dev.speed));
14041403

1405-
if (dcd_edpt_iso_activate)
1406-
{
1407-
_usbd_dev.ep_status[epnum][dir].stalled = false;
1408-
_usbd_dev.ep_status[epnum][dir].busy = false;
1409-
_usbd_dev.ep_status[epnum][dir].claimed = false;
1410-
return dcd_edpt_iso_activate(rhport, desc_ep);
1411-
}
1412-
else
1413-
return false;
1404+
_usbd_dev.ep_status[epnum][dir].stalled = false;
1405+
_usbd_dev.ep_status[epnum][dir].busy = false;
1406+
_usbd_dev.ep_status[epnum][dir].claimed = false;
1407+
return dcd_edpt_iso_activate(rhport, desc_ep);
14141408
}
14151409

14161410
#endif

0 commit comments

Comments
 (0)