Skip to content

Commit 271f905

Browse files
committed
add tuh_descriptor_string_manufacturer/produce/serial_get
1 parent 15ced09 commit 271f905

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

src/host/usbh.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ typedef struct {
8686
};
8787

8888
//------------- device descriptor -------------//
89+
uint8_t ep0_size;
90+
8991
uint16_t vid;
9092
uint16_t pid;
9193

92-
uint8_t ep0_size;
9394
uint8_t i_manufacturer;
9495
uint8_t i_product;
9596
uint8_t i_serial;
@@ -248,7 +249,6 @@ bool tuh_vid_pid_get(uint8_t dev_addr, uint16_t* vid, uint16_t* pid)
248249
*vid = *pid = 0;
249250

250251
TU_VERIFY(tuh_mounted(dev_addr));
251-
252252
usbh_device_t const* dev = get_device(dev_addr);
253253

254254
*vid = dev->vid;
@@ -308,7 +308,7 @@ bool tuh_descriptor_configuration_get(uint8_t daddr, uint8_t index, void* buffer
308308
}
309309

310310
bool tuh_descriptor_string_get(uint8_t daddr, uint16_t language_id, uint8_t index,
311-
void* buf, uint16_t len, tuh_control_complete_cb_t complete_cb)
311+
void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb)
312312
{
313313
tusb_control_request_t const request =
314314
{
@@ -324,29 +324,32 @@ bool tuh_descriptor_string_get(uint8_t daddr, uint16_t language_id, uint8_t inde
324324
.wLength = tu_htole16(len)
325325
};
326326

327-
TU_ASSERT( tuh_control_xfer(daddr, &request, buf, complete_cb) );
327+
TU_ASSERT( tuh_control_xfer(daddr, &request, buffer, complete_cb) );
328328
return true;
329329
}
330330

331-
uint8_t tuh_i_manufacturer_get(uint8_t dev_addr) {
332-
TU_VERIFY(tuh_mounted(dev_addr));
333-
usbh_device_t const* dev = get_device(dev_addr);
334-
335-
return dev->i_manufacturer;
331+
// Get manufacturer string descriptor
332+
bool tuh_descriptor_string_manufacturer_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb)
333+
{
334+
TU_VERIFY(tuh_mounted(daddr));
335+
usbh_device_t const* dev = get_device(daddr);
336+
return tuh_descriptor_string_get(daddr, language_id, dev->i_manufacturer, buffer, len, complete_cb);
336337
}
337338

338-
uint8_t tuh_i_serial_get(uint8_t dev_addr) {
339-
TU_VERIFY(tuh_mounted(dev_addr));
340-
usbh_device_t const* dev = get_device(dev_addr);
341-
342-
return dev->i_serial;
339+
// Get product string descriptor
340+
bool tuh_descriptor_string_product_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb)
341+
{
342+
TU_VERIFY(tuh_mounted(daddr));
343+
usbh_device_t const* dev = get_device(daddr);
344+
return tuh_descriptor_string_get(daddr, language_id, dev->i_product, buffer, len, complete_cb);
343345
}
344346

345-
uint8_t tuh_i_product_get(uint8_t dev_addr) {
346-
TU_VERIFY(tuh_mounted(dev_addr));
347-
usbh_device_t const* dev = get_device(dev_addr);
348-
349-
return dev->i_product;
347+
// Get serial string descriptor
348+
bool tuh_descriptor_string_serial_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb)
349+
{
350+
TU_VERIFY(tuh_mounted(daddr));
351+
usbh_device_t const* dev = get_device(daddr);
352+
return tuh_descriptor_string_get(daddr, language_id, dev->i_serial, buffer, len, complete_cb);
350353
}
351354

352355
bool tuh_configuration_set(uint8_t daddr, uint8_t config_num, tuh_control_complete_cb_t complete_cb)
@@ -957,9 +960,9 @@ static bool enum_get_device_desc_complete(uint8_t dev_addr, tusb_control_request
957960

958961
dev->vid = desc_device->idVendor;
959962
dev->pid = desc_device->idProduct;
960-
dev->i_manufacturer = desc_device->iManufacturer;
961-
dev->i_product = desc_device->iProduct;
962-
dev->i_serial = desc_device->iSerialNumber;
963+
// dev->i_manufacturer = desc_device->iManufacturer;
964+
// dev->i_product = desc_device->iProduct;
965+
// dev->i_serial = desc_device->iSerialNumber;
963966

964967
// if (tuh_attach_cb) tuh_attach_cb((tusb_desc_device_t*) _usbh_ctrl_buf);
965968

src/host/usbh.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ bool tuh_descriptor_device_get(uint8_t daddr, void* buffer, uint16_t len, tuh_co
101101
bool tuh_descriptor_configuration_get(uint8_t daddr, uint8_t index, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
102102

103103
// Get string descriptor
104-
// Reads the string descriptor at the string index into the buffer. This is the
105-
// full response so the first entry is the length and the constant 0x03 for
106-
// string descriptor type.
107104
bool tuh_descriptor_string_get(uint8_t daddr, uint16_t language_id, uint8_t index,
108-
void* buf, uint16_t len, tuh_control_complete_cb_t complete_cb);
105+
void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
109106

107+
// Get manufacturer string descriptor
108+
bool tuh_descriptor_string_manufacturer_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
110109

111-
// Gets the string indices for common device descriptor data.
112-
uint8_t tuh_i_manufacturer_get(uint8_t daddr);
113-
uint8_t tuh_i_serial_get(uint8_t daddr);
114-
uint8_t tuh_i_product_get(uint8_t daddr);
110+
// Get product string descriptor
111+
bool tuh_descriptor_string_product_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
112+
113+
// Get serial string descriptor
114+
bool tuh_descriptor_string_serial_get(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, tuh_control_complete_cb_t complete_cb);
115115

116116
//--------------------------------------------------------------------+
117117
// APPLICATION CALLBACK

0 commit comments

Comments
 (0)