-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusb-interface.cpp
102 lines (93 loc) · 2.18 KB
/
usb-interface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
namespace usbd {
/**
* @brief USB interface base class
*
* Interface usually has one or more endpoints.
*
* Typical subclass of UsbInterface class looks like:
* ```cpp
* class TestInterface : public usbd::UsbInterface {
* public:
* TestEndpoint testEndpoint;
*
* virtual UsbEndpoint *getEndpoint(int index) { return index == 0 ? &testEndpoint : NULL; }
*
* };
* ```
*/
class UsbInterface {
public:
/**
* Owner device.
* This property is set internally by the library.
*/
UsbDevice *device;
/**
* Interface initialization.
*
* Called internally from the library.
*
* UsbEndpoint::init() is responsible for calling init() method of endpoints.
*/
virtual void init() {
for (int e = 0; UsbEndpoint *endpoint = getEndpoint(e); e++) {
endpoint->interface = this;
endpoint->device = device;
endpoint->init();
}
}
/**
* Gets endpoint by index.
*
* Must be overloaded by the subclass.
*
* Called internally from the library.
*
* @param index zero based in scope of interface
* @return UsbEndpoint*
*/
virtual UsbEndpoint *getEndpoint(int index) = 0;
/**
* Handler of interface control request.
*
* May be overloaded to implement vendor request.
*
* @param setupData
*/
virtual void setup(SetupData *setupData){};
/**
* Called when generating interface descriptor.
*
* Called internally from the library.
*
* May be overloaded to modify the default descriptor.
*
* @param interfaceDesriptor
*/
virtual void checkDescriptor(InterfaceDescriptor *interfaceDesriptor){};
/**
* Called when generating class descriptor.
*
* May be overloaded to add class specific descriptor.
*
* @return int
*/
virtual int getClassDescriptorLength() { return 0; }
/**
* Called when generating class descriptor.
*
* May be overloaded to add class specific descriptor.
*
* @param buffer
*/
virtual void checkClassDescriptor(unsigned char *buffer) {}
/**
* Get string identifier of the interface.
*
* May be overloaded by the subclass.
*
* @return const char*
*/
virtual const char *getLabel() { return NULL; };
};
} // namespace usbd