diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/keymap_common.c | |
parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip |
clang-format changes
Diffstat (limited to 'quantum/keymap_common.c')
-rw-r--r-- | quantum/keymap_common.c | 99 |
1 files changed, 43 insertions, 56 deletions
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index eef739a14..9af951008 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c | |||
@@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
20 | #include "keycode.h" | 20 | #include "keycode.h" |
21 | #include "action_layer.h" | 21 | #include "action_layer.h" |
22 | #if defined(__AVR__) | 22 | #if defined(__AVR__) |
23 | #include <util/delay.h> | 23 | # include <util/delay.h> |
24 | #include <stdio.h> | 24 | # include <stdio.h> |
25 | #endif | 25 | #endif |
26 | #include "action.h" | 26 | #include "action.h" |
27 | #include "action_macro.h" | 27 | #include "action_macro.h" |
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
30 | #include "quantum.h" | 30 | #include "quantum.h" |
31 | 31 | ||
32 | #ifdef MIDI_ENABLE | 32 | #ifdef MIDI_ENABLE |
33 | #include "process_midi.h" | 33 | # include "process_midi.h" |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | extern keymap_config_t keymap_config; | 36 | extern keymap_config_t keymap_config; |
@@ -38,8 +38,7 @@ extern keymap_config_t keymap_config; | |||
38 | #include <inttypes.h> | 38 | #include <inttypes.h> |
39 | 39 | ||
40 | /* converts key to action */ | 40 | /* converts key to action */ |
41 | action_t action_for_key(uint8_t layer, keypos_t key) | 41 | action_t action_for_key(uint8_t layer, keypos_t key) { |
42 | { | ||
43 | // 16bit keycodes - important | 42 | // 16bit keycodes - important |
44 | uint16_t keycode = keymap_key_to_keycode(layer, key); | 43 | uint16_t keycode = keymap_key_to_keycode(layer, key); |
45 | 44 | ||
@@ -47,7 +46,7 @@ action_t action_for_key(uint8_t layer, keypos_t key) | |||
47 | keycode = keycode_config(keycode); | 46 | keycode = keycode_config(keycode); |
48 | 47 | ||
49 | action_t action; | 48 | action_t action; |
50 | uint8_t action_layer, when, mod; | 49 | uint8_t action_layer, when, mod; |
51 | 50 | ||
52 | switch (keycode) { | 51 | switch (keycode) { |
53 | case KC_FN0 ... KC_FN31: | 52 | case KC_FN0 ... KC_FN31: |
@@ -69,18 +68,18 @@ action_t action_for_key(uint8_t layer, keypos_t key) | |||
69 | case KC_TRNS: | 68 | case KC_TRNS: |
70 | action.code = ACTION_TRANSPARENT; | 69 | action.code = ACTION_TRANSPARENT; |
71 | break; | 70 | break; |
72 | case QK_MODS ... QK_MODS_MAX: ; | 71 | case QK_MODS ... QK_MODS_MAX:; |
73 | // Has a modifier | 72 | // Has a modifier |
74 | // Split it up | 73 | // Split it up |
75 | action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key | 74 | action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key |
76 | break; | 75 | break; |
77 | case QK_FUNCTION ... QK_FUNCTION_MAX: ; | 76 | case QK_FUNCTION ... QK_FUNCTION_MAX:; |
78 | // Is a shortcut for function action_layer, pull last 12bits | 77 | // Is a shortcut for function action_layer, pull last 12bits |
79 | // This means we have 4,096 FN macros at our disposal | 78 | // This means we have 4,096 FN macros at our disposal |
80 | action.code = keymap_function_id_to_action( (int)keycode & 0xFFF ); | 79 | action.code = keymap_function_id_to_action((int)keycode & 0xFFF); |
81 | break; | 80 | break; |
82 | case QK_MACRO ... QK_MACRO_MAX: | 81 | case QK_MACRO ... QK_MACRO_MAX: |
83 | if (keycode & 0x800) // tap macros have upper bit set | 82 | if (keycode & 0x800) // tap macros have upper bit set |
84 | action.code = ACTION_MACRO_TAP(keycode & 0xFF); | 83 | action.code = ACTION_MACRO_TAP(keycode & 0xFF); |
85 | else | 84 | else |
86 | action.code = ACTION_MACRO(keycode & 0xFF); | 85 | action.code = ACTION_MACRO(keycode & 0xFF); |
@@ -88,50 +87,50 @@ action_t action_for_key(uint8_t layer, keypos_t key) | |||
88 | case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: | 87 | case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: |
89 | action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); | 88 | action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); |
90 | break; | 89 | break; |
91 | case QK_TO ... QK_TO_MAX: ; | 90 | case QK_TO ... QK_TO_MAX:; |
92 | // Layer set "GOTO" | 91 | // Layer set "GOTO" |
93 | when = (keycode >> 0x4) & 0x3; | 92 | when = (keycode >> 0x4) & 0x3; |
94 | action_layer = keycode & 0xF; | 93 | action_layer = keycode & 0xF; |
95 | action.code = ACTION_LAYER_SET(action_layer, when); | 94 | action.code = ACTION_LAYER_SET(action_layer, when); |
96 | break; | 95 | break; |
97 | case QK_MOMENTARY ... QK_MOMENTARY_MAX: ; | 96 | case QK_MOMENTARY ... QK_MOMENTARY_MAX:; |
98 | // Momentary action_layer | 97 | // Momentary action_layer |
99 | action_layer = keycode & 0xFF; | 98 | action_layer = keycode & 0xFF; |
100 | action.code = ACTION_LAYER_MOMENTARY(action_layer); | 99 | action.code = ACTION_LAYER_MOMENTARY(action_layer); |
101 | break; | 100 | break; |
102 | case QK_DEF_LAYER ... QK_DEF_LAYER_MAX: ; | 101 | case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:; |
103 | // Set default action_layer | 102 | // Set default action_layer |
104 | action_layer = keycode & 0xFF; | 103 | action_layer = keycode & 0xFF; |
105 | action.code = ACTION_DEFAULT_LAYER_SET(action_layer); | 104 | action.code = ACTION_DEFAULT_LAYER_SET(action_layer); |
106 | break; | 105 | break; |
107 | case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: ; | 106 | case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:; |
108 | // Set toggle | 107 | // Set toggle |
109 | action_layer = keycode & 0xFF; | 108 | action_layer = keycode & 0xFF; |
110 | action.code = ACTION_LAYER_TOGGLE(action_layer); | 109 | action.code = ACTION_LAYER_TOGGLE(action_layer); |
111 | break; | 110 | break; |
112 | case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: ; | 111 | case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:; |
113 | // OSL(action_layer) - One-shot action_layer | 112 | // OSL(action_layer) - One-shot action_layer |
114 | action_layer = keycode & 0xFF; | 113 | action_layer = keycode & 0xFF; |
115 | action.code = ACTION_LAYER_ONESHOT(action_layer); | 114 | action.code = ACTION_LAYER_ONESHOT(action_layer); |
116 | break; | 115 | break; |
117 | case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX: ; | 116 | case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:; |
118 | // OSM(mod) - One-shot mod | 117 | // OSM(mod) - One-shot mod |
119 | mod = mod_config(keycode & 0xFF); | 118 | mod = mod_config(keycode & 0xFF); |
120 | action.code = ACTION_MODS_ONESHOT(mod); | 119 | action.code = ACTION_MODS_ONESHOT(mod); |
121 | break; | 120 | break; |
122 | case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: | 121 | case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: |
123 | action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF); | 122 | action.code = ACTION_LAYER_TAP_TOGGLE(keycode & 0xFF); |
124 | break; | 123 | break; |
125 | case QK_LAYER_MOD ... QK_LAYER_MOD_MAX: | 124 | case QK_LAYER_MOD ... QK_LAYER_MOD_MAX: |
126 | mod = mod_config(keycode & 0xF); | 125 | mod = mod_config(keycode & 0xF); |
127 | action_layer = (keycode >> 4) & 0xF; | 126 | action_layer = (keycode >> 4) & 0xF; |
128 | action.code = ACTION_LAYER_MODS(action_layer, mod); | 127 | action.code = ACTION_LAYER_MODS(action_layer, mod); |
129 | break; | 128 | break; |
130 | case QK_MOD_TAP ... QK_MOD_TAP_MAX: | 129 | case QK_MOD_TAP ... QK_MOD_TAP_MAX: |
131 | mod = mod_config((keycode >> 0x8) & 0x1F); | 130 | mod = mod_config((keycode >> 0x8) & 0x1F); |
132 | action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF); | 131 | action.code = ACTION_MODS_TAP_KEY(mod, keycode & 0xFF); |
133 | break; | 132 | break; |
134 | #ifdef BACKLIGHT_ENABLE | 133 | #ifdef BACKLIGHT_ENABLE |
135 | case BL_ON: | 134 | case BL_ON: |
136 | action.code = ACTION_BACKLIGHT_ON(); | 135 | action.code = ACTION_BACKLIGHT_ON(); |
137 | break; | 136 | break; |
@@ -150,12 +149,12 @@ action_t action_for_key(uint8_t layer, keypos_t key) | |||
150 | case BL_STEP: | 149 | case BL_STEP: |
151 | action.code = ACTION_BACKLIGHT_STEP(); | 150 | action.code = ACTION_BACKLIGHT_STEP(); |
152 | break; | 151 | break; |
153 | #endif | 152 | #endif |
154 | #ifdef SWAP_HANDS_ENABLE | 153 | #ifdef SWAP_HANDS_ENABLE |
155 | case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX: | 154 | case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX: |
156 | action.code = ACTION(ACT_SWAP_HANDS, keycode & 0xff); | 155 | action.code = ACTION(ACT_SWAP_HANDS, keycode & 0xff); |
157 | break; | 156 | break; |
158 | #endif | 157 | #endif |
159 | 158 | ||
160 | default: | 159 | default: |
161 | action.code = ACTION_NO; | 160 | action.code = ACTION_NO; |
@@ -164,42 +163,30 @@ action_t action_for_key(uint8_t layer, keypos_t key) | |||
164 | return action; | 163 | return action; |
165 | } | 164 | } |
166 | 165 | ||
167 | __attribute__ ((weak)) | 166 | __attribute__((weak)) const uint16_t PROGMEM fn_actions[] = { |
168 | const uint16_t PROGMEM fn_actions[] = { | ||
169 | 167 | ||
170 | }; | 168 | }; |
171 | 169 | ||
172 | /* Macro */ | 170 | /* Macro */ |
173 | __attribute__ ((weak)) | 171 | __attribute__((weak)) const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) { return MACRO_NONE; } |
174 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) | ||
175 | { | ||
176 | return MACRO_NONE; | ||
177 | } | ||
178 | 172 | ||
179 | /* Function */ | 173 | /* Function */ |
180 | __attribute__ ((weak)) | 174 | __attribute__((weak)) void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {} |
181 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) | ||
182 | { | ||
183 | } | ||
184 | 175 | ||
185 | // translates key to keycode | 176 | // translates key to keycode |
186 | __attribute__ ((weak)) | 177 | __attribute__((weak)) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { |
187 | uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) | ||
188 | { | ||
189 | // Read entire word (16bits) | 178 | // Read entire word (16bits) |
190 | return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]); | 179 | return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]); |
191 | } | 180 | } |
192 | 181 | ||
193 | // translates function id to action | 182 | // translates function id to action |
194 | __attribute__ ((weak)) | 183 | __attribute__((weak)) uint16_t keymap_function_id_to_action(uint16_t function_id) { |
195 | uint16_t keymap_function_id_to_action( uint16_t function_id ) | 184 | // The compiler sees the empty (weak) fn_actions and generates a warning |
196 | { | 185 | // This function should not be called in that case, so the warning is too strict |
197 | // The compiler sees the empty (weak) fn_actions and generates a warning | 186 | // If this function is called however, the keymap should have overridden fn_actions, and then the compile |
198 | // This function should not be called in that case, so the warning is too strict | 187 | // is comparing against the wrong array |
199 | // If this function is called however, the keymap should have overridden fn_actions, and then the compile | 188 | #pragma GCC diagnostic push |
200 | // is comparing against the wrong array | 189 | #pragma GCC diagnostic ignored "-Warray-bounds" |
201 | #pragma GCC diagnostic push | 190 | return pgm_read_word(&fn_actions[function_id]); |
202 | #pragma GCC diagnostic ignored "-Warray-bounds" | 191 | #pragma GCC diagnostic pop |
203 | return pgm_read_word(&fn_actions[function_id]); | ||
204 | #pragma GCC diagnostic pop | ||
205 | } | 192 | } |