]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
add build option USB_12KRO.
authortmk <nobody@nowhere>
Thu, 25 Nov 2010 16:56:21 +0000 (01:56 +0900)
committertmk <nobody@nowhere>
Thu, 25 Nov 2010 16:56:21 +0000 (01:56 +0900)
Makefile.common
hhkb/Makefile
usb.c
usb_keyboard.c
usb_keyboard.c.bak [deleted file]
usb_keyboard.h

index 467f6e777b1cd8659a84a230c7aa75c083bc4a64..7f3f9ae50aafb7ab0bae40617bc4b17dbd48f768 100644 (file)
@@ -129,6 +129,9 @@ CDEFS += -DPRODUCT=$(PRODUCT)
 ifdef MOUSE_DELAY_TIME
 CDEFS += -DMOUSE_DELAY_TIME=$(MOUSE_DELAY_TIME)
 endif
+ifdef USB_12KRO
+CDEFS += -DUSB_12KRO
+endif
 
 
 # Place -D or -U options here for ASM sources
index 7339e70232090cec198337f78de0d3382fe47941..c248a67588d0f5085211870f11ba2d6691f8a618 100644 (file)
@@ -46,6 +46,7 @@ PRODUCT = 't.m.k. HHKB pro'
 DESCRIPTION = 't.m.k. firmware for HHKB pro'
 
 MOUSE_DELAY_TIME = 127
+USB_12KRO = yes
 
 # Target file name (without extension).
 TARGET = tmk_hhkb
diff --git a/usb.c b/usb.c
index 00708340a72e6786698736f970f5aa8e0c3f13c1..e633b9638331225cd3ec2f73384b56eefd812af6 100644 (file)
--- a/usb.c
+++ b/usb.c
 #   define STR_PRODUCT         LSTR(PRODUCT)
 #endif
 
-#define STR_KEYBOARD_INTERFACE L"t.m.k. keyboard I/F"
-#define STR_MOUSE_INTERFACE    L"t.m.k. mouse I/F"
-#define STR_DEBUG_INTERFACE    L"t.m.k. debug I/F"
-#define STR_EXTRA_INTERFACE    L"t.m.k. extrakey I/F"
-#define STR_KEYBOARD2_INTERFACE        L"t.m.k. keyboard2 I/F"
-
 
 // Mac OS-X and Linux automatically load the correct drivers.  On
 // Windows, even though the driver is supplied by Microsoft, an
@@ -100,7 +94,11 @@ static const uint8_t PROGMEM endpoint_config_table[] = {
        1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(MOUSE_SIZE)    | MOUSE_BUFFER,    // 2
        1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3
        1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(EXTRA_SIZE)    | EXTRA_BUFFER,    // 4
+#ifdef USB_12KRO
        1, EP_TYPE_INTERRUPT_IN,  EP_SIZE(KEYBOARD_SIZE) | KEYBOARD_BUFFER, // 5
+#else
+        0, // 5
+#endif
         0, // 6
 };
 
@@ -298,13 +296,17 @@ static uint8_t PROGMEM extra_hid_report_desc[] = {
     0xc0                           // END_COLLECTION
 };
 
-#define NUM_INTERFACES                 5
-#define KEYBOARD_HID_DESC_OFFSET       (9+9)
-#define MOUSE_HID_DESC_OFFSET          (9+(9+9+7)+9)
-#define DEBUG_HID_DESC_OFFSET          (9+(9+9+7)+(9+9+7)+9)
-#define EXTRA_HID_DESC_OFFSET          (9+(9+9+7)+(9+9+7)+(9+9+7)+9)
-#define KEYBOARD2_HID_DESC_OFFSET      (9+(9+9+7)+(9+9+7)+(9+9+7)+(9+9+7)+9)
-#define CONFIG1_DESC_SIZE              (9+(9+9+7)+(9+9+7)+(9+9+7)+(9+9+7)+(9+9+7))
+#define KEYBOARD_HID_DESC_OFFSET       (9+(9+9+7)*0+9)
+#define MOUSE_HID_DESC_OFFSET          (9+(9+9+7)*1+9)
+#define DEBUG_HID_DESC_OFFSET          (9+(9+9+7)*2+9)
+#define EXTRA_HID_DESC_OFFSET          (9+(9+9+7)*3+9)
+#ifdef USB_12KRO
+#   define NUM_INTERFACES              5
+#   define KEYBOARD2_HID_DESC_OFFSET   (9+(9+9+7)*4+9)
+#else
+#   define NUM_INTERFACES              4
+#endif
+#define CONFIG1_DESC_SIZE              (9+(9+9+7)*NUM_INTERFACES)
 static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
        // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
        9,                                      // bLength;
