USB_Host_Shield_2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 <inttypes.h>
21 #include <avr/pgmspace.h>
22 #include "avrpins.h"
23 #include "max3421e.h"
24 #include "usbhost.h"
25 #include "usb_ch9.h"
26 #include "Usb.h"
27 
28 #if defined(ARDUINO) && ARDUINO >=100
29 #include "Arduino.h"
30 #else
31 #include <WProgram.h>
32 #endif
33 
34 #include "printhex.h"
35 #include "hexdump.h"
36 #include "message.h"
37 #include "confdescparser.h"
38 #include "hid.h"
39 
41 {
42 public:
43  typedef void (*UsagePageFunc)(uint16_t usage);
44 
45  static void PrintGenericDesktopPageUsage(uint16_t usage);
46  static void PrintSimulationControlsPageUsage(uint16_t usage);
47  static void PrintVRControlsPageUsage(uint16_t usage);
48  static void PrintSportsControlsPageUsage(uint16_t usage);
49  static void PrintGameControlsPageUsage(uint16_t usage);
50  static void PrintGenericDeviceControlsPageUsage(uint16_t usage);
51  static void PrintLEDPageUsage(uint16_t usage);
52  static void PrintButtonPageUsage(uint16_t usage);
53  static void PrintOrdinalPageUsage(uint16_t usage);
54  static void PrintTelephonyPageUsage(uint16_t usage);
55  static void PrintConsumerPageUsage(uint16_t usage);
56  static void PrintDigitizerPageUsage(uint16_t usage);
57  static void PrintAlphanumDisplayPageUsage(uint16_t usage);
58  static void PrintMedicalInstrumentPageUsage(uint16_t usage);
59 
60  static void PrintValue(uint8_t *p, uint8_t len);
61  static void PrintByteValue(uint8_t data);
62 
63  static void PrintItemTitle(uint8_t prefix);
64 
65  static const char *usagePageTitles0[];
66  static const char *usagePageTitles1[];
67  static const char *genDesktopTitles0[];
68  static const char *genDesktopTitles1[];
69  static const char *genDesktopTitles2[];
70  static const char *genDesktopTitles3[];
71  static const char *genDesktopTitles4[];
72  static const char *simuTitles0[];
73  static const char *simuTitles1[];
74  static const char *simuTitles2[];
75  static const char *vrTitles0[];
76  static const char *vrTitles1[];
77  static const char *sportsCtrlTitles0[];
78  static const char *sportsCtrlTitles1[];
79  static const char *sportsCtrlTitles2[];
80  static const char *gameTitles0[];
81  static const char *gameTitles1[];
82  static const char *genDevCtrlTitles[];
83  static const char *ledTitles[];
84  static const char *telTitles0[];
85  static const char *telTitles1[];
86  static const char *telTitles2[];
87  static const char *telTitles3[];
88  static const char *telTitles4[];
89  static const char *telTitles5[];
90  static const char *consTitles0[];
91  static const char *consTitles1[];
92  static const char *consTitles2[];
93  static const char *consTitles3[];
94  static const char *consTitles4[];
95  static const char *consTitles5[];
96  static const char *consTitles6[];
97  static const char *consTitles7[];
98  static const char *consTitles8[];
99  static const char *consTitles9[];
100  static const char *consTitlesA[];
101  static const char *consTitlesB[];
102  static const char *consTitlesC[];
103  static const char *consTitlesD[];
104  static const char *consTitlesE[];
105  static const char *digitTitles0[];
106  static const char *digitTitles1[];
107  static const char *digitTitles2[];
108  static const char *aplphanumTitles0[];
109  static const char *aplphanumTitles1[];
110  static const char *aplphanumTitles2[];
111  static const char *medInstrTitles0[];
112  static const char *medInstrTitles1[];
113  static const char *medInstrTitles2[];
114  static const char *medInstrTitles3[];
115  static const char *medInstrTitles4[];
116 
117 protected:
119 
124 
125  uint8_t itemParseState; // Item parser state variable
126  uint8_t itemSize; // Item size
127  uint8_t itemPrefix; // Item prefix (first byte)
128  uint8_t rptSize; // Report Size
129  uint8_t rptCount; // Report Count
130 
131  uint16_t totalSize; // Report size in bits
132 
133  virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn);
134 
136 
137  static void PrintUsagePage(uint16_t page);
138  void SetUsagePage(uint16_t page);
139 
140 public:
142  itemParseState(0),
143  itemSize(0),
144  itemPrefix(0),
145  rptSize(0),
146  rptCount(0),
147  pfUsage(NULL)
148  {
152  };
153 
154  virtual void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset);
155 
156  enum
157  {
159  , enErrorIncomplete // value or record is partialy read in buffer
161  };
162 };
163 
165 {
166 };
167 
169 {
170  uint8_t rptId; // Report ID
171  uint8_t useMin; // Usage Minimum
172  uint8_t useMax; // Usage Maximum
173  uint8_t fieldCount; // Number of field being currently processed
174 
175  void OnInputItem(uint8_t itm); // Method which is called every time Input item is found
176 
177  uint8_t *pBuf; // Report buffer pointer
178  uint8_t bLen; // Report length
179 
180 protected:
181  virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn);
182 
183 public:
184  ReportDescParser2(uint16_t len, uint8_t *pbuf) :
185  ReportDescParserBase(), bLen(len), pBuf(pbuf), rptId(0), useMin(0), useMax(0), fieldCount(0)
186  {};
187 };
188 
190 {
191 public:
192  virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
193 };
194 
195 #endif // __HIDDESCRIPTORPARSER_H__