aboutsummaryrefslogtreecommitdiff
path: root/cores/xinput/PluggableUSB.h
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-07 13:48:57 +0100
committerHampusM <hampus@hampusmat.com>2022-03-07 13:48:57 +0100
commit563f69b870a7f71026c50605b531ed40d667b0a2 (patch)
treef9dd8374cae6affb3b52d79e22823c78187b99ed /cores/xinput/PluggableUSB.h
parentf4a2dc0440d17e4c9e609e01e12fcd786d268cf7 (diff)
rename arduino core dir to xinputHEADmaster
Diffstat (limited to 'cores/xinput/PluggableUSB.h')
-rw-r--r--cores/xinput/PluggableUSB.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/cores/xinput/PluggableUSB.h b/cores/xinput/PluggableUSB.h
new file mode 100644
index 0000000..507f0df
--- /dev/null
+++ b/cores/xinput/PluggableUSB.h
@@ -0,0 +1,74 @@
+/*
+ PluggableUSB.h
+ Copyright (c) 2015 Arduino LLC
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef PUSB_h
+#define PUSB_h
+
+#include "USBAPI.h"
+#include <stdint.h>
+
+#if defined(USBCON)
+
+class PluggableUSBModule {
+public:
+ PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint8_t *epType) :
+ numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType)
+ { }
+
+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] = 'A'+pluggedInterface; return 1; }
+
+ uint8_t pluggedInterface;
+ uint8_t pluggedEndpoint;
+
+ const uint8_t numEndpoints;
+ const uint8_t numInterfaces;
+ const uint8_t *endpointType;
+
+ PluggableUSBModule *next = NULL;
+
+ friend class PluggableUSB_;
+};
+
+class PluggableUSB_ {
+public:
+ PluggableUSB_();
+ bool plug(PluggableUSBModule *node);
+ int getInterface(uint8_t* interfaceCount);
+ int getDescriptor(USBSetup& setup);
+ bool setup(USBSetup& setup);
+ void getShortName(char *iSerialNum);
+
+private:
+ uint8_t lastIf;
+ uint8_t lastEp;
+ PluggableUSBModule* rootNode;
+};
+
+// Replacement for global singleton.
+// This function prevents static-initialization-order-fiasco
+// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
+PluggableUSB_& PluggableUSB();
+
+#endif
+
+#endif