Skip to content

Commit ae7441c

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 ff1b073 commit ae7441c

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

src/HID/HID.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int HID_::getInterface(uint8_t* interfaceCount)
3333
HIDDescriptor hidInterface = {
3434
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)
36+
D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x14)
3737
};
3838
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
3939
}
@@ -167,9 +167,9 @@ bool HID_::LockFeature(uint16_t id, bool lock) {
167167

168168
int HID_::SendReport(uint16_t id, const void* data, int len)
169169
{
170-
auto ret = USB_Send(HID_TX, &id, 1);
170+
auto ret = USB_Send(pluggedEndpoint, &id, 1);
171171
if (ret < 0) return ret;
172-
auto ret2 = USB_Send(HID_TX | TRANSFER_RELEASE, data, len);
172+
auto ret2 = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
173173
if (ret2 < 0) return ret2;
174174
return ret + ret2;
175175
}

src/HID/HID.h

Lines changed: 0 additions & 8 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

0 commit comments

Comments
 (0)