open hub mtt interface in 1 call

This commit is contained in:
hathach
2026-03-07 15:25:05 +07:00
parent 5817f0d2eb
commit f17da1c66e
3 changed files with 34 additions and 19 deletions

1
.idea/cmake.xml generated
View File

@ -96,6 +96,7 @@
<configuration PROFILE_NAME="itsybitsy_m4" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=itsybitsy_m4" />
<configuration PROFILE_NAME="same54_xplained" ENABLED="false" GENERATION_OPTIONS="-DBOARD=same54_xplained -DLOG=1 -DLOGGER=RTT" />
<configuration PROFILE_NAME="samg55_xplained" ENABLED="false" GENERATION_OPTIONS="-DBOARD=samg55_xplained" />
<configuration PROFILE_NAME="same70_xplained" ENABLED="false" GENERATION_OPTIONS="-DBOARD=same70_xplained -DLOG=1" />
<configuration PROFILE_NAME="feather_nrf52840_express" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=feather_nrf52840_express -DLOG=1 -DLOGGER=RTT -DMAX3421_HOST=1" />
<configuration PROFILE_NAME="nrf52840dk" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=nrf52840dk -DLOG=1 -DLOGGER=RTT -DTRACE_ETM=1" />
<configuration PROFILE_NAME="nrf52840dk-zephyr" ENABLED="false" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DBOARD=nrf52840dk -DLOG=1 -DTRACE_ETM=1 -DRTOS=zephyr" BUILD_OPTIONS="-v" />

View File

@ -218,31 +218,37 @@ bool hub_deinit(void) {
return true;
}
uint16_t hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len) {
(void) rhport;
uint16_t hub_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_interface_t *itf_desc, uint16_t max_len) {
(void)rhport;
TU_VERIFY(TUSB_CLASS_HUB == itf_desc->bInterfaceClass && 0 == itf_desc->bInterfaceSubClass, 0);
TU_VERIFY(TUSB_CLASS_HUB == itf_desc->bInterfaceClass &&
0 == itf_desc->bInterfaceSubClass, 0);
uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_desc_endpoint_t);
const uint16_t itf_ep_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_desc_endpoint_t);
uint16_t drv_len = itf_ep_len;
TU_ASSERT(drv_len <= max_len, 0);
hub_interface_t *p_hub = get_hub_itf(dev_addr);
const tusb_desc_interface_t *desc_itf_use = itf_desc; // interface to use for endpoint open
// Check device descriptor for MTT hub (bDeviceProtocol == 2)
// MTT hub has 2 alt settings: alt 0 is STT (protocol 1), alt 1 is MTT (protocol 2)
// Consume both alt settings and use alt setting 1 for endpoint
tusb_desc_device_t desc_dev;
TU_ASSERT(tuh_descriptor_get_device_local(dev_addr, &desc_dev));
// Skip STT interface of MTT hub
if (desc_dev.bDeviceProtocol == 2 && itf_desc->bInterfaceProtocol == 1) {
hub_interface_t* p_hub = get_hub_itf(dev_addr);
p_hub->mtt = true;
return drv_len;
if (tuh_descriptor_get_device_local(dev_addr, &desc_dev) && desc_dev.bDeviceProtocol == HUB_PROTOCOL_HIGH_SPEED_MTT) {
drv_len += itf_ep_len;
TU_ASSERT(drv_len <= max_len, 0);
const tusb_desc_interface_t *desc_alt1 = (const tusb_desc_interface_t *)((const uint8_t *)itf_desc + itf_ep_len);
TU_ASSERT(desc_alt1->bDescriptorType == TUSB_DESC_INTERFACE && desc_alt1->bInterfaceClass == TUSB_CLASS_HUB &&
desc_alt1->bInterfaceProtocol == HUB_PROTOCOL_HIGH_SPEED_MTT,
0);
p_hub->mtt = true;
desc_itf_use = desc_alt1;
}
// Interrupt Status endpoint
tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType &&
TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
const tusb_desc_endpoint_t *desc_ep = (const tusb_desc_endpoint_t *)tu_desc_next(desc_itf_use);
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
TU_ASSERT(tuh_edpt_open(dev_addr, desc_ep), 0);
hub_interface_t* p_hub = get_hub_itf(dev_addr);
p_hub->itf_num = itf_desc->bInterfaceNumber;
p_hub->ep_in = desc_ep->bEndpointAddress;
@ -288,8 +294,9 @@ bool hub_set_config(uint8_t daddr, uint8_t itf_num) {
TU_ASSERT(tuh_interface_set(daddr, itf_num, 1, config_get_hub_descriptor, 0));
} else {
tuh_xfer_t xfer;
xfer.daddr = daddr;
xfer.ep_addr = 0;
xfer.daddr = daddr;
xfer.ep_addr = 0;
xfer.user_data = 0;
config_get_hub_descriptor(&xfer);
}
@ -324,7 +331,7 @@ static void config_set_port_power (tuh_xfer_t* xfer) {
hub_interface_t* p_hub = get_hub_itf(daddr);
hub_epbuf_t* p_epbuf = get_hub_epbuf(daddr);
// only use number of ports in hub descriptor
// only use the number of ports in the hub descriptor
hub_desc_cs_t const* desc_hub = (hub_desc_cs_t const*) p_epbuf->ctrl_buf;
p_hub->bNbrPorts = desc_hub->bNbrPorts;
p_hub->bPwrOn2PwrGood_2ms = desc_hub->bPwrOn2PwrGood;

View File

@ -92,6 +92,13 @@ enum {
HUB_CHARS_OVER_CURRENT_INDIVIDUAL = 1,
};
// Hub Interface Protocol (USB 2.0 spec Table 11-16)
typedef enum {
HUB_PROTOCOL_FULL_SPEED = 0, // Full speed hub
HUB_PROTOCOL_HIGH_SPEED_STT = 1, // Hi-speed hub with single TT
HUB_PROTOCOL_HIGH_SPEED_MTT = 2, // Hi-speed hub with multiple TTs
} hub_protocol_t;
typedef struct TU_ATTR_PACKED{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type