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

Commite7cda3c

Browse files
committed
Initial move of USB APIs and make PluggableUSB generic
1 parentcf53821 commite7cda3c

File tree

4 files changed

+90
-28
lines changed

4 files changed

+90
-28
lines changed

‎api/ArduinoAPI.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,21 @@
3232
#include"IPAddress.h"
3333
#include"Print.h"
3434
#include"Printable.h"
35+
#include"PluggableUSB.h"
3536
#include"Server.h"
3637
#include"String.h"
3738
#include"Stream.h"
3839
#include"Udp.h"
40+
#include"USBAPI.h"
3941
#endif
4042

43+
/* Standard C library includes */
44+
#include<stdlib.h>
45+
#include<stdbool.h>
46+
#include<string.h>
47+
#include<math.h>
48+
49+
// Misc Arduino core functions
50+
#include"Common.h"
51+
4152
#endif

‎api/PluggableUSB.cpp‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
#include"USBAPI.h"
2121
#include"PluggableUSB.h"
2222

23-
#if defined(USBCON)
24-
#ifdef PLUGGABLE_USB_ENABLED
25-
26-
extern _EP_BUFFER_TYPE _EP_BUFFER_NAME[];
27-
2823
intPluggableUSB_::getInterface(uint8_t* interfaceCount)
2924
{
3025
int sent =0;
@@ -72,7 +67,7 @@ bool PluggableUSB_::setup(USBSetup& setup)
7267

7368
boolPluggableUSB_::plug(PluggableUSBModule *node)
7469
{
75-
if ((lastEp + node->numEndpoints) >USB_ENDPOINTS) {
70+
if ((lastEp + node->numEndpoints) >totalEP) {
7671
returnfalse;
7772
}
7873

@@ -90,7 +85,7 @@ bool PluggableUSB_::plug(PluggableUSBModule *node)
9085
node->pluggedEndpoint = lastEp;
9186
lastIf += node->numInterfaces;
9287
for (uint8_t i =0; i < node->numEndpoints; i++) {
93-
_EP_BUFFER_NAME[lastEp] = node->endpointType[i];
88+
*(unsignedint*)(epBuffer(lastEp)) = node->endpointType[i];
9489
lastEp++;
9590
}
9691
returntrue;
@@ -101,15 +96,4 @@ PluggableUSB_& PluggableUSB()
10196
{
10297
static PluggableUSB_ obj;
10398
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)*/
99+
}

‎api/PluggableUSB.h‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222

2323
#include"USBAPI.h"
2424
#include<stdint.h>
25+
#include<stddef.h>
2526

2627
// core need to define
27-
// EP_BUFFER_TYPE
28-
// EP_BUFFER_NAME
29-
30-
#if defined(USBCON)
28+
void*epBuffer(unsignedint n);// -> returns a poointer to the Nth element of the EP buffer structure
3129

3230
classPluggableUSBModule {
3331
public:
34-
PluggableUSBModule(uint8_t numEps,uint8_t numIfs,EP_BUFFER_TYPE *epType) :
32+
PluggableUSBModule(uint8_t numEps,uint8_t numIfs,unsignedint *epType) :
3533
numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType)
3634
{ }
3735

@@ -46,7 +44,7 @@ class PluggableUSBModule {
4644

4745
constuint8_t numEndpoints;
4846
constuint8_t numInterfaces;
49-
constEP_BUFFER_TYPE *endpointType;
47+
constunsignedint *endpointType;
5048

5149
PluggableUSBModule *next =NULL;
5250

@@ -66,13 +64,12 @@ class PluggableUSB_ {
6664
uint8_t lastIf;
6765
uint8_t lastEp;
6866
PluggableUSBModule* rootNode;
67+
uint8_t totalEP;
6968
};
7069

7170
// Replacement for global singleton.
7271
// This function prevents static-initialization-order-fiasco
7372
// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use
7473
PluggableUSB_&PluggableUSB();
7574

76-
#endif
77-
78-
#endif
75+
#endif

‎api/USBAPI.h‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
USBAPI.h
3+
Copyright (c) 2005-2014 Arduino. All right reserved.
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 __USBAPI__
21+
#define__USBAPI__
22+
23+
#include<stdint.h>
24+
25+
classUSBDevice_
26+
{
27+
public:
28+
USBDevice_();
29+
boolconfigured();
30+
31+
voidattach();
32+
voiddetach();// Serial port goes down too...
33+
voidpoll();
34+
boolwakeupHost();// returns false, when wakeup cannot be processed
35+
};
36+
extern USBDevice_ USBDevice;
37+
38+
//================================================================================
39+
//================================================================================
40+
// Low level API
41+
42+
typedefstruct__attribute__((packed))
43+
{
44+
uint8_t bmRequestType;
45+
uint8_t bRequest;
46+
uint8_t wValueL;
47+
uint8_t wValueH;
48+
uint16_t wIndex;
49+
uint16_t wLength;
50+
} USBSetup;
51+
52+
//================================================================================
53+
//================================================================================
54+
55+
#defineTRANSFER_PGM0x80
56+
#defineTRANSFER_RELEASE0x40
57+
#defineTRANSFER_ZERO0x20
58+
59+
intUSB_SendControl(uint8_t flags,constvoid* d,int len);
60+
intUSB_RecvControl(void* d,int len);
61+
intUSB_RecvControlLong(void* d,int len);
62+
63+
uint8_tUSB_Available(uint8_t ep);
64+
uint8_tUSB_SendSpace(uint8_t ep);
65+
intUSB_Send(uint8_t ep,constvoid* data,int len);// blocking
66+
intUSB_Recv(uint8_t ep,void* data,int len);// non-blocking
67+
intUSB_Recv(uint8_t ep);// non-blocking
68+
voidUSB_Flush(uint8_t ep);
69+
70+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp