Skip to content

Commit 0f9f63f

Browse files
committed
[PUSB] Made getDescriptor() and setup() more flexible
Alternatively we can only pass the wIndex to getDescriptor but I suggest to just pass the pointer aka reference of the whole setup. In guess (havent tested this) that this results in more or less the code size but its a) idential with the other functions and b) we late have more flexibility here. The Code got a quick SerialKeyboard.ino test
1 parent 6151972 commit 0f9f63f

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

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

+4-4
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ class PUSBListNode {
3535
inline uint8_t endpoint() const { return pluggedEndpoint; }
3636

3737
protected:
38-
virtual bool setup(USBSetup& setup, uint8_t interfaceNum) = 0;
38+
virtual bool setup(USBSetup& setup) = 0;
3939
virtual int getInterface(uint8_t* interfaceCount) = 0;
40-
virtual int getDescriptor(int8_t t) = 0;
40+
virtual int getDescriptor(USBSetup& setup) = 0;
4141

4242
uint8_t pluggedInterface;
4343
uint8_t pluggedEndpoint;
@@ -56,8 +56,8 @@ class PluggableUSB_ {
5656
PluggableUSB_();
5757
bool plug(PUSBListNode *node);
5858
int getInterface(uint8_t* interfaceCount);
59-
int getDescriptor(int8_t type);
60-
bool setup(USBSetup& setup, uint8_t interfaceNum);
59+
int getDescriptor(USBSetup& setup);
60+
bool setup(USBSetup& setup);
6161

6262
private:
6363
uint8_t lastIf;

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

+2-2
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

+14-15
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,21 @@ int HID_::getInterface(uint8_t* interfaceCount)
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 (interface() != 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)
@@ -76,9 +75,9 @@ void HID_::SendReport(uint8_t id, const void* data, int len)
7675
USB_Send(endpoint() | 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 (interface() != setup.wIndex) {
8281
return false;
8382
}
8483

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

+2-2
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)