Skip to content

Commit

Permalink
Added Feature Report function to BootKeyboard
Browse files Browse the repository at this point in the history
This may be added to other HID Devices as well, but Keyboard makes the most sense.
  • Loading branch information
NicoHood committed Nov 7, 2015
1 parent febc714 commit a8c292a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/SingleReport/BootKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ bool BootKeyboard_::setup(USBSetup& setup)
return true;
}
if (request == HID_GET_PROTOCOL) {
// TODO improve
UEDATX = protocol;
return true;
}
if (request == HID_GET_IDLE) {
// TODO improve
UEDATX = idle;
return true;
}
Expand All @@ -141,10 +143,38 @@ bool BootKeyboard_::setup(USBSetup& setup)
}
if (request == HID_SET_REPORT)
{
// Check if data has the correct length
auto length = setup.wLength;
if(length == sizeof(leds)){
USB_RecvControl(&leds, length);
// Check if data has the correct length afterwards
int length = setup.wLength;

// Feature (set feature report)
if(setup.wValueH == HID_REPORT_TYPE_FEATURE){
// No need to check for negative featureLength values,
// except the host tries to send more then 32k bytes.
// We dont have that much ram anyways.
if (length == featureLength) {
USB_RecvControl(featureReport, featureLength);

// Block until data is read (make length negative)
disableFeatureReport();
return true;
}
}

// Output (set led states)
else if(setup.wValueH == HID_REPORT_TYPE_OUTPUT){
if(length == sizeof(leds)){
USB_RecvControl(&leds, length);
return true;
}
}

// Input (set HID report)
else if(setup.wValueH == HID_REPORT_TYPE_INPUT)
{
if(length == sizeof(_keyReport)){
USB_RecvControl(&_keyReport, length);
return true;
}
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/SingleReport/BootKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ class BootKeyboard_ : public PluggableUSBModule, public DefaultKeyboardAPI
uint8_t getLeds(void);
uint8_t getProtocol(void);
void wakeupHost(void);

void setFeatureReport(void* report, int length){
if(length > 0){
featureReport = (uint8_t*)report;
featureLength = length;
}
}

int availableFeatureReport(void){
if(featureLength < 0){
return featureLength & ~0x8000;
}
return 0;
}

void enableFeatureReport(void){
featureLength &= ~0x8000;
}

void disableFeatureReport(void){
featureLength |= 0x8000;
}

protected:
// Implementation of the PUSBListNode
Expand All @@ -51,6 +73,9 @@ class BootKeyboard_ : public PluggableUSBModule, public DefaultKeyboardAPI

uint8_t leds;

uint8_t* featureReport;
int featureLength;

virtual int send(void) override;
};
extern BootKeyboard_ BootKeyboard;
Expand Down

0 comments on commit a8c292a

Please sign in to comment.