@@ -326,7 +328,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
        0x03,                                   // bInterfaceClass (0x03 = HID)
        0x01,                                   // bInterfaceSubClass (0x01 = Boot)
        0x01,                                   // bInterfaceProtocol (0x01 = Keyboard)
-       3,                                      // iInterface
+       0,                                      // iInterface
        // HID descriptor, HID 1.11 spec, section 6.2.1
        9,                                      // bLength
        0x21,                                   // bDescriptorType
@@ -353,7 +355,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
        0x03,                                   // bInterfaceClass (0x03 = HID)
        0x01,                                   // bInterfaceSubClass (0x01 = Boot)
        0x02,                                   // bInterfaceProtocol (0x02 = Mouse)
-       4,                                      // iInterface
+       0,                                      // iInterface
        // HID descriptor, HID 1.11 spec, section 6.2.1
        9,                                      // bLength
        0x21,                                   // bDescriptorType
@@ -380,7 +382,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
        0x03,                                   // bInterfaceClass (0x03 = HID)
        0x00,                                   // bInterfaceSubClass
        0x00,                                   // bInterfaceProtocol
-       5,                                      // iInterface
+       0,                                      // iInterface
        // HID descriptor, HID 1.11 spec, section 6.2.1
        9,                                      // bLength
        0x21,                                   // bDescriptorType
@@ -407,7 +409,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
        0x03,                                   // bInterfaceClass (0x03 = HID)
        0x00,                                   // bInterfaceSubClass
        0x00,                                   // bInterfaceProtocol
-       6,                                      // iInterface
+       0,                                      // iInterface
        // HID descriptor, HID 1.11 spec, section 6.2.1
        9,                                      // bLength
        0x21,                                   // bDescriptorType
@@ -425,6 +427,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
        EXTRA_SIZE, 0,                          // wMaxPacketSize
        10,                                     // bInterval
 
+#ifdef USB_12KRO
        // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
        9,                                      // bLength
        4,                                      // bDescriptorType
@@ -434,7 +437,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
        0x03,                                   // bInterfaceClass (0x03 = HID)
        0x00,                                   // bInterfaceSubClass (0x01 = Boot)
        0x00,                                   // bInterfaceProtocol (0x01 = Keyboard)
-       7,                                      // iInterface
+       0,                                      // iInterface
        // HID descriptor, HID 1.11 spec, section 6.2.1
        9,                                      // bLength
        0x21,                                   // bDescriptorType
@@ -451,6 +454,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
        0x03,                                   // bmAttributes (0x03=intr)
        KEYBOARD_SIZE, 0,                       // wMaxPacketSize
        1,                                      // bInterval
+#endif
 };
 
 // If you're desperate for a little extra code memory, these strings
@@ -476,31 +480,6 @@ static struct usb_string_descriptor_struct PROGMEM string2 = {
        3,
        STR_PRODUCT
 };
-static struct usb_string_descriptor_struct PROGMEM string3 = {
-       sizeof(STR_KEYBOARD_INTERFACE),
-       3,
-       STR_KEYBOARD_INTERFACE
-};
-static struct usb_string_descriptor_struct PROGMEM string4 = {
-       sizeof(STR_MOUSE_INTERFACE),
-       3,
-       STR_MOUSE_INTERFACE
-};
-static struct usb_string_descriptor_struct PROGMEM string5 = {
-       sizeof(STR_DEBUG_INTERFACE),
-       3,
-       STR_DEBUG_INTERFACE
-};
-static struct usb_string_descriptor_struct PROGMEM string6 = {
-       sizeof(STR_EXTRA_INTERFACE),
-       3,
-       STR_EXTRA_INTERFACE
-};
-static struct usb_string_descriptor_struct PROGMEM string7 = {
-       sizeof(STR_KEYBOARD2_INTERFACE),
-       3,
-       STR_KEYBOARD2_INTERFACE
-};
 
 // This table defines which descriptor data is sent for each specific
 // request from the host (in wValue and wIndex).
