usb_standard_requests.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /***********************************************************************************
  2. Filename: usb_standard_request.h
  3. Description: Handle USB standard requests.
  4. ***********************************************************************************/
  5. #ifndef USBSTANDARDREQUESTS_H
  6. #define USBSTANDARDREQUESTS_H
  7. /** \addtogroup module_usb_standard_requests USB Standard Requests (usbsr)
  8. * \brief This module contains automated functions for processing USB standard requests
  9. *
  10. * The processing functions are based on the \ref module_usb_framework, and access to the user-provided
  11. * USB descriptors through the \ref module_usb_descriptor_parser. All device classes and descriptor
  12. * combinations are supported, with no need to write or modify any source code. However, as described
  13. * below, some standard request must be fully or partially implemented by the user.
  14. *
  15. * \section section_usbsr_hooks Hooks
  16. * Standard requests that are not supported by the USB library or that refer to non-standard features,
  17. * are forwarded to the application via function hooks. This includes:
  18. * \li All \ref SET_DESCRIPTOR requests (see \ref usbsrHookSetDescriptor())
  19. * \li All \ref SYNCH_FRAME requests (see \ref usbsrHookSynchFrame())
  20. * \li \ref CLEAR_FEATURE requests that refer to unknown features (see \ref usbsrHookClearFeature())
  21. * \li \ref SET_FEATURE requests that refer to unknown features (see \ref usbsrHookSetFeature())
  22. *
  23. * These hooks must always be provided, however if the application does not either support the requests,
  24. * it should just stall endpoint 0. The processing uses the same mechanisms as for class and vendor
  25. * requests (refer to the \ref module_usb_framework module for detailed description and examples).
  26. *
  27. * When the \ref GET_STATUS request is received, the \ref usbsrHookModifyGetStatus() hook is always
  28. * called, so that additional status bits may be added.
  29. *
  30. * To have any practical purpose, "OUT data phase" standard requests need to notify the application of
  31. * certain events. This is done by passing the event via yet another function hook,
  32. * \ref usbsrHookProcessEvent(uint8 event, uint8 index). For events related to interfaces and endpoints,
  33. * the \c index parameter refers to an interface number or the least significant nibble of the endpoint
  34. * address. The following events can be generated:
  35. * \li \ref USBSR_EVENT_CONFIGURATION_CHANGING (the device configuration is about to change)
  36. * \li \ref USBSR_EVENT_CONFIGURATION_CHANGED (the device configuration has changed)
  37. * \li \ref USBSR_EVENT_INTERFACE_CHANGING (the alternate setting of the given interface is about to
  38. * change)
  39. * \li \ref USBSR_EVENT_INTERFACE_CHANGED (the alternate setting of the given interface has changed)
  40. * \li \ref USBSR_EVENT_REMOTE_WAKEUP_ENABLED (remote wakeup has been enabled by the host)
  41. * \li \ref USBSR_EVENT_REMOTE_WAKEUP_DISABLED (remote wakeup has been disabled by the host)
  42. * \li \ref USBSR_EVENT_EPIN_STALL_CLEARED (the given IN endpoint's stall condition has been cleared the
  43. * host)
  44. * \li \ref USBSR_EVENT_EPIN_STALL_SET (the given IN endpoint has been stalled by the host)
  45. * \li \ref USBSR_EVENT_EPOUT_STALL_CLEARED (the given OUT endpoint's stall condition has been cleared
  46. * the host)
  47. * \li \ref USBSR_EVENT_EPOUT_STALL_SET (the given OUT endpoint has been stalled by the PC)
  48. * @{
  49. */
  50. //-------------------------------------------------------------------------------------------------------
  51. /// \name Standard Request Codes
  52. //@{
  53. /// Standard request that returns status for the specified recipient
  54. #define GET_STATUS 0x00
  55. /// Standard request that clears or disables a specific feature
  56. #define CLEAR_FEATURE 0x01
  57. /// Standard request that sets or enables a specific feature
  58. #define SET_FEATURE 0x03
  59. /// Standard request that sets the device address for all future device accesses
  60. #define SET_ADDRESS 0x05
  61. /// Standard request that returns the specified USB descriptor
  62. #define GET_DESCRIPTOR 0x06
  63. /// Standard request that may be used to update exitsting descriptors or new descriptors may be added
  64. #define SET_DESCRIPTOR 0x07
  65. /// Standard request that returns the current device configuration value
  66. #define GET_CONFIGURATION 0x08
  67. /// Standard request that sets the device configuration
  68. #define SET_CONFIGURATION 0x09
  69. /// Standard request that returns the selected alternate setting for the specified interface
  70. #define GET_INTERFACE 0x0A
  71. /// Standard request that selects an alternate setting for the specified interface
  72. #define SET_INTERFACE 0x0B
  73. /// Standard request that is used to set and then report an endpoint's synchronization frame
  74. #define SYNCH_FRAME 0x0C
  75. //@}
  76. //-------------------------------------------------------------------------------------------------------
  77. //-------------------------------------------------------------------------------------------------------
  78. /// \name Features Indexes
  79. //@{
  80. /// Endpoint feature: Halt
  81. #define ENDPOINT_HALT 0x00
  82. /// Device feature: Remote wakeup
  83. #define DEVICE_REMOTE_WAKEUP 0x01
  84. //@}
  85. //-------------------------------------------------------------------------------------------------------
  86. //-------------------------------------------------------------------------------------------------------
  87. /// \name Event Types
  88. //@{
  89. /// The device configuration is about to change
  90. #define USBSR_EVENT_CONFIGURATION_CHANGING 0x01
  91. /// The device configuration has changed
  92. #define USBSR_EVENT_CONFIGURATION_CHANGED 0x02
  93. /// The alternate setting of the given interface about to change (index = "interface index")
  94. #define USBSR_EVENT_INTERFACE_CHANGING 0x03
  95. /// The alternate setting of the given interface has changed (index = "interface index")
  96. #define USBSR_EVENT_INTERFACE_CHANGED 0x04
  97. /// Remote wakeup has been enabled by the host
  98. #define USBSR_EVENT_REMOTE_WAKEUP_ENABLED 0x05
  99. /// Remote wakeup has been disabled by the host
  100. #define USBSR_EVENT_REMOTE_WAKEUP_DISABLED 0x06
  101. /// The given IN endpoint has been unstalled by the PC (index = "endpoint address" & 0x0F)
  102. #define USBSR_EVENT_EPIN_STALL_CLEARED 0x07 /* Endpoint index */
  103. /// The given IN endpoint has been stalled by the PC (index = "endpoint address" & 0x0F)
  104. #define USBSR_EVENT_EPIN_STALL_SET 0x08 /* Endpoint index */
  105. /// The given OUT endpoint has been unstalled by the PC (index = "endpoint address" & 0x0F)
  106. #define USBSR_EVENT_EPOUT_STALL_CLEARED 0x09 /* Endpoint index */
  107. /// The given OUT endpoint has been stalled by the PC (index = "endpoint address" & 0x0F)
  108. #define USBSR_EVENT_EPOUT_STALL_SET 0x0A /* Endpoint index */
  109. //@}
  110. //-------------------------------------------------------------------------------------------------------
  111. //-------------------------------------------------------------------------------------------------------
  112. /// \name Standard Request Hooks
  113. //@{
  114. /// Refer to the \ref section_setup_handler_usage section for a description on how to process standard
  115. /// requests.
  116. /// Hook which is called upon reception of a \ref SET_DESCRIPTOR request
  117. void usbsrHookSetDescriptor(void);
  118. /// Hook which is called upon reception of a \ref SYNCH_FRAME request (unsupported).
  119. void usbsrHookSynchFrame(void);
  120. /// Hook which is called when a \ref CLEAR_FEATURE request refers to a an unsupported featureted.
  121. void usbsrHookClearFeature(void);
  122. /// Hook which is called when a \ref SET_FEATURE request refers to a an unsupported feature.
  123. void usbsrHookSetFeature(void);
  124. /// Hook for modifying a \ref GET_STATUS request before the status value is returned to the PC.
  125. void usbsrHookModifyGetStatus(uint8 recipient, uint8 index, uint16 __xdata *pStatus);
  126. /// Hook which is called upon a standard request generated event (unsupported).
  127. void usbsrHookProcessEvent(uint8 event, uint8 index);
  128. //@}
  129. //-------------------------------------------------------------------------------------------------------
  130. //-------------------------------------------------------------------------------------------------------
  131. /// \name Handled Standard Requests
  132. //@{
  133. void usbsrGetStatus(void);
  134. void usbsrClearFeature(void);
  135. void usbsrSetFeature(void);
  136. void usbsrSetAddress(void);
  137. void usbsrGetDescriptor(void);
  138. void usbsrGetConfiguration(void);
  139. void usbsrSetConfiguration(void);
  140. void usbsrGetInterface(void);
  141. void usbsrSetInterface(void);
  142. //@}
  143. //-------------------------------------------------------------------------------------------------------
  144. //@}
  145. /*
  146. +------------------------------------------------------------------------------
  147. | Copyright 2004-2007 Texas Instruments Incorporated. All rights reserved.
  148. |
  149. | IMPORTANT: Your use of this Software is limited to those specific rights
  150. | granted under the terms of a software license agreement between the user who
  151. | downloaded the software, his/her employer (which must be your employer) and
  152. | Texas Instruments Incorporated (the "License"). You may not use this Software
  153. | unless you agree to abide by the terms of the License. The License limits
  154. | your use, and you acknowledge, that the Software may not be modified, copied
  155. | or distributed unless embedded on a Texas Instruments microcontroller or used
  156. | solely and exclusively in conjunction with a Texas Instruments radio
  157. | frequency transceiver, which is integrated into your product. Other than for
  158. | the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  159. | works of, modify, distribute, perform, display or sell this Software and/or
  160. | its documentation for any purpose.
  161. |
  162. | YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  163. | PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  164. | INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  165. | NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  166. | TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  167. | NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  168. | LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING
  169. | BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
  170. | CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
  171. | SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  172. | (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  173. |
  174. | Should you have any questions regarding your right to use this Software,
  175. | contact Texas Instruments Incorporated at www.TI.com.
  176. |
  177. +------------------------------------------------------------------------------
  178. */
  179. #endif