Skip to content

Add LED status capability #358

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

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 16 additions & 2 deletions libraries/HID/src/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ int HID_::getDescriptor(USBSetup& setup)
return -1;
total += res;
}

// Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol
// due to the USB specs, but Windows and Linux just assumes its in report mode.
protocol = HID_REPORT_PROTOCOL;

return total;
}

Expand Down Expand Up @@ -86,6 +86,11 @@ void HID_::AppendDescriptor(HIDSubDescriptor *node)
descriptorSize += node->length;
}

uint8_t HID_::getKeyboardLedsStatus(void)
{
return _keyboardLedsStatus;
}

int HID_::SendReport(uint8_t id, const void* data, int len)
{
auto ret = USB_Send(pluggedEndpoint, &id, 1);
Expand Down Expand Up @@ -133,6 +138,15 @@ bool HID_::setup(USBSetup& setup)
}
if (request == HID_SET_REPORT)
{
if (setup.wLength == 2)
{
uint8_t data[2];
if (2 == USB_RecvControl(data, 2))
{
_keyboardLedsStatus = data[1];
return true;
}
}
//uint8_t reportID = setup.wValueL;
//uint16_t length = setup.wLength;
//uint8_t data[length];
Expand Down
4 changes: 3 additions & 1 deletion libraries/HID/src/HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef struct
uint8_t descLenH;
} HIDDescDescriptor;

typedef struct
typedef struct
{
InterfaceDescriptor hid;
HIDDescDescriptor desc;
Expand All @@ -95,6 +95,7 @@ class HID_ : public PluggableUSBModule
int begin(void);
int SendReport(uint8_t id, const void* data, int len);
void AppendDescriptor(HIDSubDescriptor* node);
uint8_t getKeyboardLedsStatus(void);

protected:
// Implementation of the PluggableUSBModule
Expand All @@ -111,6 +112,7 @@ class HID_ : public PluggableUSBModule

uint8_t protocol;
uint8_t idle;
uint8_t _keyboardLedsStatus;
};

// Replacement for global singleton.
Expand Down