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 /* 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 #if !defined(__HIDUNIVERSAL_H__)
19 #define __HIDUNIVERSAL_H__
20 
21 #include "usbhid.h"
22 //#include "hidescriptorparser.h"
23 
24 class HIDUniversal : public USBHID {
25 
26  struct ReportParser {
27  uint8_t rptId;
28  HIDReportParser *rptParser;
29  } rptParsers[MAX_REPORT_PARSERS];
30 
31  // HID class specific descriptor type and length info obtained from HID descriptor
33 
34  // Returns HID class specific descriptor length by its type and order number
35  uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num);
36 
37  struct HIDInterface {
38  struct {
39  uint8_t bmInterface : 3;
40  uint8_t bmAltSet : 3;
41  uint8_t bmProtocol : 2;
42  };
43  uint8_t epIndex[maxEpPerInterface];
44  };
45 
46  uint8_t bConfNum; // configuration number
47  uint8_t bNumIface; // number of interfaces in the configuration
48  uint8_t bNumEP; // total number of EP in the configuration
49  uint32_t qNextPollTime; // next poll time
50  uint8_t pollInterval;
51  bool bPollEnable; // poll enable flag
52 
53  static const uint16_t constBuffLen = 64; // event buffer length
54  uint8_t prevBuf[constBuffLen]; // previous event buffer
55 
56  void Initialize();
57  HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto);
58 
59  void ZeroMemory(uint8_t len, uint8_t *buf);
60  bool BuffersIdentical(uint8_t len, uint8_t *buf1, uint8_t *buf2);
61  void SaveBuffer(uint8_t len, uint8_t *src, uint8_t *dest);
62 
63 protected:
66 
68 
69  uint16_t PID, VID; // PID and VID of connected device
70 
71  // HID implementation
72  HIDReportParser* GetReportParser(uint8_t id);
73 
74  virtual uint8_t OnInitSuccessful() {
75  return 0;
76  };
77 
78  virtual void ParseHIDData(USBHID *hid __attribute__((unused)), bool is_rpt_id __attribute__((unused)), uint8_t len __attribute__((unused)), uint8_t *buf __attribute__((unused))) {
79  return;
80  };
81 
82 public:
83  HIDUniversal(USB *p);
84 
85  // HID implementation
86  bool SetReportParser(uint8_t id, HIDReportParser *prs);
87 
88  // USBDeviceConfig implementation
89  uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
90  uint8_t Release();
91  uint8_t Poll();
92 
93  virtual uint8_t GetAddress() {
94  return bAddress;
95  };
96 
97  virtual bool isReady() {
98  return bPollEnable;
99  };
100 
101  // UsbConfigXtracter implementation
102  void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
103 
104  // Send report - do not mix with SetReport()!
105  uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr);
106 };
107 
108 #endif // __HIDUNIVERSAL_H__
uint16_t PID
Definition: hiduniversal.h:69
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
bool bHasReportId
Definition: hiduniversal.h:67
Definition: usbhid.h:143
virtual bool isReady()
Definition: hiduniversal.h:97
#define HID_MAX_HID_CLASS_DESCRIPTORS
Definition: usbhid.h:24
#define MAX_REPORT_PARSERS
Definition: usbhid.h:23
virtual void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: hiduniversal.h:78
HIDInterface hidInterfaces[maxHidInterfaces]
Definition: hiduniversal.h:65
uint8_t Release()
uint16_t VID
Definition: hiduniversal.h:69
virtual uint8_t OnInitSuccessful()
Definition: hiduniversal.h:74
uint8_t Poll()
HIDReportParser * GetReportParser(uint8_t id)
Definition: address.h:39
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
HIDUniversal(USB *p)
uint8_t bAddress
Definition: usbhid.h:146
static const uint8_t maxEpPerInterface
Definition: usbhid.h:153
static const uint8_t maxHidInterfaces
Definition: usbhid.h:152
static const uint8_t totalEndpoints
Definition: usbhid.h:154
uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr)
Definition: UsbCore.h:208
virtual uint8_t GetAddress()
Definition: hiduniversal.h:93
EpInfo epInfo[totalEndpoints]
Definition: hiduniversal.h:64
bool SetReportParser(uint8_t id, HIDReportParser *prs)