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_common.c 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <stdbool.h>
  15. #include <avr/pgmspace.h>
  16. #include "keymap.h"
  17. #include "keymap_in_eeprom.h"
  18. #include "keymap_common.h"
  19. static uint8_t keymaps_cache[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] = {{{0}}};
  20. static uint8_t last_layer_number = 1;
  21. void keymaps_cache_init(void)
  22. {
  23. for (uint8_t layer = 0; layer < KEYMAPS_COUNT; layer++) {
  24. uint8_t non_empty_key = 0;
  25. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  26. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  27. #ifndef KEYMAP_IN_EEPROM_ENABLE
  28. keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]);
  29. #else
  30. keymaps_cache[layer][row][col] = eeconfig_read_keymap_key(layer, row, col);
  31. #endif
  32. if (keymaps_cache[layer][row][col] > KC_TRANSPARENT) {
  33. non_empty_key++;
  34. }
  35. }
  36. }
  37. if (non_empty_key) {
  38. last_layer_number = layer;
  39. }
  40. }
  41. }
  42. uint8_t last_layer(void)
  43. {
  44. return last_layer_number;
  45. }
  46. /* translates key to keycode */
  47. uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key)
  48. {
  49. return keymaps_cache[layer][key.row][key.col];
  50. }
  51. /* translates Fn keycode to action */
  52. action_t keymap_fn_to_action(uint8_t keycode)
  53. {
  54. #ifndef KEYMAP_IN_EEPROM_ENABLE
  55. return (action_t) {
  56. .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)])
  57. };
  58. #else
  59. return (action_t) {
  60. .code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode))
  61. };
  62. #endif
  63. }
  64. #ifdef KEYMAP_IN_EEPROM_ENABLE
  65. const uint8_t* keymaps_pointer(void) {
  66. return (const uint8_t*)keymaps;
  67. }
  68. const uint16_t* fn_actions_pointer(void) {
  69. return fn_actions;
  70. }
  71. #endif