Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UsbHostMAX3421E_Hello
hidescriptorparser.h@1:2263e77400e9, 2020-07-13 (annotated)
- Committer:
- hudakz
- Date:
- Mon Jul 13 07:03:06 2020 +0000
- Revision:
- 1:2263e77400e9
- Parent:
- 0:84353c479782
MAX3421E-based USB Host Shield Library
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| hudakz | 0:84353c479782 | 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. |
| hudakz | 0:84353c479782 | 2 | |
| hudakz | 0:84353c479782 | 3 | This software may be distributed and modified under the terms of the GNU |
| hudakz | 0:84353c479782 | 4 | General Public License version 2 (GPL2) as published by the Free Software |
| hudakz | 0:84353c479782 | 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of |
| hudakz | 0:84353c479782 | 6 | this file. Please note that GPL2 Section 2[b] requires that all works based |
| hudakz | 0:84353c479782 | 7 | on this software must also be made publicly available under the terms of |
| hudakz | 0:84353c479782 | 8 | the GPL2 ("Copyleft"). |
| hudakz | 0:84353c479782 | 9 | |
| hudakz | 0:84353c479782 | 10 | Contact information |
| hudakz | 0:84353c479782 | 11 | ------------------- |
| hudakz | 0:84353c479782 | 12 | |
| hudakz | 0:84353c479782 | 13 | Circuits At Home, LTD |
| hudakz | 0:84353c479782 | 14 | Web : http://www.circuitsathome.com |
| hudakz | 0:84353c479782 | 15 | e-mail : support@circuitsathome.com |
| hudakz | 0:84353c479782 | 16 | */ |
| hudakz | 0:84353c479782 | 17 | #if !defined(__HIDDESCRIPTORPARSER_H__) |
| hudakz | 0:84353c479782 | 18 | #define __HIDDESCRIPTORPARSER_H__ |
| hudakz | 0:84353c479782 | 19 | |
| hudakz | 0:84353c479782 | 20 | #include "usbhid.h" |
| hudakz | 0:84353c479782 | 21 | |
| hudakz | 0:84353c479782 | 22 | class ReportDescParserBase : public USBReadParser { |
| hudakz | 0:84353c479782 | 23 | public: |
| hudakz | 0:84353c479782 | 24 | typedef void (*UsagePageFunc)(uint16_t usage); |
| hudakz | 0:84353c479782 | 25 | |
| hudakz | 0:84353c479782 | 26 | static void PrintGenericDesktopPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 27 | static void PrintSimulationControlsPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 28 | static void PrintVRControlsPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 29 | static void PrintSportsControlsPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 30 | static void PrintGameControlsPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 31 | static void PrintGenericDeviceControlsPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 32 | static void PrintLEDPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 33 | static void PrintButtonPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 34 | static void PrintOrdinalPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 35 | static void PrintTelephonyPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 36 | static void PrintConsumerPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 37 | static void PrintDigitizerPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 38 | static void PrintAlphanumDisplayPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 39 | static void PrintMedicalInstrumentPageUsage(uint16_t usage); |
| hudakz | 0:84353c479782 | 40 | |
| hudakz | 0:84353c479782 | 41 | static void PrintValue(uint8_t *p, uint8_t len); |
| hudakz | 0:84353c479782 | 42 | static void PrintByteValue(uint8_t data); |
| hudakz | 0:84353c479782 | 43 | |
| hudakz | 0:84353c479782 | 44 | static void PrintItemTitle(uint8_t prefix); |
| hudakz | 0:84353c479782 | 45 | |
| hudakz | 0:84353c479782 | 46 | static const char * const usagePageTitles0[]; |
| hudakz | 0:84353c479782 | 47 | static const char * const usagePageTitles1[]; |
| hudakz | 0:84353c479782 | 48 | static const char * const genDesktopTitles0[]; |
| hudakz | 0:84353c479782 | 49 | static const char * const genDesktopTitles1[]; |
| hudakz | 0:84353c479782 | 50 | static const char * const genDesktopTitles2[]; |
| hudakz | 0:84353c479782 | 51 | static const char * const genDesktopTitles3[]; |
| hudakz | 0:84353c479782 | 52 | static const char * const genDesktopTitles4[]; |
| hudakz | 0:84353c479782 | 53 | static const char * const simuTitles0[]; |
| hudakz | 0:84353c479782 | 54 | static const char * const simuTitles1[]; |
| hudakz | 0:84353c479782 | 55 | static const char * const simuTitles2[]; |
| hudakz | 0:84353c479782 | 56 | static const char * const vrTitles0[]; |
| hudakz | 0:84353c479782 | 57 | static const char * const vrTitles1[]; |
| hudakz | 0:84353c479782 | 58 | static const char * const sportsCtrlTitles0[]; |
| hudakz | 0:84353c479782 | 59 | static const char * const sportsCtrlTitles1[]; |
| hudakz | 0:84353c479782 | 60 | static const char * const sportsCtrlTitles2[]; |
| hudakz | 0:84353c479782 | 61 | static const char * const gameTitles0[]; |
| hudakz | 0:84353c479782 | 62 | static const char * const gameTitles1[]; |
| hudakz | 0:84353c479782 | 63 | static const char * const genDevCtrlTitles[]; |
| hudakz | 0:84353c479782 | 64 | static const char * const ledTitles[]; |
| hudakz | 0:84353c479782 | 65 | static const char * const telTitles0[]; |
| hudakz | 0:84353c479782 | 66 | static const char * const telTitles1[]; |
| hudakz | 0:84353c479782 | 67 | static const char * const telTitles2[]; |
| hudakz | 0:84353c479782 | 68 | static const char * const telTitles3[]; |
| hudakz | 0:84353c479782 | 69 | static const char * const telTitles4[]; |
| hudakz | 0:84353c479782 | 70 | static const char * const telTitles5[]; |
| hudakz | 0:84353c479782 | 71 | static const char * const consTitles0[]; |
| hudakz | 0:84353c479782 | 72 | static const char * const consTitles1[]; |
| hudakz | 0:84353c479782 | 73 | static const char * const consTitles2[]; |
| hudakz | 0:84353c479782 | 74 | static const char * const consTitles3[]; |
| hudakz | 0:84353c479782 | 75 | static const char * const consTitles4[]; |
| hudakz | 0:84353c479782 | 76 | static const char * const consTitles5[]; |
| hudakz | 0:84353c479782 | 77 | static const char * const consTitles6[]; |
| hudakz | 0:84353c479782 | 78 | static const char * const consTitles7[]; |
| hudakz | 0:84353c479782 | 79 | static const char * const consTitles8[]; |
| hudakz | 0:84353c479782 | 80 | static const char * const consTitles9[]; |
| hudakz | 0:84353c479782 | 81 | static const char * const consTitlesA[]; |
| hudakz | 0:84353c479782 | 82 | static const char * const consTitlesB[]; |
| hudakz | 0:84353c479782 | 83 | static const char * const consTitlesC[]; |
| hudakz | 0:84353c479782 | 84 | static const char * const consTitlesD[]; |
| hudakz | 0:84353c479782 | 85 | static const char * const consTitlesE[]; |
| hudakz | 0:84353c479782 | 86 | static const char * const digitTitles0[]; |
| hudakz | 0:84353c479782 | 87 | static const char * const digitTitles1[]; |
| hudakz | 0:84353c479782 | 88 | static const char * const digitTitles2[]; |
| hudakz | 0:84353c479782 | 89 | static const char * const aplphanumTitles0[]; |
| hudakz | 0:84353c479782 | 90 | static const char * const aplphanumTitles1[]; |
| hudakz | 0:84353c479782 | 91 | static const char * const aplphanumTitles2[]; |
| hudakz | 0:84353c479782 | 92 | static const char * const medInstrTitles0[]; |
| hudakz | 0:84353c479782 | 93 | static const char * const medInstrTitles1[]; |
| hudakz | 0:84353c479782 | 94 | static const char * const medInstrTitles2[]; |
| hudakz | 0:84353c479782 | 95 | static const char * const medInstrTitles3[]; |
| hudakz | 0:84353c479782 | 96 | static const char * const medInstrTitles4[]; |
| hudakz | 0:84353c479782 | 97 | |
| hudakz | 0:84353c479782 | 98 | protected: |
| hudakz | 0:84353c479782 | 99 | static UsagePageFunc usagePageFunctions[]; |
| hudakz | 0:84353c479782 | 100 | |
| hudakz | 0:84353c479782 | 101 | MultiValueBuffer theBuffer; |
| hudakz | 0:84353c479782 | 102 | MultiByteValueParser valParser; |
| hudakz | 0:84353c479782 | 103 | ByteSkipper theSkipper; |
| hudakz | 0:84353c479782 | 104 | uint8_t varBuffer[sizeof (USB_CONFIGURATION_DESCRIPTOR)]; |
| hudakz | 0:84353c479782 | 105 | |
| hudakz | 0:84353c479782 | 106 | uint8_t itemParseState; // Item parser state variable |
| hudakz | 0:84353c479782 | 107 | uint8_t itemSize; // Item size |
| hudakz | 0:84353c479782 | 108 | uint8_t itemPrefix; // Item prefix (first byte) |
| hudakz | 0:84353c479782 | 109 | uint8_t rptSize; // Report Size |
| hudakz | 0:84353c479782 | 110 | uint8_t rptCount; // Report Count |
| hudakz | 0:84353c479782 | 111 | |
| hudakz | 0:84353c479782 | 112 | uint16_t totalSize; // Report size in bits |
| hudakz | 0:84353c479782 | 113 | |
| hudakz | 0:84353c479782 | 114 | // Method should be defined here if virtual. |
| hudakz | 0:84353c479782 | 115 | virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn); |
| hudakz | 0:84353c479782 | 116 | |
| hudakz | 0:84353c479782 | 117 | UsagePageFunc pfUsage; |
| hudakz | 0:84353c479782 | 118 | |
| hudakz | 0:84353c479782 | 119 | static void PrintUsagePage(uint16_t page); |
| hudakz | 0:84353c479782 | 120 | void SetUsagePage(uint16_t page); |
| hudakz | 0:84353c479782 | 121 | |
| hudakz | 0:84353c479782 | 122 | public: |
| hudakz | 0:84353c479782 | 123 | |
| hudakz | 0:84353c479782 | 124 | ReportDescParserBase() : |
| hudakz | 0:84353c479782 | 125 | itemParseState(0), |
| hudakz | 0:84353c479782 | 126 | itemSize(0), |
| hudakz | 0:84353c479782 | 127 | itemPrefix(0), |
| hudakz | 0:84353c479782 | 128 | rptSize(0), |
| hudakz | 0:84353c479782 | 129 | rptCount(0), |
| hudakz | 0:84353c479782 | 130 | pfUsage(NULL) { |
| hudakz | 0:84353c479782 | 131 | theBuffer.pValue = varBuffer; |
| hudakz | 0:84353c479782 | 132 | valParser.Initialize(&theBuffer); |
| hudakz | 0:84353c479782 | 133 | theSkipper.Initialize(&theBuffer); |
| hudakz | 0:84353c479782 | 134 | }; |
| hudakz | 0:84353c479782 | 135 | |
| hudakz | 0:84353c479782 | 136 | void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset); |
| hudakz | 0:84353c479782 | 137 | |
| hudakz | 0:84353c479782 | 138 | enum { |
| hudakz | 0:84353c479782 | 139 | enErrorSuccess = 0 |
| hudakz | 0:84353c479782 | 140 | , enErrorIncomplete // value or record is partialy read in buffer |
| hudakz | 0:84353c479782 | 141 | , enErrorBufferTooSmall |
| hudakz | 0:84353c479782 | 142 | }; |
| hudakz | 0:84353c479782 | 143 | }; |
| hudakz | 0:84353c479782 | 144 | |
| hudakz | 0:84353c479782 | 145 | class ReportDescParser : public ReportDescParserBase { |
| hudakz | 0:84353c479782 | 146 | }; |
| hudakz | 0:84353c479782 | 147 | |
| hudakz | 0:84353c479782 | 148 | class ReportDescParser2 : public ReportDescParserBase { |
| hudakz | 0:84353c479782 | 149 | uint8_t rptId; // Report ID |
| hudakz | 0:84353c479782 | 150 | uint8_t useMin; // Usage Minimum |
| hudakz | 0:84353c479782 | 151 | uint8_t useMax; // Usage Maximum |
| hudakz | 0:84353c479782 | 152 | uint8_t fieldCount; // Number of field being currently processed |
| hudakz | 0:84353c479782 | 153 | |
| hudakz | 0:84353c479782 | 154 | void OnInputItem(uint8_t itm); // Method which is called every time Input item is found |
| hudakz | 0:84353c479782 | 155 | |
| hudakz | 0:84353c479782 | 156 | uint8_t *pBuf; // Report buffer pointer |
| hudakz | 0:84353c479782 | 157 | uint8_t bLen; // Report length |
| hudakz | 0:84353c479782 | 158 | |
| hudakz | 0:84353c479782 | 159 | protected: |
| hudakz | 0:84353c479782 | 160 | // Method should be defined here if virtual. |
| hudakz | 0:84353c479782 | 161 | virtual uint8_t ParseItem(uint8_t **pp, uint16_t *pcntdn); |
| hudakz | 0:84353c479782 | 162 | |
| hudakz | 0:84353c479782 | 163 | public: |
| hudakz | 0:84353c479782 | 164 | |
| hudakz | 0:84353c479782 | 165 | ReportDescParser2(uint16_t len, uint8_t *pbuf) : |
| hudakz | 0:84353c479782 | 166 | ReportDescParserBase(), rptId(0), useMin(0), useMax(0), fieldCount(0), pBuf(pbuf), bLen(len) { |
| hudakz | 0:84353c479782 | 167 | }; |
| hudakz | 0:84353c479782 | 168 | }; |
| hudakz | 0:84353c479782 | 169 | |
| hudakz | 0:84353c479782 | 170 | class UniversalReportParser : public HIDReportParser { |
| hudakz | 0:84353c479782 | 171 | public: |
| hudakz | 0:84353c479782 | 172 | // Method should be defined here if virtual. |
| hudakz | 0:84353c479782 | 173 | virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); |
| hudakz | 0:84353c479782 | 174 | }; |
| hudakz | 0:84353c479782 | 175 | |
| hudakz | 0:84353c479782 | 176 | #endif // __HIDDESCRIPTORPARSER_H__ |