Added Feature Report function to BootKeyboard
This may be added to other HID Devices as well, but Keyboard makes the most sense.
This commit is contained in:
parent
febc714df5
commit
a8c292a7bd
2 changed files with 59 additions and 4 deletions
|
|
@ -120,10 +120,12 @@ bool BootKeyboard_::setup(USBSetup& setup)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (request == HID_GET_PROTOCOL) {
|
if (request == HID_GET_PROTOCOL) {
|
||||||
|
// TODO improve
|
||||||
UEDATX = protocol;
|
UEDATX = protocol;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (request == HID_GET_IDLE) {
|
if (request == HID_GET_IDLE) {
|
||||||
|
// TODO improve
|
||||||
UEDATX = idle;
|
UEDATX = idle;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -141,10 +143,38 @@ bool BootKeyboard_::setup(USBSetup& setup)
|
||||||
}
|
}
|
||||||
if (request == HID_SET_REPORT)
|
if (request == HID_SET_REPORT)
|
||||||
{
|
{
|
||||||
// Check if data has the correct length
|
// Check if data has the correct length afterwards
|
||||||
auto length = setup.wLength;
|
int length = setup.wLength;
|
||||||
if(length == sizeof(leds)){
|
|
||||||
USB_RecvControl(&leds, length);
|
// 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,28 @@ public:
|
||||||
uint8_t getLeds(void);
|
uint8_t getLeds(void);
|
||||||
uint8_t getProtocol(void);
|
uint8_t getProtocol(void);
|
||||||
void wakeupHost(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:
|
protected:
|
||||||
// Implementation of the PUSBListNode
|
// Implementation of the PUSBListNode
|
||||||
|
|
@ -51,6 +73,9 @@ protected:
|
||||||
|
|
||||||
uint8_t leds;
|
uint8_t leds;
|
||||||
|
|
||||||
|
uint8_t* featureReport;
|
||||||
|
int featureLength;
|
||||||
|
|
||||||
virtual int send(void) override;
|
virtual int send(void) override;
|
||||||
};
|
};
|
||||||
extern BootKeyboard_ BootKeyboard;
|
extern BootKeyboard_ BootKeyboard;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue