diff options
-rw-r--r-- | common/report.h | 9 | ||||
-rw-r--r-- | common/usb_keycodes.h | 1 | ||||
-rw-r--r-- | converter/usb_usb/Makefile | 131 | ||||
-rw-r--r-- | converter/usb_usb/config.h | 40 | ||||
-rw-r--r-- | converter/usb_usb/keymap.c | 251 | ||||
-rw-r--r-- | converter/usb_usb/led.c | 24 | ||||
-rw-r--r-- | converter/usb_usb/main.cpp | 95 | ||||
-rw-r--r-- | converter/usb_usb/matrix.c | 133 | ||||
-rw-r--r-- | protocol/usb_hid/parser.cpp | 17 |
9 files changed, 699 insertions, 2 deletions
diff --git a/common/report.h b/common/report.h index 45f5c0b88..a73e0aba1 100644 --- a/common/report.h +++ b/common/report.h | |||
@@ -78,6 +78,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
78 | # define REPORT_KEYS 6 | 78 | # define REPORT_KEYS 6 |
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | |||
82 | #ifdef __cplusplus | ||
83 | extern "C" { | ||
84 | #endif | ||
85 | |||
81 | typedef struct { | 86 | typedef struct { |
82 | uint8_t mods; | 87 | uint8_t mods; |
83 | uint8_t rserved; | 88 | uint8_t rserved; |
@@ -92,4 +97,8 @@ typedef struct { | |||
92 | int8_t h; | 97 | int8_t h; |
93 | } __attribute__ ((packed)) report_mouse_t; | 98 | } __attribute__ ((packed)) report_mouse_t; |
94 | 99 | ||
100 | #ifdef __cplusplus | ||
101 | } | ||
102 | #endif | ||
103 | |||
95 | #endif | 104 | #endif |
diff --git a/common/usb_keycodes.h b/common/usb_keycodes.h index 9b6cce153..04b398fa2 100644 --- a/common/usb_keycodes.h +++ b/common/usb_keycodes.h | |||
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
24 | 24 | ||
25 | 25 | ||
26 | #define IS_ERROR(code) (KB_ROLL_OVER <= (code) && (code) <= KB_UNDEFINED) | 26 | #define IS_ERROR(code) (KB_ROLL_OVER <= (code) && (code) <= KB_UNDEFINED) |
27 | #define IS_ANY(code) (KB_A <= (code)) | ||
27 | #define IS_KEY(code) (KB_A <= (code) && (code) <= KB_EXSEL) | 28 | #define IS_KEY(code) (KB_A <= (code) && (code) <= KB_EXSEL) |
28 | #define IS_MOD(code) (KB_LCTRL <= (code) && (code) <= KB_RGUI) | 29 | #define IS_MOD(code) (KB_LCTRL <= (code) && (code) <= KB_RGUI) |
29 | #define IS_FN(code) (KB_FN0 <= (code) && (code) <= KB_FN7) | 30 | #define IS_FN(code) (KB_FN0 <= (code) && (code) <= KB_FN7) |
diff --git a/converter/usb_usb/Makefile b/converter/usb_usb/Makefile new file mode 100644 index 000000000..4565ca508 --- /dev/null +++ b/converter/usb_usb/Makefile | |||
@@ -0,0 +1,131 @@ | |||
1 | #---------------------------------------------------------------------------- | ||
2 | # On command line: | ||
3 | # | ||
4 | # make all = Make software. | ||
5 | # | ||
6 | # make clean = Clean out built project files. | ||
7 | # | ||
8 | # make coff = Convert ELF to AVR COFF. | ||
9 | # | ||
10 | # make extcoff = Convert ELF to AVR Extended COFF. | ||
11 | # | ||
12 | # make program = Download the hex file to the device. | ||
13 | # Please customize your programmer settings(PROGRAM_CMD) | ||
14 | # | ||
15 | # make teensy = Download the hex file to the device, using teensy_loader_cli. | ||
16 | # (must have teensy_loader_cli installed). | ||
17 | # | ||
18 | # make dfu = Download the hex file to the device, using dfu-programmer (must | ||
19 | # have dfu-programmer installed). | ||
20 | # | ||
21 | # make flip = Download the hex file to the device, using Atmel FLIP (must | ||
22 | # have Atmel FLIP installed). | ||
23 | # | ||
24 | # make dfu-ee = Download the eeprom file to the device, using dfu-programmer | ||
25 | # (must have dfu-programmer installed). | ||
26 | # | ||
27 | # make flip-ee = Download the eeprom file to the device, using Atmel FLIP | ||
28 | # (must have Atmel FLIP installed). | ||
29 | # | ||
30 | # make debug = Start either simulavr or avarice as specified for debugging, | ||
31 | # with avr-gdb or avr-insight as the front end for debugging. | ||
32 | # | ||
33 | # make filename.s = Just compile filename.c into the assembler code only. | ||
34 | # | ||
35 | # make filename.i = Create a preprocessed source file for use in submitting | ||
36 | # bug reports to the GCC project. | ||
37 | # | ||
38 | # To rebuild project do "make clean" then "make all". | ||
39 | #---------------------------------------------------------------------------- | ||
40 | |||
41 | # Target file name (without extension). | ||
42 | TARGET = usb_usb | ||
43 | |||
44 | TOP_DIR = ../.. | ||
45 | |||
46 | # Directory keyboard dependent files exist | ||
47 | TARGET_DIR = . | ||
48 | |||
49 | # MCU name | ||
50 | MCU = atmega32u4 | ||
51 | |||
52 | |||
53 | # Processor frequency. | ||
54 | # This will define a symbol, F_CPU, in all source code files equal to the | ||
55 | # processor frequency in Hz. You can then use this symbol in your source code to | ||
56 | # calculate timings. Do NOT tack on a 'UL' at the end, this will be done | ||
57 | # automatically to create a 32-bit value in your source code. | ||
58 | # | ||
59 | # This will be an integer division of F_USB below, as it is sourced by | ||
60 | # F_USB after it has run through any CPU prescalers. Note that this value | ||
61 | # does not *change* the processor frequency - it should merely be updated to | ||
62 | # reflect the processor speed set externally so that the code can use accurate | ||
63 | # software delays. | ||
64 | F_CPU = 16000000 | ||
65 | |||
66 | |||
67 | |||
68 | # | ||
69 | # LUFA specific | ||
70 | # | ||
71 | # Target architecture (see library "Board Types" documentation). | ||
72 | ARCH = AVR8 | ||
73 | # Input clock frequency. | ||
74 | # This will define a symbol, F_USB, in all source code files equal to the | ||
75 | # input clock frequency (before any prescaling is performed) in Hz. This value may | ||
76 | # differ from F_CPU if prescaling is used on the latter, and is required as the | ||
77 | # raw input clock is fed directly to the PLL sections of the AVR for high speed | ||
78 | # clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL' | ||
79 | # at the end, this will be done automatically to create a 32-bit value in your | ||
80 | # source code. | ||
81 | # | ||
82 | # If no clock division is performed on the input clock inside the AVR (via the | ||
83 | # CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU. | ||
84 | F_USB = $(F_CPU) | ||
85 | # Interrupt driven control endpoint task | ||
86 | OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT | ||
87 | |||
88 | |||
89 | |||
90 | # Build Options | ||
91 | # comment out to disable the options. | ||
92 | # | ||
93 | MOUSEKEY_ENABLE = yes # Mouse keys | ||
94 | EXTRAKEY_ENABLE = yes # Media control and System control | ||
95 | CONSOLE_ENABLE = yes # Console for debug | ||
96 | #NKRO_ENABLE = yes # USB Nkey Rollover | ||
97 | |||
98 | # Boot Section Size in bytes | ||
99 | # Teensy halfKay 512 | ||
100 | # Atmel DFU loader 4096 | ||
101 | # LUFA bootloader 4096 | ||
102 | #OPT_DEFS += -DBOOT_SIZE=4096 | ||
103 | |||
104 | |||
105 | |||
106 | SRC = \ | ||
107 | keymap.c \ | ||
108 | matrix.c \ | ||
109 | led.c \ | ||
110 | main.cpp | ||
111 | |||
112 | CONFIG_H = config.h | ||
113 | |||
114 | |||
115 | |||
116 | # Search Path | ||
117 | VPATH += $(TARGET_DIR) | ||
118 | VPATH += $(TOP_DIR) | ||
119 | #VPATH += $(TOP_DIR)/common | ||
120 | |||
121 | |||
122 | |||
123 | # program Leonardo | ||
124 | PROGRAM_CMD = avrdude -p$(MCU) -cavr109 -P$(DEV) -b57600 -Uflash:w:$(TARGET).hex | ||
125 | |||
126 | |||
127 | |||
128 | include $(TOP_DIR)/protocol/usb_hid.mk | ||
129 | include $(TOP_DIR)/protocol/lufa.mk | ||
130 | include $(TOP_DIR)/common.mk | ||
131 | include $(TOP_DIR)/rules.mk | ||
diff --git a/converter/usb_usb/config.h b/converter/usb_usb/config.h new file mode 100644 index 000000000..c2230fb57 --- /dev/null +++ b/converter/usb_usb/config.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef CONFIG_H | ||
19 | #define CONFIG_H | ||
20 | |||
21 | |||
22 | #define VENDOR_ID 0xFEED | ||
23 | #define PRODUCT_ID 0xCAFE | ||
24 | #define DEVICE_VER 0x0814 | ||
25 | #define MANUFACTURER t.m.k. | ||
26 | #define PRODUCT USB to USB keyboard converter | ||
27 | |||
28 | |||
29 | #define DESCRIPTION Product from t.m.k. keyboard firmware project | ||
30 | |||
31 | |||
32 | /* matrix size */ | ||
33 | #define MATRIX_ROWS 32 | ||
34 | #define MATRIX_COLS 8 | ||
35 | |||
36 | |||
37 | /* key combination for command */ | ||
38 | #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT))) | ||
39 | |||
40 | #endif | ||
diff --git a/converter/usb_usb/keymap.c b/converter/usb_usb/keymap.c new file mode 100644 index 000000000..406197450 --- /dev/null +++ b/converter/usb_usb/keymap.c | |||
@@ -0,0 +1,251 @@ | |||
1 | /* | ||
2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <avr/pgmspace.h> | ||
19 | #include "usb_keycodes.h" | ||
20 | #include "util.h" | ||
21 | #include "keymap.h" | ||
22 | |||
23 | |||
24 | #define KEYMAP( \ | ||
25 | K29,K3A,K3B,K3C,K3D,K3E,K3F,K40,K41,K42,K43,K44,K45, K46,K47,K48, \ | ||
26 | K35,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K2D,K2E,K2A, K49,K4A,K4B, K53,K54,K55,K56, \ | ||
27 | K2B,K14,K1A,K08,K15,K17,K1C,K18,K0C,K12,K13,K2F,K30,K31, K4C,K4D,K4E, K5F,K60,K61, \ | ||
28 | K39,K04,K16,K07,K09,K0A,K0B,K0D,K0E,K0F,K33,K34, K28, K5C,K5D,K5E,K57, \ | ||
29 | KE1,K1D,K1B,K06,K19,K05,K11,K10,K36,K37,K38, KE5, K52, K59,K5A,K5B, \ | ||
30 | KE0,KE3,KE2, K2C, KE6,KE7,K65,KE4, K50,K51,K4F, K62, K63,K58 \ | ||
31 | ) { \ | ||
32 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_##K04, KB_##K05, KB_##K06, KB_##K07 }, /* 00-07 */ \ | ||
33 | { KB_##K08, KB_##K09, KB_##K0A, KB_##K0B, KB_##K0C, KB_##K0D, KB_##K0E, KB_##K0F }, /* 08-0F */ \ | ||
34 | { KB_##K10, KB_##K11, KB_##K12, KB_##K13, KB_##K14, KB_##K15, KB_##K16, KB_##K17 }, /* 10-17 */ \ | ||
35 | { KB_##K18, KB_##K19, KB_##K1A, KB_##K1B, KB_##K1C, KB_##K1D, KB_##K1E, KB_##K1F }, /* 18-1F */ \ | ||
36 | { KB_##K20, KB_##K21, KB_##K22, KB_##K23, KB_##K24, KB_##K25, KB_##K26, KB_##K27 }, /* 20-27 */ \ | ||
37 | { KB_##K28, KB_##K29, KB_##K2A, KB_##K2B, KB_##K2C, KB_##K2D, KB_##K2E, KB_##K2F }, /* 28-2F */ \ | ||
38 | { KB_##K30, KB_##K31, KB_NO, KB_##K33, KB_##K34, KB_##K35, KB_##K36, KB_##K37 }, /* 30-37 */ \ | ||
39 | { KB_##K38, KB_##K39, KB_##K3A, KB_##K3B, KB_##K3C, KB_##K3D, KB_##K3E, KB_##K3F }, /* 38-3F */ \ | ||
40 | { KB_##K40, KB_##K41, KB_##K42, KB_##K43, KB_##K44, KB_##K45, KB_##K46, KB_##K47 }, /* 40-47 */ \ | ||
41 | { KB_##K48, KB_##K49, KB_##K4A, KB_##K4B, KB_##K4C, KB_##K4D, KB_##K4E, KB_##K4F }, /* 48-4F */ \ | ||
42 | { KB_##K50, KB_##K51, KB_##K52, KB_##K53, KB_##K54, KB_##K55, KB_##K56, KB_##K57 }, /* 50-57 */ \ | ||
43 | { KB_##K58, KB_##K59, KB_##K5A, KB_##K5B, KB_##K5C, KB_##K5D, KB_##K5E, KB_##K5F }, /* 58-5F */ \ | ||
44 | { KB_##K60, KB_##K61, KB_##K62, KB_##K63, KB_NO, KB_##K65, KB_NO, KB_NO }, /* 60-67 */ \ | ||
45 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* 68-6F */ \ | ||
46 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* 70-77 */ \ | ||
47 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* 78-7F */ \ | ||
48 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* 80-87 */ \ | ||
49 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* 88-8F */ \ | ||
50 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* 90-97 */ \ | ||
51 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* 98-9F */ \ | ||
52 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* A0-A7 */ \ | ||
53 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* A8-AF */ \ | ||
54 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* B0-B7 */ \ | ||
55 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* B8-BF */ \ | ||
56 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* C0-C7 */ \ | ||
57 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* C8-CF */ \ | ||
58 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* D0-D7 */ \ | ||
59 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* D8-DF */ \ | ||
60 | { KB_##KE0, KB_##KE1, KB_##KE2, KB_##KE3, KB_##KE4, KB_##KE5, KB_##KE6, KB_##KE7 }, /* E0-E7 */ \ | ||
61 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* E8-EF */ \ | ||
62 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* F0-F7 */ \ | ||
63 | { KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, /* F8-FF */ \ | ||
64 | } | ||
65 | |||
66 | |||
67 | // Layers to switch by holding Fn key(0-7) | ||
68 | static const uint8_t PROGMEM fn_layer[] = { 5, 6, 0, 0, 0, 0, 0, 0 }; | ||
69 | |||
70 | // Codes to register by clicking Fn key(0-7) | ||
71 | static const uint8_t PROGMEM fn_keycode[] = { KB_SCLN, KB_SLSH, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }; | ||
72 | |||
73 | static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
74 | /* 0: default | ||
75 | * ,---. ,---------------. ,---------------. ,---------------. ,-----------. ,-----------. | ||
76 | * |Esc| |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau| |Pwr|Slp|Wak| | ||
77 | * `---' `---------------' `---------------' `---------------' `-----------' `-----------' | ||
78 | * ,-----------------------------------------------------------. ,-----------. ,---------------. | ||
79 | * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| |Ins|Hom|PgU| |NmL| /| *| -| | ||
80 | * |-----------------------------------------------------------| |-----------| |---------------| | ||
81 | * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| |Del|End|PgD| | 7| 8| 9| | | ||
82 | * |-----------------------------------------------------------| `-----------' |-----------| +| | ||
83 | * |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return | | 4| 5| 6| | | ||
84 | * |-----------------------------------------------------------| ,---. |---------------| | ||
85 | * |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shift | |Up | | 1| 2| 3| | | ||
86 | * |-----------------------------------------------------------| ,-----------. |-----------|Ent| | ||
87 | * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| |Lef|Dow|Rig| | 0| .| | | ||
88 | * `-----------------------------------------------------------' `-----------' `---------------' | ||
89 | * ; = Fn0(to Layer 5) | ||
90 | * / = Fn1(to Layer 6) | ||
91 | */ | ||
92 | KEYMAP( | ||
93 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
94 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
95 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, | ||
96 | CAPS,A, S, D, F, G, H, J, K, L, FN0, QUOT, ENT, P4, P5, P6, PPLS, | ||
97 | LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, UP, P1, P2, P3, | ||
98 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
99 | ), | ||
100 | |||
101 | /* 1: plain Qwerty without layer switching | ||
102 | * ,-----------------------------------------------------------. | ||
103 | * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| | ||
104 | * |-----------------------------------------------------------| | ||
105 | * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| | ||
106 | * |-----------------------------------------------------------| | ||
107 | * |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Return | | ||
108 | * |-----------------------------------------------------------| | ||
109 | * |Shift | Z| X| C| V| B| N| M| ,| ,| /|Shift | | ||
110 | * |-----------------------------------------------------------| | ||
111 | * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| | ||
112 | * `-----------------------------------------------------------' | ||
113 | */ | ||
114 | KEYMAP( | ||
115 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
116 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
117 | TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, | ||
118 | CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, PPLS, | ||
119 | LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, | ||
120 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
121 | ), | ||
122 | |||
123 | /* 2: Colemak http://colemak.com | ||
124 | * ,-----------------------------------------------------------. | ||
125 | * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| | ||
126 | * |-----------------------------------------------------------| | ||
127 | * |Tab | Q| W| F| P| G| J| L| U| Y| ;| [| ]| \| | ||
128 | * |-----------------------------------------------------------| | ||
129 | * |BackSp| A| R| S| T| D| H| N| E| I| O| '|Return | | ||
130 | * |-----------------------------------------------------------| | ||
131 | * |Shift | Z| X| C| V| B| K| M| ,| ,| /|Shift | | ||
132 | * |-----------------------------------------------------------| | ||
133 | * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| | ||
134 | * `----------------------------------------------------------' | ||
135 | */ | ||
136 | KEYMAP( | ||
137 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
138 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
139 | TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, | ||
140 | BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, P4, P5, P6, PPLS, | ||
141 | LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, | ||
142 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
143 | ), | ||
144 | |||
145 | /* 3: Dvorak http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard | ||
146 | * ,-----------------------------------------------------------. | ||
147 | * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| [| ]|Backspa| | ||
148 | * |-----------------------------------------------------------| | ||
149 | * |Tab | '| ,| .| P| Y| F| G| C| R| L| /| =| \| | ||
150 | * |-----------------------------------------------------------| | ||
151 | * |BackSp| A| O| E| U| I| D| H| T| N| S| -|Return | | ||
152 | * |-----------------------------------------------------------| | ||
153 | * |Shift | ;| Q| J| K| X| B| M| Wl V| Z|Shift | | ||
154 | * |-----------------------------------------------------------| | ||
155 | * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| | ||
156 | * `-----------------------------------------------------------' | ||
157 | */ | ||
158 | KEYMAP( | ||
159 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
160 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
161 | TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, DEL, END, PGDN, P7, P8, P9, | ||
162 | CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, P4, P5, P6, PPLS, | ||
163 | LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, UP, P1, P2, P3, | ||
164 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
165 | ), | ||
166 | |||
167 | /* 4: Workman http://viralintrospection.wordpress.com/2010/09/06/a-different-philosophy-in-designing-keyboard-layouts/ | ||
168 | * ,-----------------------------------------------------------. | ||
169 | * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backspa| | ||
170 | * |-----------------------------------------------------------| | ||
171 | * |Tab | Q| D| R| W| B| J| F| U| P| ;| [| ]| \| | ||
172 | * |-----------------------------------------------------------| | ||
173 | * |CapsLo| A| S| H| T| G| Y| N| E| O| I| '|Return | | ||
174 | * |-----------------------------------------------------------| | ||
175 | * |Shift | Z| X| M| C| V| K| L| ,| ,| /|Shift | | ||
176 | * |-----------------------------------------------------------| | ||
177 | * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| | ||
178 | * `-----------------------------------------------------------' | ||
179 | */ | ||
180 | KEYMAP( | ||
181 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
182 | GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
183 | TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, | ||
184 | BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, P4, P5, P6, PPLS, | ||
185 | LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, | ||
186 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
187 | ), | ||
188 | |||
189 | /* 5: Mouse keys | ||
190 | * ,-----------------------------------------------------------. | ||
191 | * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backspa| | ||
192 | * |-----------------------------------------------------------| | ||
193 | * |Tab |MwL|MwU|McU|WwU|WwR|MwL|MwD|MwU|MwR| | | | \| | ||
194 | * |-----------------------------------------------------------| | ||
195 | * |CapsLo| |McL|McD|McR| |McL|McD|McU|McR|Fn0| |Return | | ||
196 | * |-----------------------------------------------------------| | ||
197 | * |Shift |VoD|VoU|Mut|Mb2|Mb3|Mb2|Mb1|VoD|VoU|Mut|Shift | | ||
198 | * |-----------------------------------------------------------| | ||
199 | * |Ctrl |Gui |Alt | Mb1 |Alt |Gui |Menu|Ctrl| | ||
200 | * `-----------------------------------------------------------' | ||
201 | * Mc = mouse cursor, Mw = mouse wheel, Mb = mouse button | ||
202 | * Vo = Volume, Mut = Mute | ||
203 | */ | ||
204 | KEYMAP( | ||
205 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
206 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
207 | TAB, WH_L,WH_D,MS_U,WH_U,WH_R,WH_L,WH_D,WH_U,WH_R,NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, | ||
208 | CAPS,NO, MS_L,MS_D,MS_R,NO, MS_L,MS_D,MS_U,MS_R,FN0, NO, ENT, P4, P5, P6, PPLS, | ||
209 | LSFT,VOLD,VOLU,MUTE,BTN2,BTN3,BTN2,BTN1,VOLD,VOLU,MUTE, RSFT, UP, P1, P2, P3, | ||
210 | LCTL,LGUI,LALT, BTN1, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
211 | ), | ||
212 | |||
213 | /* 6: Cursor keys | ||
214 | * ,-----------------------------------------------------------. | ||
215 | * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Backspa| | ||
216 | * |-----------------------------------------------------------| | ||
217 | * |Tab |Hom|PgU| Up|PgU|End|Hom|PgD|PgU|End| | | | \| | ||
218 | * |-----------------------------------------------------------| | ||
219 | * |CapsLo| |Lef|Dow|Rig| |Lef|Dow| Up|Rig| | |Return | | ||
220 | * |-----------------------------------------------------------| | ||
221 | * |Shift | | | | | |Hom|PgD|PgU|End|Fn1|Shift | | ||
222 | * |-----------------------------------------------------------| | ||
223 | * |Ctrl |Gui |Alt | Space |Alt |Gui |Menu|Ctrl| | ||
224 | * `-----------------------------------------------------------' | ||
225 | */ | ||
226 | KEYMAP( | ||
227 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,BRK, | ||
228 | ESC, F1, F2, F3, F4, F5, F6, F7, F8, F8, F10, F11, F12, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, | ||
229 | TAB, NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, NO, NO, NO, BSLS, DEL, END, PGDN, P7, P8, P9, | ||
230 | CAPS,NO, NO, NO, NO, NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT, P4, P5, P6, PPLS, | ||
231 | LSFT,VOLD,VOLU,MUTE,NO, NO, HOME,PGDN,PGUP,END, FN1, RSFT, UP, P1, P2, P3, | ||
232 | LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL, LEFT,DOWN,RGHT, P0, PDOT,PENT | ||
233 | ), | ||
234 | }; | ||
235 | |||
236 | |||
237 | |||
238 | uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) | ||
239 | { | ||
240 | return pgm_read_byte(&keymaps[(layer)][(row)][(col)]); | ||
241 | } | ||
242 | |||
243 | uint8_t keymap_fn_layer(uint8_t fn_bits) | ||
244 | { | ||
245 | return pgm_read_byte(&fn_layer[biton(fn_bits)]); | ||
246 | } | ||
247 | |||
248 | uint8_t keymap_fn_keycode(uint8_t fn_bits) | ||
249 | { | ||
250 | return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); | ||
251 | } | ||
diff --git a/converter/usb_usb/led.c b/converter/usb_usb/led.c new file mode 100644 index 000000000..fc0eeb0ff --- /dev/null +++ b/converter/usb_usb/led.c | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include "stdint.h" | ||
19 | #include "led.h" | ||
20 | |||
21 | |||
22 | void led_set(uint8_t usb_led) | ||
23 | { | ||
24 | } | ||
diff --git a/converter/usb_usb/main.cpp b/converter/usb_usb/main.cpp new file mode 100644 index 000000000..00d2d59b6 --- /dev/null +++ b/converter/usb_usb/main.cpp | |||
@@ -0,0 +1,95 @@ | |||
1 | #include <avr/io.h> | ||
2 | #include <avr/wdt.h> | ||
3 | #include <avr/power.h> | ||
4 | #include <util/delay.h> | ||
5 | #include <Arduino.h> | ||
6 | |||
7 | // USB HID host | ||
8 | #include "Usb.h" | ||
9 | #include "hid.h" | ||
10 | #include "hidboot.h" | ||
11 | #include "parser.h" | ||
12 | |||
13 | // LUFA | ||
14 | #include "lufa.h" | ||
15 | |||
16 | #include "debug.h" | ||
17 | #include "keyboard.h" | ||
18 | |||
19 | #include "leonardo_led.h" | ||
20 | |||
21 | |||
22 | static USB usb_host; | ||
23 | static HIDBoot<HID_PROTOCOL_KEYBOARD> kbd(&usb_host); | ||
24 | static KBDReportParser kbd_parser; | ||
25 | |||
26 | static void LUFA_setup(void) | ||
27 | { | ||
28 | /* Disable watchdog if enabled by bootloader/fuses */ | ||
29 | MCUSR &= ~(1 << WDRF); | ||
30 | wdt_disable(); | ||
31 | |||
32 | /* Disable clock division */ | ||
33 | clock_prescale_set(clock_div_1); | ||
34 | |||
35 | // Leonardo needs. Without this USB device is not recognized. | ||
36 | USB_Disable(); | ||
37 | |||
38 | USB_Init(); | ||
39 | |||
40 | // for Console_Task | ||
41 | USB_Device_EnableSOFEvents(); | ||
42 | } | ||
43 | |||
44 | static void HID_setup() | ||
45 | { | ||
46 | if (usb_host.Init() == -1) { | ||
47 | debug("HID init: failed\n"); | ||
48 | LED_TX_OFF; | ||
49 | } | ||
50 | |||
51 | _delay_ms(200); | ||
52 | |||
53 | kbd.SetReportParser(0, (HIDReportParser*)&kbd_parser); | ||
54 | } | ||
55 | |||
56 | int main(void) | ||
57 | { | ||
58 | // LED for debug | ||
59 | LED_TX_INIT; | ||
60 | LED_TX_ON; | ||
61 | |||
62 | print_enable = true; | ||
63 | debug_enable = true; | ||
64 | debug_matrix = true; | ||
65 | debug_keyboard = true; | ||
66 | debug_mouse = true; | ||
67 | |||
68 | host_set_driver(&lufa_driver); | ||
69 | keyboard_init(); | ||
70 | |||
71 | LUFA_setup(); | ||
72 | sei(); | ||
73 | |||
74 | // wait for startup of sendchar routine | ||
75 | while (USB_DeviceState != DEVICE_STATE_Configured) ; | ||
76 | if (debug_enable) { | ||
77 | _delay_ms(1000); | ||
78 | } | ||
79 | |||
80 | HID_setup(); | ||
81 | |||
82 | debug("init: done\n"); | ||
83 | for (;;) { | ||
84 | keyboard_proc(); | ||
85 | |||
86 | usb_host.Task(); | ||
87 | |||
88 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) | ||
89 | // LUFA Task for control request | ||
90 | USB_USBTask(); | ||
91 | #endif | ||
92 | } | ||
93 | |||
94 | return 0; | ||
95 | } | ||
diff --git a/converter/usb_usb/matrix.c b/converter/usb_usb/matrix.c new file mode 100644 index 000000000..1cfecde20 --- /dev/null +++ b/converter/usb_usb/matrix.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <stdint.h> | ||
19 | #include <stdbool.h> | ||
20 | #include "usb_hid.h" | ||
21 | #include "usb_keycodes.h" | ||
22 | #include "util.h" | ||
23 | #include "print.h" | ||
24 | #include "debug.h" | ||
25 | #include "matrix.h" | ||
26 | |||
27 | /* KEY CODE to Matrix | ||
28 | * | ||
29 | * HID keycode(1 byte): | ||
30 | * Higher 5 bits indicates ROW and lower 3 bits COL. | ||
31 | * | ||
32 | * 7 6 5 4 3 2 1 0 | ||
33 | * +---------------+ | ||
34 | * | ROW | COL | | ||
35 | * +---------------+ | ||
36 | * | ||
37 | * Matrix space(32 * 8): | ||
38 | * 01234567 | ||
39 | * 0 +--------+ | ||
40 | * : | | | ||
41 | * : | | | ||
42 | * 31 +--------+ | ||
43 | */ | ||
44 | #define ROW_MASK 0xF8 | ||
45 | #define COL_MASK 0x07 | ||
46 | #define CODE(row, col) (((row) << 3) | (col)) | ||
47 | #define ROW(code) (((code) & ROW_MASK) >> 3) | ||
48 | #define COL(code) ((code) & COL_MASK) | ||
49 | #define ROW_BITS(code) (1 << COL(code)) | ||
50 | |||
51 | |||
52 | uint8_t matrix_rows(void) { return MATRIX_ROWS; } | ||
53 | uint8_t matrix_cols(void) { return MATRIX_COLS; } | ||
54 | void matrix_init(void) {} | ||
55 | bool matrix_has_ghost(void) { return false; } | ||
56 | |||
57 | static bool matrix_is_mod =false; | ||
58 | |||
59 | uint8_t matrix_scan(void) { | ||
60 | static uint16_t last_time_stamp = 0; | ||
61 | |||
62 | if (last_time_stamp != usb_hid_time_stamp) { | ||
63 | last_time_stamp = usb_hid_time_stamp; | ||
64 | matrix_is_mod = true; | ||
65 | } else { | ||
66 | matrix_is_mod = false; | ||
67 | } | ||
68 | return 1; | ||
69 | } | ||
70 | |||
71 | bool matrix_is_modified(void) { | ||
72 | |||
73 | return matrix_is_mod; | ||
74 | } | ||
75 | |||
76 | bool matrix_is_on(uint8_t row, uint8_t col) { | ||
77 | uint8_t code = CODE(row, col); | ||
78 | |||
79 | if (IS_MOD(code)) { | ||
80 | if (usb_hid_keyboard_report.mods & ROW_BITS(code)) { | ||
81 | return true; | ||
82 | } | ||
83 | } | ||
84 | for (uint8_t i = 0; i < REPORT_KEYS; i++) { | ||
85 | if (usb_hid_keyboard_report.keys[i] == code) { | ||
86 | return true; | ||
87 | } | ||
88 | } | ||
89 | return false; | ||
90 | } | ||
91 | |||
92 | uint8_t matrix_get_row(uint8_t row) { | ||
93 | uint8_t row_bits = 0; | ||
94 | |||
95 | if (IS_MOD(CODE(row, 0)) && usb_hid_keyboard_report.mods) { | ||
96 | row_bits |= usb_hid_keyboard_report.mods; | ||
97 | } | ||
98 | |||
99 | for (uint8_t i = 0; i < REPORT_KEYS; i++) { | ||
100 | if (IS_ANY(usb_hid_keyboard_report.keys[i])) { | ||
101 | if (row == ROW(usb_hid_keyboard_report.keys[i])) { | ||
102 | row_bits |= ROW_BITS(usb_hid_keyboard_report.keys[i]); | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | return row_bits; | ||
107 | } | ||
108 | |||
109 | uint8_t matrix_key_count(void) { | ||
110 | uint8_t count = 0; | ||
111 | |||
112 | count += bitpop(usb_hid_keyboard_report.mods); | ||
113 | for (uint8_t i = 0; i < REPORT_KEYS; i++) { | ||
114 | if (IS_ANY(usb_hid_keyboard_report.keys[i])) { | ||
115 | count++; | ||
116 | } | ||
117 | } | ||
118 | return count; | ||
119 | } | ||
120 | |||
121 | void matrix_print(void) { | ||
122 | print("\nr/c 01234567\n"); | ||
123 | for (uint8_t row = 0; row < matrix_rows(); row++) { | ||
124 | phex(row); print(": "); | ||
125 | pbin_reverse(matrix_get_row(row)); | ||
126 | #ifdef MATRIX_HAS_GHOST | ||
127 | if (matrix_has_ghost_in_row(row)) { | ||
128 | print(" <ghost"); | ||
129 | } | ||
130 | #endif | ||
131 | print("\n"); | ||
132 | } | ||
133 | } | ||
diff --git a/protocol/usb_hid/parser.cpp b/protocol/usb_hid/parser.cpp index b03af8ae4..4077444b7 100644 --- a/protocol/usb_hid/parser.cpp +++ b/protocol/usb_hid/parser.cpp | |||
@@ -1,14 +1,27 @@ | |||
1 | #include <cstring.h> | ||
2 | |||
1 | #include "parser.h" | 3 | #include "parser.h" |
4 | #include "usb_hid.h" | ||
5 | |||
2 | #include "leonardo_led.h" | 6 | #include "leonardo_led.h" |
3 | #include "debug.h" | 7 | #include "debug.h" |
4 | 8 | ||
9 | |||
10 | report_keyboard_t usb_hid_keyboard_report; | ||
11 | uint16_t usb_hid_time_stamp; | ||
12 | |||
13 | |||
5 | void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) | 14 | void KBDReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) |
6 | { | 15 | { |
16 | ::memcpy(&usb_hid_keyboard_report, buf, sizeof(report_keyboard_t)); | ||
17 | usb_hid_time_stamp = millis(); | ||
18 | |||
7 | LED_TX_TOGGLE; | 19 | LED_TX_TOGGLE; |
8 | debug("KBDReport: "); | 20 | debug("KBDReport: "); |
9 | for (uint8_t i = 0; i < len; i++) { | 21 | debug_hex(usb_hid_keyboard_report.mods); |
10 | debug_hex(buf[i]); | 22 | for (uint8_t i = 0; i < 6; i++) { |
11 | debug(" "); | 23 | debug(" "); |
24 | debug_hex(usb_hid_keyboard_report.keys[i]); | ||
12 | } | 25 | } |
13 | debug("\r\n"); | 26 | debug("\r\n"); |
14 | } | 27 | } |