laidlow

keymap.c

Aug 2nd, 2013
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.65 KB | None | 0 0
  1. /*
  2. Copyright 2012,2013 Jun Wako <[email protected]>
  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. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include <avr/pgmspace.h>
  20. #include "keycode.h"
  21. #include "action.h"
  22. #include "action_macro.h"
  23. #include "report.h"
  24. #include "host.h"
  25. #include "print.h"
  26. #include "debug.h"
  27. #include "keymap.h"
  28.  
  29.  
  30. #define KEYMAP( \
  31.     K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, \
  32.     K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \
  33.     K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B,      K2D, K2E, \
  34.     K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A,      K3C, K3D, K3E, \
  35.     K40, K41,                K45,                K49, K4A,      K4C, K4D, K4E  \
  36. ) { \
  37.     { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07, KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E }, \
  38.     { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E }, \
  39.     { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_NO,    KC_##K2D, KC_##K2E }, \
  40.     { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_NO,    KC_##K3C, KC_##K3D, KC_##K3E }, \
  41.     { KC_##K40, KC_##K41, KC_NO,    KC_NO,    KC_NO,    KC_##K45, KC_NO,    KC_NO,    KC_NO,    KC_##K49, KC_##K4A, KC_NO,    KC_##K4C, KC_##K4D, KC_##K4E }  \
  42. }
  43.  
  44. /* ANSI variant. No extra keys for ISO */
  45. #define KEYMAP_ANSI( \
  46.     K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, \
  47.     K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \
  48.     K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B,      K2D, K2E, \
  49.     K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A,      K3C, K3D, K3E, \
  50.     K40, K41,              K45,                  K49, K4A,      K4C, K4D, K4E  \
  51. ) KEYMAP( \
  52.     K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, \
  53.     K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, \
  54.     K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B,      K2D, K2E, \
  55.     K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A,      K3C, K3D, K3E, \
  56.     K40, K41,              K45,                  K49, K4A,      K4C, K4D, K4E  \
  57. )
  58.  
  59.  
  60. static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  61.     /* Keymap 0: Default Layer
  62.      * ,-----------------------------------------------------------.
  63.      * |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0| -| =|  Bsp|Prt|
  64.      * |-----------------------------------------------------------|
  65.      * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [| ]| \|Del|
  66.      * |-----------------------------------------------------------|
  67.      * |Ctrl  |  A|  S|  D|  F|  G|  H|  J|  K|  L|; |  '|ENT  | 6 |
  68.      * |-----------------------------------------------------------|
  69.      * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|Shift |UP |APP|
  70.      * |-----------------------------------------------------------|
  71.      * |Lwin| Alt |         Space          |Caps |Fn0  |LEF|DOW|RIG|
  72.      * `-----------------------------------------------------------'
  73.      */
  74.     KEYMAP_ANSI(
  75.            ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC, PSCR      \
  76.            TAB,  Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSLS, DEL      \
  77.            LCTL,  A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,  QUOT,   ENT,  6       \
  78.            LSFT,   Z,   X,   C,   V,   B,   N,   M, COMM, DOT, SLSH,    RSFT,  UP,  APP     \
  79.            LWIN,LALT,            SPC,                       CAPS,  FN0, LEFT, DOWN, RGHT),
  80.        
  81.     /* Overlay 1: Function Layer
  82.      * ,-----------------------------------------------------------.
  83.      * |~  |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12|   |   |
  84.      * |-----------------------------------------------------------|
  85.      * |    |   |   |   |   |   |   |   |   |   |   |   |   |  |   |
  86.      * |-----------------------------------------------------------|
  87.      * |     |   |   |   |   |   |   |   |   |   |   |   |     |   |
  88.      * |-----------------------------------------------------------|
  89.      * |       |   |   |   |   |   |   |   |   |   |   |   |PGU|   |
  90.      * |-----------------------------------------------------------|
  91.      * |     |     |                       |     |     |HOM|PGD|END|  
  92.      * `-----------------------------------------------------------'
  93.      */
  94.     KEYMAP_ANSI(
  95.         GRV ,  F1,   F2,   F3,   F4,  F5,  F6,  F7,  F8,  F9,  F10,  F11,  F12, TRNS, TRNS, \
  96.         TRNS,TRNS, TRNS, TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS, TRNS, \
  97.         TRNS,TRNS, TRNS, TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,      TRNS, TRNS, \
  98.         TRNS,TRNS, TRNS, TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,     TRNS, PGUP, TRNS, \
  99.         TRNS  ,  TRNS,                 TRNS               ,  TRNS,  TRNS,HOME,PGDN, END),
  100. };
  101.  
  102. /*
  103.  * Fn action definition
  104.  */
  105. static const uint16_t PROGMEM fn_actions[] = {
  106.     [0] = ACTION_LAYER_MOMENTARY(1),
  107. };
  108.  
  109.  
  110.  
  111.  
  112. #define KEYMAPS_SIZE    (sizeof(keymaps) / sizeof(keymaps[0]))
  113. #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
  114.  
  115. /* translates key to keycode */
  116. uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
  117. {
  118.     if (layer < KEYMAPS_SIZE) {
  119.         return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
  120.     } else {
  121.         // XXX: this may cuaes bootlaoder_jump inconsistent fail.
  122.         //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n");
  123.         // fall back to layer 0
  124.         return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
  125.     }
  126. }
  127.  
  128. /* translates Fn keycode to action */
  129. action_t keymap_fn_to_action(uint8_t keycode)
  130. {
  131.     action_t action;
  132.     if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
  133.         action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
  134.     } else {
  135.         action.code = ACTION_NO;
  136.     }
  137.     return action;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment