Skip to content

Commit 5e2a8b4

Browse files
rppicomidiatoktoto
authored andcommitted
Add hooks to allow cloning an attached USB device descriptor
1 parent ceb09a3 commit 5e2a8b4

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/device/usbd_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef struct
5656
static usbd_control_xfer_t _ctrl_xfer;
5757

5858
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN
59-
static uint8_t _usbd_ctrl_buf[CFG_TUD_ENDPOINT0_SIZE];
59+
static uint8_t _usbd_ctrl_buf[/*CFG_TUD_ENDPOINT0_SIZE*/ 64];
6060

6161
//--------------------------------------------------------------------+
6262
// Application API

src/host/usbh.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
13231323
dev->i_product = desc_device->iProduct;
13241324
dev->i_serial = desc_device->iSerialNumber;
13251325

1326-
// if (tuh_attach_cb) tuh_attach_cb((tusb_desc_device_t*) _usbh_ctrl_buf);
1326+
if (tuh_desc_device_cb) tuh_desc_device_cb(daddr, (tusb_desc_device_t const*) _usbh_ctrl_buf);
13271327

13281328
// Get 9-byte for total length
13291329
uint8_t const config_idx = CONFIG_NUM - 1;
@@ -1350,9 +1350,12 @@ static void process_enumeration(tuh_xfer_t* xfer)
13501350
break;
13511351

13521352
case ENUM_SET_CONFIG:
1353+
// Got the whole configuration descriptor. Make a copy
1354+
if (tuh_desc_config_cb) tuh_desc_config_cb(daddr, (const tusb_desc_configuration_t*) _usbh_ctrl_buf);
1355+
13531356
// Parse configuration & set up drivers
13541357
// Driver open aren't allowed to make any usb transfer yet
1355-
TU_ASSERT( _parse_configuration_descriptor(daddr, (tusb_desc_configuration_t*) _usbh_ctrl_buf), );
1358+
TU_ASSERT( _parse_configuration_descriptor(daddr, (const tusb_desc_configuration_t* ) _usbh_ctrl_buf), );
13561359

13571360
TU_ASSERT( tuh_configuration_set(daddr, CONFIG_NUM, process_enumeration, ENUM_CONFIG_DRIVER), );
13581361
break;

src/host/usbh.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ enum
7878
// APPLICATION CALLBACK
7979
//--------------------------------------------------------------------+
8080

81-
//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
81+
// Give the application an opportunity to grab the device descriptor
82+
TU_ATTR_WEAK void tuh_desc_device_cb(uint8_t daddr, const tusb_desc_device_t *desc_device);
83+
84+
// Give the application an opportunity to grab the configuration descriptor
85+
TU_ATTR_WEAK void tuh_desc_config_cb(uint8_t daddr, const tusb_desc_configuration_t *desc_config);
8286

8387
// Invoked when device is mounted (configured)
8488
TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr);

src/tusb_option.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ typedef int make_iso_compilers_happy;
421421
//------------------------------------------------------------------
422422
// Configuration Validation
423423
//------------------------------------------------------------------
424-
#if CFG_TUD_ENDPOINT0_SIZE > 64
425-
#error Control Endpoint Max Packet Size cannot be larger than 64
426-
#endif
424+
//#if CFG_TUD_ENDPOINT0_SIZE > 64
425+
// #error Control Endpoint Max Packet Size cannot be larger than 64
426+
//#endif
427427

428428
#endif /* _TUSB_OPTION_H_ */
429429

0 commit comments

Comments
 (0)