Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hidescriptorparser.h Source File

hidescriptorparser.h

00001 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
00002 
00003 This software may be distributed and modified under the terms of the GNU
00004 General Public License version 2 (GPL2) as published by the Free Software
00005 Foundation and appearing in the file GPL2.TXT included in the packaging of
00006 this file. Please note that GPL2 Section 2[b] requires that all works based
00007 on this software must also be made publicly available under the terms of
00008 the GPL2 ("Copyleft").
00009 
00010 Contact information
00011 -------------------
00012 
00013 Circuits At Home, LTD
00014 Web      :  http://www.circuitsathome.com
00015 e-mail   :  support@circuitsathome.com
00016  */
00017 #if !defined(__HIDDESCRIPTORPARSER_H__)
00018 #define __HIDDESCRIPTORPARSER_H__
00019 
00020 #include "usbhid.h"
00021 
00022 class ReportDescParserBase : public USBReadParser {
00023 public:
00024         typedef void (*UsagePageFunc)(uint16_t usage);
00025 
00026         static void PrintGenericDesktopPageUsage(uint16_t usage);
00027         static void PrintSimulationControlsPageUsage(uint16_t usage);
00028         static void PrintVRControlsPageUsage(uint16_t usage);
00029         static void PrintSportsControlsPageUsage(uint16_t usage);
00030         static void PrintGameControlsPageUsage(uint16_t usage);
00031         static void PrintGenericDeviceControlsPageUsage(uint16_t usage);
00032         static void PrintLEDPageUsage(uint16_t usage);
00033         static void PrintButtonPageUsage(uint16_t usage);
00034         static void PrintOrdinalPageUsage(uint16_t usage);
00035         static void PrintTelephonyPageUsage(uint16_t usage);
00036         static void PrintConsumerPageUsage(uint16_t usage);
00037         static void PrintDigitizerPageUsage(uint16_t usage);
00038         static void PrintAlphanumDisplayPageUsage(uint16_t usage);
00039         static void PrintMedicalInstrumentPageUsage(uint16_t usage);
00040 
00041         static void PrintValue(uint8_t *p, uint8_t len);
00042         static void PrintByteValue(uint8_t data);
00043 
00044         static void PrintItemTitle(uint8_t prefix);
00045 
00046         static const char * const usagePageTitles0[];
00047         static const char * const usagePageTitles1[];
00048         static const char * const genDesktopTitles0[];
00049         static const char * const genDesktopTitles1[];
00050         static const char * const genDesktopTitles2[];
00051         static const char * const genDesktopTitles3[];
00052         static const char * const genDesktopTitles4[];
00053         static const char * const simuTitles0[];
00054         static const char * const simuTitles1[];
00055         static const char * const simuTitles2[];
00056         static const char * const vrTitles0[];
00057         static const char * const vrTitles1[];
00058         static const char * const sportsCtrlTitles0[];
00059         static const char * const sportsCtrlTitles1[];
00060         static const char * const sportsCtrlTitles2[];
00061         static const char * const gameTitles0[];
00062         static const char * const gameTitles1[];
00063         static const char * const genDevCtrlTitles[];
00064         static const char * const ledTitles[];
00065         static const char * const telTitles0[];
00066         static const char * const telTitles1[];
00067         static const char * const telTitles2[];
00068         static const char * const telTitles3[];
00069         static const char * const telTitles4[];
00070         static const char * const telTitles5[];
00071         static const char * const consTitles0[];
00072         static const char * const consTitles1[];
00073         static const char * const consTitles2[];
00074         static const char * const consTitles3[];
00075         static const char * const consTitles4[];
00076         static const char * const consTitles5[];
00077         static const char * const consTitles6[];
00078         static const char * const consTitles7[];
00079         static const char * const consTitles8[];
00080         static const char * const consTitles9[];
00081         static const char * const consTitlesA[];
00082         static const char * const consTitlesB[];
00083         static const char * const consTitlesC[];
00084         static const char * const consTitlesD[];
00085         static const char * const consTitlesE[];
00086         static const char * const digitTitles0[];
00087         static const char * const digitTitles1[];
00088         static const char * const digitTitles2[];
00089         static const char * const aplphanumTitles0[];
00090         static const char * const aplphanumTitles1[];
00091         static const char * const aplphanumTitles2[];
00092         static const char * const medInstrTitles0[];
00093         static const char * const medInstrTitles1[];
00094         static const char * const medInstrTitles2[];
00095         static const char * const medInstrTitles3[];
00096         static const char * const medInstrTitles4[];
00097 
00098 protected:
00099         static UsagePageFunc usagePageFunctions[];
00100 
00101         MultiValueBuffer theBuffer;
00102         MultiByteValueParser valParser;
00103         ByteSkipper theSkipper;
00104         uint8_t varBuffer[sizeof (USB_CONFIGURATION_DESCRIPTOR)];
00105 
00106         uint8_t itemParseState; // Item parser state variable
00107         uint8_t itemSize; // Item size
00108         uint8_t itemPrefix; // Item prefix (first byte)
00109         uint8_t rptSize; // Report Size
00110         uint8_t rptCount; // Report Count
00111 
00112         uint16_t totalSize; // Report size in bits
00113 
00114         // Method should be defined here if virtual.
00115         virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn);
00116 
00117         UsagePageFunc pfUsage;
00118 
00119         static void PrintUsagePage(uint16_t page);
00120         void SetUsagePage(uint16_t page);
00121 
00122 public:
00123 
00124         ReportDescParserBase() :
00125         itemParseState(0),
00126         itemSize(0),
00127         itemPrefix(0),
00128         rptSize(0),
00129         rptCount(0),
00130         pfUsage(NULL) {
00131                 theBuffer.pValue = varBuffer;
00132                 valParser.Initialize(&theBuffer);
00133                 theSkipper.Initialize(&theBuffer);
00134         };
00135 
00136         void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset);
00137 
00138         enum {
00139                 enErrorSuccess = 0
00140                 , enErrorIncomplete // value or record is partialy read in buffer
00141                 , enErrorBufferTooSmall
00142         };
00143 };
00144 
00145 class ReportDescParser : public ReportDescParserBase {
00146 };
00147 
00148 class ReportDescParser2 : public ReportDescParserBase {
00149         uint8_t rptId; // Report ID
00150         uint8_t useMin; // Usage Minimum
00151         uint8_t useMax; // Usage Maximum
00152         uint8_t fieldCount; // Number of field being currently processed
00153 
00154         void OnInputItem(uint8_t itm); // Method which is called every time Input item is found
00155 
00156         uint8_t *pBuf; // Report buffer pointer
00157         uint8_t bLen; // Report length
00158 
00159 protected:
00160         // Method should be defined here if virtual.
00161         virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn);
00162 
00163 public:
00164 
00165         ReportDescParser2(uint16_t len, uint8_t *pbuf) :
00166         ReportDescParserBase(), rptId(0), useMin(0), useMax(0), fieldCount(0), pBuf(pbuf), bLen(len) {
00167         };
00168 };
00169 
00170 class UniversalReportParser : public HIDReportParser {
00171 public:
00172         // Method should be defined here if virtual.
00173         virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
00174 };
00175 
00176 #endif // __HIDDESCRIPTORPARSER_H__