summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrppicomidi <[email protected]>2022-08-25 15:08:00 -0700
committeratoktoto <[email protected]>2022-11-13 14:29:16 +0100
commit70eefcb849542f386a1349da7a4944d2d02dcd40 (patch)
tree7c317a2c78f79b98fb57deeb51b99f8bd14b4aea
parent2ddd74fada9b2f272923fce9c3b1926a6e9f5c80 (diff)
Add hooks to allow cloning an attached USB device descriptor
-rw-r--r--src/device/usbd_control.c2
-rw-r--r--src/host/usbh.c7
-rw-r--r--src/host/usbh.h6
-rw-r--r--src/tusb_option.h6
4 files changed, 14 insertions, 7 deletions
diff --git a/src/device/usbd_control.c b/src/device/usbd_control.c
index 0995ef669..187547ae3 100644
--- a/src/device/usbd_control.c
+++ b/src/device/usbd_control.c
@@ -56,7 +56,7 @@ typedef struct
static usbd_control_xfer_t _ctrl_xfer;
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN
-static uint8_t _usbd_ctrl_buf[CFG_TUD_ENDPOINT0_SIZE];
+static uint8_t _usbd_ctrl_buf[/*CFG_TUD_ENDPOINT0_SIZE*/ 64];
//--------------------------------------------------------------------+
// Application API
diff --git a/src/host/usbh.c b/src/host/usbh.c
index c59f31596..44b4d3217 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -1323,7 +1323,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
dev->i_product = desc_device->iProduct;
dev->i_serial = desc_device->iSerialNumber;
- // if (tuh_attach_cb) tuh_attach_cb((tusb_desc_device_t*) _usbh_ctrl_buf);
+ if (tuh_desc_device_cb) tuh_desc_device_cb(daddr, (tusb_desc_device_t const*) _usbh_ctrl_buf);
// Get 9-byte for total length
uint8_t const config_idx = CONFIG_NUM - 1;
@@ -1350,9 +1350,12 @@ static void process_enumeration(tuh_xfer_t* xfer)
break;
case ENUM_SET_CONFIG:
+ // Got the whole configuration descriptor. Make a copy
+ if (tuh_desc_config_cb) tuh_desc_config_cb(daddr, (const tusb_desc_configuration_t*) _usbh_ctrl_buf);
+
// Parse configuration & set up drivers
// Driver open aren't allowed to make any usb transfer yet
- TU_ASSERT( _parse_configuration_descriptor(daddr, (tusb_desc_configuration_t*) _usbh_ctrl_buf), );
+ TU_ASSERT( _parse_configuration_descriptor(daddr, (const tusb_desc_configuration_t* ) _usbh_ctrl_buf), );
TU_ASSERT( tuh_configuration_set(daddr, CONFIG_NUM, process_enumeration, ENUM_CONFIG_DRIVER), );
break;
diff --git a/src/host/usbh.h b/src/host/usbh.h
index 560a1ea23..7355c83ee 100644
--- a/src/host/usbh.h
+++ b/src/host/usbh.h
@@ -78,7 +78,11 @@ enum
// APPLICATION CALLBACK
//--------------------------------------------------------------------+
-//TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device);
+// Give the application an opportunity to grab the device descriptor
+TU_ATTR_WEAK void tuh_desc_device_cb(uint8_t daddr, const tusb_desc_device_t *desc_device);
+
+// Give the application an opportunity to grab the configuration descriptor
+TU_ATTR_WEAK void tuh_desc_config_cb(uint8_t daddr, const tusb_desc_configuration_t *desc_config);
// Invoked when device is mounted (configured)
TU_ATTR_WEAK void tuh_mount_cb (uint8_t daddr);
diff --git a/src/tusb_option.h b/src/tusb_option.h
index f95ae6273..b905fc7ce 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -427,9 +427,9 @@ typedef int make_iso_compilers_happy;
//------------------------------------------------------------------
// Configuration Validation
//------------------------------------------------------------------
-#if CFG_TUD_ENDPOINT0_SIZE > 64
- #error Control Endpoint Max Packet Size cannot be larger than 64
-#endif
+//#if CFG_TUD_ENDPOINT0_SIZE > 64
+// #error Control Endpoint Max Packet Size cannot be larger than 64
+//#endif
#endif /* _TUSB_OPTION_H_ */