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__
HIDComposite::GetReportParser
HIDReportParser * GetReportParser(uint8_t id)
Definition: hidcomposite.cpp:83
HIDComposite::FindInterface
HIDInterface * FindInterface(uint8_t iface, uint8_t alt, uint8_t proto)
Definition: hidcomposite.cpp:289
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
HIDComposite::ReportParser::rptId
uint8_t rptId
Definition: hidcomposite.h:29
USB_ENDPOINT_DESCRIPTOR
Definition: usb_ch9.h:148
HIDComposite::ReportParser::rptParser
HIDReportParser * rptParser
Definition: hidcomposite.h:30
HIDComposite::GetHidClassDescrLen
uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num)
Definition: hidcomposite.cpp:32
HIDComposite::Initialize
void Initialize()
Definition: hidcomposite.cpp:43
MAX_REPORT_PARSERS
#define MAX_REPORT_PARSERS
Definition: usbhid.h:23
HIDComposite::Poll
uint8_t Poll()
Definition: hidcomposite.cpp:369
usbhid.h
HIDComposite::Init
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: hidcomposite.cpp:94
HIDComposite::HIDComposite
HIDComposite(USB *p)
Definition: hidcomposite.cpp:20
HIDComposite::OnInitSuccessful
virtual uint8_t OnInitSuccessful()
Definition: hidcomposite.h:76
HIDComposite::bConfNum
uint8_t bConfNum
Definition: hidcomposite.h:48
HID_MAX_HID_CLASS_DESCRIPTORS
#define HID_MAX_HID_CLASS_DESCRIPTORS
Definition: usbhid.h:24
HIDComposite::pollInterval
uint8_t pollInterval
Definition: hidcomposite.h:52
HIDComposite::isReady
virtual bool isReady()
Definition: hidcomposite.h:99
HIDComposite::descrInfo
HID_CLASS_DESCRIPTOR_LEN_AND_TYPE descrInfo[HID_MAX_HID_CLASS_DESCRIPTORS]
Definition: hidcomposite.h:34
HIDReportParser
Definition: usbhid.h:138
HID_CLASS_DESCRIPTOR_LEN_AND_TYPE
Definition: usb_ch9.h:168
USBHID::maxHidInterfaces
static const uint8_t maxHidInterfaces
Definition: usbhid.h:152
HIDComposite::ReportParser
Definition: hidcomposite.h:28
HIDComposite::bPollEnable
bool bPollEnable
Definition: hidcomposite.h:53
HIDComposite::HIDInterface::bmAltSet
uint8_t bmAltSet
Definition: hidcomposite.h:42
EpInfo
Definition: address.h:39
USBHID::totalEndpoints
static const uint8_t totalEndpoints
Definition: usbhid.h:154
HIDComposite::rptParsers
struct HIDComposite::ReportParser rptParsers[MAX_REPORT_PARSERS]
HIDComposite::ZeroMemory
void ZeroMemory(uint8_t len, uint8_t *buf)
Definition: hidcomposite.cpp:364
HIDComposite::epInfo
EpInfo epInfo[totalEndpoints]
Definition: hidcomposite.h:63
USB
Definition: UsbCore.h:212
HIDComposite::constBuffLen
static const uint16_t constBuffLen
Definition: hidcomposite.h:55
HIDComposite::qNextPollTime
uint32_t qNextPollTime
Definition: hidcomposite.h:51
HIDComposite::VID
uint16_t VID
Definition: hidcomposite.h:71
HIDComposite::HIDInterface::bmProtocol
uint8_t bmProtocol
Definition: hidcomposite.h:43
HIDComposite::Release
uint8_t Release()
Definition: hidcomposite.cpp:354
HIDComposite::EndpointXtract
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: hidcomposite.cpp:297
HIDComposite::SndRpt
uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr)
Definition: hidcomposite.cpp:427
HIDComposite::SelectInterface
virtual bool SelectInterface(uint8_t iface, uint8_t proto)=0
HIDComposite::GetAddress
virtual uint8_t GetAddress()
Definition: hidcomposite.h:95
HIDComposite::HIDInterface::bmInterface
uint8_t bmInterface
Definition: hidcomposite.h:41
HIDComposite::HIDInterface
Definition: hidcomposite.h:39
USBHID
Definition: usbhid.h:143
HIDComposite::hidInterfaces
HIDInterface hidInterfaces[maxHidInterfaces]
Definition: hidcomposite.h:64
HIDComposite::bNumEP
uint8_t bNumEP
Definition: hidcomposite.h:50
HIDComposite
Definition: hidcomposite.h:24
HIDComposite::PID
uint16_t PID
Definition: hidcomposite.h:71
HIDComposite::ParseHIDData
virtual void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf)
Definition: hidcomposite.h:80
HIDComposite::bHasReportId
bool bHasReportId
Definition: hidcomposite.h:69
USBHID::maxEpPerInterface
static const uint8_t maxEpPerInterface
Definition: usbhid.h:153
HIDComposite::SetReportParser
bool SetReportParser(uint8_t id, HIDReportParser *prs)
Definition: hidcomposite.cpp:72