2022-06-05 02:26:02 +02:00
|
|
|
// Copyright 2022 Nick Brassel (@tzarc)
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
// Pull the actual keymap code so that we can inspect stuff from it
|
|
|
|
#include KEYMAP_C
|
|
|
|
|
2022-07-05 00:58:35 +02:00
|
|
|
// Allow for keymap or userspace rules.mk to specify an alternate location for the keymap array
|
|
|
|
#ifdef INTROSPECTION_KEYMAP_C
|
|
|
|
# include INTROSPECTION_KEYMAP_C
|
|
|
|
#endif // INTROSPECTION_KEYMAP_C
|
|
|
|
|
2022-06-05 02:26:02 +02:00
|
|
|
#include "keymap_introspection.h"
|
2024-07-16 01:22:17 +02:00
|
|
|
#include "util.h"
|
2022-06-05 02:26:02 +02:00
|
|
|
|
2023-01-23 21:10:03 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Key mapping
|
2022-06-05 02:26:02 +02:00
|
|
|
|
2023-01-23 21:10:03 +01:00
|
|
|
#define NUM_KEYMAP_LAYERS_RAW ((uint8_t)(sizeof(keymaps) / ((MATRIX_ROWS) * (MATRIX_COLS) * sizeof(uint16_t))))
|
|
|
|
|
|
|
|
uint8_t keymap_layer_count_raw(void) {
|
|
|
|
return NUM_KEYMAP_LAYERS_RAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) uint8_t keymap_layer_count(void) {
|
|
|
|
return keymap_layer_count_raw();
|
2022-06-05 02:26:02 +02:00
|
|
|
}
|
|
|
|
|
2023-01-01 01:55:14 +01:00
|
|
|
#ifdef DYNAMIC_KEYMAP_ENABLE
|
2023-01-23 21:10:03 +01:00
|
|
|
_Static_assert(NUM_KEYMAP_LAYERS_RAW <= MAX_LAYER, "Number of keymap layers exceeds maximum set by DYNAMIC_KEYMAP_LAYER_COUNT");
|
2023-01-01 01:55:14 +01:00
|
|
|
#else
|
2023-01-23 21:10:03 +01:00
|
|
|
_Static_assert(NUM_KEYMAP_LAYERS_RAW <= MAX_LAYER, "Number of keymap layers exceeds maximum set by LAYER_STATE_(8|16|32)BIT");
|
2023-01-01 01:55:14 +01:00
|
|
|
#endif
|
2022-08-28 08:13:44 +02:00
|
|
|
|
2022-09-29 19:25:55 +02:00
|
|
|
uint16_t keycode_at_keymap_location_raw(uint8_t layer_num, uint8_t row, uint8_t column) {
|
2023-01-23 21:10:03 +01:00
|
|
|
if (layer_num < NUM_KEYMAP_LAYERS_RAW && row < MATRIX_ROWS && column < MATRIX_COLS) {
|
2022-09-29 19:25:55 +02:00
|
|
|
return pgm_read_word(&keymaps[layer_num][row][column]);
|
|
|
|
}
|
2023-01-23 21:10:03 +01:00
|
|
|
return KC_TRNS;
|
2022-09-29 19:25:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column) {
|
|
|
|
return keycode_at_keymap_location_raw(layer_num, row, column);
|
|
|
|
}
|
|
|
|
|
2023-01-23 21:10:03 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Encoder mapping
|
|
|
|
|
2022-06-05 02:26:02 +02:00
|
|
|
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
|
|
|
|
2023-04-15 17:18:44 +02:00
|
|
|
# define NUM_ENCODERMAP_LAYERS_RAW ((uint8_t)(sizeof(encoder_map) / ((NUM_ENCODERS) * (NUM_DIRECTIONS) * sizeof(uint16_t))))
|
2023-01-23 21:10:03 +01:00
|
|
|
|
|
|
|
uint8_t encodermap_layer_count_raw(void) {
|
|
|
|
return NUM_ENCODERMAP_LAYERS_RAW;
|
|
|
|
}
|
2022-06-05 02:26:02 +02:00
|
|
|
|
2023-01-23 21:10:03 +01:00
|
|
|
__attribute__((weak)) uint8_t encodermap_layer_count(void) {
|
|
|
|
return encodermap_layer_count_raw();
|
2022-06-05 02:26:02 +02:00
|
|
|
}
|
|
|
|
|
2023-01-23 21:10:03 +01:00
|
|
|
_Static_assert(NUM_KEYMAP_LAYERS_RAW == NUM_ENCODERMAP_LAYERS_RAW, "Number of encoder_map layers doesn't match the number of keymap layers");
|
2022-06-05 02:26:02 +02:00
|
|
|
|
2022-09-29 19:25:55 +02:00
|
|
|
uint16_t keycode_at_encodermap_location_raw(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
|
2023-01-23 21:10:03 +01:00
|
|
|
if (layer_num < NUM_ENCODERMAP_LAYERS_RAW && encoder_idx < NUM_ENCODERS) {
|
2022-09-29 19:25:55 +02:00
|
|
|
return pgm_read_word(&encoder_map[layer_num][encoder_idx][clockwise ? 0 : 1]);
|
|
|
|
}
|
2023-01-23 21:10:03 +01:00
|
|
|
return KC_TRNS;
|
2022-09-29 19:25:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
|
|
|
|
return keycode_at_encodermap_location_raw(layer_num, encoder_idx, clockwise);
|
|
|
|
}
|
|
|
|
|
2022-06-05 02:26:02 +02:00
|
|
|
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
|
2023-05-15 14:27:37 +02:00
|
|
|
|
2023-12-12 00:06:18 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Dip Switch mapping
|
|
|
|
|
|
|
|
#if defined(DIP_SWITCH_ENABLE) && defined(DIP_SWITCH_MAP_ENABLE)
|
|
|
|
|
|
|
|
uint16_t keycode_at_dip_switch_map_location_raw(uint8_t switch_idx, bool on) {
|
|
|
|
if (switch_idx < NUM_DIP_SWITCHES) {
|
|
|
|
return pgm_read_word(&dip_switch_map[switch_idx][!!on]);
|
|
|
|
}
|
|
|
|
return KC_TRNS;
|
|
|
|
}
|
|
|
|
|
2024-07-16 01:22:17 +02:00
|
|
|
__attribute__((weak)) uint16_t keycode_at_dip_switch_map_location(uint8_t switch_idx, bool on) {
|
2023-12-12 00:06:18 +01:00
|
|
|
return keycode_at_dip_switch_map_location_raw(switch_idx, on);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(DIP_SWITCH_ENABLE) && defined(DIP_SWITCH_MAP_ENABLE)
|
|
|
|
|
2023-05-15 14:27:37 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Combos
|
|
|
|
|
|
|
|
#if defined(COMBO_ENABLE)
|
|
|
|
|
|
|
|
uint16_t combo_count_raw(void) {
|
2024-07-16 01:22:17 +02:00
|
|
|
return ARRAY_SIZE(key_combos);
|
2023-05-15 14:27:37 +02:00
|
|
|
}
|
|
|
|
__attribute__((weak)) uint16_t combo_count(void) {
|
|
|
|
return combo_count_raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
combo_t* combo_get_raw(uint16_t combo_idx) {
|
2024-07-16 01:22:17 +02:00
|
|
|
if (combo_idx >= combo_count_raw()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2023-05-15 14:27:37 +02:00
|
|
|
return &key_combos[combo_idx];
|
|
|
|
}
|
|
|
|
__attribute__((weak)) combo_t* combo_get(uint16_t combo_idx) {
|
|
|
|
return combo_get_raw(combo_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(COMBO_ENABLE)
|
2024-07-06 01:57:54 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Tap Dance
|
|
|
|
|
|
|
|
#if defined(TAP_DANCE_ENABLE)
|
|
|
|
|
|
|
|
uint16_t tap_dance_count_raw(void) {
|
2024-07-16 01:22:17 +02:00
|
|
|
return ARRAY_SIZE(tap_dance_actions);
|
2024-07-06 01:57:54 +02:00
|
|
|
}
|
|
|
|
|
2024-07-16 01:22:17 +02:00
|
|
|
__attribute__((weak)) uint16_t tap_dance_count(void) {
|
2024-07-06 01:57:54 +02:00
|
|
|
return tap_dance_count_raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
tap_dance_action_t* tap_dance_get_raw(uint16_t tap_dance_idx) {
|
2024-07-16 01:22:17 +02:00
|
|
|
if (tap_dance_idx >= tap_dance_count_raw()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2024-07-06 01:57:54 +02:00
|
|
|
return &tap_dance_actions[tap_dance_idx];
|
|
|
|
}
|
|
|
|
|
2024-07-16 01:22:17 +02:00
|
|
|
__attribute__((weak)) tap_dance_action_t* tap_dance_get(uint16_t tap_dance_idx) {
|
2024-07-06 01:57:54 +02:00
|
|
|
return tap_dance_get_raw(tap_dance_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(TAP_DANCE_ENABLE)
|
2024-07-16 01:22:17 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Key Overrides
|
|
|
|
|
|
|
|
#if defined(KEY_OVERRIDE_ENABLE)
|
|
|
|
|
|
|
|
uint16_t key_override_count_raw(void) {
|
|
|
|
return ARRAY_SIZE(key_overrides);
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) uint16_t key_override_count(void) {
|
|
|
|
return key_override_count_raw();
|
|
|
|
}
|
|
|
|
|
|
|
|
const key_override_t* key_override_get_raw(uint16_t key_override_idx) {
|
|
|
|
if (key_override_idx >= key_override_count_raw()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return key_overrides[key_override_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) const key_override_t* key_override_get(uint16_t key_override_idx) {
|
|
|
|
return key_override_get_raw(key_override_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(KEY_OVERRIDE_ENABLE)
|