USB Host Shield 2.0
Loading...
Searching...
No Matches
hiduniversal.cpp
Go to the documentation of this file.
1/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2
3This software may be distributed and modified under the terms of the GNU
4General Public License version 2 (GPL2) as published by the Free Software
5Foundation and appearing in the file GPL2.TXT included in the packaging of
6this file. Please note that GPL2 Section 2[b] requires that all works based
7on this software must also be made publicly available under the terms of
8the GPL2 ("Copyleft").
9
10Contact information
11-------------------
12
13Circuits At Home, LTD
14Web : http://www.circuitsathome.com
15e-mail : support@circuitsathome.com
16 */
17
18#include "hiduniversal.h"
19
21 uint8_t rcode = 0;
22
23 if(!bPollEnable)
24 return 0;
25
26 if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) {
28
30
31 for(uint8_t i = 0; i < bNumIface; i++) {
33 uint16_t read = (uint16_t)epInfo[index].maxPktSize;
34
36
37 uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[index].epAddr, &read, buf);
38
39 if(rcode) {
40 if(rcode != hrNAK)
41 USBTRACE3("(hiduniversal.h) Poll:", rcode, 0x81);
42 return rcode;
43 }
44
45 if(read > constBuffLen)
46 read = constBuffLen;
47
48 // TODO: handle read == 0 ? continue like HIDComposite,
49 // return early like in the error case above?
50 // Either way passing an empty buffer to the functions below
51 // probably makes no sense?
52
53#if 0
54 Notify(PSTR("\r\nBuf: "), 0x80);
55
56 for(uint8_t i = 0; i < read; i++) {
57 D_PrintHex<uint8_t > (buf[i], 0x80);
58 Notify(PSTR(" "), 0x80);
59 }
60
61 Notify(PSTR("\r\n"), 0x80);
62#endif
63 ParseHIDData(this, bHasReportId, (uint8_t)read, buf);
64
66
67 if(prs)
68 prs->Parse(this, bHasReportId, (uint8_t)read, buf);
69 }
70 }
71 return rcode;
72}
void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset)
uint32_t qNextPollTime
HIDReportParser * GetReportParser(uint8_t id)
static const uint16_t constBuffLen
HIDInterface hidInterfaces[maxHidInterfaces]
EpInfo epInfo[totalEndpoints]
void ZeroMemory(uint8_t len, uint8_t *buf)
uint8_t bNumIface
uint8_t pollInterval
uint8_t Poll() override
uint8_t bAddress
Definition usbhid.h:146
static const uint8_t epInterruptInIndex
Definition usbhid.h:149
USB * pUsb
Definition usbhid.h:145
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
Definition Usb.cpp:209
#define USBTRACE3(s, r, l)
Definition macros.h:85
#define hrNAK
Definition max3421e.h:218
#define Notify(...)
Definition message.h:51
uint8_t epIndex[maxEpPerInterface+1]
#define PSTR(str)