Skip to content

Commit 872864e

Browse files
authored
Merge pull request #2567 from HiFiPhile/iso_alloc
ISO endpoint allocation improvments
2 parents bc10394 + e642066 commit 872864e

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

src/class/audio/audio_device.c

+6-13
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@
9696
#define USE_LINEAR_BUFFER 1
9797
#endif
9898

99-
// Temporarily put the check here
100-
#if defined(TUP_USBIP_FSDEV) || defined(TUP_USBIP_DWC2)
101-
#define USE_ISO_EP_ALLOCATION 1
102-
#else
103-
#define USE_ISO_EP_ALLOCATION 0
104-
#endif
105-
10699
// Declaration of buffers
107100

108101
// Check for maximum supported numbers
@@ -1476,7 +1469,7 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
14761469
#endif
14771470
}
14781471

1479-
#if USE_ISO_EP_ALLOCATION
1472+
#ifdef TUP_DCD_EDPT_ISO_ALLOC
14801473
{
14811474
#if CFG_TUD_AUDIO_ENABLE_EP_IN
14821475
uint8_t ep_in = 0;
@@ -1552,7 +1545,7 @@ uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
15521545
}
15531546
#endif
15541547
}
1555-
#endif // USE_ISO_EP_ALLOCATION
1548+
#endif // TUP_DCD_EDPT_ISO_ALLOC
15561549

