Skip to content

Commit 3390a10

Browse files
committed
Merge remote-tracking branch 'nico/plugfix3'
2 parents c280955 + 05477fc commit 3390a10

File tree

5 files changed

+37
-38
lines changed

5 files changed

+37
-38
lines changed

hardware/arduino/avr/cores/arduino/PluggableUSB.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ int PluggableUSB_::getInterface(uint8_t* interfaceCount)
3838
return sent;
3939
}
4040

41-
int PluggableUSB_::getDescriptor(int8_t type)
41+
int PluggableUSB_::getDescriptor(USBSetup& setup)
4242
{
4343
PUSBListNode* node;
4444
for (node = rootNode; node; node = node->next) {
45-
int ret = node->getDescriptor(type);
45+
int ret = node->getDescriptor(setup);
4646
// ret!=0 -> request has been processed
4747
if (ret)
4848
return ret;
4949
}
5050
return 0;
5151
}
5252

53-
bool PluggableUSB_::setup(USBSetup& setup, uint8_t interfaceNum)
53+
bool PluggableUSB_::setup(USBSetup& setup)
5454
{
5555
PUSBListNode* node;
5656
for (node = rootNode; node; node = node->next) {
57-
if (node->setup(setup, interfaceNum)) {
57+
if (node->setup(setup)) {
5858
return true;
5959
}
6060
}

hardware/arduino/avr/cores/arduino/PluggableUSB.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,20 @@
2727

2828
class PUSBListNode {
2929
public:
30-
PUSBListNode(int8_t numEps, int8_t numIfs, uint8_t *epType) :
30+
PUSBListNode(uint8_t numEps, uint8_t numIfs, uint8_t *epType) :
3131
numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType)
3232
{ }
3333

34-
inline uint8_t interface() const { return pluggedInterface; }
35-
inline int8_t endpoint() const { return pluggedEndpoint; }
36-
3734
protected:
38-
virtual bool setup(USBSetup& setup, uint8_t interfaceNum) = 0;
35+
virtual bool setup(USBSetup& setup) = 0;
3936
virtual int getInterface(uint8_t* interfaceCount) = 0;
40-
virtual int getDescriptor(int8_t t) = 0;
37+
virtual int getDescriptor(USBSetup& setup) = 0;
4138

4239
uint8_t pluggedInterface;
43-
int8_t pluggedEndpoint;
40+
uint8_t pluggedEndpoint;
4441

45-
const int8_t numEndpoints;
46-
const int8_t numInterfaces;
42+
const uint8_t numEndpoints;
43+
const uint8_t numInterfaces;
4744
const uint8_t *endpointType;
4845

4946
PUSBListNode *next = NULL;
@@ -56,8 +53,8 @@ class PluggableUSB_ {
5653
PluggableUSB_();
5754
bool plug(PUSBListNode *node);
5855
int getInterface(uint8_t* interfaceCount);
59-
int getDescriptor(int8_t type);
60-
bool setup(USBSetup& setup, uint8_t interfaceNum);
56+
int getDescriptor(USBSetup& setup);
57+
bool setup(USBSetup& setup);
6158

6259
private:
6360
uint8_t lastIf;

hardware/arduino/avr/cores/arduino/USBCore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ bool ClassInterfaceRequest(USBSetup& setup)
362362
return CDC_Setup(setup);
363363

364364
#ifdef PLUGGABLE_USB_ENABLED
365-
return PluggableUSB().setup(setup, i);
365+
return PluggableUSB().setup(setup);
366366
#endif
367367
return false;
368368
}
@@ -476,7 +476,7 @@ bool SendDescriptor(USBSetup& setup)
476476

477477
InitControl(setup.wLength);
478478
#ifdef PLUGGABLE_USB_ENABLED
479-
ret = PluggableUSB().getDescriptor(t);
479+
ret = PluggableUSB().getDescriptor(setup);
480480
if (ret != 0) {
481481
return (ret > 0 ? true : false);
482482
}

hardware/arduino/avr/libraries/HID/HID.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,28 @@ int HID_::getInterface(uint8_t* interfaceCount)
3131
{
3232
*interfaceCount += 1; // uses 1
3333
HIDDescriptor hidInterface = {
34-
D_INTERFACE(interface(), 1, 3, 0, 0),
34+
D_INTERFACE(pluggedInterface, 1, 3, 0, 0),
3535
D_HIDREPORT(descriptorSize),
36-
D_ENDPOINT(USB_ENDPOINT_IN(endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
36+
D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
3737
};
3838
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
3939
}
4040

41-
int HID_::getDescriptor(int8_t type)
41+
int HID_::getDescriptor(USBSetup& setup)
4242
{
43-
if (HID_REPORT_DESCRIPTOR_TYPE == type) {
44-
int total = 0;
45-
HIDDescriptorListNode* node;
46-
for (node = rootNode; node; node = node->next) {
47-
int res = USB_SendControl(TRANSFER_PGM, node->data, node->length);
48-
if (res == -1)
49-
return -1;
50-
total += res;
51-
}
52-
return total;
43+
if (pluggedInterface != setup.wIndex) {
44+
return 0;
5345
}
5446

55-
// Ignored
56-
return 0;
47+
int total = 0;
48+
HIDDescriptorListNode* node;
49+
for (node = rootNode; node; node = node->next) {
50+
int res = USB_SendControl(TRANSFER_PGM, node->data, node->length);
51+
if (res == -1)
52+
return -1;
53+
total += res;
54+
}
55+
return total;
5756
}
5857

5958
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
@@ -72,13 +71,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node)
7271

7372
void HID_::SendReport(uint8_t id, const void* data, int len)
7473
{
75-
USB_Send(endpoint(), &id, 1);
76-
USB_Send(endpoint() | TRANSFER_RELEASE, data, len);
74+
USB_Send(pluggedEndpoint, &id, 1);
75+
USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
7776
}
7877

79-
bool HID_::setup(USBSetup& setup, uint8_t interfaceNum)
78+
bool HID_::setup(USBSetup& setup)
8079
{
81-
if (interface() != interfaceNum) {
80+
if (pluggedInterface != setup.wIndex) {
8281
return false;
8382
}
8483

@@ -107,6 +106,9 @@ bool HID_::setup(USBSetup& setup, uint8_t interfaceNum)
107106
idle = setup.wValueL;
108107
return true;
109108
}
109+
if (request == HID_SET_REPORT)
110+
{
111+
}
110112
}
111113

112114
return false;

hardware/arduino/avr/libraries/HID/HID.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class HID_ : public PUSBListNode
8080
protected:
8181
// Implementation of the PUSBListNode
8282
int getInterface(uint8_t* interfaceCount);
83-
int getDescriptor(int8_t type);
84-
bool setup(USBSetup& setup, uint8_t interfaceNum);
83+
int getDescriptor(USBSetup& setup);
84+
bool setup(USBSetup& setup);
8585

8686
private:
8787
uint8_t epType[1];

0 commit comments

Comments
 (0)