Przeglądaj źródła

added tud_descriptor_bos_cb(), add support for BOS get descriptor

hathach 6 lat temu
rodzic
commit
e74aa41552
3 zmienionych plików z 29 dodań i 1 usunięć
  1. 8 0
      src/common/tusb_types.h
  2. 17 1
      src/device/usbd.c
  3. 4 0
      src/device/usbd.h

+ 8 - 0
src/common/tusb_types.h

@@ -253,6 +253,14 @@ typedef struct TU_ATTR_PACKED
   uint8_t  bNumConfigurations ; ///< Number of possible configurations.
 } tusb_desc_device_t;
 
+typedef struct TU_ATTR_PACKED
+{
+  uint8_t  bLength         ; ///< Size of this descriptor in bytes
+  uint8_t  bDescriptorType ; ///< CONFIGURATION Descriptor Type
+  uint16_t wTotalLength    ; ///< Total length of data returned for this descriptor
+  uint8_t  bNumDeviceCaps  ; ///< Number of device capability descriptors in the BOS
+} tusb_desc_bos_t;
+
 /// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */
 typedef struct TU_ATTR_PACKED
 {

+ 17 - 1
src/device/usbd.c

@@ -566,10 +566,26 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
       return usbd_control_xfer(rhport, p_request, (void*) tud_descriptor_device_cb(), sizeof(tusb_desc_device_t));
     break;
 
+    case TUSB_DESC_BOS:
+    {
+      // requested by host if USB > 2.0 ( i.e 2.1 or 3.x )
+      if (!tud_descriptor_bos_cb) return false;
+
+      tusb_desc_bos_t const* desc_bos = (tusb_desc_bos_t const*) tud_descriptor_bos_cb();
+      uint16_t total_len;
+      memcpy(&total_len, &desc_bos->wTotalLength, 2); // possibly mis-aligned memory
+
+      return usbd_control_xfer(rhport, p_request, (void*) desc_bos, total_len);
+    }
+    break;
+
     case TUSB_DESC_CONFIGURATION:
     {
       tusb_desc_configuration_t const* desc_config = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(desc_index);
-      return usbd_control_xfer(rhport, p_request, (void*) desc_config, desc_config->wTotalLength);
+      uint16_t total_len;
+      memcpy(&total_len, &desc_config->wTotalLength, 2); // possibly mis-aligned memory
+
+      return usbd_control_xfer(rhport, p_request, (void*) desc_config, total_len);
     }
     break;
 

+ 4 - 0
src/device/usbd.h

@@ -67,6 +67,10 @@ bool tud_remote_wakeup(void);
 // Application return pointer to descriptor
 uint8_t const * tud_descriptor_device_cb(void);
 
+// Invoked when received GET BOS DESCRIPTOR request
+// Application return pointer to descriptor
+TU_ATTR_WEAK uint8_t const * tud_descriptor_bos_cb(void);
+
 // Invoked when received GET CONFIGURATION DESCRIPTOR request
 // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
 uint8_t const * tud_descriptor_configuration_cb(uint8_t index);