]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
added USB_EXTRA feature to HHKB/V-USB
authortmk <nobody@nowhere>
Sat, 21 May 2011 01:28:57 +0000 (10:28 +0900)
committertmk <nobody@nowhere>
Sat, 21 May 2011 01:28:57 +0000 (10:28 +0900)
command.c
hhkb/Makefile.vusb
host.h
keyboard.c
pjrc/host.c
pjrc/usb.c
vusb/host.c

index cd51b79cb30f2cb532ce44981d83244e92f1de81..ca149dbd08e4954404c37c3eeda8c048d5230f2a 100755 (executable)
--- a/command.c
+++ b/command.c
@@ -122,11 +122,15 @@ uint8_t command_proc(void)
 #endif
 #ifdef USB_EXTRA_ENABLE
         case KB_ESC:
+#ifdef HOST_PJRC
             if (suspend && remote_wakeup) {
                 usb_remote_wakeup();
             } else {
-                usb_extra_system_send(SYSTEM_POWER_DOWN);
+                host_system_send(SYSTEM_POWER_DOWN);
             }
+#else
+            host_system_send(SYSTEM_POWER_DOWN);
+#endif
             break;
 #endif
         case KB_BSPC:
index ea89a6f6a06799af60d441e0dbc1cf2743a50ed1..7826ffd02574c8c459c831953ab9e3c5975521ca 100644 (file)
@@ -42,7 +42,7 @@ F_CPU = 20000000
 #   comment out to disable the options.
 #
 MOUSEKEY_ENABLE = yes  # Mouse keys
-#USB_EXTRA_ENABLE = yes        # Enhanced feature for Windows(Audio control and System control)
+USB_EXTRA_ENABLE = yes # Enhanced feature for Windows(Audio control and System control)
 #USB_NKRO_ENABLE = yes # USB Nkey Rollover
 
 
diff --git a/host.h b/host.h
index 045ccd8e694fddef5592335fe4ea91f6fc68e20f..7ba9dd43c2b329de899563675f3f882b7c4ac9ad 100644 (file)
--- a/host.h
+++ b/host.h
@@ -4,6 +4,11 @@
 #include <stdint.h>
 
 
+/* report id */
+#define REPORT_ID_MOUSE     1
+#define REPORT_ID_SYSTEM    2
+#define REPORT_ID_AUDIO     3
+
 /* keyboard Modifiers in boot protocol report */
 #define BIT_LCTRL   (1<<0)
 #define BIT_LSHIFT  (1<<1)
 #define MOUSE_BTN4 (1<<3)
 #define MOUSE_BTN5 (1<<4)
 
+// Consumer Page(0x0C) Consumer Control(0x01)
+#define AUDIO_VOL_UP           (1<<0)
+#define AUDIO_VOL_DOWN         (1<<1)
+#define AUDIO_MUTE             (1<<2)
+
+// Generic Desktop Page(0x01) System Control(0x80)
+#define SYSTEM_POWER_DOWN      (1<<0)
+#define SYSTEM_SLEEP           (1<<1)
+#define SYSTEM_WAKE_UP         (1<<2)
+
 
 #if defined(HOST_PJRC)
 #   include "usb.h"
