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 "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/processor/types.h"
25#include "pedigree/kernel/utilities/Vector.h"
26#include "pedigree/kernel/utilities/new"
27
28#include "modules/drivers/common/hid/HidUtils.h"
29
30class EXPORTED_PUBLIC HidReport {
31 public:
32 HidReport();
33 virtual ~HidReport();
34
36 void parseDescriptor(uint8_t* pDescriptor, size_t nDescriptorLength);
37 bool valid() const {
38 return m_Valid;
39 }
40
42 void feedInput(uint8_t* pBuffer, uint8_t* pOldBuffer, size_t nBufferSize);
43
44 private:
46 enum ItemType { MainItem = 0, GlobalItem = 1, LocalItem = 2 };
47
49 enum ItemTag {
50 // Main items tags
51 InputItem = 0x8,
52 OutputItem = 0x9,
53 FeatureItem = 0xb,
54 CollectionItem = 0xa,
55 EndCollectionItem = 0xc,
56
57 // Global items tags
58 UsagePageItem = 0x0,
59 LogMinItem = 0x1,
60 LogMaxItem = 0x2,
61 PhysMinItem = 0x3,
62 PhysMaxItem = 0x4,
63 UnitExpItem = 0x5,
64 UnitItem = 0x6,
65 ReportSizeItem = 0x7,
66 ReportIDItem = 0x8,
67 ReportCountItem = 0x9,
68 PushItem = 0xa,
69 PopItem = 0xb,
70
71 // Local items tags
72 UsageItem = 0x0,
73 UsageMinItem = 0x1,
74 UsageMaxItem = 0x2
75 };
76
78 enum InputItemFlags { InputConstant = 1, InputVariable = 2, InputRelative = 4 };
79
81 struct LocalState {
83 LocalState();
84 virtual ~LocalState();
85
86 // Global values
87 int64_t nUsagePage;
88 int64_t nLogMin;
89 int64_t nLogMax;
90 int64_t nPhysMin;
91 int64_t nPhysMax;
92 int64_t nReportSize;
93 int64_t nReportID;
94 int64_t nReportCount;
95
96 // Local values
97 Vector<size_t>* pUsages;
98 int64_t nUsageMin;
99 int64_t nUsageMax;
100
102 void resetLocalValues();
103
105 uint16_t getUsageByIndex(uint16_t nUsageIndex);
106
108 LocalState& operator=(LocalState& s);
109 void copyGlobals(const LocalState& s);
110 };
111
113 struct InputBlock {
115 void feedInput(uint8_t* pBuffer, uint8_t* pOldBuffer, size_t nBufferSize, size_t& nBitOffset,
116 HidDeviceType deviceType, uint8_t reportId, HidUtils::InputState& inputState);
117
119 enum { Constant, Absolute, Relative, Array } type;
120
123 };
124
126 struct Collection {
127 ~Collection();
128 // Trickery to allow putting different type childs in the same vector
129 enum ChildType { CollectionChild, InputBlockChild };
130 struct Child {
131 inline Child(Collection* pC) : type(CollectionChild), pCollection(pC) {}
132 inline Child(InputBlock* pIB) : type(InputBlockChild), pInputBlock(pIB) {}
133
134 ChildType type;
135 union {
136 Collection* pCollection;
137 InputBlock* pInputBlock;
138 };
139 };
140
143 void feedInput(uint8_t* pBuffer, uint8_t* pOldBuffer, size_t nBufferSize, size_t& nBitOffset,
144 uint8_t reportId, HidUtils::InputState& inputState);
145
148 HidDeviceType guessInputDevice();
149
152
155
158 };
159
162 size_t m_ReportBits[256];
163 uint8_t* m_OldReports[256];
164 HidUtils::InputState* m_InputStates[256];
165 bool m_HasReportIds;
166 bool m_Valid;
167};
168
169#endif
InputItemFlags
Input item flags.
Definition HidReport.h:78
ItemType
The HID item types.
Definition HidReport.h:46
ItemTag
The HID item tags.
Definition HidReport.h:49
Collection * m_pRootCollection
The root collection, under which everything is.
Definition HidReport.h:161
Held input belongs to a report instance and is retired with that instance.
Definition HidUtils.h:32
A vector / dynamic array.
Definition Vector.h:33
Structure representing a Collection whitin a report.
Definition HidReport.h:126
LocalState state
The local state of the collection.
Definition HidReport.h:157
Collection * pParent
Our parent.
Definition HidReport.h:154
Vector< Child * > childs
All the childs in this collection.
Definition HidReport.h:151
Structure representing an Input block whitin a Collection.
Definition HidReport.h:113
LocalState state
The local state of the input block.
Definition HidReport.h:122
Structure holding various global and local values for a Main item.
Definition HidReport.h:81