USB Host Shield 2.0
hidcomposite.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(__HIDCOMPOSITE_H__)
19 #define __HIDCOMPOSITE_H__
20 
21 #include "usbhid.h"
22 //#include "hidescriptorparser.h"
23 
24 class HIDComposite : 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 
55  void Initialize();
56  HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto);
57 
58  void ZeroMemory(uint8_t len, uint8_t *buf);
59 
60 protected:
63 
65 
66  uint16_t PID, VID; // PID and VID of connected device
67 
68  // HID implementation
69  HIDReportParser* GetReportParser(uint8_t id);
70 
71  virtual uint8_t OnInitSuccessful() {
72  return 0;
73  };
74 
75  virtual void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) {
76  return;
77  };
78 
79 public:
80  HIDComposite(USB *p);
81 
82  // HID implementation
83  bool SetReportParser(uint8_t id, HIDReportParser *prs);
84 
85  // USBDeviceConfig implementation
86  uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
87  uint8_t Release();
88  uint8_t Poll();
89 
90  virtual uint8_t GetAddress() {
91  return bAddress;
92  };
93 
94  virtual bool isReady() {
95  return bPollEnable;
96  };
97 
98  // UsbConfigXtracter implementation
99  void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
100 
101  // Send report - do not mix with SetReport()!
102  uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr);
103 
104  // Returns true if we should listen on an interface, false if not
105  virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0;
106 };
107 
108 #endif // __HIDCOMPOSITE_H__
Definition: usbhid.h:143
#define HID_MAX_HID_CLASS_DESCRIPTORS
Definition: usbhid.h:24
#define MAX_REPORT_PARSERS
Definition: usbhid.h:23
virtual uint8_t OnInitSuccessful()
Definition: hidcomposite.h:71
virtual bool isReady()
Definition: hidcomposite.h:94
HIDInterface hidInterfaces[maxHidInterfaces]
Definition: hidcomposite.h:62
virtual void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: hidcomposite.h:75
bool bHasReportId
Definition: hidcomposite.h:64
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
EpInfo epInfo[totalEndpoints]
Definition: hidcomposite.h:61
Definition: address.h:32
virtual uint8_t GetAddress()
Definition: hidcomposite.h:90
uint8_t bAddress
Definition: usbhid.h:146
uint8_t Poll()
static const uint8_t maxEpPerInterface
Definition: usbhid.h:153
uint16_t PID
Definition: hidcomposite.h:66
virtual bool SelectInterface(uint8_t iface, uint8_t proto)=0
HIDComposite(USB *p)
static const uint8_t maxHidInterfaces
Definition: usbhid.h:152
uint16_t VID
Definition: hidcomposite.h:66
static const uint8_t totalEndpoints
Definition: usbhid.h:154
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
uint8_t Release()
uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr)
Definition: UsbCore.h:197
bool SetReportParser(uint8_t id, HIDReportParser *prs)
HIDReportParser * GetReportParser(uint8_t id)