Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd5ad836

Browse files
committed
Move PluggableUSB out of core
The core need to defineEP_BUFFER_TYPE (eg: uint8_t uint32_tEP_BUFFER_NAME (eg: _initEndpoints)
1 parent48eb5d1 commitd5ad836

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

‎api/PluggableUSB.cpp‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
26+
extern _EP_BUFFER_TYPE _EP_BUFFER_NAME[];
27+
28+
intPluggableUSB_::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+
41+
intPluggableUSB_::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+
return0;
51+
}
52+
53+
voidPluggableUSB_::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+
62+
boolPluggableUSB_::setup(USBSetup& setup)
63+
{
64+
PluggableUSBModule* node;
65+
for (node = rootNode; node; node = node->next) {
66+
if (node->setup(setup)) {
67+
returntrue;
68+
}
69+
}
70+
returnfalse;
71+
}
72+
73+
boolPluggableUSB_::plug(PluggableUSBModule *node)
74+
{
75+
if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) {
76+
returnfalse;
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+
_EP_BUFFER_NAME[lastEp] = node->endpointType[i];
94+
lastEp++;
95+
}
96+
returntrue;
97+
// restart USB layer???
98+
}
99+
100+
PluggableUSB_&PluggableUSB()
101+
{
102+
static PluggableUSB_ obj;
103+
return obj;
104+
}
105+
106+
PluggableUSB_::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)*/

‎api/PluggableUSB.h‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
#definePUSB_h
22+
23+
#include"USBAPI.h"
24+
#include<stdint.h>
25+
26+
// core need to define
27+
// EP_BUFFER_TYPE
28+
// EP_BUFFER_NAME
29+
30+
#if defined(USBCON)
31+
32+
classPluggableUSBModule {
33+
public:
34+
PluggableUSBModule(uint8_t numEps,uint8_t numIfs, EP_BUFFER_TYPE *epType) :
35+
numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType)
36+
{ }
37+
38+
protected:
39+
virtualboolsetup(USBSetup& setup) = 0;
40+
virtualintgetInterface(uint8_t* interfaceCount) = 0;
41+
virtualintgetDescriptor(USBSetup& setup) = 0;
42+
virtualuint8_tgetShortName(char *name) { name[0] ='A'+pluggedInterface;return1; }
43+
44+
uint8_t pluggedInterface;
45+
uint8_t pluggedEndpoint;
46+
47+
constuint8_t numEndpoints;
48+
constuint8_t numInterfaces;
49+
const EP_BUFFER_TYPE *endpointType;
50+
51+
PluggableUSBModule *next =NULL;
52+
53+
friendclassPluggableUSB_;
54+
};
55+
56+
classPluggableUSB_ {
57+
public:
58+
PluggableUSB_();
59+
boolplug(PluggableUSBModule *node);
60+
intgetInterface(uint8_t* interfaceCount);
61+
intgetDescriptor(USBSetup& setup);
62+
boolsetup(USBSetup& setup);
63+
voidgetShortName(char *iSerialNum);
64+
65+
private:
66+
uint8_t lastIf;
67+
uint8_t lastEp;
68+
PluggableUSBModule* rootNode;
69+
};
70+
71+
// Replacement for global singleton.
72+
// This function prevents static-initialization-order-fiasco
73+
// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
74+
PluggableUSB_&PluggableUSB();
75+
76+
#endif
77+
78+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp