PageRenderTime 29ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/hidescriptorparser.h

https://gitlab.com/joseangeljimenez/USB_Host_Shield_2.0
C Header | 176 lines | 131 code | 26 blank | 19 comment | 0 complexity | 8edc966ee91646a46f9f786ce8bb70cb MD5 | raw file
  1. /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  2. This software may be distributed and modified under the terms of the GNU
  3. General Public License version 2 (GPL2) as published by the Free Software
  4. Foundation and appearing in the file GPL2.TXT included in the packaging of
  5. this file. Please note that GPL2 Section 2[b] requires that all works based
  6. on this software must also be made publicly available under the terms of
  7. the GPL2 ("Copyleft").
  8. Contact information
  9. -------------------
  10. Circuits At Home, LTD
  11. Web : http://www.circuitsathome.com
  12. e-mail : support@circuitsathome.com
  13. */
  14. #if !defined(__HIDDESCRIPTORPARSER_H__)
  15. #define __HIDDESCRIPTORPARSER_H__
  16. #include "usbhid.h"
  17. class ReportDescParserBase : public USBReadParser {
  18. public:
  19. typedef void (*UsagePageFunc)(uint16_t usage);
  20. static void PrintGenericDesktopPageUsage(uint16_t usage);
  21. static void PrintSimulationControlsPageUsage(uint16_t usage);
  22. static void PrintVRControlsPageUsage(uint16_t usage);
  23. static void PrintSportsControlsPageUsage(uint16_t usage);
  24. static void PrintGameControlsPageUsage(uint16_t usage);
  25. static void PrintGenericDeviceControlsPageUsage(uint16_t usage);
  26. static void PrintLEDPageUsage(uint16_t usage);
  27. static void PrintButtonPageUsage(uint16_t usage);
  28. static void PrintOrdinalPageUsage(uint16_t usage);
  29. static void PrintTelephonyPageUsage(uint16_t usage);
  30. static void PrintConsumerPageUsage(uint16_t usage);
  31. static void PrintDigitizerPageUsage(uint16_t usage);
  32. static void PrintAlphanumDisplayPageUsage(uint16_t usage);
  33. static void PrintMedicalInstrumentPageUsage(uint16_t usage);
  34. static void PrintValue(uint8_t *p, uint8_t len);
  35. static void PrintByteValue(uint8_t data);
  36. static void PrintItemTitle(uint8_t prefix);
  37. static const char * const usagePageTitles0[];
  38. static const char * const usagePageTitles1[];
  39. static const char * const genDesktopTitles0[];
  40. static const char * const genDesktopTitles1[];
  41. static const char * const genDesktopTitles2[];
  42. static const char * const genDesktopTitles3[];
  43. static const char * const genDesktopTitles4[];
  44. static const char * const simuTitles0[];
  45. static const char * const simuTitles1[];
  46. static const char * const simuTitles2[];
  47. static const char * const vrTitles0[];
  48. static const char * const vrTitles1[];
  49. static const char * const sportsCtrlTitles0[];
  50. static const char * const sportsCtrlTitles1[];
  51. static const char * const sportsCtrlTitles2[];
  52. static const char * const gameTitles0[];
  53. static const char * const gameTitles1[];
  54. static const char * const genDevCtrlTitles[];
  55. static const char * const ledTitles[];
  56. static const char * const telTitles0[];
  57. static const char * const telTitles1[];
  58. static const char * const telTitles2[];
  59. static const char * const telTitles3[];
  60. static const char * const telTitles4[];
  61. static const char * const telTitles5[];
  62. static const char * const consTitles0[];
  63. static const char * const consTitles1[];
  64. static const char * const consTitles2[];
  65. static const char * const consTitles3[];
  66. static const char * const consTitles4[];
  67. static const char * const consTitles5[];
  68. static const char * const consTitles6[];
  69. static const char * const consTitles7[];
  70. static const char * const consTitles8[];
  71. static const char * const consTitles9[];
  72. static const char * const consTitlesA[];
  73. static const char * const consTitlesB[];
  74. static const char * const consTitlesC[];
  75. static const char * const consTitlesD[];
  76. static const char * const consTitlesE[];
  77. static const char * const digitTitles0[];
  78. static const char * const digitTitles1[];
  79. static const char * const digitTitles2[];
  80. static const char * const aplphanumTitles0[];
  81. static const char * const aplphanumTitles1[];
  82. static const char * const aplphanumTitles2[];
  83. static const char * const medInstrTitles0[];
  84. static const char * const medInstrTitles1[];
  85. static const char * const medInstrTitles2[];
  86. static const char * const medInstrTitles3[];
  87. static const char * const medInstrTitles4[];
  88. protected:
  89. static UsagePageFunc usagePageFunctions[];
  90. MultiValueBuffer theBuffer;
  91. MultiByteValueParser valParser;
  92. ByteSkipper theSkipper;
  93. uint8_t varBuffer[sizeof (USB_CONFIGURATION_DESCRIPTOR)];
  94. uint8_t itemParseState; // Item parser state variable
  95. uint8_t itemSize; // Item size
  96. uint8_t itemPrefix; // Item prefix (first byte)
  97. uint8_t rptSize; // Report Size
  98. uint8_t rptCount; // Report Count
  99. uint16_t totalSize; // Report size in bits
  100. // Method should be defined here if virtual.
  101. virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn);
  102. UsagePageFunc pfUsage;
  103. static void PrintUsagePage(uint16_t page);
  104. void SetUsagePage(uint16_t page);
  105. public:
  106. ReportDescParserBase() :
  107. itemParseState(0),
  108. itemSize(0),
  109. itemPrefix(0),
  110. rptSize(0),
  111. rptCount(0),
  112. pfUsage(NULL) {
  113. theBuffer.pValue = varBuffer;
  114. valParser.Initialize(&theBuffer);
  115. theSkipper.Initialize(&theBuffer);
  116. };
  117. void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset);
  118. enum {
  119. enErrorSuccess = 0
  120. , enErrorIncomplete // value or record is partialy read in buffer
  121. , enErrorBufferTooSmall
  122. };
  123. };
  124. class ReportDescParser : public ReportDescParserBase {
  125. };
  126. class ReportDescParser2 : public ReportDescParserBase {
  127. uint8_t rptId; // Report ID
  128. uint8_t useMin; // Usage Minimum
  129. uint8_t useMax; // Usage Maximum
  130. uint8_t fieldCount; // Number of field being currently processed
  131. void OnInputItem(uint8_t itm); // Method which is called every time Input item is found
  132. uint8_t *pBuf; // Report buffer pointer
  133. uint8_t bLen; // Report length
  134. protected:
  135. // Method should be defined here if virtual.
  136. virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn);
  137. public:
  138. ReportDescParser2(uint16_t len, uint8_t *pbuf) :
  139. ReportDescParserBase(), rptId(0), useMin(0), useMax(0), fieldCount(0), pBuf(pbuf), bLen(len) {
  140. };
  141. };
  142. class UniversalReportParser : public HIDReportParser {
  143. public:
  144. // Method should be defined here if virtual.
  145. virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
  146. };
  147. #endif // __HIDDESCRIPTORPARSER_H__