summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-09-09 14:34:03 +0700
committerhathach <[email protected]>2021-09-09 15:17:19 +0700
commitf81368174b613f4168ddb0e2ec1822c8dbc31d59 (patch)
tree7b944408208865293be2221649613c8abee79df3 /src
parentd66d817c38d3da25198dbef90e8e0cd516f4508e (diff)
add other speed descriptor callback tud_descriptor_other_speed_configuration_cb()
example implement tud_descriptor_device_qualifier_cb() and tud_descriptor_other_speed_configuration_cb() on high speed device to fully compliant to usbcv
Diffstat (limited to 'src')
-rw-r--r--src/common/tusb_types.h5
-rw-r--r--src/device/usbd.c40
-rw-r--r--src/device/usbd.h9
3 files changed, 31 insertions, 23 deletions
diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h
index d23c6b2dd..f26983a74 100644
--- a/src/common/tusb_types.h
+++ b/src/common/tusb_types.h
@@ -372,7 +372,7 @@ typedef struct TU_ATTR_PACKED
uint8_t bNumInterfaces ; ///< Number of interfaces supported by this speed configuration
uint8_t bConfigurationValue ; ///< Value to use to select configuration
- uint8_t IConfiguration ; ///< Index of string descriptor
+ uint8_t iConfiguration ; ///< Index of string descriptor
uint8_t bmAttributes ; ///< Same as Configuration descriptor
uint8_t bMaxPower ; ///< Same as Configuration descriptor
} tusb_desc_other_speed_t;
@@ -387,11 +387,14 @@ typedef struct TU_ATTR_PACKED
uint8_t bDeviceClass ; ///< Class Code
uint8_t bDeviceSubClass ; ///< SubClass Code
uint8_t bDeviceProtocol ; ///< Protocol Code
+
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for other speed
uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
uint8_t bReserved ; ///< Reserved for future use, must be zero
} tusb_desc_device_qualifier_t;
+TU_VERIFY_STATIC( sizeof(tusb_desc_device_qualifier_t) == 10, "size is not correct");
+
/// USB Interface Association Descriptor (IAD ECN)
typedef struct TU_ATTR_PACKED
{
diff --git a/src/device/usbd.c b/src/device/usbd.c
index a52ea9afe..58b3a5701 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -1002,10 +1002,22 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
break;
case TUSB_DESC_CONFIGURATION:
+ case TUSB_DESC_OTHER_SPEED_CONFIG:
{
- TU_LOG2(" Configuration[%u]\r\n", desc_index);
+ tusb_desc_configuration_t const* desc_config;
+
+ if ( desc_type == TUSB_DESC_CONFIGURATION )
+ {
+ TU_LOG2(" Configuration[%u]\r\n", desc_index);
+ desc_config = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(desc_index);
+ }else
+ {
+ // Host only request this after getting Device Qualifier descriptor
+ TU_LOG2(" Other Speed Configuration\r\n");
+ TU_VERIFY( tud_descriptor_other_speed_configuration_cb );
+ desc_config = (tusb_desc_configuration_t const*) tud_descriptor_other_speed_configuration_cb(desc_index);
+ }
- tusb_desc_configuration_t const* desc_config = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(desc_index);
TU_ASSERT(desc_config);
// Use offsetof to avoid pointer to the odd/misaligned address
@@ -1031,27 +1043,13 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
case TUSB_DESC_DEVICE_QUALIFIER:
TU_LOG2(" Device Qualifier\r\n");
- // Host sends this request to ask why our device with USB BCD from 2.0
- // but is running at Full/Low Speed. If not highspeed capable stall this request,
- // otherwise return the descriptor that could work in highspeed mode
- if ( tud_descriptor_device_qualifier_cb )
- {
- uint8_t const* desc_qualifier = tud_descriptor_device_qualifier_cb();
- TU_ASSERT(desc_qualifier);
+ TU_VERIFY( tud_descriptor_device_qualifier_cb );
- // first byte of descriptor is its size
- return tud_control_xfer(rhport, p_request, (void*) desc_qualifier, desc_qualifier[0]);
- }else
- {
- return false;
- }
- break;
+ uint8_t const* desc_qualifier = tud_descriptor_device_qualifier_cb();
+ TU_VERIFY(desc_qualifier);
- case TUSB_DESC_OTHER_SPEED_CONFIG:
- TU_LOG2(" Other Speed Configuration\r\n");
-
- // After Device Qualifier descriptor is received host will ask for this descriptor
- return false; // not supported
+ // first byte of descriptor is its size
+ return tud_control_xfer(rhport, p_request, (void*) desc_qualifier, desc_qualifier[0]);
break;
default: return false;
diff --git a/src/device/usbd.h b/src/device/usbd.h
index 9becf2d0d..638d93094 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -113,9 +113,16 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid);
TU_ATTR_WEAK uint8_t const * tud_descriptor_bos_cb(void);
// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
-// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
+// device_qualifier descriptor describes information about a high-speed capable device that would
+// change if the device were operating at the other speed. If not highspeed capable stall this request.
TU_ATTR_WEAK uint8_t const* tud_descriptor_device_qualifier_cb(void);
+// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
+TU_ATTR_WEAK uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index);
+
// Invoked when device is mounted (configured)
TU_ATTR_WEAK void tud_mount_cb(void);