Skip to content

Commit 34a75d9

Browse files
committed
[PUSB] Selected interface and endpoint are now part of PUSBListNode
The method int8_t PluggableUSB::addFunction(PUSBListNode *, uint8_t *) has been changed to bool PluggableUSB::plug(PUSBListNode *node) since both EP and Interfaces are now saved directly into node
1 parent 7811c2c commit 34a75d9

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

cores/arduino/PluggableUSB.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ bool PluggableUSB_::setup(USBSetup& setup, u8 j)
6868
return ret;
6969
}
7070

71-
int8_t PluggableUSB_::addFunction(PUSBListNode *node, u8* interface)
71+
bool PluggableUSB_::plug(PUSBListNode *node)
7272
{
7373
if (modules_count >= MAX_MODULES) {
74-
return 0;
74+
return false;
7575
}
7676

7777
if (modules_count == 0) {
@@ -84,14 +84,15 @@ int8_t PluggableUSB_::addFunction(PUSBListNode *node, u8* interface)
8484
current->next = node;
8585
}
8686

87-
*interface = lastIf;
87+
node->pluggedInterface = lastIf;
88+
node->pluggedEndpoint = lastEp;
8889
lastIf += node->numInterfaces;
89-
for ( u8 i = 0; i< node->numEndpoints; i++) {
90+
for (uint8_t i=0; i<node->numEndpoints; i++) {
9091
_initEndpoints[lastEp] = node->endpointType[i];
9192
lastEp++;
9293
}
9394
modules_count++;
94-
return lastEp - node->numEndpoints;
95+
return true;
9596
// restart USB layer???
9697
}
9798

cores/arduino/PluggableUSB.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,22 @@ class PUSBListNode {
3535
int8_t numInterfaces;
3636
uint8_t *endpointType;
3737

38+
inline uint8_t interface() const { return pluggedInterface; }
39+
inline int8_t endpoint() const { return pluggedEndpoint; }
40+
41+
protected:
42+
uint8_t pluggedInterface;
43+
int8_t pluggedEndpoint;
44+
3845
public:
3946
PUSBListNode *next = NULL;
47+
48+
friend class PluggableUSB_;
4049
};
4150

4251
class PluggableUSB_ {
4352
public:
44-
static int8_t addFunction(PUSBListNode *node, u8 *interface);
53+
static bool plug(PUSBListNode *node);
4554
static int getInterface(u8* interfaceNum);
4655
static int getDescriptor(int8_t t);
4756
static bool setup(USBSetup& setup, u8 i);

libraries/HID/HID.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@
2323

2424
HID_ HID;
2525

26-
static uint8_t HID_ENDPOINT_INT;
27-
2826
//================================================================================
2927
//================================================================================
3028
// HID Interface
3129

32-
static uint8_t HID_INTERFACE;
33-
3430
HIDDescriptor _hidInterface;
3531

3632
static HIDDescriptorListNode* rootNode = NULL;
@@ -50,9 +46,9 @@ int HID_GetInterface(uint8_t* interfaceNum)
5046
interfaceNum[0] += 1; // uses 1
5147
_hidInterface =
5248
{
53-
D_INTERFACE(HID_INTERFACE,1,3,0,0),
49+
D_INTERFACE(HID.interface(), 1, 3, 0, 0),
5450
D_HIDREPORT(sizeof_hidReportDescriptor),
55-
D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,USB_EP_SIZE,0x01)
51+
D_ENDPOINT(USB_ENDPOINT_IN(HID.endpoint()), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01)
5652
};
5753
return USB_SendControl(0,&_hidInterface,sizeof(_hidInterface));
5854
}
@@ -89,13 +85,13 @@ void HID_::AppendDescriptor(HIDDescriptorListNode *node)
8985

9086
void HID_::SendReport(u8 id, const void* data, int len)
9187
{
92-
USB_Send(HID_TX, &id, 1);
93-
USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
88+
USB_Send(HID.endpoint(), &id, 1);
89+
USB_Send(HID.endpoint() | TRANSFER_RELEASE,data,len);
9490
}
9591

9692
bool HID_Setup(USBSetup& setup, uint8_t i)
9793
{
98-
if (HID_INTERFACE != i) {
94+
if (HID.interface() != i) {
9995
return false;
10096
} else {
10197
uint8_t r = setup.bRequest;
@@ -141,7 +137,7 @@ HID_::HID_(void)
141137
numInterfaces = 1;
142138
endpointType = epType;
143139

144-
HID_ENDPOINT_INT = PluggableUSB.addFunction(this, &HID_INTERFACE);
140+
PluggableUSB.plug(this);
145141
}
146142

147143
int HID_::begin(void)

libraries/HID/HID.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ typedef struct
8383
EndpointDescriptor in;
8484
} HIDDescriptor;
8585

86-
#define HID_TX HID_ENDPOINT_INT
87-
8886
#define D_HIDREPORT(_descriptorLength) \
8987
{ 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength & 0xFF, _descriptorLength >> 8 }
9088

0 commit comments

Comments
 (0)