Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 47 additions & 38 deletions examples/dual/dynamic_switch/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,18 @@ void usb_mode_switch(void);
static void print_one_device(uint8_t daddr);
static void print_utf16(uint16_t* temp_buf, size_t buf_len);

// Declare buffer for USB transfer
// Device descriptor and serial string, copied out of the transfer buffer
static tusb_desc_device_t desc_device;
static uint16_t desc_serial[64];

// Declare buffer for USB transfer: a control IN buffer holds whole 64-byte packets (TUH_CTRL_BUFSIZE)
typedef union {
tusb_desc_device_t device;
uint16_t str[128];
} desc_buf_t;

CFG_TUH_MEM_SECTION struct {
TUH_EPBUF_TYPE_DEF(tusb_desc_device_t, device);
TUH_EPBUF_DEF(serial, 64*sizeof(uint16_t));
TUH_EPBUF_DEF(buf, 128*sizeof(uint16_t));
TUH_EPBUF_TYPE_DEF(desc_buf_t, buf);
} desc;

//--------------------------------------------------------------------+
Expand Down Expand Up @@ -420,69 +427,71 @@ void print_devinfo_task(void *param) {

static void print_one_device(uint8_t daddr) {
// Get Device Descriptor
uint8_t xfer_result = tuh_descriptor_get_device_sync(daddr, &desc.device, 18);
uint8_t xfer_result = tuh_descriptor_get_device_sync(daddr, &desc.buf.device, 18);
if (XFER_RESULT_SUCCESS != xfer_result) {
printf("Failed to get device descriptor\r\n");
return;
}
desc_device = desc.buf.device;

printf("Device %u: ID %04x:%04x SN ", daddr, desc.device.idVendor, desc.device.idProduct);
printf("Device %u: ID %04x:%04x SN ", daddr, desc_device.idVendor, desc_device.idProduct);

xfer_result = XFER_RESULT_FAILED;
if (desc.device.iSerialNumber != 0) {
xfer_result = tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, desc.serial, sizeof(desc.serial));
if (desc_device.iSerialNumber != 0) {
xfer_result = tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, desc.buf.str, sizeof(desc_serial));
}
if (XFER_RESULT_SUCCESS != xfer_result) {
uint16_t* serial = (uint16_t*)(uintptr_t) desc.serial;
serial[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * 3 + 2));
serial[1] = 'n';
serial[2] = '/';
serial[3] = 'a';
serial[4] = 0;
if (XFER_RESULT_SUCCESS == xfer_result) {
memcpy(desc_serial, desc.buf.str, sizeof(desc_serial));
} else {
desc_serial[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * 3 + 2));
desc_serial[1] = 'n';
desc_serial[2] = '/';
desc_serial[3] = 'a';
desc_serial[4] = 0;
}
print_utf16((uint16_t*)(uintptr_t) desc.serial, sizeof(desc.serial)/2);
print_utf16(desc_serial, TU_ARRAY_SIZE(desc_serial));
printf("\r\n");

printf("Device Descriptor:\r\n");
printf(" bLength %u\r\n", desc.device.bLength);
printf(" bDescriptorType %u\r\n", desc.device.bDescriptorType);
printf(" bcdUSB %04x\r\n", desc.device.bcdUSB);
printf(" bDeviceClass %u\r\n", desc.device.bDeviceClass);
printf(" bDeviceSubClass %u\r\n", desc.device.bDeviceSubClass);
printf(" bDeviceProtocol %u\r\n", desc.device.bDeviceProtocol);
printf(" bMaxPacketSize0 %u\r\n", desc.device.bMaxPacketSize0);
printf(" idVendor 0x%04x\r\n", desc.device.idVendor);
printf(" idProduct 0x%04x\r\n", desc.device.idProduct);
printf(" bcdDevice %04x\r\n", desc.device.bcdDevice);
printf(" bLength %u\r\n", desc_device.bLength);
printf(" bDescriptorType %u\r\n", desc_device.bDescriptorType);
printf(" bcdUSB %04x\r\n", desc_device.bcdUSB);
printf(" bDeviceClass %u\r\n", desc_device.bDeviceClass);
printf(" bDeviceSubClass %u\r\n", desc_device.bDeviceSubClass);
printf(" bDeviceProtocol %u\r\n", desc_device.bDeviceProtocol);
printf(" bMaxPacketSize0 %u\r\n", desc_device.bMaxPacketSize0);
printf(" idVendor 0x%04x\r\n", desc_device.idVendor);
printf(" idProduct 0x%04x\r\n", desc_device.idProduct);
printf(" bcdDevice %04x\r\n", desc_device.bcdDevice);