@@ -523,17 +502,14 @@ static struct descriptor_list_struct {
        {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
        {0x2100, EXTRA_INTERFACE, config1_descriptor+EXTRA_HID_DESC_OFFSET, 9},
        {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)},
+#ifdef USB_12KRO
        {0x2100, KEYBOARD_INTERFACE2, config1_descriptor+KEYBOARD2_HID_DESC_OFFSET, 9},
        {0x2200, KEYBOARD_INTERFACE2, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
+#endif
         // STRING descriptors
        {0x0300, 0x0000, (const uint8_t *)&string0, 4},
        {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
-       {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)},
-       {0x0303, 0x0409, (const uint8_t *)&string3, sizeof(STR_KEYBOARD_INTERFACE)},
-       {0x0304, 0x0409, (const uint8_t *)&string4, sizeof(STR_MOUSE_INTERFACE)},
-       {0x0305, 0x0409, (const uint8_t *)&string5, sizeof(STR_DEBUG_INTERFACE)},
-       {0x0306, 0x0409, (const uint8_t *)&string6, sizeof(STR_EXTRA_INTERFACE)},
-       {0x0307, 0x0409, (const uint8_t *)&string7, sizeof(STR_KEYBOARD2_INTERFACE)},
+       {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)}
 };
 #define NUM_DESC_LIST (sizeof(descriptor_list)/sizeof(struct descriptor_list_struct))
 
index 7f32a9083e47867cce3c65a1cd84cd3d78905820..3e13ae4e36d8967656e8cb866c46bf766dd26516 100644 (file)
@@ -64,6 +64,7 @@ int8_t usb_keyboard_send_report(usb_keyboard_report_t *report)
        UEINTX = 0x3A;
        SREG = intr_state;
 
+#ifdef USB_12KRO
        if (!usb_configured()) return -1;
        intr_state = SREG;
        cli();
@@ -82,17 +83,18 @@ int8_t usb_keyboard_send_report(usb_keyboard_report_t *report)
                cli();
                UENUM = KEYBOARD_ENDPOINT2;
        }
-       UEDATX = 0;
+       UEDATX = report->mods;
        UEDATX = 0;
        for (i = 6; i < 12; i++) {
                UEDATX = report->keys[i];
        }
        UEINTX = 0x3A;
        SREG = intr_state;
+#endif
 
        usb_keyboard_idle_count = 0;
-        report->is_sent =true;
-        usb_keyboard_print_report(report);
+       report->is_sent =true;
+       usb_keyboard_print_report(report);
        return 0;
 }
 
