usb_descriptor.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /***********************************************************************************
  2. Filename: usb_descriptor.h
  3. Description: Interface to USB descriptors.
  4. ***********************************************************************************/
  5. #ifndef USBDESCRIPTOR_H
  6. #define USBDESCRIPTOR_H
  7. #ifndef ASM_FILE
  8. #include "usb_framework_structs.h"
  9. #endif
  10. /** \addtogroup module_usb_descriptor USB Descriptor
  11. * \brief This module contains contains USB descriptor definitions, and guidelines on how to write
  12. * descriptor sets that work with the USB library.
  13. *
  14. * Information on the specific USB descriptor types is available in the USB 2.0 specification and
  15. * in device class documentation. Examples of complete descriptor sets can be found in the Chipcon USB
  16. * application examples.
  17. *
  18. * \section section_usbdsc_standard Standard Descriptors
  19. * The library requires the USB descriptor set to be organized as follows:
  20. * - Device descriptor (\ref USB_DEVICE_DESCRIPTOR)
  21. * - Configuration descriptor (\ref USB_CONFIGURATION_DESCRIPTOR)
  22. * - Interface descriptor (\ref USB_INTERFACE_DESCRIPTOR)
  23. * - Endpoint descriptor (\ref USB_ENDPOINT_DESCRIPTOR)
  24. * - More endpoint descriptors
  25. * - More interface descriptors
  26. * - More configuration descriptors
  27. * - String descriptor (\ref USB_STRING_DESCRIPTOR)
  28. * - More string descriptors
  29. *
  30. * Different USB device classes, such as "HID" and "Audio", may add other standard format descriptor
  31. * types to the hierarchy, and even extend the existing types. This is also supported by the library.
  32. *
  33. * Refer to the \ref module_usb_descriptor_parser module for information on
  34. * \li Where in memory the descriptor set can be placed
  35. * \li How to set the required markers (symbols), \ref usbDescStart and \ref usbDescEnd.
  36. *
  37. * \section section_usbdsc_other Other Descriptors
  38. * Differently formatted descriptors are not supported by the parsing mechanism, and are instead located
  39. * through a \ref DESC_LUT_INFO look-up table. Each entry in the \ref usbDescLut table contains the
  40. * index and value parameters for relevant \ref GET_DESCRIPTOR requests, and the locations and lengths
  41. * of the corresponding descriptors:
  42. * \code
  43. * ; Make the symbols public
  44. * PUBLIC usbDescLut;
  45. * PUBLIC usbDescLutEnd;
  46. *
  47. * ...
  48. *
  49. * usbDescLut: DB HID_REPORT, 00H ; value (MSB, LSB)
  50. * DB 00H, 00H ; index (MSB, LSB)
  51. * DW hidReportDesc0Start ; pDescStart
  52. * DW hidReportDesc0End - hidReportDesc0Start ; length
  53. *
  54. * DB HID_REPORT, 01H ; value (MSB, LSB)
  55. * DB 00H, 00H ; index (MSB, LSB)
  56. * DW hidReportDesc1Start ; pDescStart
  57. * DW hidReportDesc1End - hidReportDesc1Start ; length
  58. * usbDescLutEnd:
  59. * \endcode
  60. *
  61. * An additional look-up table is needed configure endpoint double-buffering. The table must contain one
  62. * \ref DBLBUF_LUT_INFO entry for each interface descriptor with non-zero \c bNumEndpoints:
  63. * \code
  64. * ; Make the symbol public
  65. * PUBLIC usbDblbufLut;
  66. *
  67. * ...
  68. *
  69. * usbDblbufLut: DW interface0Desc ; pInterface
  70. * DB 02H ; inMask (example: EP1 IN is double-buffered)
  71. * DB 00H ; outMask (example: No double-buffered OUT endpoints)
  72. *
  73. * DW interface1Desc ; pInterface
  74. * DB 10H ; inMask (example: EP4 IN is double-buffered)
  75. * DB 08H ; outMask (example: EP3 OUT is double-buffered)
  76. * \endcode
  77. * @{
  78. */
  79. #ifdef EXTERN
  80. #undef EXTERN
  81. #endif
  82. #ifdef USBDESCRIPTORPARSER_C
  83. #define EXTERN ///< Definition used only for usb_descriptor_parser.c
  84. #else
  85. #define EXTERN extern ///< Definition used in other source files to declare external
  86. #endif
  87. //-------------------------------------------------------------------------------------------------------
  88. /// \name Sizes
  89. //@{
  90. #define EP0_PACKET_SIZE 32 ///< The maximum data packet size for endpoint 0
  91. //@}
  92. /// \name Standard Descriptor Types
  93. //@{
  94. #define DESC_TYPE_DEVICE 0x01 ///< Device
  95. #define DESC_TYPE_CONFIG 0x02 ///< Configuration
  96. #define DESC_TYPE_STRING 0x03 ///< String
  97. #define DESC_TYPE_INTERFACE 0x04 ///< Interface
  98. #define DESC_TYPE_ENDPOINT 0x05 ///< Endpoint
  99. //@}
  100. /// \name HID Class Descriptor Types
  101. //@{
  102. #define DESC_TYPE_HID 0x21 ///< HID descriptor (included in the interface descriptor)
  103. #define DESC_TYPE_HIDREPORT 0x22 ///< Report descriptor (referenced in \ref usbDescLut)
  104. //@}
  105. /// \name Endpoint Types
  106. //@{
  107. #define EP_ATTR_CTRL 0x00 ///< Control (endpoint 0 only)
  108. #define EP_ATTR_ISO 0x01 ///< Isochronous (not acknowledged)
  109. #define EP_ATTR_BULK 0x02 ///< Bulk
  110. #define EP_ATTR_INT 0x03 ///< Interrupt (guaranteed polling interval)
  111. #define EP_ATTR_TYPE_BM 0x03 ///< Endpoint type bitmask
  112. //@}
  113. //-------------------------------------------------------------------------------------------------------
  114. #ifndef ASM_FILE
  115. //-------------------------------------------------------------------------------------------------------
  116. /// \name USB Descriptor Marker
  117. //@{
  118. /// USB descriptor markers which the USB Firmware Library imports from the application
  119. typedef struct {
  120. uint8 __code* const pUsbDescStart; ///< USB descriptor start pointer
  121. uint8 __code* const pUsbDescEnd; ///< USB descriptor end pointer
  122. DESC_LUT_INFO __code* const pUsbDescLut; ///< Start of USB desc look-up table pointer
  123. DESC_LUT_INFO __code* const pUsbDescLutEnd; ///< End of USB desc look-up table pointer
  124. DBLBUF_LUT_INFO __code* const pUsbDblbufLut; ///< Start of double-buffering look-up table pointer
  125. DBLBUF_LUT_INFO __code* const pUsbDblbufLutEnd; ///< End of double-buffering look-up table pointer
  126. } USB_DESCRIPTOR_MARKER;
  127. extern USB_DESCRIPTOR_MARKER __xdata usbDescriptorMarker; ///< USB descriptor marker
  128. //-------------------------------------------------------------------------------------------------------
  129. // Import marker symbols for the USB descriptor to use (from <app>_usb_descriptor.s51)
  130. // They need to be defined here or in application FW
  131. // The source file <app>_usb_descriptor.s51 need to use these names, or update
  132. // the names used here with the ones used in <app>_usb_descriptor.s51.
  133. extern void __code* usbDescStart; ///< Pointer to start of (standard) USB descriptor
  134. extern void __code* usbDescEnd; ///< Pointer to end of (standard) USB descriptor
  135. extern void __code* usbDescLut; ///< Pointer to start of lookup table for non-standard USB descriptors
  136. extern void __code* usbDescLutEnd; ///< Pointer to end of lookup table for non-standard USB descriptors
  137. extern void __code* usbDblbufLut; ///< Pointer to start of lookup table for endpoints' double-buffer settings
  138. extern void __code* usbDblbufLutEnd; ///< Pointer to end of lookup table for endpoints' double-buffer settings
  139. //@}
  140. #endif // ASM_FILE
  141. //@}
  142. /*
  143. +------------------------------------------------------------------------------
  144. | Copyright 2004-2009 Texas Instruments Incorporated. All rights reserved.
  145. |
  146. | IMPORTANT: Your use of this Software is limited to those specific rights
  147. | granted under the terms of a software license agreement between the user who
  148. | downloaded the software, his/her employer (which must be your employer) and
  149. | Texas Instruments Incorporated (the "License"). You may not use this Software
  150. | unless you agree to abide by the terms of the License. The License limits
  151. | your use, and you acknowledge, that the Software may not be modified, copied
  152. | or distributed unless embedded on a Texas Instruments microcontroller or used
  153. | solely and exclusively in conjunction with a Texas Instruments radio
  154. | frequency transceiver, which is integrated into your product. Other than for
  155. | the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  156. | works of, modify, distribute, perform, display or sell this Software and/or
  157. | its documentation for any purpose.
  158. |
  159. | YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  160. | PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  161. | INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  162. | NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  163. | TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  164. | NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  165. | LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING
  166. | BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
  167. | CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
  168. | SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  169. | (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  170. |
  171. | Should you have any questions regarding your right to use this Software,
  172. | contact Texas Instruments Incorporated at www.TI.com.
  173. |
  174. +------------------------------------------------------------------------------
  175. */
  176. #endif