Pico-Arduino
PluggableUSB.h
1 /*
2  PluggableUSB.h
3  Copyright (c) 2015 Arduino LLC
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #ifndef PUSB_h
21 #define PUSB_h
22 
23 #include "USBAPI.h"
24 #include <stdint.h>
25 #include <stddef.h>
26 
27 namespace arduino {
28 
30 public:
31  PluggableUSBModule(uint8_t numEps, uint8_t numIfs, unsigned int *epType) :
32  numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType)
33  { }
34 
35 protected:
36  virtual bool setup(USBSetup& setup) = 0;
37  virtual int getInterface(uint8_t* interfaceCount) = 0;
38  virtual int getDescriptor(USBSetup& setup) = 0;
39  virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; }
40 
41  uint8_t pluggedInterface;
42  uint8_t pluggedEndpoint;
43 
44  const uint8_t numEndpoints;
45  const uint8_t numInterfaces;
46  const unsigned int *endpointType;
47 
48  PluggableUSBModule *next = NULL;
49 
50  friend class PluggableUSB_;
51 };
52 
54 public:
55  PluggableUSB_();
56  bool plug(PluggableUSBModule *node);
57  int getInterface(uint8_t* interfaceCount);
58  int getDescriptor(USBSetup& setup);
59  bool setup(USBSetup& setup);
60  void getShortName(char *iSerialNum);
61 
62 private:
63  uint8_t lastIf;
64  uint8_t lastEp;
65  PluggableUSBModule* rootNode;
66  uint8_t totalEP;
67 };
68 }
69 
70 // core need to define
71 void* epBuffer(unsigned int n); // -> returns a pointer to the Nth element of the EP buffer structure
72 
73 // Replacement for global singleton.
74 // This function prevents static-initialization-order-fiasco
75 // https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
76 arduino::PluggableUSB_& PluggableUSB();
77 
78 #endif
Definition: PluggableUSB.h:53
Definition: PluggableUSB.h:29