MAX3421E-based USB Host Shield Library

Dependents:   UsbHostMAX3421E_Hello

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?

UserRevisionLine numberNew 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(__HIDCOMPOSITE_H__)
hudakz 0:84353c479782 19 #define __HIDCOMPOSITE_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 HIDComposite : 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];
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
hudakz 0:84353c479782 55 void Initialize();
hudakz 0:84353c479782 56 HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto);
hudakz 0:84353c479782 57
hudakz 0:84353c479782 58 void ZeroMemory(uint8_t len, uint8_t *buf);
hudakz 0:84353c479782 59
hudakz 0:84353c479782 60 protected:
hudakz 0:84353c479782 61 EpInfo epInfo[totalEndpoints];
hudakz 0:84353c479782 62 HIDInterface hidInterfaces[maxHidInterfaces];
hudakz 0:84353c479782 63
hudakz 0:84353c479782 64 bool bHasReportId;
hudakz 0:84353c479782 65
hudakz 0:84353c479782 66 uint16_t PID, VID; // PID and VID of connected device
hudakz 0:84353c479782 67
hudakz 0:84353c479782 68 // HID implementation
hudakz 0:84353c479782 69 HIDReportParser* GetReportParser(uint8_t id);
hudakz 0:84353c479782 70
hudakz 0:84353c479782 71 virtual uint8_t OnInitSuccessful() {
hudakz 0:84353c479782 72 return 0;
hudakz 0:84353c479782 73 };
hudakz 0:84353c479782 74
hudakz 0:84353c479782 75 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))) {
hudakz 0:84353c479782 76 return;
hudakz 0:84353c479782 77 };
hudakz 0:84353c479782 78
hudakz 0:84353c479782 79 public:
hudakz 1:2263e77400e9 80 HIDComposite(Usb *p);
hudakz 0:84353c479782 81
hudakz 0:84353c479782 82 // HID implementation
hudakz 0:84353c479782 83 bool SetReportParser(uint8_t id, HIDReportParser *prs);
hudakz 0:84353c479782 84
hudakz 0:84353c479782 85 // USBDeviceConfig implementation
hudakz 0:84353c479782 86 uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
hudakz 0:84353c479782 87 uint8_t Release();
hudakz 0:84353c479782 88 uint8_t Poll();
hudakz 0:84353c479782 89
hudakz 0:84353c479782 90 virtual uint8_t GetAddress() {
hudakz 0:84353c479782 91 return bAddress;
hudakz 0:84353c479782 92 };
hudakz 0:84353c479782 93
hudakz 0:84353c479782 94 virtual bool isReady() {
hudakz 0:84353c479782 95 return bPollEnable;
hudakz 0:84353c479782 96 };
hudakz 0:84353c479782 97
hudakz 0:84353c479782 98 // UsbConfigXtracter implementation
hudakz 0:84353c479782 99 void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
hudakz 0:84353c479782 100
hudakz 0:84353c479782 101 // Send report - do not mix with SetReport()!
hudakz 0:84353c479782 102 uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr);
hudakz 0:84353c479782 103
hudakz 0:84353c479782 104 // Returns true if we should listen on an interface, false if not
hudakz 0:84353c479782 105 virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0;
hudakz 0:84353c479782 106 };
hudakz 0:84353c479782 107
hudakz 0:84353c479782 108 #endif // __HIDCOMPOSITE_H__