]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/hiduniversal.h
lufa: usb-usb: Use LUFA startup instead of cusotom
[max/tmk_keyboard.git] / tmk_core / protocol / usb_hid / USB_Host_Shield_2.0 / hiduniversal.h
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 "hid.h"
22 //#include "hidescriptorparser.h"
23
24 class HIDUniversal : public HID {
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
32         HID_CLASS_DESCRIPTOR_LEN_AND_TYPE descrInfo[HID_MAX_HID_CLASS_DESCRIPTORS];
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:
64         EpInfo epInfo[totalEndpoints];
65         HIDInterface hidInterfaces[maxHidInterfaces];
66
67         bool bHasReportId;
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(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
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__