Skip to content

Commit 60e6d53

Browse files
authored
Merge pull request #3061 from hathach/update-endpoint-open
fix(hcd) hcd_edpt_open() return true if endpoint is already opened.
2 parents 8c1802e + 4787cd5 commit 60e6d53

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

examples/host/device_info/src/main.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,18 @@ void tuh_mount_cb(uint8_t daddr) {
124124
}
125125

126126
printf("Device %u: ID %04x:%04x SN ", daddr, desc.device.idVendor, desc.device.idProduct);
127-
xfer_result = tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, desc.serial, sizeof(desc.serial));
127+
128+
xfer_result = XFER_RESULT_FAILED;
129+
if (desc.device.iSerialNumber != 0) {
130+
xfer_result = tuh_descriptor_get_serial_string_sync(daddr, LANGUAGE_ID, desc.serial, sizeof(desc.serial));
131+
}
128132
if (XFER_RESULT_SUCCESS != xfer_result) {
129133
uint16_t* serial = (uint16_t*)(uintptr_t) desc.serial;
130-
serial[0] = 'n';
131-
serial[1] = '/';
132-
serial[2] = 'a';
133-
serial[3] = 0;
134+
serial[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * 3 + 2));
135+
serial[1] = 'n';
136+
serial[2] = '/';
137+
serial[3] = 'a';
138+
serial[4] = 0;
134139
}
135140
print_utf16((uint16_t*)(uintptr_t) desc.serial, sizeof(desc.serial)/2);
136141
printf("\r\n");
@@ -150,16 +155,20 @@ void tuh_mount_cb(uint8_t daddr) {
150155
// Get String descriptor using Sync API
151156

152157
printf(" iManufacturer %u ", desc.device.iManufacturer);
153-
xfer_result = tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, desc.buf, sizeof(desc.buf));
154-
if (XFER_RESULT_SUCCESS == xfer_result) {
155-
print_utf16((uint16_t*)(uintptr_t) desc.buf, sizeof(desc.buf)/2);
158+
if (desc.device.iManufacturer != 0) {
159+
xfer_result = tuh_descriptor_get_manufacturer_string_sync(daddr, LANGUAGE_ID, desc.buf, sizeof(desc.buf));
160+
if (XFER_RESULT_SUCCESS == xfer_result) {
161+
print_utf16((uint16_t*)(uintptr_t) desc.buf, sizeof(desc.buf)/2);
162+
}
156163
}
157164
printf("\r\n");
158165

159166
printf(" iProduct %u ", desc.device.iProduct);
160-
xfer_result = tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, desc.buf, sizeof(desc.buf));
161-
if (XFER_RESULT_SUCCESS == xfer_result) {
162-
print_utf16((uint16_t*)(uintptr_t) desc.buf, sizeof(desc.buf)/2);
167+
if (desc.device.iProduct != 0) {
168+
xfer_result = tuh_descriptor_get_product_string_sync(daddr, LANGUAGE_ID, desc.buf, sizeof(desc.buf));
169+
if (XFER_RESULT_SUCCESS == xfer_result) {
170+
print_utf16((uint16_t*)(uintptr_t) desc.buf, sizeof(desc.buf)/2);
171+
}
163172
}
164173
printf("\r\n");
165174

src/host/hcd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
163163
//--------------------------------------------------------------------+
164164

165165
// Open an endpoint
166+
// return true if successfully opened or endpoint is currently opened
166167
bool hcd_edpt_open(uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const * ep_desc);
167168

168169
// Close an endpoint

src/portable/analog/max3421/hcd_max3421.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const * e
611611
ep = &_hcd_data.ep[0];
612612
}else {
613613
if (NULL != find_ep_not_addr0(daddr, ep_num, ep_dir)) {
614-
return false; // endpoint already opened
614+
return true; // already opened
615615
}
616616
ep = allocate_ep();
617617
TU_ASSERT(ep);

src/portable/ehci/ehci.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
381381
if (ep_desc->bEndpointAddress == 0) {
382382
p_qhd = qhd_control(dev_addr);
383383
} else {
384-
TU_VERIFY(NULL == qhd_get_from_addr(dev_addr, ep_desc->bEndpointAddress)); // ep not opened yet
384+
if (NULL != qhd_get_from_addr(dev_addr, ep_desc->bEndpointAddress)) {
385+
return true; // already opened
386+
}
385387
p_qhd = qhd_find_free();
386388
}
387389
TU_ASSERT(p_qhd);

0 commit comments

Comments
 (0)