Skip to content

Commit 51bb27a

Browse files
committed
Optimize descriptor looping.
1 parent 35fa6b6 commit 51bb27a

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

src/class/audio/audio_device.c

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,28 @@
106106
#define USE_LINEAR_BUFFER 1
107107
#endif
108108

109+
#if defined(STM32F102x6) || defined(STM32F102xB) || \
110+
defined(STM32F103x6) || defined(STM32F103xB) || \
111+
defined(STM32F103xE) || defined(STM32F103xG)
112+
#define STM32F1_FSDEV
113+
#endif
114+
115+
#if defined(STM32L412xx) || defined(STM32L422xx) || \
116+
defined(STM32L432xx) || defined(STM32L433xx) || \
117+
defined(STM32L442xx) || defined(STM32L443xx) || \
118+
defined(STM32L452xx) || defined(STM32L462xx)
119+
#define STM32L4_FSDEV
120+
#endif
121+
109122
// Temporarily put the check here for stm32_fsdev
110123
#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || \
111124
CFG_TUSB_MCU == OPT_MCU_STM32F3 || \
112125
CFG_TUSB_MCU == OPT_MCU_STM32L0 || \
113126
CFG_TUSB_MCU == OPT_MCU_STM32L1 || \
114127
CFG_TUSB_MCU == OPT_MCU_STM32G4 || \
115-
CFG_TUSB_MCU == OPT_MCU_STM32WB
128+
CFG_TUSB_MCU == OPT_MCU_STM32WB || \
129+
(TU_CHECK_MCU(OPT_MCU_STM32F1) && defined(STM32F1_FSDEV)) || \
130+
(TU_CHECK_MCU(OPT_MCU_STM32L4) && defined(STM32L4_FSDEV))
116131
#define USE_ISO_EP_ALLOCATION 1
117132
#else
118133
#define USE_ISO_EP_ALLOCATION 0
@@ -1481,18 +1496,17 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
14811496

14821497
#if USE_ISO_EP_ALLOCATION
14831498
#if CFG_TUD_AUDIO_ENABLE_EP_IN
1484-
uint8_t ep_in = 0;
1499+
uint8_t ep_in = 0;
14851500
uint16_t ep_in_size = 0;
14861501
#endif
14871502
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
1488-
uint8_t ep_out = 0;
1503+
uint8_t ep_out = 0;
14891504
uint16_t ep_out_size = 0;
14901505
#endif
14911506
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
14921507
uint8_t ep_fb = 0;
14931508
#endif
14941509

1495-
// First find EP addr
14961510
uint8_t const *p_desc = _audiod_fct[i].p_desc;
14971511
uint8_t const *p_desc_end = p_desc + _audiod_fct[i].desc_length - TUD_AUDIO_DESC_IAD_LEN;
14981512
while (p_desc < p_desc_end)
@@ -1516,11 +1530,13 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
15161530
{
15171531
#if CFG_TUD_AUDIO_ENABLE_EP_IN
15181532
ep_in = desc_ep->bEndpointAddress;
1533+
ep_in_size = TU_MAX(tu_edpt_packet_size(desc_ep), ep_in_size);
15191534
#endif
15201535
} else
15211536
{
15221537
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
15231538
ep_out = desc_ep->bEndpointAddress;
1539+
ep_out_size = TU_MAX(tu_edpt_packet_size(desc_ep), ep_out_size);
15241540
#endif
15251541
}
15261542
}
@@ -1530,32 +1546,6 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
15301546
p_desc = tu_desc_next(p_desc);
15311547
}
15321548

1533-
// Then find EP max size
1534-
p_desc = _audiod_fct[i].p_desc;
1535-
while (p_desc < p_desc_end)
1536-
{
1537-
if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT)
1538-
{
1539-
tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *) p_desc;
1540-
if (desc_ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS)
1541-
{
1542-
#if CFG_TUD_AUDIO_ENABLE_EP_IN
1543-
if (desc_ep->bEndpointAddress == ep_in)
1544-
{
1545-
ep_in_size = TU_MAX(tu_edpt_packet_size(desc_ep), ep_in_size);
1546-
}
1547-
#endif
1548-
#if CFG_TUD_AUDIO_ENABLE_EP_OUT
1549-
if (desc_ep->bEndpointAddress == ep_out)
1550-
{
1551-
ep_out_size = TU_MAX(tu_edpt_packet_size(desc_ep), ep_out_size);
1552-
}
1553-
#endif
1554-
}
1555-
}
1556-
p_desc = tu_desc_next(p_desc);
1557-
}
1558-
15591549
#if CFG_TUD_AUDIO_ENABLE_EP_IN
15601550
if (ep_in)
15611551
{

0 commit comments

Comments
 (0)