Skip to content

Commit 5d6e56c

Browse files
committed
[HID] Now HID extends directly PluggableUSBListNode
This avoid duplicate instatiation of callback and save a considerable amount of flash.
1 parent ee3cf76 commit 5d6e56c

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ HIDDescriptor _hidInterface;
3636
static HIDDescriptorListNode* rootNode = NULL;
3737
static uint16_t sizeof_hidReportDescriptor = 0;
3838
static uint8_t modules_count = 0;
39+
static uint8_t epType[] = { EP_TYPE_INTERRUPT_IN };
40+
3941
//================================================================================
4042
//================================================================================
4143
// Driver
@@ -132,18 +134,14 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
132134

133135
HID_::HID_(void)
134136
{
135-
static uint8_t endpointType[1];
136-
endpointType[0] = EP_TYPE_INTERRUPT_IN;
137-
138-
static PUSBListNode node;
139-
node.setup = &HID_Setup,
140-
node.getInterface = &HID_GetInterface,
141-
node.getDescriptor = &HID_GetDescriptor,
142-
node.numEndpoints = 1,
143-
node.numInterfaces = 1,
144-
node.endpointType = endpointType,
145-
146-
HID_ENDPOINT_INT = PluggableUSB.addFunction(&node, &HID_INTERFACE);
137+
setup = &HID_Setup;
138+
getInterface = &HID_GetInterface;
139+
getDescriptor = &HID_GetDescriptor;
140+
numEndpoints = 1;
141+
numInterfaces = 1;
142+
endpointType = epType;
143+
144+
HID_ENDPOINT_INT = PluggableUSB.addFunction(this, &HID_INTERFACE);
147145
}
148146

149147
int HID_::begin(void)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <stdint.h>
2626
#include <Arduino.h>
27+
#include "PluggableUSB.h"
2728

2829
#if defined(USBCON)
2930

@@ -53,7 +54,7 @@ class HIDDescriptorListNode {
5354
uint16_t length;
5455
};
5556

56-
class HID_
57+
class HID_ : public PUSBListNode
5758
{
5859
public:
5960
HID_(void);

0 commit comments

Comments
 (0)