Skip to content

Commit 16daad8

Browse files
authored
Merge pull request hathach#1960 from hathach/fix-host-enumerate-mul-device
Fix host enumerate multiple devices from multiple host controllers
2 parents 96d064e + 511f5be commit 16daad8

File tree

14 files changed

+72
-53
lines changed

14 files changed

+72
-53
lines changed

examples/host/bare_api/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ target_include_directories(${PROJECT} PUBLIC
2525
# Configure compilation flags and libraries for the example... see the corresponding function
2626
# in hw/bsp/FAMILY/family.cmake for details.
2727
family_configure_host_example(${PROJECT})
28+
29+
# Add pico-pio-usb for rp2040 since user can choose to run on bit-banging host
30+
if(FAMILY STREQUAL "rp2040")
31+
family_add_pico_pio_usb(${PROJECT})
32+
endif()

examples/host/bare_api/src/tusb_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -100,7 +100,7 @@
100100

101101
// max device support (excluding hub device)
102102
// 1 hub typically has 4 ports
103-
#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1)
103+
#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
104104

105105
// Max endpoint per device
106106
#define CFG_TUH_ENDPOINT_MAX 8

examples/host/cdc_msc_hid/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ target_include_directories(${PROJECT} PUBLIC
2828
# Configure compilation flags and libraries for the example... see the corresponding function
2929
# in hw/bsp/FAMILY/family.cmake for details.
3030
family_configure_host_example(${PROJECT})
31+
32+
# Add pico-pio-usb for rp2040 since user can choose to run on bit-banging host
33+
if(FAMILY STREQUAL "rp2040")
34+
family_add_pico_pio_usb(${PROJECT})
35+
endif()

examples/host/cdc_msc_hid/src/tusb_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -101,8 +101,8 @@
101101
#define CFG_TUH_MSC 1
102102
#define CFG_TUH_VENDOR 0
103103

104-
// max device support (excluding hub device)
105-
#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1) // hub typically has 4 ports
104+
// max device support (excluding hub device): 1 hub typically has 4 ports
105+
#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
106106

107107
//------------- HID -------------//
108108
#define CFG_TUH_HID_EPIN_BUFSIZE 64

examples/host/hid_controller/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ target_include_directories(${PROJECT} PUBLIC
2626
# Configure compilation flags and libraries for the example... see the corresponding function
2727
# in hw/bsp/FAMILY/family.cmake for details.
2828
family_configure_host_example(${PROJECT})
29+
30+
# Add pico-pio-usb for rp2040 since user can choose to run on bit-banging host
31+
if(FAMILY STREQUAL "rp2040")
32+
family_add_pico_pio_usb(${PROJECT})
33+
endif()

examples/host/hid_controller/src/tusb_config.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -101,9 +101,8 @@
101101
#define CFG_TUH_MSC 0
102102
#define CFG_TUH_VENDOR 0
103103

104-
// max device support (excluding hub device)
105-
// 1 hub typically has 4 ports
106-
#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1)
104+
// max device support (excluding hub device): 1 hub typically has 4 ports
105+
#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
107106

108107
//------------- HID -------------//
109108

examples/host/msc_file_explorer/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ target_include_directories(${PROJECT} PUBLIC
3232
# in hw/bsp/FAMILY/family.cmake for details.
3333
family_configure_host_example(${PROJECT})
3434

35+
# Add pico-pio-usb for rp2040 since user can choose to run on bit-banging host
36+
if(FAMILY STREQUAL "rp2040")
37+
family_add_pico_pio_usb(${PROJECT})
38+
endif()

examples/host/msc_file_explorer/src/tusb_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -101,8 +101,8 @@
101101
#define CFG_TUH_HID 0 // typical keyboard + mouse device can have 3-4 HID interfaces
102102
#define CFG_TUH_VENDOR 0
103103

104-
// max device support (excluding hub device)
105-
#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1) // hub typically has 4 ports
104+
// max device support (excluding hub device): 1 hub typically has 4 ports
105+
#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)
106106

107107
//------------- MSC -------------//
108108
#define CFG_TUH_MSC_MAXLUN 4 // typical for most card reader

hw/bsp/rp2040/family.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ $(BUILD):
1313
all: $(BUILD)
1414
$(MAKE) -C $(BUILD)
1515

16-
clean:
17-
$(RM) -rf $(BUILD)
18-
1916
flash: flash-pyocd
2017
flash-uf2:
2118
@$(CP) $(BUILD)/$(PROJECT).uf2 /media/$(USER)/RPI-RP2

src/class/cdc/cdc_host.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -97,7 +97,7 @@ static inline uint8_t get_idx_by_ep_addr(uint8_t daddr, uint8_t ep_addr)
9797
}
9898
}
9999

100-
return TUSB_INDEX_INVALID;
100+
return TU_INDEX_INVALID_8;
101101
}
102102

103103

@@ -124,7 +124,7 @@ uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num)
124124
if (p_cdc->daddr == daddr && p_cdc->bInterfaceNumber == itf_num) return i;
125125
}
126126

127-
return TUSB_INDEX_INVALID;
127+
return TU_INDEX_INVALID_8;
128128
}
129129

130130
bool tuh_cdc_itf_get_info(uint8_t idx, tuh_cdc_itf_info_t* info)
@@ -533,7 +533,7 @@ static void process_cdc_config(tuh_xfer_t* xfer)
533533
uintptr_t const state = xfer->user_data;
534534
uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
535535
uint8_t const idx = tuh_cdc_itf_get_index(xfer->daddr, itf_num);
536-
TU_ASSERT(idx != TUSB_INDEX_INVALID, );
536+
TU_ASSERT(idx != TU_INDEX_INVALID_8, );
537537

538538
switch(state)
539539
{

0 commit comments

Comments
 (0)