From anonymous, 5 Years ago, written in C.
This paste is a reply to TI USB from The Compiler
- view diff
Embed
  1. //*****************************************************************************
  2. //
  3. // HID device configuration descriptor.
  4. //
  5. // It is vital that the configuration descriptor bConfigurationValue field
  6. // (byte 6) is 1 for the first configuration and increments by 1 for each
  7. // additional configuration defined here.  This relationship is assumed in the
  8. // device stack for simplicity even though the USB 2.0 specification imposes
  9. // no such restriction on the bConfigurationValue values.
  10. //
  11. // Note that this structure is deliberately located in RAM since we need to
  12. // be able to patch some values in it based on client requirements.
  13. //
  14. //*****************************************************************************
  15. uint8_t g_pui8MouseDescriptor[] =
  16. {
  17.     //
  18.     // Configuration descriptor header.
  19.     //
  20.     9,                          // Size of the configuration descriptor.
  21.     USB_DTYPE_CONFIGURATION,    // Type of this descriptor.
  22.     USBShort(34),               // The total size of this full structure.
  23.     1,                          // The number of interfaces in this
  24.                                 // configuration.
  25.     1,                          // The unique value for this configuration.
  26.     5,                          // The string identifier that describes this
  27.                                 // configuration.
  28.     USB_CONF_ATTR_BUS_PWR,     // Bus Powered, Self Powered, remote wake up.
  29.     250,                        // The maximum power in 2mA increments.
  30. };
  31.  
  32. //*****************************************************************************
  33. //
  34. // The remainder of the configuration descriptor is stored in flash since we
  35. // don't need to modify anything in it at runtime.
  36. //
  37. //*****************************************************************************
  38. uint8_t g_pui8HIDInterface[HIDINTERFACE_SIZE] =
  39. {
  40.     //
  41.     // HID Device Class Interface Descriptor.
  42.     //
  43.     9,                          // Size of the interface descriptor.
  44.     USB_DTYPE_INTERFACE,        // Type of this descriptor.
  45.     0,                          // The index for this interface.
  46.     0,                          // The alternate setting for this interface.
  47.     1,                          // The number of endpoints used by this
  48.                                 // interface.
  49.     USB_CLASS_HID,              // The interface class
  50.     USB_HID_SCLASS_BOOT,        // The interface sub-class.
  51.     USB_HID_PROTOCOL_MOUSE,     // The interface protocol for the sub-class
  52.                                 // specified above.
  53.     4,                          // The string index for this interface.
  54. };
  55.  
  56. const uint8_t g_pui8HIDInEndpoint[HIDINENDPOINT_SIZE] =
  57. {
  58.     //
  59.     // Interrupt IN endpoint descriptor
  60.     //
  61.     7,                          // The size of the endpoint descriptor.
  62.     USB_DTYPE_ENDPOINT,         // Descriptor type is an endpoint.
  63.     USB_EP_DESC_IN | USBEPToIndex(USB_EP_1),
  64.     USB_EP_ATTR_INT,            // Endpoint is an interrupt endpoint.
  65.     USBShort(USBFIFOSizeToBytes(USB_FIFO_SZ_64)),
  66.                                 // The maximum packet size.
  67.     16,                         // The polling interval for this endpoint.
  68. };
  69.  
  70.  
  71. //*****************************************************************************
  72. //
  73. // The HID configuration descriptor is defined as four or five sections
  74. // depending upon the client's configuration choice.  These sections are:
  75. //
  76. // 1.  The 9 byte configuration descriptor (RAM).
  77. // 2.  The interface descriptor (RAM).
  78. // 3.  The HID report and physical descriptors (provided by the client)
  79. //     (FLASH).
  80. // 4.  The mandatory interrupt IN endpoint descriptor (FLASH).
  81. // 5.  The optional interrupt OUT endpoint descriptor (FLASH).
  82. //
  83. //*****************************************************************************
  84. const tConfigSection g_sHIDConfigSection =
  85. {
  86.     sizeof(g_pui8MouseDescriptor),
  87.     g_pui8MouseDescriptor
  88. };
  89.  
  90. const tConfigSection g_sHIDInterfaceSection =
  91. {
  92.     sizeof(g_pui8HIDInterface),
  93.     g_pui8HIDInterface
  94. };
  95.  
  96. const tConfigSection g_sHIDInEndpointSection =
  97. {
  98.     sizeof(g_pui8HIDInEndpoint),
  99.     g_pui8HIDInEndpoint
  100. };
  101.  
  102. //*****************************************************************************
  103. //
  104. // Place holder for the user's HID descriptor block.
  105. //
  106. //*****************************************************************************
  107. tConfigSection g_sHIDDescriptorSection =
  108. {
  109.    sizeof(g_sMouseHIDDescriptor),
  110.    (const uint8_t *)&g_sMouseHIDDescriptor
  111. };
  112.  
  113. //*****************************************************************************
  114. //
  115. // This array lists all the sections that must be concatenated to make a
  116. // single, complete HID configuration descriptor.
  117. //
  118. //*****************************************************************************
  119. const tConfigSection *g_psHIDSections[] =
  120. {
  121.     &g_sHIDConfigSection,
  122.     &g_sHIDInterfaceSection,
  123.     &g_sHIDDescriptorSection,
  124.     &g_sHIDInEndpointSection,
  125. };
  126.  
  127. #define NUM_HID_SECTIONS        (sizeof(g_psHIDSections) /                    \
  128.                                  sizeof(g_psHIDSections[0]))
  129.  
  130. //*****************************************************************************
  131. //
  132. // The header for the single configuration we support.  This is the root of
  133. // the data structure that defines all the bits and pieces that are pulled
  134. // together to generate the configuration descriptor.  Note that this must be
  135. // in RAM since we need to include or exclude the final section based on
  136. // client supplied initialization parameters.
  137. //
  138. //*****************************************************************************
  139. tConfigHeader g_sHIDConfigHeader =
  140. {
  141.     NUM_HID_SECTIONS,
  142.     g_psHIDSections
  143. };
  144.  
  145. //*****************************************************************************
  146. //
  147. // Configuration Descriptor.
  148. //
  149. //*****************************************************************************
  150. const tConfigHeader * const g_ppsHIDConfigDescriptors[] =
  151. {
  152.     &g_sHIDConfigHeader
  153. };
  154.  
  155. /////////// end of Config descriptors
  156.  
  157. tUSBDHIDDevice g_sUsbCanCh =
  158. {
  159.     // ...
  160.     g_pStringDescriptors,
  161.     NUM_STRING_DESCRIPTORS,
  162.     g_ppsHIDConfigDescriptors,
  163. };
  164.