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