Skip to content

Commit 2bdf4d8

Browse files
committed
add tuh_descriptor_configuration_get()
1 parent 7480c2e commit 2bdf4d8

File tree

2 files changed

+13
-35
lines changed

2 files changed

+13
-35
lines changed

src/host/usbh.c

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ bool tuh_descriptor_device_get(uint8_t daddr, void* buffer, uint16_t len, tuh_co
285285
return tuh_descriptor_get(daddr, TUSB_DESC_DEVICE, 0, buffer, len, complete_cb);
286286
}
287287

288+
bool tuh_descriptor_configuration_get(uint8_t daddr, uint8_t index, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb)
289+
{
290+
return tuh_descriptor_get(daddr, TUSB_DESC_CONFIGURATION, index, buffer, len, complete_cb);
291+
}
292+
288293
uint8_t tuh_i_manufacturer_get(uint8_t dev_addr) {
289294
TU_VERIFY(tuh_mounted(dev_addr));
290295
usbh_device_t const* dev = get_device(dev_addr);
@@ -948,23 +953,9 @@ static bool enum_get_device_desc_complete(uint8_t dev_addr, tusb_control_request
948953

949954
// if (tuh_attach_cb) tuh_attach_cb((tusb_desc_device_t*) _usbh_ctrl_buf);
950955

951-
TU_LOG2("Get 9 bytes of Configuration Descriptor\r\n");
952-
tusb_control_request_t const new_request =
953-
{
954-
.bmRequestType_bit =
955-
{
956-
.recipient = TUSB_REQ_RCPT_DEVICE,
957-
.type = TUSB_REQ_TYPE_STANDARD,
958-
.direction = TUSB_DIR_IN
959-
},
960-
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
961-
.wValue = (TUSB_DESC_CONFIGURATION << 8) | (CONFIG_NUM - 1),
962-
.wIndex = 0,
963-
.wLength = 9
964-
};
965-
966-
TU_ASSERT( tuh_control_xfer(dev_addr, &new_request, _usbh_ctrl_buf, enum_get_9byte_config_desc_complete) );
967-
956+
// Get 9-byte for total length
957+
TU_LOG2("Get Configuration[0] Descriptor (9 bytes)\r\n");
958+
TU_ASSERT( tuh_descriptor_configuration_get(dev_addr, 0, _usbh_ctrl_buf, 9, enum_get_9byte_config_desc_complete) );
968959
return true;
969960
}
970961

@@ -982,24 +973,8 @@ static bool enum_get_9byte_config_desc_complete(uint8_t dev_addr, tusb_control_r
982973
TU_ASSERT(total_len <= CFG_TUH_ENUMERATION_BUFSIZE);
983974

984975
// Get full configuration descriptor
985-
TU_LOG2("Get Configuration Descriptor\r\n");
986-
tusb_control_request_t const new_request =
987-
{
988-
.bmRequestType_bit =
989-
{
990-
.recipient = TUSB_REQ_RCPT_DEVICE,
991-
.type = TUSB_REQ_TYPE_STANDARD,
992-
.direction = TUSB_DIR_IN
993-
},
994-
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
995-
.wValue = (TUSB_DESC_CONFIGURATION << 8) | (CONFIG_NUM - 1),
996-
.wIndex = 0,
997-
.wLength = total_len
998-
999-
};
1000-
1001-
TU_ASSERT( tuh_control_xfer(dev_addr, &new_request, _usbh_ctrl_buf, enum_get_config_desc_complete) );
1002-
976+
TU_LOG2("Get Configuration[0] Descriptor\r\n");
977+
TU_ASSERT( tuh_descriptor_configuration_get(dev_addr, 0, _usbh_ctrl_buf, total_len, enum_get_config_desc_complete) );
1003978
return true;
1004979
}
1005980

src/host/usbh.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ bool tuh_descriptor_get(uint8_t daddr, uint8_t type, uint8_t index,
6767
// Get device descriptor
6868
bool tuh_descriptor_device_get(uint8_t daddr, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
6969

70+
// Get configuration descriptor
71+
bool tuh_descriptor_configuration_get(uint8_t daddr, uint8_t index, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
72+
7073
bool tuh_vid_pid_get(uint8_t daddr, uint16_t* vid, uint16_t* pid);
7174

7275
// Gets the string indices for common device descriptor data.

0 commit comments

Comments
 (0)