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