Skip to content

Commit 4747184

Browse files
committed
HID: Replace manual defines with pluggedEndpoint member
Adopt coding style from https://github.com/arduino/ArduinoCore-avr/blob/master/libraries/HID/src/HID.cpp that uses "pluggedEndpoint" from the PluggableUSBModule base-class as endpoint number instead of a hardcoded preprocessor define. This allows removal of several defines in the header that are now unused. Benefits: * Closer alignment to the upstream Arduino sources. * Fewer hardcoded values, which will simplify future scaling to support multiple batteries in a USB composite device.
1 parent c798e14 commit 4747184

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

src/HID/HID.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ int HID_::getInterface(uint8_t* interfaceCount)
3131
{
3232
*interfaceCount += 1; // uses 1
3333
HIDDescriptor hidInterface = {
34-
D_INTERFACE(pluggedInterface, 2, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
34+
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
3535
D_HIDREPORT(descriptorSize),
36-
D_ENDPOINT(USB_ENDPOINT_IN(HID_TX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x14),
37-
D_ENDPOINT(USB_ENDPOINT_OUT(HID_RX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x0A)
36+
D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x14)
3837
};
3938
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
4039
}
@@ -168,9 +167,9 @@ bool HID_::LockFeature(uint16_t id, bool lock) {
168167

169168
int HID_::SendReport(uint16_t id, const void* data, int len)
170169
{
171-
auto ret = USB_Send(HID_TX, &id, 1);
170+
auto ret = USB_Send(pluggedEndpoint, &id, 1);
172171
if (ret < 0) return ret;
173-
auto ret2 = USB_Send(HID_TX | TRANSFER_RELEASE, data, len);
172+
auto ret2 = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
174173
if (ret2 < 0) return ret2;
175174
return ret + ret2;
176175
}
@@ -254,12 +253,11 @@ bool HID_::setup(USBSetup& setup)
254253
return false;
255254
}
256255

257-
HID_::HID_(void) : PluggableUSBModule(2, 1, epType),
256+
HID_::HID_(void) : PluggableUSBModule(1, 1, epType),
258257
rootNode(NULL), descriptorSize(0),
259258
protocol(HID_REPORT_PROTOCOL), idle(1)
260259
{
261260
epType[0] = EP_TYPE_INTERRUPT_IN;
262-
epType[1] = EP_TYPE_INTERRUPT_OUT;
263261
PluggableUSB().plug(this);
264262
}
265263

src/HID/HID.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@
6161
#define HID_REPORT_TYPE_OUTPUT 2
6262
#define HID_REPORT_TYPE_FEATURE 3
6363

64-
#define HID_INTERFACE (CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT) // HID Interface
65-
#define HID_FIRST_ENDPOINT (CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT)
66-
#define HID_ENDPOINT_INT (HID_FIRST_ENDPOINT)
67-
#define HID_ENDPOINT_OUT (HID_FIRST_ENDPOINT+1)
68-
69-
#define HID_TX HID_ENDPOINT_INT
70-
#define HID_RX HID_ENDPOINT_OUT //++ EP HID_RX for ease of use with USB_Available & USB_Rec
71-
7264
typedef struct
7365
{
7466
uint8_t len; // 9
@@ -87,7 +79,6 @@ typedef struct
8779
InterfaceDescriptor hid;
8880
HIDDescDescriptor desc;
8981
EndpointDescriptor in;
90-
EndpointDescriptor out; //added
9182
} HIDDescriptor;
9283

9384
class HIDReport {
@@ -138,7 +129,7 @@ class HID_ : public PluggableUSBModule
138129
uint8_t getShortName(char* name) override;
139130

140131
private:
141-
uint8_t epType[2];
132+
uint8_t epType[1];
142133

143134
HIDSubDescriptor* rootNode;
144135
uint16_t descriptorSize;

0 commit comments

Comments
 (0)