The Pedigree Project  0.1
HidReport.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef HIDREPORT_H
21 #define HIDREPORT_H
22 
23 #include "modules/drivers/common/hid/HidUtils.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/utilities/Vector.h"
27 #include "pedigree/kernel/utilities/new"
28 
30 {
31  public:
32  HidReport();
33  virtual ~HidReport();
34 
36  void parseDescriptor(uint8_t *pDescriptor, size_t nDescriptorLength);
37 
39  void feedInput(uint8_t *pBuffer, uint8_t *pOldBuffer, size_t nBufferSize);
40 
41  private:
43  enum ItemType
44  {
45  MainItem = 0,
46  GlobalItem = 1,
47  LocalItem = 2
48  };
49 
51  enum ItemTag
52  {
53  // Main items tags
54  InputItem = 0x8,
55  OutputItem = 0x9,
56  FeatureItem = 0xb,
57  CollectionItem = 0xa,
58  EndCollectionItem = 0xc,
59 
60  // Global items tags
61  UsagePageItem = 0x0,
62  LogMinItem = 0x1,
63  LogMaxItem = 0x2,
64  PhysMinItem = 0x3,
65  PhysMaxItem = 0x4,
66  UnitExpItem = 0x5,
67  UnitItem = 0x6,
68  ReportSizeItem = 0x7,
69  ReportIDItem = 0x8,
70  ReportCountItem = 0x9,
71  PushItem = 0xa,
72  PopItem = 0xb,
73 
74  // Local items tags
75  UsageItem = 0x0,
76  UsageMinItem = 0x1,
77  UsageMaxItem = 0x2
78  };
79 
82  {
83  InputConstant = 1,
84  InputVariable = 2,
85  InputRelative = 4
86  };
87 
89  struct LocalState
90  {
92  LocalState();
93  virtual ~LocalState();
94 
95  // Global values
96  int64_t nUsagePage;
97  int64_t nLogMin;
98  int64_t nLogMax;
99  int64_t nPhysMin;
100  int64_t nPhysMax;
101  int64_t nReportSize;
102  int64_t nReportID;
103  int64_t nReportCount;
104 
105  // Local values
106  Vector<size_t> *pUsages;
107  int64_t nUsageMin;
108  int64_t nUsageMax;
109 
111  void resetLocalValues();
112 
114  uint16_t getUsageByIndex(uint16_t nUsageIndex);
115 
117  LocalState &operator=(LocalState &s);
118  };
119 
121  struct InputBlock
122  {
124  void feedInput(
125  uint8_t *pBuffer, uint8_t *pOldBuffer, size_t nBufferSize,
126  size_t &nBitOffset, HidDeviceType deviceType);
127 
129  enum
130  {
131  Constant,
132  Absolute,
133  Relative,
134  Array
135  } type;
136 
139  };
140 
142  struct Collection
143  {
144  // Trickery to allow putting different type childs in the same vector
145  enum ChildType
146  {
147  CollectionChild,
148  InputBlockChild
149  };
150  struct Child
151  {
152  inline Child(Collection *pC)
153  : type(CollectionChild), pCollection(pC)
154  {
155  }
156  inline Child(InputBlock *pIB)
157  : type(InputBlockChild), pInputBlock(pIB)
158  {
159  }
160 
161  ChildType type;
162  union
163  {
164  Collection *pCollection;
165  InputBlock *pInputBlock;
166  };
167  };
168 
171  void feedInput(
172  uint8_t *pBuffer, uint8_t *pOldBuffer, size_t nBufferSize,
173  size_t &nBitOffset);
174 
177  HidDeviceType guessInputDevice();
178 
181 
184 
187  };
188 
191 };
192 
193 #endif
LocalState state
The local state of the input block.
Definition: HidReport.h:138
Collection * m_pRootCollection
The root collection, under which everything is.
Definition: HidReport.h:190
Structure representing a Collection whitin a report.
Definition: HidReport.h:142
ItemType
The HID item types.
Definition: HidReport.h:43
Structure representing an Input block whitin a Collection.
Definition: HidReport.h:121
Collection * pParent
Our parent.
Definition: HidReport.h:183
Structure holding various global and local values for a Main item.
Definition: HidReport.h:89
LocalState state
The local state of the collection.
Definition: HidReport.h:186
InputItemFlags
Input item flags.
Definition: HidReport.h:81
ItemTag
The HID item tags.
Definition: HidReport.h:51
Vector< Child * > childs
All the childs in this collection.
Definition: HidReport.h:180