USB Host Shield 2.0
hiduniversal.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2 
3 This software may be distributed and modified under the terms of the GNU
4 General Public License version 2 (GPL2) as published by the Free Software
5 Foundation and appearing in the file GPL2.TXT included in the packaging of
6 this file. Please note that GPL2 Section 2[b] requires that all works based
7 on this software must also be made publicly available under the terms of
8 the GPL2 ("Copyleft").
9 
10 Contact information
11 -------------------
12 
13 Circuits At Home, LTD
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
16  */
17 
18 #include "hiduniversal.h"
19 
20 uint8_t HIDUniversal::Poll() {
21  uint8_t rcode = 0;
22 
23  if(!bPollEnable)
24  return 0;
25 
26  if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) {
27  qNextPollTime = (uint32_t)millis() + pollInterval;
28 
29  uint8_t buf[constBuffLen];
30 
31  for(uint8_t i = 0; i < bNumIface; i++) {
32  uint8_t index = hidInterfaces[i].epIndex[epInterruptInIndex];
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 
65  HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0));
66 
67  if(prs)
68  prs->Parse(this, bHasReportId, (uint8_t)read, buf);
69  }
70  }
71  return rcode;
72 }
hrNAK
#define hrNAK
Definition: max3421e.h:218
HIDComposite::GetReportParser
HIDReportParser * GetReportParser(uint8_t id)
Definition: hidcomposite.cpp:83
USBHID::bAddress
uint8_t bAddress
Definition: usbhid.h:146
HIDComposite::bNumIface
uint8_t bNumIface
Definition: hidcomposite.h:49
HIDComposite::HIDInterface::epIndex
uint8_t epIndex[maxEpPerInterface+1]
Definition: hidcomposite.h:45
hiduniversal.h
USBTRACE3
#define USBTRACE3(s, r, l)
Definition: macros.h:85
USBHID::epInterruptInIndex
static const uint8_t epInterruptInIndex
Definition: usbhid.h:149
Notify
#define Notify(...)
Definition: message.h:51
HIDComposite::pollInterval
uint8_t pollInterval
Definition: hidcomposite.h:52
HIDReportParser
Definition: usbhid.h:138
HIDComposite::bPollEnable
bool bPollEnable
Definition: hidcomposite.h:53
HIDComposite::ZeroMemory
void ZeroMemory(uint8_t len, uint8_t *buf)
Definition: hidcomposite.cpp:364
USBHID::pUsb
USB * pUsb
Definition: usbhid.h:145
HIDComposite::epInfo
EpInfo epInfo[totalEndpoints]
Definition: hidcomposite.h:63
HIDComposite::constBuffLen
static const uint16_t constBuffLen
Definition: hidcomposite.h:55
USB::inTransfer
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
Definition: Usb.cpp:209
L
@ L
Definition: controllerEnums.h:102
HIDComposite::qNextPollTime
uint32_t qNextPollTime
Definition: hidcomposite.h:51
HIDReportParser::Parse
virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)=0
PSTR
#define PSTR(str)
Definition: version_helper.h:54
HIDComposite::hidInterfaces
HIDInterface hidInterfaces[maxHidInterfaces]
Definition: hidcomposite.h:64
HIDUniversal::Poll
uint8_t Poll() override
Definition: hiduniversal.cpp:20
HIDComposite::bHasReportId
bool bHasReportId
Definition: hidcomposite.h:69