-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PluggableUSB.h
69 lines (56 loc) · 1.58 KB
/
PluggableUSB.h
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
/**
* @file PluggableUSB.h
* @author Daniel Starke
* @copyright Copyright 2020 Daniel Starke
* @date 2020-05-21
* @version 2020-06-21
*/
#ifndef __PLUGGABLEUSB_H__
#define __PLUGGABLEUSB_H__
#include <stdint.h>
#include "USBAPI.h"
#ifdef USBCON
#ifdef PLUGGABLE_USB_ENABLED
class PluggableUSBModule {
protected:
friend class PluggableUSB_;
uint8_t pluggedInterface;
uint8_t pluggedEndpoint;
const uint8_t numEndpoints;
const uint8_t numInterfaces;
const uint8_t * endpointType; /**< @warning Pointer type is compatible to AVR Arduino, not SAMD Arduino. */
PluggableUSBModule * next = NULL;
public:
PluggableUSBModule(const uint8_t numEps, const uint8_t numIfs, const uint8_t * epType):
numEndpoints(numEps),
numInterfaces(numIfs),
endpointType(epType)
{}
virtual ~PluggableUSBModule() {}
protected:
virtual bool setup(USBSetup & setup) = 0;
virtual int getInterface(uint8_t * interfaceCount) = 0;
virtual int getDescriptor(USBSetup & setup) = 0;
virtual uint8_t getShortName(char * name) {
name[0] = char('A' + this->pluggedInterface);
return 1;
}
};
class PluggableUSB_ {
private:
uint8_t lastIf;
uint8_t lastEp;
PluggableUSBModule * rootNode;
public:
PluggableUSB_();
bool plug(PluggableUSBModule * node);
int getInterface(uint8_t * interfaceCount);
int getDescriptor(USBSetup & setup);
bool setup(USBSetup & setup);
uint8_t getShortName(char * iSerialNum);
};
/* Replacement for global singleton to prevent static initialization issues. */
PluggableUSB_ & PluggableUSB();
#endif /* PLUGGABLE_USB_ENABLED */
#endif /* USBCON */
#endif /* __PLUGGABLEUSB_H__ */