]> git.donarmstrong.com Git - tmk_firmware.git/blob - converter/next_usb/keymap.c
Change key_t to keypos_t
[tmk_firmware.git] / converter / next_usb / keymap.c
1 /*
2 NeXT non-ADB Keyboard USB Converter
3  
4 Copyright 2013, Benjamin Gould (bgould@github.com)
5
6 Based on:
7 ---------
8 * TMK firmware code Copyright 2011,2012 Jun WAKO <wakojun@gmail.com>
9 * Arduino code by "Ladyada" Limor Fried (http://ladyada.net/, http://adafruit.com/) \
10     released under BSD license \
11     https://github.com/adafruit/USB-NeXT-Keyboard
12
13 Timing reference thanks to http://m0115.web.fc2.com/ (dead link), http://cfile7.uf.tistory.com/image/14448E464F410BF22380BB
14 Pinouts thanks to http://www.68k.org/~degs/nextkeyboard.html
15 Keycodes from http://ftp.netbsd.org/pub/NetBSD/NetBSD-release-6/src/sys/arch/next68k/dev/
16
17 This software is licensed with a Modified BSD License.
18 All of this is supposed to be Free Software, Open Source, DFSG-free,
19 GPL-compatible, and OK to use in both free and proprietary applications.
20 Additions and corrections to this file are welcome.
21
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions are met:
24
25 * Redistributions of source code must retain the above copyright
26   notice, this list of conditions and the following disclaimer.
27
28 * Redistributions in binary form must reproduce the above copyright
29   notice, this list of conditions and the following disclaimer in
30   the documentation and/or other materials provided with the
31   distribution.
32
33 * Neither the name of the copyright holders nor the names of
34   contributors may be used to endorse or promote products derived
35   from this software without specific prior written permission.
36
37 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
41 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47 POSSIBILITY OF SUCH DAMAGE.
48
49 */
50
51 #include <stdint.h>
52 #include <stdbool.h>
53 #include <avr/pgmspace.h>
54 #include "keycode.h"
55 #include "print.h"
56 #include "debug.h"
57 #include "util.h"
58 #include "keymap.h"
59 #include "keycode.h"
60
61 // 32*8(256) byte array which converts PS/2 code into USB code
62 static const uint16_t PROGMEM fn_actions[] = {
63     ACTION_LAYER_MOMENTARY(1),                  // FN0 - left command key
64     ACTION_LAYER_MOMENTARY(1),                  // FN1 - right command key
65     ACTION_KEY(KC_BSLS),                        // FN2 - number pad slash & backslash
66     ACTION_MODS_KEY(MOD_LSFT, KC_BSLS),         // FN3 - number pad equals & pipe
67     ACTION_MODS_KEY(MOD_LCTL, KC_Z),            // FN4 - cmd+undo  on layer 1
68     ACTION_MODS_KEY(MOD_LCTL, KC_X),            // FN5 - cmd+cut   on layer 1
69     ACTION_MODS_KEY(MOD_LCTL, KC_C),            // FN6 - cmd+copy  on layer 1
70     ACTION_MODS_KEY(MOD_LCTL, KC_V),            // FN7 - cmd+paste on layer 1
71 };
72
73 /* This is the physical layout that I am starting with:
74  *   Note: there is some strangeness on the number pad; 
75  *         the equal sign shifts to pipe and forward slash shifts to backslash
76  * ,-----------------------------------------------------------. ,-----------. ,---------------.
77  * |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|   BS  | |VUp|Pwr|BrU| |`  |  =|  /|  *|
78  * |-----------------------------------------------------------| |-----------| |---------------|
79  * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|     | |VDn|   |BrD| |  7|  8|  9|  -|
80  * |------------------------------------------------------     | `---'   `---' |-----------|---|
81  * |Ctrl  |  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|  Return|               |  4|  5|  6|  +|
82  * |-----------------------------------------------------------|     ,---.     |---------------|
83  * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift     |     |Up |     |  1|  2|  3|   |
84  * |-----------------------------------------------------------| ,-----------. |-----------|Ent|
85  * |Alt  |Cmd  |              Space                |Cmd  |Alt  | |Lef|Dow|Rig| |      0|  .|   |
86  * `-----------------------------------------------------------' `-----------' `---------------'
87  *
88  * Keymap array:
89  *     8 bytes
90  *   +---------+
91  *  0|         |
92  *  :|         | 0x00-0x87
93  *  ;|         |
94  * 11|         |
95  *   +---------+
96  */
97 #define KEYMAP( \
98     K49,K4A,K4B,K4C,K4D,K50,K4F,K4E,K1E,K1F,K20,K1D,K1C,K1B,  K1A,K58,K19,  K26,K27,K28,K25, \
99     K41,K42,K43,K44,K45,K48,K47,K46,K06,K07,K08,K05,K04,K03,  K02,    K01,  K21,K22,K23,K24, \
100     K57,K39,K3A,K3B,K3C,K3D,K40,K3F,K3E,K2D,K2C,K2B,    K2A,                K12,K18,K13,K15, \
101     K56,    K31,K32,K33,K34,K35,K37,K36,K2E,K2F,K30,    K55,      K16,      K11,K17,K14,     \
102     K52,K54,                  K38,                  K53,K51,  K09,K0F,K10,  K0B,    K0C,K0D  \
103 ) { \
104     { KC_NO,    KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
105     { KC_##K08, KC_##K09, KC_##K10, KC_##K0B, KC_##K0C, KC_##K0D, KC_NO,    KC_##K0F }, \
106     { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
107     { KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F }, \
108     { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
109     { KC_##K28, KC_NO,    KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \
110     { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37 }, \
111     { KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_##K3F }, \
112     { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47 }, \
113     { KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F }, \
114     { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56, KC_##K57 }, \
115     { KC_##K58, KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,   }, \
116 }
117
118
119 static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
120     
121     /* Layer 0: default
122      * ,-----------------------------------------------------------. ,-----------. ,---------------.
123      * |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|   BS  | |Ins|Ref|Hom| |`  |  =|  /|  *|
124      * |-----------------------------------------------------------| |-----------| |---------------|
125      * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|     | |Del|   |End| |  7|  8|  9|  -|
126      * |-----------------------------------------------------'     | `---'   `---' |-----------|---|
127      * |Ctrl  |  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|  Return|               |  4|  5|  6|  +|
128      * |-----------------------------------------------------------|     ,---.     |---------------|
129      * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift     |     |Up |     |  1|  2|  3|   |
130      * |-----------------------------------------------------------| ,-----------. |-----------|Ent|
131      * |Fn0  |Alt  |              Space                |LGui |Fn1  | |Lef|Dow|Rig| |      0|  .|   |
132      * `-----------------------------------------------------------' `-----------' `---------------'
133      */
134     KEYMAP(
135     ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC,  INS, WREF,HOME,  GRV, FN3, FN2, PAST,
136     TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,NO,    DEL,      END,   P7,  P8,  P9,  PMNS,
137     LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,     ENT,                    P4,  P5,  P6,  PPLS,
138     LSFT,     Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,     RSFT,       UP,         P1,  P2,  P3,  
139     FN0, LALT,                    SPC,                          LGUI,FN1,  LEFT,DOWN,RGHT,  P0,       PDOT,PENT
140     
141     ),
142
143     /* Layer 1: extra keys
144      * ,-----------------------------------------------------------. ,-----------. ,---------------.
145      * |Grv| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|   BS  | |VUp|VMu|PgU| |`  |  =|  /|  *|
146      * |-----------------------------------------------------------| |-----------| |---------------|
147      * |Tab  |Pau|  W|  E|  R|  T|  Y|  U|  I|  O|PSc|  \|  ]|     | |VDn|   |PgD| |  7|  8|  9|  -|
148      * |-----------------------------------------------------'     | `---'   `---' |-----------|---|
149      * |Ctrl  |  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|  Return|               |  4|  5|  6|  +|
150      * |-----------------------------------------------------------|     ,---.     |---------------|
151      * |Shift   |UND|CUT|COP|PST|  B|  N|  M|  ,|  .|  /|Shift     |     |Up |     |  1|  2|  3|   |
152      * |-----------------------------------------------------------| ,-----------. |-----------|Ent|
153      * |Fn0  |Alt  |              Space                |RGui |Fn1  | |Lef|Dow|Rig| |      0|  .|   |
154      * `-----------------------------------------------------------' `-----------' `---------------'
155      */
156     KEYMAP(
157     
158     GRV, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, TRNS,  VOLU,MUTE,PGUP,  TRNS,TRNS,TRNS,TRNS,
159     TRNS,PAUS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,FN3, BSLS,TRNS,  VOLD,     PGDN,  BTN1,MS_U,BTN2,WH_U,
160     TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,     TRNS,                   MS_L,MS_D,MS_R,WH_D,
161     TRNS,     FN4, FN5, FN6, FN7, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,     TRNS,       TRNS,       TRNS,TRNS,TRNS,  
162     TRNS,RALT,                    TRNS,                         RGUI,TRNS,  TRNS,TRNS,TRNS,  TRNS,     TRNS,TRNS
163     
164     )
165 };
166
167 /* translates key to keycode */
168 uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
169 {
170     return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
171 }
172
173 /* translates Fn keycode to action */
174 action_t keymap_fn_to_action(uint8_t keycode)
175 {
176     return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
177 }