Skip to content

Commit b765656

Browse files
hathachclaude
andcommitted
fix hid_generic_inout for TUD_ENDPOINT_ONE_DIRECTION_ONLY MCUs
Use separate endpoint numbers (EP1 OUT, EP2 IN) on MCUs with shared FIFO that cannot support the same endpoint number in both directions. Also add missing static qualifier to print_musb_info(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6c895e7 commit b765656

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

examples/device/hid_generic_inout/src/usb_descriptors.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,23 @@ enum
9797

9898
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
9999

100-
#define EPNUM_HID 0x01
100+
#if defined(TUD_ENDPOINT_ONE_DIRECTION_ONLY)
101+
// MCUs that don't support a same endpoint number with different direction IN and OUT defined in tusb_mcu.h
102+
// e.g EP1 OUT & EP1 IN cannot exist together
103+
#define EPNUM_HID_OUT 0x01
104+
#define EPNUM_HID_IN 0x82
105+
#else
106+
#define EPNUM_HID_OUT 0x01
107+
#define EPNUM_HID_IN 0x81
108+
#endif
101109

102110
uint8_t const desc_configuration[] =
103111
{
104112
// Config number, interface count, string index, total length, attribute, power in mA
105113
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
106114

107115
// Interface number, string index, protocol, report descriptor len, EP Out & In address, size & polling interval
108-
TUD_HID_INOUT_DESCRIPTOR(ITF_NUM_HID, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, 0x80 | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10)
116+
TUD_HID_INOUT_DESCRIPTOR(ITF_NUM_HID, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID_OUT, EPNUM_HID_IN, CFG_TUD_HID_EP_BUFSIZE, 10)
109117
};
110118

111119
// Invoked when received GET CONFIGURATION DESCRIPTOR

src/portable/mentor/musb/dcd_musb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static void process_bus_reset(uint8_t rhport) {
494494
*------------------------------------------------------------------*/
495495

496496
#if CFG_TUSB_DEBUG >= MUSB_DEBUG
497-
void print_musb_info(musb_regs_t* musb_regs) {
497+
static void print_musb_info(musb_regs_t* musb_regs) {
498498
// print version, epinfo, raminfo, config_data0, fifo_size
499499
TU_LOG1("musb version = %u.%u\r\n", musb_regs->hwvers_bit.major, musb_regs->hwvers_bit.minor);
500500
TU_LOG1("Number of endpoints: %u TX, %u RX\r\n", musb_regs->epinfo_bit.tx_ep_num, musb_regs->epinfo_bit.rx_ep_num);

0 commit comments

Comments
 (0)