Advertisement
Guest User

Untitled

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