usbdhidmouse.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. //*****************************************************************************
  2. //
  3. // usbdhidmouse.h - Public header file for the USB HID Mouse device class
  4. // driver
  5. //
  6. // Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved.
  7. // Software License Agreement
  8. //
  9. // Texas Instruments (TI) is supplying this software for use solely and
  10. // exclusively on TI's microcontroller products. The software is owned by
  11. // TI and/or its suppliers, and is protected under applicable copyright
  12. // laws. You may not combine this software with "viral" open-source
  13. // software in order to form a larger program.
  14. //
  15. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  16. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  17. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  19. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  20. // DAMAGES, FOR ANY REASON WHATSOEVER.
  21. //
  22. // This is part of AM1808 StarterWare USB Library and reused from revision 6288
  23. // of the Stellaris USB Library.
  24. //
  25. //*****************************************************************************
  26. #ifndef __USBDHIDMOUSE_H__
  27. #define __USBDHIDMOUSE_H__
  28. //*****************************************************************************
  29. //
  30. // If building with a C++ compiler, make all of the definitions in this header
  31. // have a C binding.
  32. //
  33. //*****************************************************************************
  34. #ifdef __cplusplus
  35. extern "C"
  36. {
  37. #endif
  38. //*****************************************************************************
  39. //
  40. //! \addtogroup hid_mouse_device_class_api
  41. //! @{
  42. //
  43. //*****************************************************************************
  44. //*****************************************************************************
  45. //
  46. // PRIVATE
  47. //
  48. // The first few sections of this header are private defines that are used by
  49. // the USB HID mouse code and are here only to help with the application
  50. // allocating the correct amount of memory for the HID mouse device code.
  51. //
  52. //*****************************************************************************
  53. //*****************************************************************************
  54. //
  55. // PRIVATE
  56. //
  57. // The size of the mouse input report sent to the host.
  58. //
  59. //*****************************************************************************
  60. #define MOUSE_REPORT_SIZE 3
  61. //*****************************************************************************
  62. //
  63. // PRIVATE
  64. //
  65. // This enumeration holds the various states that the mouse can be in during
  66. // normal operation.
  67. //
  68. //*****************************************************************************
  69. typedef enum
  70. {
  71. //
  72. // Unconfigured.
  73. //
  74. HID_MOUSE_STATE_UNCONFIGURED,
  75. //
  76. // No keys to send and not waiting on data.
  77. //
  78. HID_MOUSE_STATE_IDLE,
  79. //
  80. // Waiting on report data from the host.
  81. //
  82. HID_MOUSE_STATE_WAIT_DATA,
  83. //
  84. // Waiting on data to be sent out.
  85. //
  86. HID_MOUSE_STATE_SEND
  87. }
  88. tMouseState;
  89. //*****************************************************************************
  90. //
  91. // PRIVATE
  92. //
  93. // This structure provides the private instance data structure for the USB
  94. // HID Mouse device. This structure forms the RAM workspace used by each
  95. // instance of the mouse.
  96. //
  97. //*****************************************************************************
  98. typedef struct
  99. {
  100. //
  101. // The USB configuration number set by the host or 0 of the device is
  102. // currently unconfigured.
  103. //
  104. unsigned char ucUSBConfigured;
  105. //
  106. // The protocol requested by the host, USB_HID_PROTOCOL_BOOT or
  107. // USB_HID_PROTOCOL_REPORT.
  108. //
  109. unsigned char ucProtocol;
  110. //
  111. // A buffer used to hold the last input report sent to the host.
  112. //
  113. unsigned char pucReport[MOUSE_REPORT_SIZE];
  114. //
  115. // The current state of the mouse interrupt IN endpoint.
  116. //
  117. volatile tMouseState eMouseState;
  118. //
  119. // The idle timeout control structure for our input report. This is
  120. // required by the lower level HID driver.
  121. //
  122. tHIDReportIdle sReportIdle;
  123. //
  124. // The lower level HID driver's instance data.
  125. //
  126. tHIDInstance sHIDInstance;
  127. //
  128. // This is needed for the lower level HID driver.
  129. //
  130. tUSBDHIDDevice sHIDDevice;
  131. }
  132. tHIDMouseInstance;
  133. #ifndef DEPRECATED
  134. //*****************************************************************************
  135. //
  136. // The number of bytes of workspace required by the HID mouse driver.
  137. // The client must provide a block of RAM of at least this size in the
  138. // tHIDMouseInstance field of the tUSBHIDMouseDevice structure passed on
  139. // USBDHIDMouseInit(). The HID mouse driver needs space for the generic HID
  140. // interface + the Mouse Report Buffer + HID mouse interface.
  141. //
  142. // This value is deprecated and should not be used, any new code should just
  143. // pass in a tHIDMouseInstance structure in the psPrivateHIDMouseData field.
  144. //
  145. //*****************************************************************************
  146. #define USB_HID_MOUSE_WORKSPACE_SIZE \
  147. (sizeof(tHIDMouseInstance))
  148. #endif
  149. //*****************************************************************************
  150. //
  151. //! This structure is used by the application to define operating parameters
  152. //! for the HID mouse device.
  153. //
  154. //*****************************************************************************
  155. typedef struct
  156. {
  157. //
  158. //! The vendor ID that this device is to present in the device descriptor.
  159. //
  160. unsigned short usVID;
  161. //
  162. //! The product ID that this device is to present in the device descriptor.
  163. //
  164. unsigned short usPID;
  165. //
  166. //! The maximum power consumption of the device, expressed in milliamps.
  167. //
  168. unsigned short usMaxPowermA;
  169. //
  170. //! Indicates whether the device is self- or bus-powered and whether or not
  171. //! it supports remote wakeup. Valid values are USB_CONF_ATTR_SELF_PWR or
  172. //! USB_CONF_ATTR_BUS_PWR, optionally ORed with USB_CONF_ATTR_RWAKE.
  173. //
  174. unsigned char ucPwrAttributes;
  175. //
  176. //! A pointer to the callback function which will be called to notify
  177. //! the application of events relating to the operation of the mouse.
  178. //
  179. tUSBCallback pfnCallback;
  180. //
  181. //! A client-supplied pointer which will be sent as the first
  182. //! parameter in all calls made to the mouse callback, pfnCallback.
  183. //
  184. void *pvCBData;
  185. //
  186. //! A pointer to the string descriptor array for this device. This array
  187. //! must contain the following string descriptor pointers in this order.
  188. //! Language descriptor, Manufacturer name string (language 1), Product
  189. //! name string (language 1), Serial number string (language 1),HID
  190. //! Interface description string (language 1), Configuration description
  191. //! string (language 1).
  192. //!
  193. //! If supporting more than 1 language, the descriptor block (except for
  194. //! string descriptor 0) must be repeated for each language defined in the
  195. //! language descriptor.
  196. //
  197. const unsigned char * const *ppStringDescriptors;
  198. //
  199. //! The number of descriptors provided in the ppStringDescriptors
  200. //! array. This must be (1 + (5 * (num languages))).
  201. //
  202. unsigned int ulNumStringDescriptors;
  203. //
  204. //! A pointer to private instance data for this device. This memory must
  205. //! remain accessible for as long as the mouse device is in use and must
  206. //! not be modified by any code outside the HID mouse driver.
  207. //
  208. tHIDMouseInstance *psPrivateHIDMouseData;
  209. }
  210. tUSBDHIDMouseDevice;
  211. //*****************************************************************************
  212. //
  213. //! This return code from USBDHIDMouseStateChange indicates success.
  214. //
  215. //*****************************************************************************
  216. #define MOUSE_SUCCESS 0
  217. //*****************************************************************************
  218. //
  219. //! This return code from USBDHIDMouseStateChange indicates that an error was
  220. //! reported while attempting to send a report to the host. A client should
  221. //! assume that the host has disconnected if this return code is seen.
  222. //
  223. //*****************************************************************************
  224. #define MOUSE_ERR_TX_ERROR 2
  225. //*****************************************************************************
  226. //
  227. //! USBDHIDMouseStateChange returns this value if it is called before the
  228. //! USB host has connected and configured the device. All mouse state
  229. //! information passed on the call will have been ignored.
  230. //
  231. //*****************************************************************************
  232. #define MOUSE_ERR_NOT_CONFIGURED \
  233. 4
  234. //*****************************************************************************
  235. //
  236. //! Setting this bit in the ucButtons parameter to USBDHIDMouseStateChange
  237. //! indicates to the USB host that button 1 on the mouse is pressed.
  238. //
  239. //*****************************************************************************
  240. #define MOUSE_REPORT_BUTTON_1 0x01
  241. //*****************************************************************************
  242. //
  243. //! Setting this bit in the ucButtons parameter to USBDHIDMouseStateChange
  244. //! indicates to the USB host that button 2 on the mouse is pressed.
  245. //
  246. //*****************************************************************************
  247. #define MOUSE_REPORT_BUTTON_2 0x02
  248. //*****************************************************************************
  249. //
  250. //! Setting this bit in the ucButtons parameter to USBDHIDMouseStateChange
  251. //! indicates to the USB host that button 3 on the mouse is pressed.
  252. //
  253. //*****************************************************************************
  254. #define MOUSE_REPORT_BUTTON_3 0x04
  255. //*****************************************************************************
  256. //
  257. // API Function Prototypes
  258. //
  259. //*****************************************************************************
  260. extern void *USBDHIDMouseInit(unsigned int ulIndex,
  261. const tUSBDHIDMouseDevice *psDevice);
  262. extern void *USBDHIDMouseCompositeInit(unsigned int ulIndex,
  263. const tUSBDHIDMouseDevice *psDevice);
  264. extern void USBDHIDMouseTerm(void *pvInstance);
  265. extern void *USBDHIDMouseSetCBData(void *pvInstance, void *pvCBData);
  266. extern unsigned int USBDHIDMouseStateChange(void *pvInstance, char cDeltaX,
  267. char cDeltaY,
  268. unsigned char ucButtons);
  269. extern void USBDHIDMousePowerStatusSet(void *pvInstance,
  270. unsigned char ucPower);
  271. extern tBoolean USBDHIDMouseRemoteWakeupRequest(void *pvInstance);
  272. //*****************************************************************************
  273. //
  274. // Close the Doxygen group.
  275. //! @}
  276. //
  277. //*****************************************************************************
  278. //*****************************************************************************
  279. //
  280. // Mark the end of the C bindings section for C++ compilers.
  281. //
  282. //*****************************************************************************
  283. #ifdef __cplusplus
  284. }
  285. #endif
  286. #endif // __USBDHIDMOUSE_H__