15571550
#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL
15581551
{
@@ -1674,7 +1667,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
16741667
if (audio->ep_in_as_intf_num == itf)
16751668
{
16761669
audio->ep_in_as_intf_num = 0;
1677-
#if !USE_ISO_EP_ALLOCATION
1670+
#ifndef TUP_DCD_EDPT_ISO_ALLOC
16781671
usbd_edpt_close(rhport, audio->ep_in);
16791672
#endif
16801673

@@ -1705,7 +1698,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
17051698
if (audio->ep_out_as_intf_num == itf)
17061699
{
17071700
audio->ep_out_as_intf_num = 0;
1708-
#if !USE_ISO_EP_ALLOCATION
1701+
#ifndef TUP_DCD_EDPT_ISO_ALLOC
17091702
usbd_edpt_close(rhport, audio->ep_out);
17101703
#endif
17111704

@@ -1726,7 +1719,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
17261719

17271720
// Close corresponding feedback EP
17281721
#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
1729-
#if !USE_ISO_EP_ALLOCATION
1722+
#ifndef TUP_DCD_EDPT_ISO_ALLOC
17301723
usbd_edpt_close(rhport, audio->ep_fb);
17311724
#endif
17321725
audio->ep_fb = 0;
@@ -1758,7 +1751,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
17581751
if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT)
17591752
{
17601753
tusb_desc_endpoint_t const* desc_ep = (tusb_desc_endpoint_t const *) p_desc;
1761-
#if USE_ISO_EP_ALLOCATION
1754+
#ifdef TUP_DCD_EDPT_ISO_ALLOC
17621755
TU_ASSERT(usbd_edpt_iso_activate(rhport, desc_ep));
17631756
#else
17641757
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));

src/class/video/video_device.c

+36-11
Original file line numberDiff line numberDiff line change
@@ -755,15 +755,20 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
755755
TU_LOG_DRV(" reopen VS %d\r\n", altnum);
756756
uint8_t const *desc = _videod_itf[stm->index_vc].beg;
757757

758+
#ifndef TUP_DCD_EDPT_ISO_ALLOC
758759
/* Close endpoints of previous settings. */
759760
for (i = 0; i < TU_ARRAY_SIZE(stm->desc.ep); ++i) {
760761
uint_fast16_t ofs_ep = stm->desc.ep[i];
761762
if (!ofs_ep) break;
762-
uint8_t ep_adr = _desc_ep_addr(desc + ofs_ep);
763-
usbd_edpt_close(rhport, ep_adr);
764-
stm->desc.ep[i] = 0;
765-
TU_LOG_DRV(" close EP%02x\r\n", ep_adr);
763+
tusb_desc_endpoint_t const *ep = (tusb_desc_endpoint_t const*)(desc + ofs_ep);
764+
/* Only ISO endpoints needs to be closed */
765+
if(ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) {
766+
usbd_edpt_close(rhport, ep->bEndpointAddress);
767+
stm->desc.ep[i] = 0;
768+
TU_LOG_DRV(" close EP%02x\r\n", ep->bEndpointAddress);
769+
}
766770
}
771+
#endif
767772

768773
/* clear transfer management information */
769774
stm->buffer = NULL;
@@ -788,16 +793,18 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
788793
TU_ASSERT(cur < end);
789794
tusb_desc_endpoint_t const *ep = (tusb_desc_endpoint_t const*)cur;
790795
uint_fast32_t max_size = stm->max_payload_transfer_size;
791-
if (altnum) {
792-
if ((TUSB_XFER_ISOCHRONOUS == ep->bmAttributes.xfer) &&
793-
(tu_edpt_packet_size(ep) < max_size)) {
794-
/* FS must be less than or equal to max packet size */
795-
return false;
796-
}
796+
if (altnum && (TUSB_XFER_ISOCHRONOUS == ep->bmAttributes.xfer)) {
797+
/* FS must be less than or equal to max packet size */
798+
TU_VERIFY (tu_edpt_packet_size(ep) >= max_size);
799+
#ifdef TUP_DCD_EDPT_ISO_ALLOC
800+
usbd_edpt_iso_activate(rhport, ep);
801+
#else
802+
TU_ASSERT(usbd_edpt_open(rhport, ep));
803+
#endif
797804
} else {
798805
TU_VERIFY(TUSB_XFER_BULK == ep->bmAttributes.xfer);
806+
TU_ASSERT(usbd_edpt_open(rhport, ep));
799807
}
800-
TU_ASSERT(usbd_edpt_open(rhport, ep));
801808
stm->desc.ep[i] = (uint16_t) (cur - desc);
802809
TU_LOG_DRV(" open EP%02x\r\n", _desc_ep_addr(cur));
803810
}
@@ -1283,6 +1290,24 @@ uint16_t videod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uin
12831290
cur = _next_desc_itf(cur, end);
12841291
stm->desc.end = (uint16_t) ((uintptr_t)cur - (uintptr_t)itf_desc);
12851292
stm->state = VS_STATE_PROBING;
1293+
#ifdef TUP_DCD_EDPT_ISO_ALLOC
1294+
/* Allocate ISO endpoints */
1295+
uint16_t ep_size = 0;
1296+
uint16_t ep_addr = 0;
1297+
uint8_t const *p_desc = (uint8_t const*)itf_desc + stm->desc.beg;
1298+
uint8_t const *p_desc_end = (uint8_t const*)itf_desc + stm->desc.end;
1299+
while (p_desc < p_desc_end) {
1300+
if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT) {
1301+
tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *) p_desc;
1302+
if (desc_ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) {
1303+
ep_addr = desc_ep->bEndpointAddress;
1304+
ep_size = TU_MAX(tu_edpt_packet_size(desc_ep), ep_size);
1305+
}
1306+
}
1307+
p_desc = tu_desc_next(p_desc);
1308+
}
1309+
if(ep_addr > 0 && ep_size > 0) usbd_edpt_iso_alloc(rhport, ep_addr, ep_size);
1310+
#endif
12861311
if (0 == stm_idx && 1 == bInCollection) {
12871312
/* If there is only one streaming interface and no alternate settings,
12881313
* host may not issue set_interface so open the streaming interface here. */

src/common/tusb_mcu.h

+4
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,8 @@
441441
#define TU_ATTR_FAST_FUNC
442442
#endif
443443

444+
#if defined(TUP_USBIP_DWC2) || defined(TUP_USBIP_FSDEV)
445+
#define TUP_DCD_EDPT_ISO_ALLOC
446+
#endif
447+
444448
#endif

0 commit comments

Comments
 (0)