Skip to content

Adds support for Keyboard LED (Caps Lock, Scroll Lock, Num Lock) #446

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 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
29 changes: 26 additions & 3 deletions libraries/HID/src/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,48 @@ bool HID_::setup(USBSetup& setup)
}
if (request == HID_SET_REPORT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is keyboard LEDs the only time this kind of request is being actively used? I'd prefer to add some more generic API as in PluggableUSB framework

{
//uint8_t reportID = setup.wValueL;
//uint16_t length = setup.wLength;
//uint8_t data[length];
uint8_t reportID = setup.wValueL;
uint16_t length = setup.wLength;
uint8_t data[length];
// Make sure to not read more data than USB_EP_SIZE.
// You can read multiple times through a loop.
// The first byte (may!) contain the reportID on a multreport.
//USB_RecvControl(data, length);
if ((reportID == 2) && (length == 2))
{
if (2 == USB_RecvControl(data, length))
{
_keyboardLedsStatus = data[1];
if (keyboardLedsStatusReportCallback != 0)
{
keyboardLedsStatusReportCallback();
}
return true;
}
}
}
}

return false;
}

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

void HID_::setKeyboardLedsStatusReportCallback(void (*callback) (void) )
{
keyboardLedsStatusReportCallback = callback;
}

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

int HID_::begin(void)
Expand Down
6 changes: 5 additions & 1 deletion libraries/HID/src/HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ 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);
void setKeyboardLedsStatusReportCallback(void (*callback) (void) );

protected:
// Implementation of the PluggableUSBModule
int getInterface(uint8_t* interfaceCount);
Expand All @@ -111,6 +113,8 @@ class HID_ : public PluggableUSBModule

uint8_t protocol;
uint8_t idle;
uint8_t _keyboardLedsStatus;
void (*keyboardLedsStatusReportCallback) (void);
};

// Replacement for global singleton.
Expand Down