1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
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
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
17 #if !defined(__HIDDESCRIPTORPARSER_H__)
18 #define __HIDDESCRIPTORPARSER_H__
22 class ReportDescParserBase
: public USBReadParser
{
24 typedef void (*UsagePageFunc
)(uint16_t usage
);
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
);
41 static void PrintValue(uint8_t *p
, uint8_t len
);
42 static void PrintByteValue(uint8_t data
);
44 static void PrintItemTitle(uint8_t prefix
);
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
[];
99 static UsagePageFunc usagePageFunctions
[];
101 MultiValueBuffer theBuffer
;
102 MultiByteValueParser valParser
;
103 ByteSkipper theSkipper
;
104 uint8_t varBuffer
[sizeof (USB_CONFIGURATION_DESCRIPTOR
)];
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
112 uint16_t totalSize
; // Report size in bits
114 // Method should be defined here if virtual.
115 virtual uint8_t ParseItem(uint8_t **pp
, uint16_t *pcntdn
);
117 UsagePageFunc pfUsage
;
119 static void PrintUsagePage(uint16_t page
);
120 void SetUsagePage(uint16_t page
);
124 ReportDescParserBase() :
131 theBuffer
.pValue
= varBuffer
;
132 valParser
.Initialize(&theBuffer
);
133 theSkipper
.Initialize(&theBuffer
);
136 void Parse(const uint16_t len
, const uint8_t *pbuf
, const uint16_t &offset
);
140 , enErrorIncomplete
// value or record is partialy read in buffer
141 , enErrorBufferTooSmall
145 class ReportDescParser
: public ReportDescParserBase
{
148 class ReportDescParser2
: public ReportDescParserBase
{
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
154 void OnInputItem(uint8_t itm
); // Method which is called every time Input item is found
156 uint8_t *pBuf
; // Report buffer pointer
157 uint8_t bLen
; // Report length
160 // Method should be defined here if virtual.
161 virtual uint8_t ParseItem(uint8_t **pp
, uint16_t *pcntdn
);
165 ReportDescParser2(uint16_t len
, uint8_t *pbuf
) :
166 ReportDescParserBase(), rptId(0), useMin(0), useMax(0), fieldCount(0), pBuf(pbuf
), bLen(len
) {
170 class UniversalReportParser
: public HIDReportParser
{
172 // Method should be defined here if virtual.
173 virtual void Parse(HID
*hid
, bool is_rpt_id
, uint8_t len
, uint8_t *buf
);
176 #endif // __HIDDESCRIPTORPARSER_H__