Skip to content

HID: Replace manual defines with pluggedEndpoint member #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/HID/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ int HID_::getInterface(uint8_t* interfaceCount)
{
*interfaceCount += 1; // uses 1
HIDDescriptor hidInterface = {
D_INTERFACE(pluggedInterface, 2, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
D_HIDREPORT(descriptorSize),
D_ENDPOINT(USB_ENDPOINT_IN(HID_TX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x14),
D_ENDPOINT(USB_ENDPOINT_OUT(HID_RX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x0A)
D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x14)
};
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
}
Expand Down Expand Up @@ -168,9 +167,9 @@ bool HID_::LockFeature(uint16_t id, bool lock) {

int HID_::SendReport(uint16_t id, const void* data, int len)
{
auto ret = USB_Send(HID_TX, &id, 1);
auto ret = USB_Send(pluggedEndpoint, &id, 1);
if (ret < 0) return ret;
auto ret2 = USB_Send(HID_TX | TRANSFER_RELEASE, data, len);
auto ret2 = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
if (ret2 < 0) return ret2;
return ret + ret2;
}
Expand Down Expand Up @@ -254,12 +253,11 @@ bool HID_::setup(USBSetup& setup)
return false;
}

HID_::HID_(void) : PluggableUSBModule(2, 1, epType),
HID_::HID_(void) : PluggableUSBModule(1, 1, epType),
rootNode(NULL), descriptorSize(0),
protocol(HID_REPORT_PROTOCOL), idle(1)
{
epType[0] = EP_TYPE_INTERRUPT_IN;
epType[1] = EP_TYPE_INTERRUPT_OUT;
PluggableUSB().plug(this);
}

Expand Down
11 changes: 1 addition & 10 deletions src/HID/HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@
#define HID_REPORT_TYPE_OUTPUT 2
#define HID_REPORT_TYPE_FEATURE 3

#define HID_INTERFACE (CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT) // HID Interface
#define HID_FIRST_ENDPOINT (CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT)
#define HID_ENDPOINT_INT (HID_FIRST_ENDPOINT)
#define HID_ENDPOINT_OUT (HID_FIRST_ENDPOINT+1)

#define HID_TX HID_ENDPOINT_INT
#define HID_RX HID_ENDPOINT_OUT //++ EP HID_RX for ease of use with USB_Available & USB_Rec

typedef struct
{
uint8_t len; // 9
Expand All @@ -87,7 +79,6 @@ typedef struct
InterfaceDescriptor hid;
HIDDescDescriptor desc;
EndpointDescriptor in;
EndpointDescriptor out; //added
} HIDDescriptor;

class HIDReport {
Expand Down Expand Up @@ -139,7 +130,7 @@ class HID_ : public PluggableUSBModule
uint8_t getShortName(char* name) override;

private:
uint8_t epType[2];
uint8_t epType[1];

HIDSubDescriptor* rootNode;
uint16_t descriptorSize;
Expand Down