diff --git a/usb_keyboard.c.bak b/usb_keyboard.c.bak
deleted file mode 100644 (file)
index e136307..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-#include <avr/interrupt.h>
-#include <avr/pgmspace.h>
-#include "usb_keycodes.h"
-#include "usb_keyboard.h"
-#include "print.h"
-#include "debug.h"
-
-
-// keyboard report.
-static usb_keyboard_report_t _report0 = { {0}, 0 };
-static usb_keyboard_report_t _report1 = { {0}, 0 };
-usb_keyboard_report_t *usb_keyboard_report = &_report0;
-usb_keyboard_report_t *usb_keyboard_report_back = &_report1;
-
-// protocol setting from the host.  We use exactly the same report
-// either way, so this variable only stores the setting since we
-// are required to be able to report which setting is in use.
-uint8_t usb_keyboard_protocol=1;
-
-// the idle configuration, how often we send the report to the
-// host (ms * 4) even when it hasn't changed
-uint8_t usb_keyboard_idle_config=125;
-
-// count until idle timeout
-uint8_t usb_keyboard_idle_count=0;
-
-// 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
-volatile uint8_t usb_keyboard_leds=0;
-
-
-int8_t usb_keyboard_send(void)
-{
-    return usb_keyboard_send_report(usb_keyboard_report);
-}
-
-
-int8_t usb_keyboard_send_report(usb_keyboard_report_t *report)
-{
-       uint8_t i, intr_state, timeout;
-
-       if (!usb_configured()) return -1;
-
-       timeout = UDFNUML + 50;
-        do {
-               intr_state = SREG;
-               cli();
-               UENUM = KEYBOARD_ENDPOINT;
-               // are we ready to transmit?
-               if (UEINTX & (1<<RWAL)) break;
-               SREG = intr_state;
-
-               // has the USB gone offline?
-               if (!usb_configured()) return -1;
-               // have we waited too long?
-               if (UDFNUML == timeout) return -1;
-       } while (1);
-       UEDATX = report->mods;
-       UEDATX = 0;
-       for (i = 0; i < 6; i++) {
-               UEDATX = report->keys[i];
-       }
-       UEINTX = 0x3A;
-
-/*
-       timeout = UDFNUML + 50;
-       do {
-               intr_state = SREG;
-               cli();
-               UENUM = KEYBOARD_ENDPOINT2;
-               // are we ready to transmit?
-               if (UEINTX & (1<<RWAL)) break;
-               SREG = intr_state;
-
-               // has the USB gone offline?
-               if (!usb_configured()) return -1;
-               // have we waited too long?
-               if (UDFNUML == timeout) return -1;
-       } while (1);
-       UEDATX = 0;
-       UEDATX = 0;
-       for (i = 6; i < 12; i++) {
-               UEDATX = report->keys[i];
-       }
-       UEINTX = 0x3A;
-*/
-
-       usb_keyboard_idle_count = 0;
-       report->is_sent =true;
-       usb_keyboard_print_report(report);
-       return 0;
-}
-
-void usb_keyboard_swap_report(void) {
-    usb_keyboard_report_t *tmp = usb_keyboard_report_back;
-    usb_keyboard_report_back = usb_keyboard_report;
-    usb_keyboard_report = tmp;
-}
-
-void usb_keyboard_clear_report(void) {
-    usb_keyboard_clear_keys();
-    usb_keyboard_clear_mods();
-    usb_keyboard_report->is_sent = false;
-}
-
-void usb_keyboard_clear_keys(void) {
-    for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) usb_keyboard_report->keys[i] = 0;
-}
-
-void usb_keyboard_clear_mods(void)
-{
-    usb_keyboard_report->mods = 0;
-}
-
-void usb_keyboard_add_code(uint8_t code)
-{
-    if (IS_MOD(code)) {
-        usb_keyboard_add_mod(code);
-    } else {
-        usb_keyboard_add_key(code);
-    }
-}
-
-void usb_keyboard_add_key(uint8_t code)
-{
-    for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) {
-        if (!usb_keyboard_report->keys[i]) {
-            usb_keyboard_report->keys[i] = code;
-            return;
-        }
-    }
-}
-
-void usb_keyboard_set_keys(uint8_t *keys)
-{
-    for (int i = 0; i < KEYBOARD_REPORT_MAX; i++)
-        usb_keyboard_report->keys[i] = keys[i];
-}
-
-void usb_keyboard_set_mods(uint8_t mods)
-{
-    usb_keyboard_report->mods = mods;
-}
-
-void usb_keyboard_add_mod(uint8_t code)
-{
-    usb_keyboard_report->mods |= MOD_BIT(code);
-}
-
-void usb_keyboard_del_code(uint8_t code)
-{
-    if (IS_MOD(code)) {
-        usb_keyboard_del_mod(code);
-    } else {
-        usb_keyboard_del_key(code);
-    }
-}
-
-void usb_keyboard_del_key(uint8_t code)
-{
-    for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) {
-        if (usb_keyboard_report->keys[i] == code) {
-            usb_keyboard_report->keys[i] = KB_NO;
-            return;
-        }
-    }
-}
-
-void usb_keyboard_del_mod(uint8_t code)
-{
-    usb_keyboard_report->mods &= ~MOD_BIT(code);
-}
-
-bool usb_keyboard_is_sent(void)
-{
-    return usb_keyboard_report->is_sent;
-}
-
-bool usb_keyboard_has_key(void)
-{
-    uint8_t keys = 0;    
-    for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) keys |= usb_keyboard_report->keys[i];
-    return keys ? true : false;
-}
-
-bool usb_keyboard_has_mod(void)
-{
-    return usb_keyboard_report->mods ? true : false;
-}
-
-void usb_keyboard_print_report(usb_keyboard_report_t *report)
-{
-    if (!debug_keyboard) return;
-    print("keys: ");
-    for (int i = 0; i < KEYBOARD_REPORT_MAX; i++) { phex(report->keys[i]); print(" "); }
-    print(" mods: "); phex(report->mods); print("\n");
-}
index 6c8fa0b543b854e815be94c6a3a50efc4f3930c8..872e2afc7215cf7b5d6c93fbe22088a0012d2ffd 100644 (file)
@@ -8,8 +8,10 @@
 
 #define KEYBOARD_INTERFACE     0
 #define KEYBOARD_ENDPOINT      1
+#ifdef USB_12KRO
 #define KEYBOARD_INTERFACE2    4
 #define KEYBOARD_ENDPOINT2     5
+#endif
 #define KEYBOARD_SIZE          8
 #define KEYBOARD_BUFFER                EP_DOUBLE_BUFFER
 
 #define BIT_LSFT BIT_LSHIFT
 #define BIT_RSFT BIT_RSHIFT
 
-#define KEYBOARD_REPORT_MAX    12
+#ifdef USB_12KRO
+#   define KEYBOARD_REPORT_MAX 12
+#else
+#   define KEYBOARD_REPORT_MAX 6
+#endif
 typedef struct report {
     uint8_t keys[KEYBOARD_REPORT_MAX];
     uint8_t mods;