Skip to content

Commit 56a955e

Browse files
committed
Modify class Serial_ for the new PluggableUSB API
The new class PluggableUSBModule in ArduinoCore-API does not implement the fuction void handleEndpoint(int ep) which was implemented in the previous version of the same class. This function now needs to be called as proper of SerialUSB and not of PluggableUSB().
1 parent 21a4780 commit 56a955e

File tree

4 files changed

+91
-97
lines changed

4 files changed

+91
-97
lines changed

Diff for: cores/arduino/USB/CDC.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <Arduino.h>
2020
#include <Reset.h> // Needed for auto-reset with 1200bps port touch
2121
#include "CDC.h"
22+
#include "USBAPI.h"
2223
#include "SAMD21_USBDevice.h"
2324

2425
#include <stdlib.h>

Diff for: cores/arduino/USB/CDC.h

+1-84
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "USBDesc.h"
77
#include "USBAPI.h"
8-
#include "PluggableUSB.h"
8+
#include "api/PluggableUSB.h"
99

1010

1111
#define CDC_V1_10 0x0110
@@ -74,88 +74,5 @@ typedef struct
7474
} CDCDescriptor;
7575

7676

77-
//================================================================================
78-
// Serial over CDC (Serial1 is the physical port)
79-
80-
class Serial_ : public Stream, public PluggableUSBModule {
81-
public:
82-
Serial_(USBDeviceClass &_usb);
83-
84-
void begin(uint32_t baud_count);
85-
void begin(unsigned long, uint8_t);
86-
void end(void);
87-
88-
virtual int available(void);
89-
virtual int availableForWrite(void);
90-
virtual int peek(void);
91-
virtual int read(void);
92-
virtual void flush(void);
93-
virtual void clear(void);
94-
virtual size_t write(uint8_t);
95-
virtual size_t write(const uint8_t *buffer, size_t size);
96-
using Print::write; // pull in write(str) from Print
97-
operator bool();
98-
99-
size_t readBytes(char *buffer, size_t length);
100-
101-
// This method allows processing "SEND_BREAK" requests sent by
102-
// the USB host. Those requests indicate that the host wants to
103-
// send a BREAK signal and are accompanied by a single uint16_t
104-
// value, specifying the duration of the break. The value 0
105-
// means to end any current break, while the value 0xffff means
106-
// to start an indefinite break.
107-
// readBreak() will return the value of the most recent break
108-
// request, but will return it at most once, returning -1 when
109-
// readBreak() is called again (until another break request is
110-
// received, which is again returned once).
111-
// This also mean that if two break requests are received
112-
// without readBreak() being called in between, the value of the
113-
// first request is lost.
114-
// Note that the value returned is a long, so it can return
115-
// 0-0xffff as well as -1.
116-
int32_t readBreak();
117-
118-
// These return the settings specified by the USB host for the
119-
// serial port. These aren't really used, but are offered here
120-
// in case a sketch wants to act on these settings.
121-
uint32_t baud();
122-
uint8_t stopbits();
123-
uint8_t paritytype();
124-
uint8_t numbits();
125-
bool dtr();
126-
bool rts();
127-
enum {
128-
ONE_STOP_BIT = 0,
129-
ONE_AND_HALF_STOP_BIT = 1,
130-
TWO_STOP_BITS = 2,
131-
};
132-
enum {
133-
NO_PARITY = 0,
134-
ODD_PARITY = 1,
135-
EVEN_PARITY = 2,
136-
MARK_PARITY = 3,
137-
SPACE_PARITY = 4,
138-
};
139-
140-
protected:
141-
// Implementation of the PUSBListNode
142-
int getInterface(uint8_t* interfaceNum);
143-
int getDescriptor(USBSetup& setup);
144-
bool setup(USBSetup& setup);
145-
uint8_t getShortName(char* name);
146-
void handleEndpoint(int ep);
147-
void enableInterrupt();
148-
149-
friend USBDeviceClass;
150-
151-
private:
152-
int availableForStore(void);
153-
154-
USBDeviceClass &usb;
155-
bool stalled;
156-
uint32_t epType[3];
157-
};
158-
extern Serial_ SerialUSB;
159-
16077
#endif
16178
#endif

Diff for: cores/arduino/USB/USBAPI.h

+82-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "api/Stream.h"
3434
#include "api/RingBuffer.h"
3535
#include "api/USBAPI.h"
36+
#include "CDC.h"
3637