// Get Manufacturer string
if (desc.device.iManufacturer) {
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, desc.buf, sizeof(desc.buf))) {
printf(" iManufacturer %u ", desc.device.iManufacturer);
print_utf16((uint16_t*)(uintptr_t) desc.buf, sizeof(desc.buf)/2);
if (desc_device.iManufacturer) {
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, desc.buf.str, sizeof(desc.buf.str))) {
printf(" iManufacturer %u ", desc_device.iManufacturer);
print_utf16(desc.buf.str, TU_ARRAY_SIZE(desc.buf.str));
printf("\r\n");
}
}

// Get Product string
if (desc.device.iProduct) {
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, desc.buf, sizeof(desc.buf))) {
printf(" iProduct %u ", desc.device.iProduct);
print_utf16((uint16_t*)(uintptr_t) desc.buf, sizeof(desc.buf)/2);
if (desc_device.iProduct) {
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, desc.buf.str, sizeof(desc.buf.str))) {
printf(" iProduct %u ", desc_device.iProduct);
print_utf16(desc.buf.str, TU_ARRAY_SIZE(desc.buf.str));
printf("\r\n");
}
}

// Get Serial string
if (desc.device.iSerialNumber) {
printf(" iSerialNumber %u ", desc.device.iSerialNumber);
print_utf16((uint16_t*)(uintptr_t) desc.serial, sizeof(desc.serial)/2);
if (desc_device.iSerialNumber) {
printf(" iSerialNumber %u ", desc_device.iSerialNumber);
print_utf16(desc_serial, TU_ARRAY_SIZE(desc_serial));
printf("\r\n");
} else {
printf(" iSerialNumber 0\r\n");
}

printf(" bNumConfigurations %u\r\n", desc.device.bNumConfigurations);
printf(" bNumConfigurations %u\r\n", desc_device.bNumConfigurations);
printf("\r\n");
}

Expand Down
31 changes: 19 additions & 12 deletions examples/host/bare_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@
#define BUF_COUNT 4


// buffers handed to the stack for usb transfers: in USB/DMA memory with the host controller's alignment
CFG_TUH_MEM_SECTION CFG_TUH_MEM_ALIGN tusb_desc_device_t desc_device;
// device descriptor, copied out of temp_buf
static tusb_desc_device_t desc_device;

// buffers handed to the stack for usb transfers: in USB/DMA memory with the host controller's alignment
CFG_TUH_MEM_SECTION CFG_TUH_MEM_ALIGN uint8_t buf_pool[BUF_COUNT][64];
uint8_t buf_owner[BUF_COUNT] = { 0 }; // device address that owns buffer

CFG_TUH_MEM_SECTION CFG_TUH_MEM_ALIGN uint16_t temp_buf[128]; // temp buffer for string descriptor
// temp buffer for device, string and configuration descriptors: a control IN buffer holds whole 64-byte packets
// (TUH_CTRL_BUFSIZE)
CFG_TUH_MEM_SECTION CFG_TUH_MEM_ALIGN union {
tusb_desc_device_t device;
uint16_t str[128];
} temp_buf;

//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
Expand Down Expand Up @@ -122,10 +128,11 @@ void print_devinfo_task(void) {

static void print_one_device(uint8_t daddr) {
// Get Device Descriptor
if (XFER_RESULT_SUCCESS != tuh_descriptor_get_device_sync(daddr, &desc_device, 18)) {
if (XFER_RESULT_SUCCESS != tuh_descriptor_get_device_sync(daddr, &temp_buf.device, 18)) {
printf("Failed to get device descriptor\r\n");
return;
}
desc_device = temp_buf.device;

printf("Device %u: ID %04x:%04x\r\n", daddr, desc_device.idVendor, desc_device.idProduct);
printf("Device Descriptor:\r\n");
Expand All @@ -141,28 +148,28 @@ static void print_one_device(uint8_t daddr) {
printf(" bcdDevice %04x\r\n" , desc_device.bcdDevice);

printf(" iManufacturer %u ", desc_device.iManufacturer);
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, temp_buf, sizeof(temp_buf))) {
print_utf16(temp_buf, TU_ARRAY_SIZE(temp_buf));
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, temp_buf.str, sizeof(temp_buf.str))) {
print_utf16(temp_buf.str, TU_ARRAY_SIZE(temp_buf.str));
}
printf("\r\n");

printf(" iProduct %u ", desc_device.iProduct);
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, temp_buf, sizeof(temp_buf))) {
print_utf16(temp_buf, TU_ARRAY_SIZE(temp_buf));
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, temp_buf.str, sizeof(temp_buf.str))) {
print_utf16(temp_buf.str, TU_ARRAY_SIZE(temp_buf.str));
}
printf("\r\n");

printf(" iSerialNumber %u ", desc_device.iSerialNumber);
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, temp_buf, sizeof(temp_buf))) {
print_utf16(temp_buf, TU_ARRAY_SIZE(temp_buf));
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, temp_buf.str, sizeof(temp_buf.str))) {
print_utf16(temp_buf.str, TU_ARRAY_SIZE(temp_buf.str));
}
printf("\r\n");

printf(" bNumConfigurations %u\r\n", desc_device.bNumConfigurations);

// Get configuration descriptor with sync API
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_configuration_sync(daddr, 0, temp_buf, sizeof(temp_buf))) {
parse_config_descriptor(daddr, (tusb_desc_configuration_t *) temp_buf);
if (XFER_RESULT_SUCCESS == tuh_descriptor_get_configuration_sync(daddr, 0, temp_buf.str, sizeof(temp_buf.str))) {
parse_config_descriptor(daddr, (tusb_desc_configuration_t *) temp_buf.str);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/class/audio/audio_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@
TUD_EPBUF_DEF(buf_3, CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX);
#endif
} lin_buf_out;

// An OUT transfer is one whole packet into the linear buffer: a controller (e.g. dwc2) accepts a full packet whatever
// the transfer has left, so the endpoint's packet size must fit the buffer
static uint16_t audiod_lin_buf_out_size(uint8_t func_id) {
Comment thread
HiFiPhile marked this conversation as resolved.
Resolved
switch (func_id) {
#if CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX > 0
case 0: return CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX;
#endif
#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX > 0
case 1: return CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX;
#endif
#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX > 0
case 2: return CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX;
#endif
default: return 0;
}
Comment thread
HiFiPhile marked this conversation as resolved.
Resolved
}
#endif// CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_EDPT_DEDICATED_HWFIFO

// Control buffer
Expand Down Expand Up @@ -1210,6 +1227,7 @@

// Prepare for incoming data
#if !CFG_TUD_EDPT_DEDICATED_HWFIFO
TU_VERIFY(TUD_VALIDATE_BASIC(audio->ep_out_sz <= audiod_lin_buf_out_size(func_id)));
TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz, false));
#else
TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz, false));
Expand Down
8 changes: 4 additions & 4 deletions src/class/audio/audio_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ typedef struct {

typedef struct {
// Clock discovery finishes before mount, so its buffer can be reused by
// runtime sampling-frequency and Feature Unit requests.
// runtime sampling-frequency and Feature Unit requests. Control IN buffers hold whole packets (TUH_CTRL_BUFSIZE)
union {
#if CFG_TUH_AUDIO_PROTOCOLS & TUH_AUDIO_PROTOCOL_UAC2
TUH_EPBUF_DEF(clock_range, AUDIOH_CLOCK_RANGE_BUFSIZE);
TUH_EPBUF_DEF(clock_range, TUH_CTRL_BUFSIZE(AUDIOH_CLOCK_RANGE_BUFSIZE));
#endif
struct {
TUH_EPBUF_DEF(rate_ctrl, 4);
TUH_EPBUF_DEF(fu_ctrl, 8);
TUH_EPBUF_DEF(rate_ctrl, TUH_CTRL_BUFSIZE(4));
TUH_EPBUF_DEF(fu_ctrl, TUH_CTRL_BUFSIZE(8));
} runtime;
} control;
// Feedback transfers may overlap runtime control transfers, so the feedback buffer is separate.
Expand Down
15 changes: 9 additions & 6 deletions src/class/bth/bth_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,17 @@ uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_
&_btd_itf.ep_acl_in),
0);

