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 {
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__
ReportDescParserBase::genDesktopTitles3
static const char *const genDesktopTitles3[]
Definition: hidescriptorparser.h:51
ReportDescParserBase::PrintGenericDeviceControlsPageUsage
static void PrintGenericDeviceControlsPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1346
ReportDescParserBase::consTitlesB
static const char *const consTitlesB[]
Definition: hidescriptorparser.h:82
ReportDescParserBase::usagePageTitles0
static const char *const usagePageTitles0[]
Definition: hidescriptorparser.h:46
ReportDescParserBase::PrintOrdinalPageUsage
static void PrintOrdinalPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1287
ReportDescParserBase::PrintTelephonyPageUsage
static void PrintTelephonyPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1362
ReportDescParserBase
Definition: hidescriptorparser.h:22
ReportDescParserBase::itemSize
uint8_t itemSize
Definition: hidescriptorparser.h:107
ReportDescParserBase::genDesktopTitles1
static const char *const genDesktopTitles1[]
Definition: hidescriptorparser.h:49
ReportDescParserBase::ledTitles
static const char *const ledTitles[]
Definition: hidescriptorparser.h:64
ReportDescParserBase::aplphanumTitles1
static const char *const aplphanumTitles1[]
Definition: hidescriptorparser.h:90
ReportDescParserBase::consTitlesC
static const char *const consTitlesC[]
Definition: hidescriptorparser.h:83
ReportDescParserBase::theBuffer
MultiValueBuffer theBuffer
Definition: hidescriptorparser.h:101
ReportDescParserBase::telTitles1
static const char *const telTitles1[]
Definition: hidescriptorparser.h:66
ReportDescParserBase::medInstrTitles0
static const char *const medInstrTitles0[]
Definition: hidescriptorparser.h:92
ReportDescParserBase::PrintGameControlsPageUsage
static void PrintGameControlsPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1337
ReportDescParserBase::telTitles3
static const char *const telTitles3[]
Definition: hidescriptorparser.h:68
ReportDescParserBase::medInstrTitles3
static const char *const medInstrTitles3[]
Definition: hidescriptorparser.h:95
ReportDescParserBase::PrintVRControlsPageUsage
static void PrintVRControlsPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1318
ReportDescParser2
Definition: hidescriptorparser.h:148
ReportDescParserBase::telTitles4
static const char *const telTitles4[]
Definition: hidescriptorparser.h:69
ReportDescParserBase::aplphanumTitles2
static const char *const aplphanumTitles2[]
Definition: hidescriptorparser.h:91
ReportDescParserBase::gameTitles0
static const char *const gameTitles0[]
Definition: hidescriptorparser.h:61
ReportDescParserBase::Parse
void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset)
Definition: hidescriptorparser.cpp:993
ReportDescParserBase::consTitles8
static const char *const consTitles8[]
Definition: hidescriptorparser.h:79
ReportDescParserBase::simuTitles1
static const char *const simuTitles1[]
Definition: hidescriptorparser.h:54
ReportDescParserBase::digitTitles1
static const char *const digitTitles1[]
Definition: hidescriptorparser.h:87
ReportDescParser
Definition: hidescriptorparser.h:145
ReportDescParserBase::consTitles5
static const char *const consTitles5[]
Definition: hidescriptorparser.h:76
ByteSkipper::Initialize
void Initialize(MultiValueBuffer *pbuf)
Definition: parsetools.h:72
ReportDescParserBase::PrintByteValue
static void PrintByteValue(uint8_t data)
Definition: hidescriptorparser.cpp:1020
ReportDescParserBase::gameTitles1
static const char *const gameTitles1[]
Definition: hidescriptorparser.h:62
ReportDescParserBase::sportsCtrlTitles2
static const char *const sportsCtrlTitles2[]
Definition: hidescriptorparser.h:60
ReportDescParserBase::rptCount
uint8_t rptCount
Definition: hidescriptorparser.h:110
ReportDescParserBase::enErrorSuccess
@ enErrorSuccess
Definition: hidescriptorparser.h:139
ReportDescParserBase::consTitlesE
static const char *const consTitlesE[]
Definition: hidescriptorparser.h:85
ReportDescParserBase::consTitlesA
static const char *const consTitlesA[]
Definition: hidescriptorparser.h:81
ReportDescParserBase::consTitles3
static const char *const consTitles3[]
Definition: hidescriptorparser.h:74
ReportDescParserBase::vrTitles0
static const char *const vrTitles0[]
Definition: hidescriptorparser.h:56
usbhid.h
ReportDescParserBase::genDesktopTitles2
static const char *const genDesktopTitles2[]
Definition: hidescriptorparser.h:50
ReportDescParserBase::genDesktopTitles0
static const char *const genDesktopTitles0[]
Definition: hidescriptorparser.h:48
ReportDescParserBase::pfUsage
UsagePageFunc pfUsage
Definition: hidescriptorparser.h:117
ReportDescParserBase::totalSize
uint16_t totalSize
Definition: hidescriptorparser.h:112
ReportDescParserBase::PrintGenericDesktopPageUsage
static void PrintGenericDesktopPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1296
ReportDescParserBase::genDesktopTitles4
static const char *const genDesktopTitles4[]
Definition: hidescriptorparser.h:52
ReportDescParserBase::PrintAlphanumDisplayPageUsage
static void PrintAlphanumDisplayPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1407
ReportDescParserBase::itemPrefix
uint8_t itemPrefix
Definition: hidescriptorparser.h:108
ReportDescParserBase::valParser
MultiByteValueParser valParser
Definition: hidescriptorparser.h:102
USBReadParser
Definition: UsbCore.h:205
ReportDescParserBase::simuTitles0
static const char *const simuTitles0[]
Definition: hidescriptorparser.h:53
ReportDescParserBase::itemParseState
uint8_t itemParseState
Definition: hidescriptorparser.h:106
ReportDescParserBase::PrintLEDPageUsage
static void PrintLEDPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1354
HIDReportParser
Definition: usbhid.h:138
ReportDescParserBase::usagePageFunctions
static UsagePageFunc usagePageFunctions[]
Definition: hidescriptorparser.h:99
ReportDescParserBase::aplphanumTitles0
static const char *const aplphanumTitles0[]
Definition: hidescriptorparser.h:89
ReportDescParserBase::consTitles0
static const char *const consTitles0[]
Definition: hidescriptorparser.h:71
ReportDescParserBase::medInstrTitles4
static const char *const medInstrTitles4[]
Definition: hidescriptorparser.h:96
ReportDescParserBase::UsagePageFunc
void(* UsagePageFunc)(uint16_t usage)
Definition: hidescriptorparser.h:24
MultiByteValueParser::Initialize
void Initialize(MultiValueBuffer *const pbuf)
Definition: parsetools.h:54
ReportDescParserBase::PrintSimulationControlsPageUsage
static void PrintSimulationControlsPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1308
ReportDescParserBase::PrintButtonPageUsage
static void PrintButtonPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1279
ReportDescParserBase::PrintUsagePage
static void PrintUsagePage(uint16_t page)
Definition: hidescriptorparser.cpp:1254
ByteSkipper
Definition: parsetools.h:62
ReportDescParserBase::PrintValue
static void PrintValue(uint8_t *p, uint8_t len)
Definition: hidescriptorparser.cpp:1013
ReportDescParserBase::consTitles4
static const char *const consTitles4[]
Definition: hidescriptorparser.h:75
ReportDescParserBase::telTitles0
static const char *const telTitles0[]
Definition: hidescriptorparser.h:65
ReportDescParserBase::PrintConsumerPageUsage
static void PrintConsumerPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1375
ReportDescParserBase::enErrorBufferTooSmall
@ enErrorBufferTooSmall
Definition: hidescriptorparser.h:141
UniversalReportParser
Definition: hidescriptorparser.h:170
USB_CONFIGURATION_DESCRIPTOR
Definition: usb_ch9.h:123
UniversalReportParser::Parse
virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: hidescriptorparser.cpp:1587
ReportDescParserBase::PrintSportsControlsPageUsage
static void PrintSportsControlsPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1327
ReportDescParserBase::medInstrTitles2
static const char *const medInstrTitles2[]
Definition: hidescriptorparser.h:94
ReportDescParserBase::digitTitles0
static const char *const digitTitles0[]
Definition: hidescriptorparser.h:86
ReportDescParserBase::telTitles2
static const char *const telTitles2[]
Definition: hidescriptorparser.h:67
ReportDescParserBase::consTitles9
static const char *const consTitles9[]
Definition: hidescriptorparser.h:80
ReportDescParserBase::digitTitles2
static const char *const digitTitles2[]
Definition: hidescriptorparser.h:88
ReportDescParser2::ReportDescParser2
ReportDescParser2(uint16_t len, uint8_t *pbuf)
Definition: hidescriptorparser.h:165
ReportDescParserBase::varBuffer
uint8_t varBuffer[sizeof(USB_CONFIGURATION_DESCRIPTOR)]
Definition: hidescriptorparser.h:104
ReportDescParserBase::ParseItem
virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn)
Definition: hidescriptorparser.cpp:1091
ReportDescParserBase::simuTitles2
static const char *const simuTitles2[]
Definition: hidescriptorparser.h:55
ReportDescParserBase::sportsCtrlTitles1
static const char *const sportsCtrlTitles1[]
Definition: hidescriptorparser.h:59
ReportDescParserBase::consTitles7
static const char *const consTitles7[]
Definition: hidescriptorparser.h:78
ReportDescParserBase::enErrorIncomplete
@ enErrorIncomplete
Definition: hidescriptorparser.h:140
ReportDescParserBase::telTitles5
static const char *const telTitles5[]
Definition: hidescriptorparser.h:70
ReportDescParserBase::sportsCtrlTitles0
static const char *const sportsCtrlTitles0[]
Definition: hidescriptorparser.h:58
ReportDescParserBase::SetUsagePage
void SetUsagePage(uint16_t page)
Definition: hidescriptorparser.cpp:1236
ReportDescParserBase::consTitles2
static const char *const consTitles2[]
Definition: hidescriptorparser.h:73
MultiValueBuffer::pValue
void * pValue
Definition: parsetools.h:32
MultiValueBuffer
Definition: parsetools.h:30
ReportDescParserBase::consTitles6
static const char *const consTitles6[]
Definition: hidescriptorparser.h:77
USBHID
Definition: usbhid.h:143
ReportDescParserBase::vrTitles1
static const char *const vrTitles1[]
Definition: hidescriptorparser.h:57
ReportDescParserBase::usagePageTitles1
static const char *const usagePageTitles1[]
Definition: hidescriptorparser.h:47
ReportDescParserBase::PrintMedicalInstrumentPageUsage
static void PrintMedicalInstrumentPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1417
ReportDescParserBase::ReportDescParserBase
ReportDescParserBase()
Definition: hidescriptorparser.h:124
ReportDescParserBase::consTitlesD
static const char *const consTitlesD[]
Definition: hidescriptorparser.h:84
ReportDescParserBase::genDevCtrlTitles
static const char *const genDevCtrlTitles[]
Definition: hidescriptorparser.h:63
ReportDescParser2::ParseItem
virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn)
Definition: hidescriptorparser.cpp:1432
ReportDescParserBase::PrintItemTitle
static void PrintItemTitle(uint8_t prefix)
Definition: hidescriptorparser.cpp:1026
ReportDescParserBase::PrintDigitizerPageUsage
static void PrintDigitizerPageUsage(uint16_t usage)
Definition: hidescriptorparser.cpp:1397
MultiByteValueParser
Definition: parsetools.h:40
ReportDescParserBase::medInstrTitles1
static const char *const medInstrTitles1[]
Definition: hidescriptorparser.h:93
ReportDescParserBase::rptSize
uint8_t rptSize
Definition: hidescriptorparser.h:109
ReportDescParserBase::consTitles1
static const char *const consTitles1[]
Definition: hidescriptorparser.h:72
ReportDescParserBase::theSkipper
ByteSkipper theSkipper
Definition: hidescriptorparser.h:103