@@ -44,6 +59,7 @@ typedef struct {
 } report_keyboard_t;
 
 typedef struct {
+    uint8_t report_id;
     uint8_t buttons;
     int8_t x;
     int8_t y;
@@ -74,6 +90,12 @@ uint8_t host_get_first_key(void);
 
 
 void host_send_keyboard_report(void);
+#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
 void host_mouse_send(report_mouse_t *report);
+#endif
+#ifdef USB_EXTRA_ENABLE
+void host_system_send(uint8_t data);
+void host_audio_send(uint8_t data);
+#endif
 
 #endif
index 03db3257a2d83e4dac6295a2740f32f7618daf39..fd6e23042d1747e8f4fe300f3a68de097783066a 100644 (file)
@@ -11,9 +11,7 @@
 #ifdef MOUSEKEY_ENABLE
 #include "mousekey.h"
 #endif
-/* TODO: shoud make new API */
 #ifdef USB_EXTRA_ENABLE
-#include "usb_extra.h"
 #include <util/delay.h>
 #endif
 
@@ -68,23 +66,27 @@ void keyboard_proc(void)
 #ifdef USB_EXTRA_ENABLE
             // audio control & system control
             else if (code == KB_MUTE) {
-                usb_extra_audio_send(AUDIO_MUTE);
-                usb_extra_audio_send(0);
+                host_audio_send(AUDIO_MUTE);
                 _delay_ms(500);
+                host_audio_send(0);
             } else if (code == KB_VOLU) {
-                usb_extra_audio_send(AUDIO_VOL_UP);
-                usb_extra_audio_send(0);
+                host_audio_send(AUDIO_VOL_UP);
                 _delay_ms(200);
+                host_audio_send(0);
             } else if (code == KB_VOLD) {
-                usb_extra_audio_send(AUDIO_VOL_DOWN);
-                usb_extra_audio_send(0);
+                host_audio_send(AUDIO_VOL_DOWN);
                 _delay_ms(200);
+                host_audio_send(0);
             } else if (code == KB_PWR) {
+#ifdef HOST_PJRC
                 if (suspend && remote_wakeup) {
                     usb_remote_wakeup();
                 } else {
-                    usb_extra_system_send(SYSTEM_POWER_DOWN);
+                    host_system_send(SYSTEM_POWER_DOWN);
                 }
+#else
+                host_system_send(SYSTEM_POWER_DOWN);
+#endif
                 _delay_ms(1000);
             }
 #endif
index b69c6cb20c513af34347200bc6fc686c97f6814a..2a81e4c5ead1a4599c7dae84a06d0a753bc18c99 100644 (file)
@@ -2,7 +2,12 @@
 #include <avr/interrupt.h>
 #include "usb_keycodes.h"
 #include "usb_keyboard.h"
+#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
 #include "usb_mouse.h"
+#endif
+#ifdef USB_EXTRA_ENABLE
+#include "usb_extra.h"
+#endif
 #include "debug.h"
 #include "host.h"
 #include "util.h"
@@ -104,10 +109,24 @@ void host_send_keyboard_report(void)
     usb_keyboard_send_report(keyboard_report);
 }
 
+#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
 void host_mouse_send(report_mouse_t *report)
 {
     usb_mouse_send(report->x, report->y, report->v, report->h, report->buttons);
 }
+#endif
+
+#ifdef USB_EXTRA_ENABLE
+void host_system_send(uint8_t data)
+{
+    usb_extra_system_send(data);
+}
+
+void host_audio_send(uint8_t data)
+{
+    usb_extra_audio_send(data);
+}
+#endif
 
 
 static inline void add_key_byte(uint8_t code)
index b2c18d98dd2623d662f9a4fcf41aa866e6261bbe..711c0e68a0e178b90587fffb425a7b11f967bbd4 100755 (executable)
@@ -682,7 +682,11 @@ ISR(USB_GEN_vect)
                        }
                }
                 /* TODO: should keep IDLE rate on each keyboard interface */
