Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

keymap.c 9.9KB

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