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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

keymap.c 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright 2014 Ralf Schmitt <[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 "debug.h"
  23. #include "keymap.h"
  24. /* Map physical keyboard layout to matrix array */
  25. #define KEYMAP( \
  26. K5A, K5B, K5C, K5D, \
  27. K4A, K4B, K4C, K4D, \
  28. K3A, K3B, K3C, K3D, \
  29. K2A, K2B, K2C, \
  30. K1A, K1B, K1C, K1D, \
  31. K0A, K0B, K0C \
  32. ) { \
  33. /* 0 1 2 3 */ \
  34. /* 5 */ { KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D}, \
  35. /* 4 */ { KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D}, \
  36. /* 3 */ { KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D}, \
  37. /* 2 */ { KC_##K2A, KC_##K2B, KC_##K2C, KC_NO}, \
  38. /* 1 */ { KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D}, \
  39. /* 0 */ { KC_##K0A, KC_##K0B, KC_##K0C, KC_NO, } \
  40. }
  41. #include "keymap_lightpad.h"
  42. #define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
  43. #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
  44. /* translates key to keycode */
  45. uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
  46. {
  47. if (layer < KEYMAPS_SIZE) {
  48. return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
  49. } else {
  50. // fall back to layer 0
  51. return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
  52. }
  53. }
  54. /* translates Fn keycode to action */
  55. action_t keymap_fn_to_action(uint8_t keycode)
  56. {
  57. action_t action;
  58. if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
  59. action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
  60. } else {
  61. action.code = ACTION_NO;
  62. }
  63. return action;
  64. }