forked from felis/USB_Host_Shield_2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hiduniversal.cpp
72 lines (53 loc) · 2.58 KB
/
hiduniversal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Circuits At Home, LTD
Web : http://www.circuitsathome.com
e-mail : [email protected]
*/
#include "hiduniversal.h"
uint8_t HIDUniversal::Poll() {
uint8_t rcode = 0;
if(!bPollEnable)
return 0;
if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) {
qNextPollTime = (uint32_t)millis() + pollInterval;
uint8_t buf[constBuffLen];
for(uint8_t i = 0; i < bNumIface; i++) {
uint8_t index = hidInterfaces[i].epIndex[epInterruptInIndex];
uint16_t read = (uint16_t)epInfo[index].maxPktSize;
ZeroMemory(constBuffLen, buf);
uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[index].epAddr, &read, buf);
if(rcode) {
if(rcode != hrNAK)
USBTRACE3("(hiduniversal.h) Poll:", rcode, 0x81);
return rcode;
}
if(read > constBuffLen)
read = constBuffLen;
// TODO: handle read == 0 ? continue like HIDComposite,
// return early like in the error case above?
// Either way passing an empty buffer to the functions below
// probably makes no sense?
#if 0
Notify(PSTR("\r\nBuf: "), 0x80);
for(uint8_t i = 0; i < read; i++) {
D_PrintHex<uint8_t > (buf[i], 0x80);
Notify(PSTR(" "), 0x80);
}
Notify(PSTR("\r\n"), 0x80);
#endif
ParseHIDData(this, bHasReportId, (uint8_t)read, buf);
HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0));
if(prs)
prs->Parse(this, bHasReportId, (uint8_t)read, buf);
}
}
return rcode;
}