Index

auto-plow / 71172f4

A wheelchair motor-propelled battery-powered ESP32-driven remote control snow plow.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
630 Nov 2018 18:364a63c8cInclude Arduino core filesJoshua11150N

Blob @ auto-plow / include / arduino / PluggableUSB.cpp

text/plain2725 bytesdownload raw
1/*
2 PluggableUSB.cpp
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#include "USBAPI.h"
21#include "PluggableUSB.h"
22
23#if defined(USBCON)
24#ifdef PLUGGABLE_USB_ENABLED
25
26extern uint8_t _initEndpoints[];
27
28int PluggableUSB_::getInterface(uint8_t* interfaceCount)
29{
30 int sent = 0;
31 PluggableUSBModule* node;
32 for (node = rootNode; node; node = node->next) {
33 int res = node->getInterface(interfaceCount);
34 if (res < 0)
35 return -1;
36 sent += res;
37 }
38 return sent;
39}
40
41int PluggableUSB_::getDescriptor(USBSetup& setup)
42{
43 PluggableUSBModule* node;
44 for (node = rootNode; node; node = node->next) {
45 int ret = node->getDescriptor(setup);
46 // ret!=0 -> request has been processed
47 if (ret)
48 return ret;
49 }
50 return 0;
51}
52
53void PluggableUSB_::getShortName(char *iSerialNum)
54{
55 PluggableUSBModule* node;
56 for (node = rootNode; node; node = node->next) {
57 iSerialNum += node->getShortName(iSerialNum);
58 }
59 *iSerialNum = 0;
60}
61
62bool PluggableUSB_::setup(USBSetup& setup)
63{
64 PluggableUSBModule* node;
65 for (node = rootNode; node; node = node->next) {
66 if (node->setup(setup)) {
67 return true;
68 }
69 }
70 return false;
71}
72
73bool PluggableUSB_::plug(PluggableUSBModule *node)
74{
75 if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) {
76 return false;
77 }
78
79 if (!rootNode) {
80 rootNode = node;
81 } else {
82 PluggableUSBModule *current = rootNode;
83 while (current->next) {
84 current = current->next;
85 }
86 current->next = node;
87 }
88
89 node->pluggedInterface = lastIf;
90 node->pluggedEndpoint = lastEp;
91 lastIf += node->numInterfaces;
92 for (uint8_t i = 0; i < node->numEndpoints; i++) {
93 _initEndpoints[lastEp] = node->endpointType[i];
94 lastEp++;
95 }
96 return true;
97 // restart USB layer???
98}
99
100PluggableUSB_& PluggableUSB()
101{
102 static PluggableUSB_ obj;
103 return obj;
104}
105
106PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT),
107 lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT),
108 rootNode(NULL)
109{
110 // Empty
111}
112
113#endif
114
115#endif /* if defined(USBCON) */
116