USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hiduniversal.h
Go to the documentation of this file.
1 #if !defined(__HIDUNIVERSAL_H__)
2 #define __HIDUNIVERSAL_H__
3 
4 #include "hid.h"
5 //#include "hidescriptorparser.h"
6 
7 class HIDUniversal : public HID {
8 
9  struct ReportParser {
10  uint8_t rptId;
11  HIDReportParser *rptParser;
12  } rptParsers[MAX_REPORT_PARSERS];
13 
14  // HID class specific descriptor type and length info obtained from HID descriptor
16 
17  // Returns HID class specific descriptor length by its type and order number
18  uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num);
19 
20  EpInfo epInfo[totalEndpoints];
21 
22  struct HIDInterface {
23 
24  struct {
25  uint8_t bmInterface : 3;
26  uint8_t bmAltSet : 3;
27  uint8_t bmProtocol : 2;
28  };
29  uint8_t epIndex[maxEpPerInterface];
30  };
31 
32  HIDInterface hidInterfaces[maxHidInterfaces];
33 
34  uint8_t bConfNum; // configuration number
35  uint8_t bNumIface; // number of interfaces in the configuration
36  uint8_t bNumEP; // total number of EP in the configuration
37  uint32_t qNextPollTime; // next poll time
38  uint8_t pollInterval;
39  bool bPollEnable; // poll enable flag
40 
41  static const uint16_t constBuffLen = 64; // event buffer length
42  uint8_t prevBuf[constBuffLen]; // previous event buffer
43 
44  void Initialize();
45  HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto);
46 
47  void ZeroMemory(uint8_t len, uint8_t *buf);
48  bool BuffersIdentical(uint8_t len, uint8_t *buf1, uint8_t *buf2);
49  void SaveBuffer(uint8_t len, uint8_t *src, uint8_t *dest);
50 
51 protected:
53 
54  uint16_t PID, VID; // PID and VID of connected device
55 
56  // HID implementation
57  virtual HIDReportParser* GetReportParser(uint8_t id);
58 
59  virtual uint8_t OnInitSuccessful() {
60  return 0;
61  };
62 
63  virtual void ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
64  return;
65  };
66 
67 public:
68  HIDUniversal(USB *p);
69 
70  // HID implementation
71  virtual bool SetReportParser(uint8_t id, HIDReportParser *prs);
72 
73  // USBDeviceConfig implementation
74  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
75  virtual uint8_t Release();
76  virtual uint8_t Poll();
77 
78  virtual uint8_t GetAddress() {
79  return bAddress;
80  };
81 
82  virtual bool isReady() {
83  return bPollEnable;
84  };
85 
86  // UsbConfigXtracter implementation
87  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
88 };
89 
90 #endif // __HIDUNIVERSAL_H__
uint16_t PID
Definition: hiduniversal.h:54
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
bool bHasReportId
Definition: hiduniversal.h:52
virtual bool isReady()
Definition: hiduniversal.h:82
uint8_t bAddress
Definition: hid.h:146
virtual uint8_t Release()
uint16_t VID
Definition: hiduniversal.h:54
virtual uint8_t OnInitSuccessful()
Definition: hiduniversal.h:59
virtual uint8_t Poll()
virtual void ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: hiduniversal.h:63
virtual HIDReportParser * GetReportParser(uint8_t id)
Definition: address.h:32
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
HIDUniversal(USB *p)
Definition: hiduniversal.cpp:3
Definition: hid.h:143
#define MAX_REPORT_PARSERS
Definition: hid.h:23
Definition: UsbCore.h:176
virtual uint8_t GetAddress()
Definition: hiduniversal.h:78
static const uint8_t totalEndpoints
Definition: hid.h:154
#define HID_MAX_HID_CLASS_DESCRIPTORS
Definition: hid.h:24
static const uint8_t maxEpPerInterface
Definition: hid.h:153
virtual bool SetReportParser(uint8_t id, HIDReportParser *prs)
static const uint8_t maxHidInterfaces
Definition: hid.h:152