您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. Copyright 2012,2013 Jun Wako <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <avr/pgmspace.h>
  17. #include "keycode.h"
  18. #include "action.h"
  19. #include "action_macro.h"
  20. #include "report.h"
  21. #include "host.h"
  22. #include "print.h"
  23. #include "debug.h"
  24. #include "keymap.h"
  25. #include "keymap_ex.h"
  26. /* GHPad keymap definition macro
  27. */
  28. #define KEYMAP( \
  29. K0A, K0B, K0C, K0D, \
  30. K1A, K1B, K1C, K1D, \
  31. K2A, K2B, K2C, K2D, \
  32. K3A, K3B, K3C, K3D, \
  33. K4A, K4B, K4C, K4D, \
  34. K5A, K5B, K5C, K5D \
  35. ) { \
  36. { KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D }, \
  37. { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D }, \
  38. { KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D }, \
  39. { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D }, \
  40. { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D }, \
  41. { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D } \
  42. }
  43. #if defined(KEYMAP_PLAIN)
  44. #include "keymap_plain.h"
  45. #else
  46. #ifdef KEYMAP_SECTION_ENABLE
  47. const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
  48. #else
  49. static const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
  50. #endif
  51. /* Keymap 0: Default Layer
  52. * ,---------------.
  53. * |Num|/ |* |- |
  54. * |---+---+---+---|
  55. * |7 |8 |9 |+ |
  56. * |---+---+---| |
  57. * |4 |5 |6 | |
  58. * |---+---+---+---|
  59. * |1 |2 |3 |Ent|
  60. * |---+---+---| |
  61. * |0 |Up |. | |
  62. * |---+---+---+---|
  63. * |Lef|Dow|Rig|Fn0|
  64. * `---------------'
  65. */
  66. [0] = KEYMAP(
  67. NLCK,PSLS,PAST,PMNS, \
  68. P7, P8, P9, PPLS, \
  69. P4, P5, P6, NO, \
  70. P1, P2, P3, PENT, \
  71. P0, UP, PDOT,NO, \
  72. LEFT,DOWN,RGHT,FN0),
  73. /* Keymap 1: */
  74. [1] = KEYMAP(
  75. TRNS,TRNS,TRNS,TRNS, \
  76. TRNS,TRNS,TRNS,TRNS, \
  77. TRNS,TRNS,TRNS,TRNS, \
  78. TRNS,TRNS,TRNS,TRNS, \
  79. TRNS,TRNS,TRNS,TRNS, \
  80. TRNS,TRNS,TRNS,TRNS),
  81. };
  82. /*
  83. * Fn action definition
  84. */
  85. #ifdef KEYMAP_SECTION_ENABLE
  86. const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = {
  87. #else
  88. static const uint16_t fn_actions[] PROGMEM = {
  89. #endif
  90. [0] = ACTION_LAYER_MOMENTARY(1)
  91. };
  92. #endif
  93. #define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
  94. #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
  95. #ifdef KEYMAP_EX_ENABLE
  96. const uint8_t* keymaps_pointer(void) {
  97. return (const uint8_t*)keymaps;
  98. }
  99. const uint16_t* fn_actions_pointer(void) {
  100. return fn_actions;
  101. }
  102. uint16_t keys_count(void) {
  103. return KEYMAPS_SIZE * MATRIX_ROWS * MATRIX_COLS;
  104. }
  105. uint16_t fn_actions_count(void) {
  106. return FN_ACTIONS_SIZE;
  107. }
  108. #endif
  109. /* translates key to keycode */
  110. uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
  111. {
  112. if (layer < KEYMAPS_SIZE) {
  113. #ifndef KEYMAP_EX_ENABLE
  114. return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
  115. #else
  116. return eeconfig_read_keymap_key(layer, key.row, key.col);
  117. #endif
  118. } else {
  119. // XXX: this may cuaes bootlaoder_jump inconsistent fail.
  120. //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n");
  121. // fall back to layer 0
  122. #ifndef KEYMAP_EX_ENABLE
  123. return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
  124. #else
  125. return eeconfig_read_keymap_key(0, key.row, key.col);
  126. #endif
  127. }
  128. }
  129. /* translates Fn keycode to action */
  130. action_t keymap_fn_to_action(uint8_t keycode)
  131. {
  132. action_t action;
  133. if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
  134. #ifndef KEYMAP_EX_ENABLE
  135. action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
  136. #else
  137. action.code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode));
  138. #endif
  139. } else {
  140. action.code = ACTION_NO;
  141. }
  142. return action;
  143. }