From b1362aa792552373a6a2c028aefcc8a0878f09c6 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Tue, 5 Nov 2013 19:16:15 +0100 Subject: HID: added set_feature_report(). --- usb/hid.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/usb/hid.h b/usb/hid.h index 5e3447e..bb5b9d7 100644 --- a/usb/hid.h +++ b/usb/hid.h @@ -233,6 +233,7 @@ class USB_HID : public USB_class_driver { enum ControlState { None, SetOutputReport, + SetFeatureReport, }; const uint8_t interface_num; @@ -278,6 +279,12 @@ class USB_HID : public USB_class_driver { return SetupStatus::Ok; } + // Set feature report. + if(bmRequestType == 0x21 && wIndex == interface_num && bRequest == 0x09 && (wValue & 0xff00) == 0x0300) { + controlstate = SetFeatureReport; + return SetupStatus::Ok; + } + return SetupStatus::Unhandled; } @@ -292,21 +299,36 @@ class USB_HID : public USB_class_driver { return; } + bool res = false; + switch(controlstate) { case SetOutputReport: usb.read(ep, buf, len); - set_output_report(buf, len); + res = set_output_report(buf, len); + break; + + case SetFeatureReport: + usb.read(ep, buf, len); + res = set_feature_report(buf, len); break; + default: break; } - - usb.write(0, nullptr, 0); + if(res) { + usb.write(0, nullptr, 0); + } else { + usb.hw_set_stall(0); + } } virtual bool set_output_report(uint32_t* buf, uint32_t len) { return false; } + + virtual bool set_feature_report(uint32_t* buf, uint32_t len) { + return false; + } }; #endif -- cgit v1.2.3