]> git.donarmstrong.com Git - tmk_firmware.git/commitdiff
Add LED indicator support in mbed
authortmk <nobody@nowhere>
Fri, 20 Jun 2014 05:39:49 +0000 (14:39 +0900)
committertmk <nobody@nowhere>
Wed, 30 Jul 2014 05:07:43 +0000 (14:07 +0900)
protocol/mbed/HIDKeyboard.cpp
protocol/mbed/HIDKeyboard.h
protocol/mbed/mbed_driver.cpp

index f40c2d2f2ab57a6b8ae4324f7f8ec6736b0079e8..947077cd2453c64ad1bbad9ef3beaed33734608d 100644 (file)
@@ -17,6 +17,10 @@ bool HIDKeyboard::sendReport(report_keyboard_t report) {
     return true;
 }
 
+uint8_t HIDKeyboard::leds() {
+    return led_state;
+}
+
 bool HIDKeyboard::USBCallback_setConfiguration(uint8_t configuration) {
     if (configuration != DEFAULT_CONFIGURATION) {
         return false;
@@ -228,29 +232,40 @@ bool HIDKeyboard::USBCallback_request() {
     }
 
     // Process class-specific requests
-/*
     if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
     {
-        switch (transfer->setup.bRequest)
-        {
-             case SET_REPORT:
-                // First byte will be used for report ID
-                //outputReport.data[0] = transfer->setup.wValue & 0xff;
-                //outputReport.length = transfer->setup.wLength + 1;
-                outputReport.length = transfer->setup.wLength;
-
-                //transfer->remaining = sizeof(outputReport.data) - 1;
-                //transfer->ptr = &outputReport.data[1];
-                transfer->remaining = sizeof(outputReport.data);
-                transfer->ptr = &outputReport.data[0];
+        switch (transfer->setup.bRequest) {
+            case SET_REPORT:
+                // LED indicator
+                // TODO: check Interface and Report length?
+                // if (transfer->setup.wIndex == INTERFACE_KEYBOAD) { }
+                // if (transfer->setup.wLength == 1)
+
+                transfer->remaining = 1;
+                //transfer->ptr = ?? what ptr should be set when OUT(not used?)
                 transfer->direction = HOST_TO_DEVICE;
-                transfer->notify = true;
+                transfer->notify = true;    /* notify with USBCallback_requestCompleted */
                 success = true;
             default:
                 break;
         }
     }
-*/
 
     return success;
 }
+
+void HIDKeyboard::USBCallback_requestCompleted(uint8_t * buf, uint32_t length)
+{
+    if (length > 0) {
+        CONTROL_TRANSFER *transfer = getTransferPtr();
+        if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
+            switch (transfer->setup.bRequest) {
+                case SET_REPORT:
+                    led_state = buf[0];
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+}
index 4ebe610a6379bafa65480a1412720aca96d66888..c537e5ecee18c8e951ce11572b81fedda9fa2caf 100644 (file)
@@ -11,6 +11,7 @@ public:
     HIDKeyboard(uint16_t vendor_id = 0xFEED, uint16_t product_id = 0xabed, uint16_t product_release = 0x0001);
 
     bool sendReport(report_keyboard_t report);
+    uint8_t leds(void);
 protected:
     uint16_t reportLength;
     virtual bool USBCallback_setConfiguration(uint8_t configuration);
@@ -22,6 +23,9 @@ protected:
     virtual uint8_t * configurationDesc();
     //virtual uint8_t * deviceDesc();
     virtual bool USBCallback_request();
+    virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length);
+private:
+    uint8_t led_state;
 };
 
 #endif
index 333f8e3782cb763adee8cf0da4c943d093f089a6..6c7b16e23d2313acd43cb331fe71d9050f1dac20 100644 (file)
@@ -24,7 +24,7 @@ host_driver_t mbed_driver = {
 
 static uint8_t keyboard_leds(void)
 {
-    return 0;
+    return keyboard.leds();
 }
 static void send_keyboard(report_keyboard_t *report)
 {