Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UsbHostMAX3421E_Hello
hiduniversal.h@1:2263e77400e9, 2020-07-13 (annotated)
- Committer:
- hudakz
- Date:
- Mon Jul 13 07:03:06 2020 +0000
- Revision:
- 1:2263e77400e9
- Parent:
- 0:84353c479782
MAX3421E-based USB Host Shield Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:84353c479782 | 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. |
hudakz | 0:84353c479782 | 2 | |
hudakz | 0:84353c479782 | 3 | This software may be distributed and modified under the terms of the GNU |
hudakz | 0:84353c479782 | 4 | General Public License version 2 (GPL2) as published by the Free Software |
hudakz | 0:84353c479782 | 5 | Foundation and appearing in the file GPL2.TXT included in the packaging of |
hudakz | 0:84353c479782 | 6 | this file. Please note that GPL2 Section 2[b] requires that all works based |
hudakz | 0:84353c479782 | 7 | on this software must also be made publicly available under the terms of |
hudakz | 0:84353c479782 | 8 | the GPL2 ("Copyleft"). |
hudakz | 0:84353c479782 | 9 | |
hudakz | 0:84353c479782 | 10 | Contact information |
hudakz | 0:84353c479782 | 11 | ------------------- |
hudakz | 0:84353c479782 | 12 | |
hudakz | 0:84353c479782 | 13 | Circuits At Home, LTD |
hudakz | 0:84353c479782 | 14 | Web : http://www.circuitsathome.com |
hudakz | 0:84353c479782 | 15 | e-mail : support@circuitsathome.com |
hudakz | 0:84353c479782 | 16 | */ |
hudakz | 0:84353c479782 | 17 | |
hudakz | 0:84353c479782 | 18 | #if !defined(__HIDUNIVERSAL_H__) |
hudakz | 0:84353c479782 | 19 | #define __HIDUNIVERSAL_H__ |
hudakz | 0:84353c479782 | 20 | |
hudakz | 0:84353c479782 | 21 | #include "usbhid.h" |
hudakz | 0:84353c479782 | 22 | //#include "hidescriptorparser.h" |
hudakz | 0:84353c479782 | 23 | |
hudakz | 0:84353c479782 | 24 | class HIDUniversal : public USBHID { |
hudakz | 0:84353c479782 | 25 | |
hudakz | 0:84353c479782 | 26 | struct ReportParser { |
hudakz | 0:84353c479782 | 27 | uint8_t rptId; |
hudakz | 0:84353c479782 | 28 | HIDReportParser *rptParser; |
hudakz | 0:84353c479782 | 29 | } rptParsers[MAX_REPORT_PARSERS]; |
hudakz | 0:84353c479782 | 30 | |
hudakz | 0:84353c479782 | 31 | // HID class specific descriptor type and length info obtained from HID descriptor |
hudakz | 0:84353c479782 | 32 | HID_CLASS_DESCRIPTOR_LEN_AND_TYPE descrInfo[HID_MAX_HID_CLASS_DESCRIPTORS]; |
hudakz | 0:84353c479782 | 33 | |
hudakz | 0:84353c479782 | 34 | // Returns HID class specific descriptor length by its type and order number |
hudakz | 0:84353c479782 | 35 | uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num); |
hudakz | 0:84353c479782 | 36 | |
hudakz | 0:84353c479782 | 37 | struct HIDInterface { |
hudakz | 0:84353c479782 | 38 | struct { |
hudakz | 0:84353c479782 | 39 | uint8_t bmInterface : 3; |
hudakz | 0:84353c479782 | 40 | uint8_t bmAltSet : 3; |
hudakz | 0:84353c479782 | 41 | uint8_t bmProtocol : 2; |
hudakz | 0:84353c479782 | 42 | }; |
hudakz | 0:84353c479782 | 43 | uint8_t epIndex[maxEpPerInterface + 1]; // We need to make room for the control endpoint as well |
hudakz | 0:84353c479782 | 44 | }; |
hudakz | 0:84353c479782 | 45 | |
hudakz | 0:84353c479782 | 46 | uint8_t bConfNum; // configuration number |
hudakz | 0:84353c479782 | 47 | uint8_t bNumIface; // number of interfaces in the configuration |
hudakz | 0:84353c479782 | 48 | uint8_t bNumEP; // total number of EP in the configuration |
hudakz | 0:84353c479782 | 49 | uint32_t qNextPollTime; // next poll time |
hudakz | 0:84353c479782 | 50 | uint8_t pollInterval; |
hudakz | 0:84353c479782 | 51 | bool bPollEnable; // poll enable flag |
hudakz | 0:84353c479782 | 52 | |
hudakz | 0:84353c479782 | 53 | static const uint16_t constBuffLen = 64; // event buffer length |
hudakz | 0:84353c479782 | 54 | uint8_t prevBuf[constBuffLen]; // previous event buffer |
hudakz | 0:84353c479782 | 55 | |
hudakz | 0:84353c479782 | 56 | void Initialize(); |
hudakz | 0:84353c479782 | 57 | HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto); |
hudakz | 0:84353c479782 | 58 | |
hudakz | 0:84353c479782 | 59 | void ZeroMemory(uint8_t len, uint8_t *buf); |
hudakz | 0:84353c479782 | 60 | bool BuffersIdentical(uint8_t len, uint8_t *buf1, uint8_t *buf2); |
hudakz | 0:84353c479782 | 61 | void SaveBuffer(uint8_t len, uint8_t *src, uint8_t *dest); |
hudakz | 0:84353c479782 | 62 | |
hudakz | 0:84353c479782 | 63 | protected: |
hudakz | 0:84353c479782 | 64 | EpInfo epInfo[totalEndpoints]; |
hudakz | 0:84353c479782 | 65 | HIDInterface hidInterfaces[maxHidInterfaces]; |
hudakz | 0:84353c479782 | 66 | |
hudakz | 0:84353c479782 | 67 | bool bHasReportId; |
hudakz | 0:84353c479782 | 68 | |
hudakz | 0:84353c479782 | 69 | uint16_t PID, VID; // PID and VID of connected device |
hudakz | 0:84353c479782 | 70 | |
hudakz | 0:84353c479782 | 71 | // HID implementation |
hudakz | 0:84353c479782 | 72 | HIDReportParser* GetReportParser(uint8_t id); |
hudakz | 0:84353c479782 | 73 | |
hudakz | 0:84353c479782 | 74 | virtual uint8_t OnInitSuccessful() { |
hudakz | 0:84353c479782 | 75 | return 0; |
hudakz | 0:84353c479782 | 76 | }; |
hudakz | 0:84353c479782 | 77 | |
hudakz | 0:84353c479782 | 78 | virtual void ParseHIDData(USBHID *hid __attribute__((unused)), bool is_rpt_id __attribute__((unused)), uint8_t len __attribute__((unused)), uint8_t *buf __attribute__((unused))) { |
hudakz | 0:84353c479782 | 79 | return; |
hudakz | 0:84353c479782 | 80 | }; |
hudakz | 0:84353c479782 | 81 | |
hudakz | 0:84353c479782 | 82 | public: |
hudakz | 1:2263e77400e9 | 83 | HIDUniversal(Usb *p); |
hudakz | 0:84353c479782 | 84 | |
hudakz | 0:84353c479782 | 85 | // HID implementation |
hudakz | 0:84353c479782 | 86 | bool SetReportParser(uint8_t id, HIDReportParser *prs); |
hudakz | 0:84353c479782 | 87 | |
hudakz | 0:84353c479782 | 88 | // USBDeviceConfig implementation |
hudakz | 0:84353c479782 | 89 | uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); |
hudakz | 0:84353c479782 | 90 | uint8_t Release(); |
hudakz | 0:84353c479782 | 91 | uint8_t Poll(); |
hudakz | 0:84353c479782 | 92 | |
hudakz | 0:84353c479782 | 93 | virtual uint8_t GetAddress() { |
hudakz | 0:84353c479782 | 94 | return bAddress; |
hudakz | 0:84353c479782 | 95 | }; |
hudakz | 0:84353c479782 | 96 | |
hudakz | 0:84353c479782 | 97 | virtual bool isReady() { |
hudakz | 0:84353c479782 | 98 | return bPollEnable; |
hudakz | 0:84353c479782 | 99 | }; |
hudakz | 0:84353c479782 | 100 | |
hudakz | 0:84353c479782 | 101 | // UsbConfigXtracter implementation |
hudakz | 0:84353c479782 | 102 | void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); |
hudakz | 0:84353c479782 | 103 | |
hudakz | 0:84353c479782 | 104 | // Send report - do not mix with SetReport()! |
hudakz | 0:84353c479782 | 105 | uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr); |
hudakz | 0:84353c479782 | 106 | }; |
hudakz | 0:84353c479782 | 107 | |
hudakz | 0:84353c479782 | 108 | #endif // __HIDUNIVERSAL_H__ |