-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_map.c
110 lines (97 loc) · 3.65 KB
/
layer_map.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2023 Christopher Courtney, aka Drashna Jael're (@drashna) <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "quantum.h"
#include "layer_map.h"
ASSERT_COMMUNITY_MODULES_MIN_API_VERSION(1, 0, 0);
volatile uint16_t layer_map[LAYER_MAP_ROWS][LAYER_MAP_COLS] = {0};
static bool layer_map_set = true;
extern bool peek_matrix(uint8_t row_index, uint8_t col_index, bool read_raw);
static bool layer_map_has_updated = false;
#if defined(SWAP_HANDS_ENABLE) && defined(ENCODER_MAP_ENABLE)
# include "encoder.h"
extern const uint8_t PROGMEM encoder_hand_swap_config[NUM_ENCODERS];
#endif // SWAP_HANDS_ENABLE && ENCODER_MAP_ENABLE
void set_layer_map_dirty(void) {
layer_map_set = true;
}
bool get_layer_map_has_updated(void) {
return layer_map_has_updated;
}
void set_layer_map_has_updated(bool value) {
layer_map_has_updated = value;
}
void populate_layer_map(void) {
for (uint8_t i = 0; i < LAYER_MAP_ROWS; i++) {
for (uint8_t j = 0; j < LAYER_MAP_COLS; j++) {
#ifdef LAYER_MAP_REMAPPING
keypos_t key = layer_remap[i][j];
#else // LAYER_MAP_REMAPPING
keypos_t key = {.row = i, .col = j};
#endif // LAYER_MAP_REMAPPING
#ifdef SWAP_HANDS_ENABLE
if (is_swap_hands_on()) {
if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
# ifdef LAYER_MAP_REMAPPING
key.row = pgm_read_byte(&hand_swap_config[layer_remap[i][j].row][layer_remap[i][j].col].row);
key.col = pgm_read_byte(&hand_swap_config[layer_remap[i][j].row][layer_remap[i][j].col].col);
# else // LAYER_MAP_REMAPPING
key.row = pgm_read_byte(&hand_swap_config[i][j].row);
key.col = pgm_read_byte(&hand_swap_config[i][j].col);
# endif // LAYER_MAP_REMAPPING
} else if (key.row == KEYLOC_ENCODER_CCW || key.row == KEYLOC_ENCODER_CW) {
key.col = pgm_read_byte(&encoder_hand_swap_config[key.col]);
}
}
#endif // SWAP_HANDS_ENABLE
layer_map[i][j] = keymap_key_to_keycode(layer_switch_get_layer(key), key);
}
}
#ifdef CUSTOM_QUANTUM_PAINTER_ENABLE
layer_map_has_updated = true;
#endif
}
bool peek_matrix_layer_map(uint8_t row, uint8_t col) {
#ifdef LAYER_MAP_REMAPPING
if (layer_remap[row][col].row >= KEYLOC_DIP_SWITCH_OFF) {
return false;
}
return peek_matrix(layer_remap[row][col].row, layer_remap[row][col].col, false);
#else // LAYER_MAP_REMAPPING
if (row >= KEYLOC_DIP_SWITCH_OFF) {
return false;
}
return peek_matrix(row, col, false);
#endif // LAYER_MAP_REMAPPING
}
void housekeeping_task_layer_map(void) {
static layer_state_t last_layer_state = 0, last_default_layer_state = 0;
if (layer_state != last_layer_state || default_layer_state != last_default_layer_state) {
last_layer_state = layer_state;
last_default_layer_state = default_layer_state;
layer_map_set = true;
}
#ifdef SWAP_HANDS_ENABLE
static bool swap_hands = false;
if (is_swap_hands_on() != swap_hands) {
swap_hands = is_swap_hands_on();
layer_map_set = true;
}
#endif // SWAP_HANDS_ENABLE
if (layer_map_set) {
populate_layer_map();
layer_map_set = false;
}
}
#ifdef VIA_ENABLE
# include "via.h"
bool via_command_kb(uint8_t *data, uint8_t length) {
switch (data[0]) {
case id_dynamic_keymap_set_keycode:
case id_dynamic_keymap_reset:
case id_dynamic_keymap_set_buffer:
case id_dynamic_keymap_set_encoder:
layer_map_set = true;
}
return false;
}
#endif // VIA_ENABLE