+#ifdef USB_NKRO_ENABLE
                if (!keyboard_nkro && usb_keyboard_idle_config && (++div4 & 3) == 0) {
+#else
+               if (usb_keyboard_idle_config && (++div4 & 3) == 0) {
+#endif
                        UENUM = KBD_ENDPOINT;
                        if (UEINTX & (1<<RWAL)) {
                                usb_keyboard_idle_count++;
index c49eb62ae0a892dd0008411874839f37a7ee9f64..6b091a723fe2f12a613749a1785c491a0f6d6d2e 100644 (file)
@@ -133,14 +133,41 @@ void host_send_keyboard_report(void)
 }
 
 
+#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE)
 void host_mouse_send(report_mouse_t *report)
 {
+    report->report_id = REPORT_ID_MOUSE;
     if (usbInterruptIsReady3()) {
         usbSetInterrupt3((void *)report, sizeof(*report));
     } else {
         debug("Int3 not ready\n");
     }
 }
+#endif
+
+#ifdef USB_EXTRA_ENABLE
+void host_system_send(uint8_t data)
+{
+    static uint8_t report[] = { REPORT_ID_SYSTEM, 0 };
+    report[1] = data;
+    if (usbInterruptIsReady3()) {
+        usbSetInterrupt3((void *)&report, sizeof(report));
+    } else {
+        debug("Int3 not ready\n");
+    }
+}
+
+void host_audio_send(uint8_t data)
+{
+    static uint8_t report[] = { REPORT_ID_AUDIO, 0 };
+    report[1] = data;
+    if (usbInterruptIsReady3()) {
+        usbSetInterrupt3((void *)&report, sizeof(report));
+    } else {
+        debug("Int3 not ready\n");
+    }
+}
+#endif
 
 
 
@@ -265,77 +292,87 @@ PROGMEM uchar keyboard_hid_report[] = {
  * http://www.microsoft.com/whdc/device/input/wheel.mspx
  */
 PROGMEM uchar mouse_hid_report[] = {
-    /* from HID 1.11 spec example */
+    /* mouse */
     0x05, 0x01,        // USAGE_PAGE (Generic Desktop)
     0x09, 0x02,        // USAGE (Mouse)
     0xa1, 0x01,        // COLLECTION (Application)
-    0x09, 0x02,        //   USAGE (Mouse)
-    0xa1, 0x02,        //   COLLECTION (Logical)
-    0x09, 0x01,        //     USAGE (Pointer)
-    0xa1, 0x00,        //     COLLECTION (Physical)
-                       // ------------------------------  Buttons
-    0x05, 0x09,        //       USAGE_PAGE (Button)
-    0x19, 0x01,        //       USAGE_MINIMUM (Button 1)
-    0x29, 0x05,        //       USAGE_MAXIMUM (Button 5)
-    0x15, 0x00,        //       LOGICAL_MINIMUM (0)
-    0x25, 0x01,        //       LOGICAL_MAXIMUM (1)
-    0x75, 0x01,        //       REPORT_SIZE (1)
-    0x95, 0x05,        //       REPORT_COUNT (5)
-    0x81, 0x02,        //       INPUT (Data,Var,Abs)
-                       // ------------------------------  Padding
-    0x75, 0x03,        //       REPORT_SIZE (3)
-    0x95, 0x01,        //       REPORT_COUNT (1)
-    0x81, 0x03,        //       INPUT (Cnst,Var,Abs)
-                       // ------------------------------  X,Y position
-    0x05, 0x01,        //       USAGE_PAGE (Generic Desktop)
-    0x09, 0x30,        //       USAGE (X)
-    0x09, 0x31,        //       USAGE (Y)
-    0x15, 0x81,        //       LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,        //       LOGICAL_MAXIMUM (127)
-    0x75, 0x08,        //       REPORT_SIZE (8)
-    0x95, 0x02,        //       REPORT_COUNT (2)
-    0x81, 0x06,        //       INPUT (Data,Var,Rel)
-    0xa1, 0x02,        //       COLLECTION (Logical)
-                       // ------------------------------  Vertical wheel res multiplier
-    0x09, 0x48,        //         USAGE (Resolution Multiplier)
-    0x15, 0x00,        //         LOGICAL_MINIMUM (0)
-    0x25, 0x01,        //         LOGICAL_MAXIMUM (1)
-    0x35, 0x01,        //         PHYSICAL_MINIMUM (1)
-    0x45, 0x04,        //         PHYSICAL_MAXIMUM (4)
-    0x75, 0x02,        //         REPORT_SIZE (2)
-    0x95, 0x01,        //         REPORT_COUNT (1)
-    0xa4,              //         PUSH
-    0xb1, 0x02,        //         FEATURE (Data,Var,Abs)
-                       // ------------------------------  Vertical wheel
-    0x09, 0x38,        //         USAGE (Wheel)
-    0x15, 0x81,        //         LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,        //         LOGICAL_MAXIMUM (127)
-    0x35, 0x00,        //         PHYSICAL_MINIMUM (0)        - reset physical
-    0x45, 0x00,        //         PHYSICAL_MAXIMUM (0)
-    0x75, 0x08,        //         REPORT_SIZE (8)
-    0x81, 0x06,        //         INPUT (Data,Var,Rel)
-    0xc0,              //       END_COLLECTION
-    0xa1, 0x02,        //       COLLECTION (Logical)
-                       // ------------------------------  Horizontal wheel res multiplier
-    0x09, 0x48,        //         USAGE (Resolution Multiplier)
-    0xb4,              //         POP
-    0xb1, 0x02,        //         FEATURE (Data,Var,Abs)
-                       // ------------------------------  Padding for Feature report
-    0x35, 0x00,        //         PHYSICAL_MINIMUM (0)        - reset physical
-    0x45, 0x00,        //         PHYSICAL_MAXIMUM (0)
-    0x75, 0x04,        //         REPORT_SIZE (4)
-    0xb1, 0x03,        //         FEATURE (Cnst,Var,Abs)
-                       // ------------------------------  Horizontal wheel
-    0x05, 0x0c,        //         USAGE_PAGE (Consumer Devices)
-    0x0a, 0x38, 0x02,  //         USAGE (AC Pan)
-    0x15, 0x81,        //         LOGICAL_MINIMUM (-127)
-    0x25, 0x7f,        //         LOGICAL_MAXIMUM (127)
-    0x75, 0x08,        //         REPORT_SIZE (8)
-    0x81, 0x06,        //         INPUT (Data,Var,Rel)
-    0xc0,              //       END_COLLECTION
-    0xc0,              //     END_COLLECTION
+    0x85, 0x01,        //   REPORT_ID (1)
+    0x09, 0x01,        //   USAGE (Pointer)
+    0xa1, 0x00,        //   COLLECTION (Physical)
+                       // ----------------------------  Buttons
+    0x05, 0x09,        //     USAGE_PAGE (Button)
+    0x19, 0x01,        //     USAGE_MINIMUM (Button 1)
+    0x29, 0x05,        //     USAGE_MAXIMUM (Button 5)
+    0x15, 0x00,        //     LOGICAL_MINIMUM (0)
+    0x25, 0x01,        //     LOGICAL_MAXIMUM (1)
+    0x75, 0x01,        //     REPORT_SIZE (1)
+    0x95, 0x05,        //     REPORT_COUNT (5)
+    0x81, 0x02,        //     INPUT (Data,Var,Abs)
+                       // ----------------------------  Padding
+    0x75, 0x03,        //     REPORT_SIZE (3)
+    0x95, 0x01,        //     REPORT_COUNT (1)
+    0x81, 0x03,        //     INPUT (Cnst,Var,Abs)
+                       // ----------------------------  X,Y position
+    0x05, 0x01,        //     USAGE_PAGE (Generic Desktop)
+    0x09, 0x30,        //     USAGE (X)
+    0x09, 0x31,        //     USAGE (Y)
+    0x15, 0x81,        //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,        //     LOGICAL_MAXIMUM (127)
+    0x75, 0x08,        //     REPORT_SIZE (8)
+    0x95, 0x02,        //     REPORT_COUNT (2)
+    0x81, 0x06,        //     INPUT (Data,Var,Rel)
+                       // ----------------------------  Vertical wheel
+    0x09, 0x38,        //     USAGE (Wheel)
+    0x15, 0x81,        //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,        //     LOGICAL_MAXIMUM (127)
+    0x35, 0x00,        //     PHYSICAL_MINIMUM (0)        - reset physical
+    0x45, 0x00,        //     PHYSICAL_MAXIMUM (0)
+    0x75, 0x08,        //     REPORT_SIZE (8)
+    0x95, 0x01,        //     REPORT_COUNT (1)
+    0x81, 0x06,        //     INPUT (Data,Var,Rel)
+                       // ----------------------------  Horizontal wheel
+    0x05, 0x0c,        //     USAGE_PAGE (Consumer Devices)
+    0x0a, 0x38, 0x02,  //     USAGE (AC Pan)
+    0x15, 0x81,        //     LOGICAL_MINIMUM (-127)
+    0x25, 0x7f,        //     LOGICAL_MAXIMUM (127)
+    0x75, 0x08,        //     REPORT_SIZE (8)
+    0x95, 0x01,        //     REPORT_COUNT (1)
+    0x81, 0x06,        //     INPUT (Data,Var,Rel)
     0xc0,              //   END_COLLECTION
-    0xc0               // END_COLLECTION
+    0xc0,              // END_COLLECTION
+    /* system */
+    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
+    0x09, 0x80,                    // USAGE (System Control)
+    0xa1, 0x01,                    // COLLECTION (Application)
+    0x85, 0x02,                    //   REPORT_ID (2)
+    0x19, 0x81,                    //   USAGE_MINIMUM (System Power Down)
+    0x29, 0x83,                    //   USAGE_MAXIMUM (System Wake Up)
+    0x75, 0x01,                    //   REPORT_SIZE (1)
+    0x95, 0x03,                    //   REPORT_COUNT (3)
+    0x81, 0x06,                    //   INPUT (Data,Var,Rel)
+    0x95, 0x05,                    //   REPORT_COUNT (5)
+    0x81, 0x07,                    //   INPUT (Cnst,Var,Rel)
+    0xc0,                          // END_COLLECTION
+    /* audio */
+    0x05, 0x0c,                    // USAGE_PAGE (Consumer Devices)
+    0x09, 0x01,                    // USAGE (Consumer Control)
+    0xa1, 0x01,                    // COLLECTION (Application)
+    0x85, 0x03,                    //   REPORT_ID (3)
+    0x09, 0xe9,                    //   USAGE (Volume Up)
+    0x09, 0xea,                    //   USAGE (Volume Down)
+    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
+    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
+    0x75, 0x01,                    //   REPORT_SIZE (1)
+    0x95, 0x02,                    //   REPORT_COUNT (2)
+    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
+    0x09, 0xe2,                    //   USAGE (Mute)
+    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
+    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
+    0x95, 0x01,                    //   REPORT_COUNT (1)
+    0x81, 0x06,                    //   INPUT (Data,Var,Rel)
+    0x95, 0x05,                    //   REPORT_COUNT (5)
+    0x81, 0x07,                    //   INPUT (Cnst,Var,Abs)
+    0xc0,                          // END_COLLECTION
 };