3738
#if ARDUINO_API_VERSION > 10000
3839
using namespace arduino;
@@ -97,12 +98,87 @@ class USBDeviceClass {
9798
extern USBDeviceClass USBDevice;
9899

99100
//================================================================================
100-
//================================================================================
101-
// MSC 'Driver'
101+
// Serial over CDC (Serial1 is the physical port)
102+
103+
class Serial_ : public Stream, public arduino::PluggableUSBModule
104+
{
105+
public:
106+
Serial_(USBDeviceClass &_usb);
107+
void begin(uint32_t baud_count);
108+
void begin(unsigned long, uint8_t);
109+
void end(void);
110+
111+
virtual int available(void);
112+
virtual int availableForWrite(void);
113+
virtual int peek(void);
114+
virtual int read(void);
115+
virtual void flush(void);
116+
virtual void clear(void);
117+
virtual size_t write(uint8_t);
118+
virtual size_t write(const uint8_t *buffer, size_t size);
119+
using Print::write; // pull in write(str) from Print
120+
operator bool();
121+
122+
size_t readBytes(char *buffer, size_t length);
123+
124+
// This method allows processing "SEND_BREAK" requests sent by
125+
// the USB host. Those requests indicate that the host wants to
126+
// send a BREAK signal and are accompanied by a single uint16_t
127+
// value, specifying the duration of the break. The value 0
128+
// means to end any current break, while the value 0xffff means
129+
// to start an indefinite break.
130+
// readBreak() will return the value of the most recent break
131+
// request, but will return it at most once, returning -1 when
132+
// readBreak() is called again (until another break request is
133+
// received, which is again returned once).
134+
// This also mean that if two break requests are received
135+
// without readBreak() being called in between, the value of the
136+
// first request is lost.
137+
// Note that the value returned is a long, so it can return
138+
// 0-0xffff as well as -1.
139+
int32_t readBreak();
140+
141+
// These return the settings specified by the USB host for the
142+
// serial port. These aren't really used, but are offered here
143+
// in case a sketch wants to act on these settings.
144+
uint32_t baud();
145+
uint8_t stopbits();
146+
uint8_t paritytype();
147+
uint8_t numbits();
148+
bool dtr();
149+
bool rts();
150+
enum {
151+
ONE_STOP_BIT = 0,
152+
ONE_AND_HALF_STOP_BIT = 1,
153+
TWO_STOP_BITS = 2,
154+
};
155+
enum {
156+
NO_PARITY = 0,
157+
ODD_PARITY = 1,
158+
EVEN_PARITY = 2,
159+
MARK_PARITY = 3,
160+
SPACE_PARITY = 4,
161+
};
162+
163+
protected:
164+
// Implementation of the PUSBListNode
165+
int getInterface(uint8_t* interfaceNum);
166+
int getDescriptor(USBSetup& setup);
167+
bool setup(USBSetup& setup);
168+
uint8_t getShortName(char* name);
169+
void handleEndpoint(int ep);
170+
void enableInterrupt();
171+
172+
friend USBDeviceClass;
102173

103-
uint32_t MSC_GetInterface(uint8_t* interfaceNum);
104-
uint32_t MSC_GetDescriptor(uint32_t i);
105-
bool MSC_Setup(USBSetup& setup);
106-
bool MSC_Data(uint8_t rx,uint8_t tx);
174+
private:
175+
int availableForStore(void);
176+
177+
USBDeviceClass &usb;
178+
bool stalled;
179+
unsigned int epType[3];
180+
181+
};
182+
extern Serial_ SerialUSB;
107183

108184
#endif // __cplusplus

Diff for: cores/arduino/USB/USBCore.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <Arduino.h>
2222

23+
#include "api/USBAPI.h"
24+
#include "USBAPI.h"
2325
#include "SAMD21_USBDevice.h"
2426
#include "CDC.h"
2527
#include "api/PluggableUSB.h"
@@ -230,11 +232,9 @@ bool USBDeviceClass::sendDescriptor(USBSetup &setup)
230232
memset(name, 0, sizeof(name));
231233
uint8_t idx = 0;
232234
#ifdef PLUGGABLE_USB_ENABLED
233-
idx += PluggableUSB().getShortName(&name[idx]);
235+
PluggableUSB().getShortName(name);
236+
return sendStringDescriptor((uint8_t*)name, setup.wLength);
234237
#endif
235-
if (idx > 0) {
236-
return sendStringDescriptor((uint8_t*)name, setup.wLength);
237-
}
238238
}
239239
else {
240240
return false;
@@ -918,7 +918,7 @@ void USBDeviceClass::ISRHandler()
918918
epHandlers[ep]->handleEndpoint();
919919
} else {
920920
#if defined(PLUGGABLE_USB_ENABLED)
921-
PluggableUSB().handleEndpoint(ep);
921+
SerialUSB.handleEndpoint(ep);
922922
usbd.epAckPendingInterrupts(ep);
923923
#endif
924924
}
@@ -927,8 +927,8 @@ void USBDeviceClass::ISRHandler()
927927
}
928928

929929
// PluggableUSB contructor
930-
PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT),
931-
lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT),
930+
PluggableUSB_::PluggableUSB_() : lastIf(0),
931+
lastEp(1),
932932
rootNode(NULL), totalEP(USB_ENDPOINTS)
933933
{
934934
// Empty

0 commit comments

Comments
 (0)