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 protected:
27 
28  struct ReportParser {
29  uint8_t rptId;
32 
33  // HID class specific descriptor type and length info obtained from HID descriptor
35 
36  // Returns HID class specific descriptor length by its type and order number
37  uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num);
38 
39  struct HIDInterface {
40  struct {
41  uint8_t bmInterface : 3;
42  uint8_t bmAltSet : 3;
43  uint8_t bmProtocol : 2;
44  };
45  uint8_t epIndex[maxEpPerInterface + 1]; // We need to make room for the control endpoint as well
46  };
47 
48  uint8_t bConfNum; // configuration number
49  uint8_t bNumIface; // number of interfaces in the configuration
50  uint8_t bNumEP; // total number of EP in the configuration
51  uint32_t qNextPollTime; // next poll time
52  uint8_t pollInterval;
53  bool bPollEnable; // poll enable flag
54 
55  static const uint16_t constBuffLen = 64; // event buffer length
56 
57  void Initialize();
58  HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto);
59 
60  void ZeroMemory(uint8_t len, uint8_t *buf);
61 
62 
65 
66  // FIXME: bHasReportId is never set (except to false in constructor)
67  // should probably be in EpInfo, /maybe/ in HIDInterface
68  // but setting it isn't that easy (requires parsing report descriptors)
70 
71  uint16_t PID, VID; // PID and VID of connected device
72 
73  // HID implementation
74  HIDReportParser* GetReportParser(uint8_t id);
75 
76  virtual uint8_t OnInitSuccessful() {
77  return 0;
78  };
79 
80  virtual void ParseHIDData(USBHID *hid __attribute__((unused)), uint8_t ep __attribute__((unused)), bool is_rpt_id __attribute__((unused)), uint8_t len __attribute__((unused)), uint8_t *buf __attribute__((unused))) {
81  return;
82  };
83 
84 public:
85  HIDComposite(USB *p);
86 
87  // HID implementation
88  bool SetReportParser(uint8_t id, HIDReportParser *prs);
89 
90  // USBDeviceConfig implementation
91  uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
92  uint8_t Release();
93  uint8_t Poll();
94 
95  virtual uint8_t GetAddress() {
96  return bAddress;
97  };
98 
99  virtual bool isReady() {
100  return bPollEnable;
101  };
102 
103  // UsbConfigXtracter implementation
104  void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
105 
106  // Send report - do not mix with SetReport()!
107  uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr);
108 
109  // Returns true if we should listen on an interface, false if not
110  virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0;
111 };
112 
113 #endif // __HIDCOMPOSITE_H__
virtual uint8_t OnInitSuccessful()
Definition: hidcomposite.h:76
uint16_t PID
Definition: hidcomposite.h:71
uint32_t qNextPollTime
Definition: hidcomposite.h:51
HIDReportParser * GetReportParser(uint8_t id)
uint8_t Release()
static const uint16_t constBuffLen
Definition: hidcomposite.h:55
HIDInterface hidInterfaces[maxHidInterfaces]
Definition: hidcomposite.h:64
void Initialize()
virtual bool isReady()
Definition: hidcomposite.h:99
EpInfo epInfo[totalEndpoints]
Definition: hidcomposite.h:63
bool bPollEnable
Definition: hidcomposite.h:53
HIDInterface * FindInterface(uint8_t iface, uint8_t alt, uint8_t proto)
struct HIDComposite::ReportParser rptParsers[MAX_REPORT_PARSERS]
uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr)
HID_CLASS_DESCRIPTOR_LEN_AND_TYPE descrInfo[HID_MAX_HID_CLASS_DESCRIPTORS]
Definition: hidcomposite.h:34
virtual uint8_t GetAddress()
Definition: hidcomposite.h:95
uint8_t bConfNum
Definition: hidcomposite.h:48
bool SetReportParser(uint8_t id, HIDReportParser *prs)
void ZeroMemory(uint8_t len, uint8_t *buf)
uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num)
HIDComposite(USB *p)
bool bHasReportId
Definition: hidcomposite.h:69
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
virtual void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: hidcomposite.h:80
uint8_t bNumIface
Definition: hidcomposite.h:49
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
uint16_t VID
Definition: hidcomposite.h:71
virtual bool SelectInterface(uint8_t iface, uint8_t proto)=0
uint8_t pollInterval
Definition: hidcomposite.h:52
uint8_t Poll()
uint8_t bNumEP
Definition: hidcomposite.h:50
Definition: usbhid.h:143
static const uint8_t totalEndpoints
Definition: usbhid.h:154
uint8_t bAddress
Definition: usbhid.h:146
static const uint8_t maxHidInterfaces
Definition: usbhid.h:152
static const uint8_t maxEpPerInterface
Definition: usbhid.h:153
Definition: UsbCore.h:212
Definition: address.h:39
uint8_t epIndex[maxEpPerInterface+1]
Definition: hidcomposite.h:45
HIDReportParser * rptParser
Definition: hidcomposite.h:30
#define HID_MAX_HID_CLASS_DESCRIPTORS
Definition: usbhid.h:24
#define MAX_REPORT_PARSERS
Definition: usbhid.h:23