// Save acl in endpoint max packet size
tusb_desc_endpoint_t const *desc_ep_acl_in = desc_ep;
// Save acl in endpoint max packet size. The acl out transfer is armed as whole packets into the buffer: a controller
// (e.g. dwc2) accepts a full packet whatever the transfer has left
tusb_desc_endpoint_t const *desc_ep_acl = desc_ep;
for (size_t p = 0; p < 2; p++) {
if (tu_edpt_dir(desc_ep_acl_in->bEndpointAddress) == TUSB_DIR_IN) {
_btd_itf.ep_acl_in_pkt_sz = tu_edpt_packet_size(desc_ep_acl_in);
break;
uint16_t const ep_mps = tu_edpt_packet_size(desc_ep_acl);
if (tu_edpt_dir(desc_ep_acl->bEndpointAddress) == TUSB_DIR_IN) {
_btd_itf.ep_acl_in_pkt_sz = ep_mps;
} else {
TU_ASSERT(TUD_VALIDATE_BASIC(ep_mps > 0 && (CFG_TUD_BTH_DATA_EPSIZE % ep_mps) == 0), 0);
}
desc_ep_acl_in = (tusb_desc_endpoint_t const *) tu_desc_next(desc_ep_acl_in);
desc_ep_acl = (tusb_desc_endpoint_t const *) tu_desc_next(desc_ep_acl);
}

itf_desc = (tusb_desc_interface_t const *) tu_desc_next(tu_desc_next(desc_ep));
Expand Down
6 changes: 6 additions & 0 deletions src/class/cdc/cdc_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ uint16_t cdcd_open(uint8_t rhport, const tusb_desc_interface_t* itf_desc, uint16

const tusb_desc_endpoint_t *desc_ep = (const tusb_desc_endpoint_t *)p_desc;
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_BULK == desc_ep->bmAttributes.xfer, 0);
// OUT is armed as whole packets into the buffer (dwc2 accepts a full packet whatever the transfer has left):
// the whole buffer with CFG_TUD_CDC_RX_NEED_ZLP, else one packet. A dedicated hw FIFO has no RAM buffer
TU_ASSERT(TUD_VALIDATE_BASIC(tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN ||
p_cdc->rx_stream.ep_buf == NULL ||
tu_edpt_rx_buf_fits(desc_ep, CFG_TUD_CDC_RX_EPSIZE, CFG_TUD_CDC_RX_NEED_ZLP)),
0);

TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
Expand Down
2 changes: 1 addition & 1 deletion src/class/cdc/cdc_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef struct {
typedef struct {
TUH_EPBUF_DEF(tx, CFG_TUH_CDC_TX_EPSIZE);
TUH_EPBUF_DEF(rx, CFG_TUH_CDC_RX_EPSIZE);
TUH_EPBUF_DEF(ctrl, 8);
TUH_EPBUF_DEF(ctrl, TUH_CTRL_BUFSIZE(8)); // control IN of up to 8 bytes: whole packets, see TUH_CTRL_BUFSIZE
} cdch_epbuf_t;

// Each bulk transfer is wMaxPacketSize long, which tuh_edpt_open() bounds to TUH_EPSIZE_BULK_MAX
Expand Down
24 changes: 22 additions & 2 deletions src/class/hid/hid_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct {
uint8_t ep_out; // optional Out endpoint
uint8_t itf_protocol; // Boot mouse or keyboard

uint16_t out_xfer_len; // OUT arm length: the whole packets that fit CFG_TUD_HID_EP_BUFSIZE
uint16_t report_desc_len;
uint8_t protocol_mode; // Boot (0) or Report protocol (1)
uint8_t idle_rate; // up to application to handle idle rate
Expand Down Expand Up @@ -230,6 +231,25 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const *desc_itf, uint16

//------------- Endpoint Descriptor -------------//
p_desc = tu_desc_next(p_desc);

// The OUT transfer is armed as the whole buffer. A controller that writes a full packet whatever the transfer has left
// (TUP_DCD_EDPT_OUT_WHOLE_PACKET, e.g. dwc2 DMA) takes the whole packets that fit it: with a buffer that is not a
// multiple of the packet size, a report longer than those arrives in two callbacks
uint8_t const *p_ep = p_desc;
for (uint8_t i = 0; i < desc_itf->bNumEndpoints; i++) {
tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *) p_ep;
if (tu_desc_type(p_ep) == TUSB_DESC_ENDPOINT && tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_OUT) {
TU_ASSERT(TUD_VALIDATE_BASIC(tu_edpt_rx_buf_fits(desc_ep, CFG_TUD_HID_EP_BUFSIZE, false)), 0);
p_hid->out_xfer_len = CFG_TUD_HID_EP_BUFSIZE;
#if TUP_DCD_EDPT_OUT_WHOLE_PACKET
uint16_t const ep_mps = tu_edpt_packet_size(desc_ep);
TU_ASSERT(ep_mps > 0, 0); // divides below
p_hid->out_xfer_len = (uint16_t) (CFG_TUD_HID_EP_BUFSIZE - (CFG_TUD_HID_EP_BUFSIZE % ep_mps));
Comment thread
HiFiPhile marked this conversation as resolved.
Resolved
#endif
}
p_ep = tu_desc_next(p_ep);
}

TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, desc_itf->bNumEndpoints, TUSB_XFER_INTERRUPT, &p_hid->ep_out, &p_hid->ep_in), 0);

