Skip to content

Commit a0d8aa0

Browse files
authored
Merge pull request #1024 from nbriggs/issue_1015_big-endian-LP64
2 parents 294b833 + 1db2eec commit a0d8aa0

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

drivers/hidparser.c

+6-17
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef struct {
4141

4242
uint16_t Pos; /* Store current pos in descriptor */
4343
uint8_t Item; /* Store current Item */
44-
long Value; /* Store current Value */
44+
uint32_t Value; /* Store current Value */
4545

4646
HIDData_t Data; /* Store current environment */
4747

@@ -121,10 +121,10 @@ static uint8_t *GetReportOffset(HIDParser_t* pParser, const uint8_t ReportID, co
121121
}
122122

123123
/*
124-
* FormatValue(long Value, uint8_t Size)
124+
* FormatValue(uint32_t Value, uint8_t Size)
125125
* Format Value to fit with long format with respect of negative values
126126
* -------------------------------------------------------------------------- */
127-
static long FormatValue(long Value, uint8_t Size)
127+
static long FormatValue(uint32_t Value, uint8_t Size)
128128
{
129129
switch(Size)
130130
{
@@ -150,27 +150,16 @@ static long FormatValue(long Value, uint8_t Size)
150150
* -------------------------------------------------------------------------- */
151151
static int HIDParse(HIDParser_t *pParser, HIDData_t *pData)
152152
{
153-
int Found = -1;
153+
int Found = -1, i;
154154

155155
while ((Found < 0) && (pParser->Pos < pParser->ReportDescSize)) {
156156
/* Get new pParser->Item if current pParser->Count is empty */
157157
if (pParser->Count == 0) {
158158
pParser->Item = pParser->ReportDesc[pParser->Pos++];
159159
pParser->Value = 0;
160-
#if (defined (WORDS_BIGENDIAN)) && (WORDS_BIGENDIAN)
161-
{
162-
int i;
163-
unsigned long valTmp = 0;
164-
165-
for (i = 0; i < ItemSize[pParser->Item & SIZE_MASK]; i++) {
166-
memcpy(&valTmp, &pParser->ReportDesc[(pParser->Pos)+i], 1);
167-
pParser->Value += valTmp >> ((3-i)*8);
168-
valTmp = 0;
169-
}
160+
for (i = 0; i < ItemSize[pParser->Item & SIZE_MASK]; i++) {
161+
pParser->Value += pParser->ReportDesc[(pParser->Pos)+i] << (8*i);
170162
}
171-
#else
172-
memcpy(&pParser->Value, &pParser->ReportDesc[pParser->Pos], ItemSize[pParser->Item & SIZE_MASK]);
173-
#endif
174163
/* Pos on next item */
175164
pParser->Pos += ItemSize[pParser->Item & SIZE_MASK];
176165
}

0 commit comments

Comments
 (0)