usbdhid.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  1. //*****************************************************************************
  2. //
  3. // usbdhid.h - Definitions used by HID class devices.
  4. //
  5. // Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of AM1808 StarterWare USB Library and reused from revision 6288
  22. // of the Stellaris USB Library.
  23. //
  24. //*****************************************************************************
  25. #ifndef __USBDHID_H__
  26. #define __USBDHID_H__
  27. //*****************************************************************************
  28. //
  29. // If building with a C++ compiler, make all of the definitions in this header
  30. // have a C binding.
  31. //
  32. //*****************************************************************************
  33. #ifdef __cplusplus
  34. extern "C"
  35. {
  36. #endif
  37. //*****************************************************************************
  38. //
  39. //! \addtogroup hid_device_class_api
  40. //! @{
  41. //
  42. //*****************************************************************************
  43. //*****************************************************************************
  44. //
  45. //! The size of the memory that should be allocated to create a configuration
  46. //! descriptor for a single instance of the USB HID Device.
  47. //! This does not include the configuration descriptor which is automatically
  48. //! ignored by the composite device class.
  49. //
  50. // For reference this is
  51. // sizeof(g_sHIDInterfaceSection) + sizeof(g_sHIDDescriptorSection) +
  52. // sizeof(g_sHIDInEndpointSection) + sizeof(g_sHIDOutEndpointSection)
  53. //
  54. //*****************************************************************************
  55. #define COMPOSITE_DHID_SIZE (32)
  56. //*****************************************************************************
  57. //
  58. // Macros used to create the static Report Descriptors.
  59. //
  60. //*****************************************************************************
  61. //*****************************************************************************
  62. //
  63. //! This is a macro to assist adding Usage Page entries in HID report
  64. //! descriptors.
  65. //!
  66. //! \param ucValue is the Usage Page value.
  67. //!
  68. //! This macro takes a value and prepares it to be placed as a Usage Page entry
  69. //! into a HID report structure. These are defined by the USB HID
  70. //! specification.
  71. //!
  72. //! \return Not a function.
  73. //
  74. //*****************************************************************************
  75. #define UsagePage(ucValue) 0x05, ((ucValue) & 0xff)
  76. //*****************************************************************************
  77. //
  78. //! This is a macro to assist adding Usage entries in HID report descriptors.
  79. //!
  80. //! \param ucValue is the Usage value.
  81. //!
  82. //! This macro takes a value and prepares it to be placed as a Usage entry into
  83. //! a HID report structure. These are defined by the USB HID specification.
  84. //!
  85. //! \return Not a function.
  86. //
  87. //*****************************************************************************
  88. #define Usage(ucValue) 0x09, ((ucValue) & 0xff)
  89. //*****************************************************************************
  90. //
  91. //! This is a macro to assist adding Usage Minimum entries in HID report
  92. //! descriptors.
  93. //!
  94. //! \param ucValue is the Usage Minimum value.
  95. //!
  96. //! This macro takes a value and prepares it to be placed as a Usage Minimum
  97. //! entry into a HID report structure. This is the first or minimum value
  98. //! associated with a usage value.
  99. //!
  100. //! \return Not a function.
  101. //
  102. //*****************************************************************************
  103. #define UsageMinimum(ucValue) 0x19, ((ucValue) & 0xff)
  104. //*****************************************************************************
  105. //
  106. //! This is a macro to assist adding Usage Maximum entries in HID report
  107. //! descriptors.
  108. //!
  109. //! \param ucValue is the Usage Maximum value.
  110. //!
  111. //! This macro takes a value and prepares it to be placed as a Usage Maximum
  112. //! entry into a HID report structure. This is the last or maximum value
  113. //! associated with a usage value.
  114. //!
  115. //! \return Not a function.
  116. //
  117. //*****************************************************************************
  118. #define UsageMaximum(ucValue) 0x29, ((ucValue) & 0xff)
  119. //*****************************************************************************
  120. //
  121. //! This is a macro to assist adding Logical Minimum entries in HID report
  122. //! descriptors.
  123. //!
  124. //! \param cValue is the Logical Minimum value.
  125. //!
  126. //! This macro takes a value and prepares it to be placed as a Logical Minimum
  127. //! entry into a HID report structure. This is the actual minimum value for a
  128. //! range of values associated with a field.
  129. //!
  130. //! \return Not a function.
  131. //
  132. //*****************************************************************************
  133. #define LogicalMinimum(cValue) 0x15, ((cValue) & 0xff)
  134. //*****************************************************************************
  135. //
  136. //! This is a macro to assist adding Logical Maximum entries in HID report
  137. //! descriptors.
  138. //!
  139. //! \param cValue is the Logical Maximum value.
  140. //!
  141. //! This macro takes a value and prepares it to be placed as a Logical Maximum
  142. //! entry into a HID report structure. This is the actual maximum value for a
  143. //! range of values associated with a field.
  144. //!
  145. //! \return Not a function.
  146. //
  147. //*****************************************************************************
  148. #define LogicalMaximum(cValue) 0x25, ((cValue) & 0xff)
  149. //*****************************************************************************
  150. //
  151. //! This is a macro to assist adding Physical Minimum entries in HID report
  152. //! descriptors.
  153. //!
  154. //! \param sValue is the Physical Minimum value. It is a signed, 16 bit
  155. //! number.
  156. //!
  157. //! This macro takes a value and prepares it to be placed as a Physical Minimum
  158. //! entry into a HID report structure. This is value is used in conversion of
  159. //! the control logical value, as returned to the host in the relevant report,
  160. //! to a physical measurement in the appropriate units.
  161. //!
  162. //! \return Not a function.
  163. //
  164. //*****************************************************************************
  165. #define PhysicalMinimum(sValue) 0x36, ((sValue) & 0xFF), \
  166. (((sValue) >> 8) & 0xFF)
  167. //*****************************************************************************
  168. //
  169. //! This is a macro to assist adding Physical Maximum entries in HID report
  170. //! descriptors.
  171. //!
  172. //! \param sValue is the Physical Maximum value. It is a signed, 16 bit
  173. //! number.
  174. //!
  175. //! This macro takes a value and prepares it to be placed as a Physical Maximum
  176. //! entry into a HID report structure. This is value is used in conversion of
  177. //! the control logical value, as returned to the host in the relevant report,
  178. //! to a physical measurement in the appropriate units.
  179. //!
  180. //! \return Not a function.
  181. //
  182. //*****************************************************************************
  183. #define PhysicalMaximum(sValue) 0x46, ((sValue) & 0xFF), \
  184. (((sValue) >> 8) & 0xFF)
  185. //*****************************************************************************
  186. //
  187. //! This is a macro to assist adding Collection entries in HID report
  188. //! descriptors.
  189. //!
  190. //! \param ucValue is the type of Collection.
  191. //!
  192. //! This macro takes a value and prepares it to be placed as a Collection
  193. //! entry into a HID report structure. This is the type of values that are
  194. //! being grouped together, for instance input, output or features can be
  195. //! grouped together as a collection.
  196. //!
  197. //! \return Not a function.
  198. //
  199. //*****************************************************************************
  200. #define Collection(ucValue) 0xa1, ((ucValue) & 0xff)
  201. //*****************************************************************************
  202. //
  203. //! This is a macro to assist adding End Collection entries in HID report
  204. //! descriptors.
  205. //!
  206. //! This macro can be used to place an End Collection entry into a HID report
  207. //! structure. This is a tag to indicate that a collection of entries has
  208. //! ended in the HID report structure. This terminates a previous Collection()
  209. //! entry.
  210. //!
  211. //! \return Not a function.
  212. //
  213. //*****************************************************************************
  214. #define EndCollection 0xc0
  215. //*****************************************************************************
  216. //
  217. //! This is a macro to assist adding Report Count entries in HID report
  218. //! descriptors.
  219. //!
  220. //! \param ucValue is the number of items in a report item.
  221. //!
  222. //! This macro takes a value and prepares it to be placed as a Report Count
  223. //! entry into a HID report structure. This is number of entries of Report
  224. //! Size for a given item.
  225. //!
  226. //! \return Not a function.
  227. //
  228. //*****************************************************************************
  229. #define ReportCount(ucValue) 0x95, ((ucValue) & 0xff)
  230. //*****************************************************************************
  231. //
  232. //! This is a macro to assist adding Report ID entries in HID report
  233. //! descriptors.
  234. //!
  235. //! \param ucValue is the identifier prefix for the current report.
  236. //!
  237. //! This macro takes a value and prepares it to be placed as a Report ID
  238. //! entry into a HID report structure. This value is used as a 1 byte prefix
  239. //! for the report it is contained within.
  240. //!
  241. //! \return Not a function.
  242. //
  243. //*****************************************************************************
  244. #define ReportID(ucValue) 0x85, ((ucValue) & 0xff)
  245. //*****************************************************************************
  246. //
  247. //! This is a macro to assist adding Report Size entries in HID report
  248. //! descriptors.
  249. //!
  250. //! \param ucValue is the size, in bits, of items in a report item.
  251. //!
  252. //! This macro takes a value and prepares it to be placed as a Report Size
  253. //! entry into a HID report structure. This is size in bits of the entries of
  254. //! of a report entry. The Report Count specifies how many entries of Report
  255. //! Size are in a given item. These can be individual bits or bit fields.
  256. //!
  257. //! \return Not a function.
  258. //
  259. //*****************************************************************************
  260. #define ReportSize(ucValue) 0x75, ((ucValue) & 0xff)
  261. //*****************************************************************************
  262. //
  263. //! This is a macro to assist adding Input entries in HID report descriptors.
  264. //!
  265. //! \param ucValue is bit mask to specify the type of a set of input report
  266. //! items. Note that if the USB_HID_INPUT_BITF flag is required, the Input2
  267. //! macro (which uses a 2 byte version of the Input item tag) must be used
  268. //! instead of this macro.
  269. //!
  270. //! This macro takes a value and prepares it to be placed as an Input entry
  271. //! into a HID report structure. This specifies the type of an input item in
  272. //! a report structure. These refer to a bit mask of flags that indicate the
  273. //! type of input for a set of items.
  274. //!
  275. //! \return Not a function.
  276. //
  277. //*****************************************************************************
  278. #define Input(ucValue) 0x81, ((ucValue) & 0xff)
  279. //*****************************************************************************
  280. //
  281. //! This is a macro to assist adding Input entries in HID report descriptors.
  282. //!
  283. //! \param usValue is bit mask to specify the type of a set of input report
  284. //! items. Note that this macro uses a version of the Input item tag with a
  285. //! two byte payload and allows any of the 8 possible data bits for the tag to
  286. //! be used. If USB_HID_INPUT_BITF (bit 8) is not required, the Input macro
  287. //! may be used instead.
  288. //!
  289. //! This macro takes a value and prepares it to be placed as an Input entry
  290. //! into a HID report structure. This specifies the type of an input item in
  291. //! a report structure. These refer to a bit mask of flags that indicate the
  292. //! type of input for a set of items.
  293. //!
  294. //! \return Not a function.
  295. //
  296. //*****************************************************************************
  297. #define Input2(usValue) 0x82, ((usValue) & 0xff), \
  298. (((usValue) >> 8) & 0xFF)
  299. //*****************************************************************************
  300. //
  301. //! This is a macro to assist adding Feature entries in HID report descriptors.
  302. //!
  303. //! \param ucValue is bit mask to specify the type of a set of feature report
  304. //! items. Note that if the USB_HID_FEATURE_BITF flag is required, the
  305. //! Feature2 macro (which uses a 2 byte version of the Feature item tag) must
  306. //! be used instead of this macro.
  307. //!
  308. //! This macro takes a value and prepares it to be placed as a Feature entry
  309. //! into a HID report structure. This specifies the type of a feature item in
  310. //! a report structure. These refer to a bit mask of flags that indicate the
  311. //! type of feature for a set of items.
  312. //!
  313. //! \return Not a function.
  314. //
  315. //*****************************************************************************
  316. #define Feature(ucValue) 0xB1, ((ucValue) & 0xff)
  317. //*****************************************************************************
  318. //
  319. //! This is a macro to assist adding Feature entries in HID report descriptors.
  320. //!
  321. //! \param usValue is bit mask to specify the type of a set of feature report
  322. //! items. Note that this macro uses a version of the Feature item tag with a
  323. //! two byte payload and allows any of the 8 possible data bits for the tag to
  324. //! be used. If USB_HID_FEATURE_BITF (bit 8) is not required, the Feature
  325. //! macro may be used instead.
  326. //!
  327. //! This macro takes a value and prepares it to be placed as a Feature entry
  328. //! into a HID report structure. This specifies the type of a feature item in
  329. //! a report structure. These refer to a bit mask of flags that indicate the
  330. //! type of feature for a set of items.
  331. //!
  332. //! \return Not a function.
  333. //
  334. //*****************************************************************************
  335. #define Feature2(usValue) 0xB2, ((usValue) & 0xff), \
  336. (((usValue) >> 8) & 0xFF)
  337. //*****************************************************************************
  338. //
  339. //! This is a macro to assist adding Output entries in HID report descriptors.
  340. //!
  341. //! \param ucValue is bit mask to specify the type of a set of output report
  342. //! items. Note that if the USB_HID_OUTPUT_BITF flag is required, the Output2
  343. //! macro (which uses a 2 byte version of the Output item tag) must be used
  344. //! instead of this macro.
  345. //!
  346. //! This macro takes a value and prepares it to be placed as an Output entry
  347. //! into a HID report structure. This specifies the type of an output item in
  348. //! a report structure. These refer to a bit mask of flags that indicate the
  349. //! type of output for a set of items.
  350. //!
  351. //! \return Not a function.
  352. //
  353. //*****************************************************************************
  354. #define Output(ucValue) 0x91, ((ucValue) & 0xff)
  355. //*****************************************************************************
  356. //
  357. //! This is a macro to assist adding Output entries in HID report descriptors.
  358. //!
  359. //! \param usValue is bit mask to specify the type of a set of output report
  360. //! items. Note that this macro uses a version of the Output item tag with a
  361. //! two byte payload and allows any of the 8 possible data bits for the tag to
  362. //! be used. If USB_HID_OUTPUT_BITF (bit 8) is not required, the Output macro
  363. //! may be used instead.
  364. //!
  365. //! This macro takes a value and prepares it to be placed as an Output entry
  366. //! into a HID report structure. This specifies the type of an output item in
  367. //! a report structure. These refer to a bit mask of flags that indicate the
  368. //! type of output for a set of items.
  369. //!
  370. //! \return Not a function.
  371. //
  372. //*****************************************************************************
  373. #define Output2(usValue) 0x92, ((usValue) & 0xff), \
  374. (((usValue) >> 8) & 0xFF)
  375. //*****************************************************************************
  376. //
  377. //! This is a macro to assist adding Unit Exponent entries in HID report
  378. //! descriptors.
  379. //!
  380. //! \param cValue is the required exponent in the range [-8, 7].
  381. //!
  382. //! This macro takes a value and prepares it to be placed as a Unit Exponent
  383. //! entry into a HID report structure. This is the exponent applied to
  384. //! PhysicalMinimum and PhysicalMaximum when scaling and converting control
  385. //! values to "real" units.
  386. //!
  387. //! \return Not a function.
  388. //
  389. //*****************************************************************************
  390. #define UnitExponent(cValue) 0x55, ((cValue) & 0x0f)
  391. //*****************************************************************************
  392. //
  393. //! This is a macro to assist adding Unit entries for uncommon units in HID
  394. //! report descriptors.
  395. //!
  396. //! \param ulValue is the definition of the unit required as defined in section
  397. //! 6.2.2.7 of the USB HID device class definition document.
  398. //!
  399. //! This macro takes a value and prepares it to be placed as a Unit entry into
  400. //! a HID report structure. Note that individual macros are defined for common
  401. //! units and this macro is intended for use when a complex or uncommon unit
  402. //! is needed. It allows entry of a 5 nibble unit definition into the report
  403. //! descriptor.
  404. //!
  405. //! \return Not a function.
  406. //
  407. //*****************************************************************************
  408. #define Unit(ulValue) 0x67, (ulValue) & 0x0f), \
  409. (((ulValue) >> 8) & 0xFF), \
  410. (((ulValue) >> 16) & 0xFF), \
  411. (((ulValue) >> 24) & 0xFF)
  412. //*****************************************************************************
  413. //
  414. //! This macro inserts a Unit entry for centimeters into a report descriptor.
  415. //!
  416. //*****************************************************************************
  417. #define UnitDistance_cm 0x66, 0x11, 0x00
  418. //*****************************************************************************
  419. //
  420. //! This macro inserts a Unit entry for inches into a report descriptor.
  421. //!
  422. //*****************************************************************************
  423. #define UnitDistance_i 0x66, 0x13, 0x00
  424. //*****************************************************************************
  425. //
  426. //! This macro inserts a Unit entry for degrees into a report descriptor.
  427. //!
  428. //*****************************************************************************
  429. #define UnitRotation_deg 0x66, 0x14, 0x00
  430. //*****************************************************************************
  431. //
  432. //! This macro inserts a Unit entry for radians into a report descriptor.
  433. //!
  434. //*****************************************************************************
  435. #define UnitRotation_rad 0x66, 0x12, 0x00
  436. //*****************************************************************************
  437. //
  438. //! This macro inserts a Unit entry for grams into a report descriptor.
  439. //!
  440. //*****************************************************************************
  441. #define UnitMass_g 0x66, 0x01, 0x01
  442. //*****************************************************************************
  443. //
  444. //! This macro inserts a Unit entry for seconds into a report descriptor.
  445. //!
  446. //*****************************************************************************
  447. #define UnitTime_s 0x66, 0x01, 0x10
  448. //*****************************************************************************
  449. //
  450. //! This macro inserts a Unit entry for temperature in Kelvin into a report
  451. //! descriptor.
  452. //!
  453. //*****************************************************************************
  454. #define UnitTemp_K 0x67, 0x01, 0x00, 0x01, 0x00
  455. //*****************************************************************************
  456. //
  457. //! This macro inserts a Unit entry for temperature in Fahrenheit into a report
  458. //! descriptor.
  459. //!
  460. //*****************************************************************************
  461. #define UnitTemp_F 0x67, 0x03, 0x00, 0x01, 0x00
  462. //*****************************************************************************
  463. //
  464. //! This macro inserts a Unit entry for velocity in cm/s into a report
  465. //! descriptor.
  466. //!
  467. //*****************************************************************************
  468. #define UnitVelocitySI 0x66, 0x11, 0xF0
  469. //*****************************************************************************
  470. //
  471. //! This macro inserts a Unit entry for momentum in (grams * cm)/s into a
  472. //! report descriptor.
  473. //!
  474. //*****************************************************************************
  475. #define UnitMomentumSI 0x66, 0x11, 0xF1
  476. //*****************************************************************************
  477. //
  478. //! This macro inserts a Unit entry for acceleration in cm/s**2 into a
  479. //! report descriptor.
  480. //!
  481. //*****************************************************************************
  482. #define UnitAccelerationSI 0x66, 0x11, 0xE0
  483. //*****************************************************************************
  484. //
  485. //! This macro inserts a Unit entry for force in (cm * grams)/s**2 into a
  486. //! report descriptor.
  487. //!
  488. //*****************************************************************************
  489. #define UnitForceSI 0x66, 0x11, 0xE1
  490. //*****************************************************************************
  491. //
  492. //! This macro inserts a Unit entry for energy in (grams * cm**2)/s**2 into a
  493. //! report descriptor.
  494. //!
  495. //*****************************************************************************
  496. #define UnitEnergySI 0x66, 0x21, 0xE1
  497. //*****************************************************************************
  498. //
  499. //! This macro inserts a Unit entry for angular acceleration in degrees/s**2
  500. //! into a report descriptor.
  501. //!
  502. //*****************************************************************************
  503. #define UnitAngAccelerationSI 0x66, 0x12, 0xE0
  504. //*****************************************************************************
  505. //
  506. //! This macro inserts a Unit entry for voltage into a a report descriptor.
  507. //!
  508. //*****************************************************************************
  509. #define UnitVoltage 0x67, 0x21, 0xD1, 0xF0, 0x00
  510. //*****************************************************************************
  511. //
  512. //! This macro inserts a Unit entry for voltage into a a report descriptor.
  513. //!
  514. //*****************************************************************************
  515. #define UnitCurrent_A 0x67, 0x01, 0x00, 0x10, 0x00
  516. //*****************************************************************************
  517. //
  518. // PRIVATE
  519. //
  520. // The first few sections of this header are private defines that are used by
  521. // the USB HID code and are here only to help with the application
  522. // allocating the correct amount of memory for the HID device code.
  523. //
  524. //*****************************************************************************
  525. //*****************************************************************************
  526. //
  527. // PRIVATE
  528. //
  529. // This enumeration holds the various states that the device can be in during
  530. // normal operation.
  531. //
  532. //*****************************************************************************
  533. typedef enum
  534. {
  535. //
  536. // Unconfigured.
  537. //
  538. HID_STATE_UNCONFIGURED,
  539. //
  540. // No outstanding transaction remains to be completed.
  541. //
  542. HID_STATE_IDLE,
  543. //
  544. // Waiting on completion of a send or receive transaction.
  545. //
  546. HID_STATE_WAIT_DATA
  547. }
  548. tHIDState;
  549. //*****************************************************************************
  550. //
  551. // PRIVATE
  552. //
  553. // This structure defines the private instance data and state variables for
  554. // HID devices. The memory for this structure is pointed to by the
  555. // psPrivateHIDData field in the tUSBDHIDDevice structure passed in the
  556. // USBDHIDInit() function.
  557. //
  558. //*****************************************************************************
  559. typedef struct
  560. {
  561. unsigned int ulUSBBase;
  562. tDeviceInfo *psDevInfo;
  563. tConfigDescriptor *psConfDescriptor;
  564. volatile tHIDState eHIDRxState;
  565. volatile tHIDState eHIDTxState;
  566. volatile unsigned short usDeferredOpFlags;
  567. unsigned short usInReportSize;
  568. unsigned short usInReportIndex;
  569. unsigned short usOutReportSize;
  570. unsigned char *pucInReportData;
  571. unsigned char *pucOutReportData;
  572. volatile tBoolean bConnected;
  573. volatile tBoolean bSendInProgress;
  574. tBoolean bGetRequestPending;
  575. unsigned char ucINEndpoint;
  576. unsigned char ucOUTEndpoint;
  577. unsigned char ucInterface;
  578. }
  579. tHIDInstance;
  580. #ifndef DEPRECATED
  581. //*****************************************************************************
  582. //
  583. // The number of bytes of workspace required by the HID device class driver.
  584. // The client must provide a block of RAM of at least this size in the
  585. // pvWorkspace field of the tUSBDHIDDevice structure passed on USBDHIDInit.
  586. //
  587. //*****************************************************************************
  588. #define USB_HID_WORKSPACE_SIZE sizeof(tHIDInstance)
  589. #endif
  590. //*****************************************************************************
  591. //
  592. //! The structure used to track idle time for reports. An array of these
  593. //! structures is passed to the HID device class driver during USBDHIDInit and
  594. //! is used to track automatic resending of each report (if not disabled by
  595. //! the host).
  596. //
  597. //*****************************************************************************
  598. typedef struct
  599. {
  600. //
  601. //! The idle duration for the report expressed in units of 4mS. 0
  602. //! indicates infinite and informs the class driver not to send the report
  603. //! unless a state change occurs.
  604. //
  605. unsigned char ucDuration4mS;
  606. //
  607. //! The ID of the report which this structure applies to. This is the
  608. //! report ID as specified using a ReportID tag in the report descriptor
  609. //! rather than the index of the report in the HID class descriptor array.
  610. //! If only a single Input report is supported and, thus, no ReportID tag
  611. //! is present, this field should be set to 0.
  612. //
  613. unsigned char ucReportID;
  614. //
  615. //! The number of milliseconds before we need to send a copy of a given
  616. //! report back to the host. This field is updated by the HID driver and
  617. //! used to time sending of USBD_HID_EVENT_IDLE_TIMEOUT.
  618. //
  619. unsigned short usTimeTillNextmS;
  620. //
  621. //! The number of milliseconds that have passed since the last time this
  622. //! report was sent. The HID class driver needs to track this since
  623. //! Set_Idle requests are required to take effect as if issued immediately
  624. //! after the last transmission of the report to which they refer.
  625. //
  626. unsigned int ulTimeSinceReportmS;
  627. }
  628. tHIDReportIdle;
  629. //*****************************************************************************
  630. //
  631. //! The structure used by the application to define operating parameters for
  632. //! the HID device.
  633. //
  634. //*****************************************************************************
  635. typedef struct
  636. {
  637. //
  638. //! The vendor ID that this device is to present in the device descriptor.
  639. //
  640. unsigned short usVID;
  641. //
  642. //! The product ID that this device is to present in the device descriptor.
  643. //
  644. unsigned short usPID;
  645. //
  646. //! The maximum power consumption of the device, expressed in milliamps.
  647. //
  648. unsigned short usMaxPowermA;
  649. //
  650. //! Indicates whether the device is self- or bus-powered and whether or not
  651. //! it supports remote wakeup. Valid values are USB_CONF_ATTR_SELF_PWR or
  652. //! USB_CONF_ATTR_BUS_PWR, optionally ORed with USB_CONF_ATTR_RWAKE.
  653. //
  654. unsigned char ucPwrAttributes;
  655. //
  656. //! The interface subclass to publish to the server for this HID device.
  657. //
  658. unsigned char ucSubclass;
  659. //
  660. //! The interface protocol to publish to the server for this HID device.
  661. //
  662. unsigned char ucProtocol;
  663. //
  664. //! The number of Input reports that this device supports. This field
  665. //! must equal the number of reports published in the HID class descriptors
  666. //! for the device and also the number of entries in the array whose first
  667. //! element is pointed to by field psReportIdle below.
  668. //
  669. unsigned char ucNumInputReports;
  670. //
  671. //! A pointer to the first element in an array of structures used to track
  672. //! idle time for each Input report. When USBDHIDInit is called, the
  673. //! ucDuration4mS and ucReportID fields of each of these array members
  674. //! should be initialized to indicate the default idle timeout for each
  675. //! input report. This array must be in RAM since the HID device class
  676. //! driver will update values in it in response to requests from the host
  677. //! and to track elapsed time. The number of elements in the array must
  678. //! match the number supplied in the ucNumInputReports field above.
  679. //
  680. tHIDReportIdle *psReportIdle;
  681. //! A pointer to the callback function which will be called to notify
  682. //! the application of general events, events related to report transfers
  683. //! on endpoint zero and events related to reception of Output and Feature
  684. //! reports via the (optional) interrupt OUT endpoint.
  685. //
  686. tUSBCallback pfnRxCallback;
  687. //
  688. //! A client-supplied pointer which will be sent as the first
  689. //! parameter in all calls made to the receive channel callback,
  690. //! pfnRxCallback.
  691. //
  692. void *pvRxCBData;
  693. //
  694. //! A pointer to the callback function which will be called to notify
  695. //! the application of events related to transmission of Input reports
  696. //! via the interrupt IN endpoint.
  697. //
  698. tUSBCallback pfnTxCallback;
  699. //
  700. //! A client-supplied pointer which will be sent as the first
  701. //! parameter in all calls made to the transmit channel callback,
  702. //! pfnTxCallback.
  703. //
  704. void *pvTxCBData;
  705. //
  706. //! If set to true, this field indicates that the device should use a
  707. //! dedicated interrupt OUT endpoint to receive reports from the host. In
  708. //! this case, reports from the host are passed to the application via the
  709. //! receive callback using USB_EVENT_RX_AVAILABLE events. If false,
  710. //! reports from the host are received via endpoint zero and passed to the
  711. //! application via USBD_HID_EVENT_REPORT_SENT events.
  712. //
  713. tBoolean bUseOutEndpoint;
  714. //
  715. //! The HID descriptor that the device is to publish (following the
  716. //! standard interface descriptor and prior to the endpoint descriptors for
  717. //! the interface).
  718. //
  719. const tHIDDescriptor *psHIDDescriptor;
  720. //
  721. //! The HID class descriptors offered by the device are defined in an
  722. //! array of byte pointers and this field points to that array. The
  723. //! order and number of elements in the array must match the associated
  724. //! information provided in the HID descriptor in field by psHIDDescriptor.
  725. //
  726. const unsigned char * const *ppClassDescriptors;
  727. //
  728. //! A pointer to the string descriptor array for this device. This array
  729. //! must contain the following string descriptor pointers in this order.
  730. //! Language descriptor, Manufacturer name string (language 1), Product
  731. //! name string (language 1), Serial number string (language 1),HID
  732. //! Interface description string (language 1), Configuration description
  733. //! string (language 1), (optionally) First HID device-specific string
  734. //! (language 1), (optionally) Second HID device-specific string (language
  735. //! 1), etc.
  736. //!
  737. //! If supporting more than 1 language, the descriptor block (except for
  738. //! string descriptor 0) must be repeated for each language defined in the
  739. //! language descriptor.
  740. //!
  741. //! The number of HID device-specific strings is dependent upon the content
  742. //! of the report descriptor passed to the interface and is, thus,
  743. //! application controlled.
  744. //
  745. const unsigned char * const *ppStringDescriptors;
  746. //
  747. //! The number of descriptors provided in the ppStringDescriptors
  748. //! array. This must be 1 + ((5 + (num HID strings)) * (num languages)).
  749. //
  750. unsigned int ulNumStringDescriptors;
  751. //
  752. //! A pointer to private instance data for this device instance. This
  753. //! memory must remain accessible for as long as the HID device is in use
  754. //! and must not be modified by any code outside the HID class driver.
  755. //
  756. tHIDInstance *psPrivateHIDData;
  757. }
  758. tUSBDHIDDevice;
  759. //*****************************************************************************
  760. //
  761. // HID-specific device class driver events
  762. //
  763. //*****************************************************************************
  764. //*****************************************************************************
  765. //
  766. //! This event indicates that the host is requesting a particular report be
  767. //! returned via endpoint 0, the control endpoint. The ulMsgValue parameter
  768. //! contains the requested report type in the high byte and report ID in the
  769. //! low byte (as passed in the wValue field of the USB request structure).
  770. //! The pvMsgData parameter contains a pointer which must be written with the
  771. //! address of the first byte of the requested report. The callback must
  772. //! return the size in bytes of the report pointed to by *pvMsgData. The
  773. //! memory returned in response to this event must remain unaltered until
  774. //! USBD_HID_EVENT_REPORT_SENT is sent.
  775. //
  776. //*****************************************************************************
  777. #define USBD_HID_EVENT_GET_REPORT \
  778. (USBD_HID_EVENT_BASE + 0)
  779. //*****************************************************************************
  780. //
  781. //! This event indicates that a report previously requested via a
  782. //! USBD_HID_EVENT_GET_REPORT has been successfully transmitted to the host.
  783. //! The application may now free or reuse the report memory passed on the
  784. //! previous event. Although this would seem to be an event that would be
  785. //! passed to the transmit channel callback, it is actually passed to the
  786. //! receive channel callback. This ensures that all events related to the
  787. //! request and transmission of reports via endpoint zero can be handled in
  788. //! a single function.
  789. //
  790. //*****************************************************************************
  791. #define USBD_HID_EVENT_REPORT_SENT \
  792. (USBD_HID_EVENT_BASE + 1)
  793. //*****************************************************************************
  794. //
  795. //! This event indicates that the host has sent a Set_Report request to
  796. //! the device and requests that the device provide a buffer into which the
  797. //! report can be written. The ulMsgValue parameter contains the received
  798. //! report type in the high byte and report ID in the low byte (as passed in
  799. //! the wValue field of the USB request structure). The pvMsgData parameter
  800. //! contains the length of buffer requested. Note that this is the actual
  801. //! length value cast to a "void *" type and not a pointer in this case.
  802. //! The callback must return a pointer to a suitable buffer (cast to the
  803. //! standard "unsigned int" return type for the callback).
  804. //
  805. //*****************************************************************************
  806. #define USBD_HID_EVENT_GET_REPORT_BUFFER \
  807. (USBD_HID_EVENT_BASE + 2)
  808. //*****************************************************************************
  809. //
  810. //! This event indicates that the host has sent the device a report via
  811. //! endpoint 0, the control endpoint. The ulMsgValue field indicates the
  812. //! size of the report and pvMsgData points to the first byte of the report.
  813. //! The report buffer will previously have been returned in response to an
  814. //! earlier USBD_HID_EVENT_GET_REPORT_BUFFER callback. The HID device class
  815. //! driver will not access the memory pointed to by pvMsgData after this
  816. //! callback is made so the application is free to reuse or free it at this
  817. //! point.
  818. //
  819. //*****************************************************************************
  820. #define USBD_HID_EVENT_SET_REPORT \
  821. (USBD_HID_EVENT_BASE + 3)
  822. //*****************************************************************************
  823. //
  824. //! This event is sent in response to a Get_Protocol request from the host.
  825. //! The callback should provide the current protocol via the return code,
  826. //! USB_HID_PROTOCOL_BOOT or USB_HID_PROTOCOL_REPORT.
  827. //
  828. //*****************************************************************************
  829. #define USBD_HID_EVENT_GET_PROTOCOL \
  830. (USBD_HID_EVENT_BASE + 4)
  831. //*****************************************************************************
  832. //
  833. //! This event is sent in response to a Set_Protocol request from the host.
  834. //! The ulMsgData value will contain the requested protocol,
  835. //! USB_HID_PROTOCOL_BOOT or USB_HID_PROTOCOL_REPORT.
  836. //
  837. //*****************************************************************************
  838. #define USBD_HID_EVENT_SET_PROTOCOL \
  839. (USBD_HID_EVENT_BASE + 5)
  840. //*****************************************************************************
  841. //
  842. //! This event indicates to an application that a report idle timeout has
  843. //! occurred and requests a pointer to the report that must be sent back to
  844. //! the host. The ulMsgData value will contain the requested report ID and
  845. //! pvMsgData contains a pointer that must be written with a pointer to the
  846. //! report data that is to be sent. The callback must return the number of
  847. //! bytes in the report pointed to by *pvMsgData.
  848. //
  849. //*****************************************************************************
  850. #define USBD_HID_EVENT_IDLE_TIMEOUT \
  851. (USBD_HID_EVENT_BASE + 6)
  852. extern tDeviceInfo g_sHIDDeviceInfo;
  853. //*****************************************************************************
  854. //
  855. // API Function Prototypes
  856. //
  857. //*****************************************************************************
  858. extern void *USBDHIDInit(unsigned int ulIndex,
  859. const tUSBDHIDDevice *psHIDDevice);
  860. extern void *USBDHIDCompositeInit(unsigned int ulIndex,
  861. const tUSBDHIDDevice *psDevice);
  862. extern void USBDHIDTerm(void *pvInstance);
  863. extern void *USBDHIDSetRxCBData(void *pvInstance, void *pvCBData);
  864. extern void *USBDHIDSetTxCBData(void *pvInstance, void *pvCBData);
  865. extern unsigned int USBDHIDReportWrite(void *pvInstance,
  866. unsigned char *pcData,
  867. unsigned int ulLength,
  868. tBoolean bLast);
  869. extern unsigned int USBDHIDPacketRead(void *pvInstance,
  870. unsigned char *pcData,
  871. unsigned int ulLength,
  872. tBoolean bLast);
  873. extern unsigned int USBDHIDTxPacketAvailable(void *pvInstance);
  874. extern unsigned int USBDHIDRxPacketAvailable(void *pvInstance);
  875. extern void USBDHIDPowerStatusSet(void *pvInstance, unsigned char ucPower);
  876. extern tBoolean USBDHIDRemoteWakeupRequest(void *pvInstance);
  877. //*****************************************************************************
  878. //
  879. // Close the Doxygen group.
  880. //! @}
  881. //
  882. //*****************************************************************************
  883. //*****************************************************************************
  884. //
  885. // Mark the end of the C bindings section for C++ compilers.
  886. //
  887. //*****************************************************************************
  888. #ifdef __cplusplus
  889. }
  890. #endif
  891. #endif // __USBDHID_H__