if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT) {
Expand All @@ -244,7 +264,7 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const *desc_itf, uint16

// Prepare for output endpoint
if (p_hid->ep_out) {
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_epbuf->epout, CFG_TUD_HID_EP_BUFSIZE, false), drv_len);
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_epbuf->epout, p_hid->out_xfer_len, false), drv_len);
}

return drv_len;
Expand Down Expand Up @@ -396,7 +416,7 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
}

// prepare for new transfer
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_epbuf->epout, CFG_TUD_HID_EP_BUFSIZE, false));
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_epbuf->epout, p_hid->out_xfer_len, false));
}

return true;
Expand Down
5 changes: 5 additions & 0 deletions src/class/midi/midi2_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,11 @@ uint16_t midi2d_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint
p_midi->ep_stream.tx.mps = tu_edpt_packet_size(desc_ep);
tu_fifo_clear(&p_midi->ep_stream.tx.ff);
} else {
// one whole packet per transfer: the buffer must hold it (a controller accepts a full packet). A dedicated hw
// FIFO has no RAM buffer
TU_ASSERT(TUD_VALIDATE_BASIC(p_midi->ep_stream.rx.ep_buf == NULL ||
tu_edpt_rx_buf_fits(desc_ep, CFG_TUD_MIDI2_RX_EPSIZE, false)),
0);
tu_edpt_stream_open(&p_midi->ep_stream.rx, rhport, desc_ep, tu_edpt_packet_size(desc_ep));
tu_edpt_stream_clear(&p_midi->ep_stream.rx);
TU_ASSERT(tu_edpt_stream_read_xfer(&p_midi->ep_stream.rx) > 0, 0);
Expand Down
14 changes: 10 additions & 4 deletions src/class/midi/midi2_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ static const uint8_t* midih2_parse_descriptors_alt0(midih2_interface_t *p_midi,
case TUSB_DESC_ENDPOINT: {
const tusb_desc_endpoint_t *p_ep = (const tusb_desc_endpoint_t *) p_desc;

// tuh_edpt_open() bounds bulk to TUH_EPSIZE_BULK_MAX, interrupt and isochronous can still exceed _midi2_epbuf
TU_VERIFY(p_ep->bmAttributes.xfer == TUSB_XFER_BULK || tu_edpt_packet_size(p_ep) <= TUH_EPSIZE_BULK_MAX,
// tuh_edpt_open() bounds bulk to TUH_EPSIZE_BULK_MAX, interrupt and isochronous can still exceed _midi2_epbuf,
// or, for IN, not be the power of 2 the receive stream needs
TU_VERIFY(p_ep->bmAttributes.xfer == TUSB_XFER_BULK ||
(tu_edpt_packet_size(p_ep) <= TUH_EPSIZE_BULK_MAX &&
(tu_edpt_dir(p_ep->bEndpointAddress) == TUSB_DIR_OUT || tu_is_power_of_two(tu_edpt_packet_size(p_ep)))),
NULL);
TU_ASSERT(tuh_edpt_open(p_midi->daddr, p_ep), NULL);
// kept as opened, after tuh_edpt_open() which can rewrite a bulk size, to restore it (midih2_alt0_reopen)
Expand Down Expand Up @@ -320,8 +323,11 @@ static bool midih2_parse_alt1_endpoint(midih2_interface_t *p_midi, const tusb_de
return true;
}

// a bulk size is bounded after the open, which can rewrite it
TU_VERIFY(type == TUSB_XFER_BULK || tu_edpt_packet_size(p_ep) <= TUH_EPSIZE_BULK_MAX);
// a bulk size is bounded after the open, which can rewrite it. An Interrupt IN one must also be the power of 2 the
// receive stream needs, else the device stays on setting 0; OUT sends whole UMPs of any size (_tuh_tx_start_xfer)
TU_VERIFY(type == TUSB_XFER_BULK ||
(tu_edpt_packet_size(p_ep) <= TUH_EPSIZE_BULK_MAX &&
(dir == TUSB_DIR_OUT || tu_is_power_of_two(tu_edpt_packet_size(p_ep)))));
alt1_ep->desc = *p_ep;

if (ep_addr == alt0_ep->bEndpointAddress) {
Expand Down
Loading
Loading