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.

111 lines
3.9 KiB

  1. // Copyright 2022 Nick Brassel (@tzarc)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. // Pull the actual keymap code so that we can inspect stuff from it
  4. #include KEYMAP_C
  5. // Allow for keymap or userspace rules.mk to specify an alternate location for the keymap array
  6. #ifdef INTROSPECTION_KEYMAP_C
  7. # include INTROSPECTION_KEYMAP_C
  8. #endif // INTROSPECTION_KEYMAP_C
  9. #include "keymap_introspection.h"
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. // Key mapping
  12. #define NUM_KEYMAP_LAYERS_RAW ((uint8_t)(sizeof(keymaps) / ((MATRIX_ROWS) * (MATRIX_COLS) * sizeof(uint16_t))))
  13. uint8_t keymap_layer_count_raw(void) {
  14. return NUM_KEYMAP_LAYERS_RAW;
  15. }
  16. __attribute__((weak)) uint8_t keymap_layer_count(void) {
  17. return keymap_layer_count_raw();
  18. }
  19. #ifdef DYNAMIC_KEYMAP_ENABLE
  20. _Static_assert(NUM_KEYMAP_LAYERS_RAW <= MAX_LAYER, "Number of keymap layers exceeds maximum set by DYNAMIC_KEYMAP_LAYER_COUNT");
  21. #else
  22. _Static_assert(NUM_KEYMAP_LAYERS_RAW <= MAX_LAYER, "Number of keymap layers exceeds maximum set by LAYER_STATE_(8|16|32)BIT");
  23. #endif
  24. uint16_t keycode_at_keymap_location_raw(uint8_t layer_num, uint8_t row, uint8_t column) {
  25. if (layer_num < NUM_KEYMAP_LAYERS_RAW && row < MATRIX_ROWS && column < MATRIX_COLS) {
  26. return pgm_read_word(&keymaps[layer_num][row][column]);
  27. }
  28. return KC_TRNS;
  29. }
  30. __attribute__((weak)) uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column) {
  31. return keycode_at_keymap_location_raw(layer_num, row, column);
  32. }
  33. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. // Encoder mapping
  35. #if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
  36. # define NUM_ENCODERMAP_LAYERS_RAW ((uint8_t)(sizeof(encoder_map) / ((NUM_ENCODERS) * (NUM_DIRECTIONS) * sizeof(uint16_t))))
  37. uint8_t encodermap_layer_count_raw(void) {
  38. return NUM_ENCODERMAP_LAYERS_RAW;
  39. }
  40. __attribute__((weak)) uint8_t encodermap_layer_count(void) {
  41. return encodermap_layer_count_raw();
  42. }
  43. _Static_assert(NUM_KEYMAP_LAYERS_RAW == NUM_ENCODERMAP_LAYERS_RAW, "Number of encoder_map layers doesn't match the number of keymap layers");
  44. uint16_t keycode_at_encodermap_location_raw(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
  45. if (layer_num < NUM_ENCODERMAP_LAYERS_RAW && encoder_idx < NUM_ENCODERS) {
  46. return pgm_read_word(&encoder_map[layer_num][encoder_idx][clockwise ? 0 : 1]);
  47. }
  48. return KC_TRNS;
  49. }
  50. __attribute__((weak)) uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
  51. return keycode_at_encodermap_location_raw(layer_num, encoder_idx, clockwise);
  52. }
  53. #endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
  54. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  55. // Dip Switch mapping
  56. #if defined(DIP_SWITCH_ENABLE) && defined(DIP_SWITCH_MAP_ENABLE)
  57. uint16_t keycode_at_dip_switch_map_location_raw(uint8_t switch_idx, bool on) {
  58. if (switch_idx < NUM_DIP_SWITCHES) {
  59. return pgm_read_word(&dip_switch_map[switch_idx][!!on]);
  60. }
  61. return KC_TRNS;
  62. }
  63. uint16_t keycode_at_dip_switch_map_location(uint8_t switch_idx, bool on) {
  64. return keycode_at_dip_switch_map_location_raw(switch_idx, on);
  65. }
  66. #endif // defined(DIP_SWITCH_ENABLE) && defined(DIP_SWITCH_MAP_ENABLE)
  67. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  68. // Combos
  69. #if defined(COMBO_ENABLE)
  70. uint16_t combo_count_raw(void) {
  71. return sizeof(key_combos) / sizeof(combo_t);
  72. }
  73. __attribute__((weak)) uint16_t combo_count(void) {
  74. return combo_count_raw();
  75. }
  76. combo_t* combo_get_raw(uint16_t combo_idx) {
  77. return &key_combos[combo_idx];
  78. }
  79. __attribute__((weak)) combo_t* combo_get(uint16_t combo_idx) {
  80. return combo_get_raw(combo_idx);
  81. }
  82. #endif // defined(COMBO_ENABLE)