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 /tmk_core/common/action_util.c | |
parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip |
clang-format changes
Diffstat (limited to 'tmk_core/common/action_util.c')
-rw-r--r-- | tmk_core/common/action_util.c | 159 |
1 files changed, 64 insertions, 95 deletions
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 365ed6a1d..335aa36e6 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c | |||
@@ -24,23 +24,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
24 | 24 | ||
25 | extern keymap_config_t keymap_config; | 25 | extern keymap_config_t keymap_config; |
26 | 26 | ||
27 | 27 | static uint8_t real_mods = 0; | |
28 | static uint8_t real_mods = 0; | 28 | static uint8_t weak_mods = 0; |
29 | static uint8_t weak_mods = 0; | ||
30 | static uint8_t macro_mods = 0; | 29 | static uint8_t macro_mods = 0; |
31 | 30 | ||
32 | #ifdef USB_6KRO_ENABLE | 31 | #ifdef USB_6KRO_ENABLE |
33 | #define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) | 32 | # define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) |
34 | #define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS) | 33 | # define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS) |
35 | #define RO_INC(a) RO_ADD(a, 1) | 34 | # define RO_INC(a) RO_ADD(a, 1) |
36 | #define RO_DEC(a) RO_SUB(a, 1) | 35 | # define RO_DEC(a) RO_SUB(a, 1) |
37 | static int8_t cb_head = 0; | 36 | static int8_t cb_head = 0; |
38 | static int8_t cb_tail = 0; | 37 | static int8_t cb_tail = 0; |
39 | static int8_t cb_count = 0; | 38 | static int8_t cb_count = 0; |
40 | #endif | 39 | #endif |
41 | 40 | ||
42 | // TODO: pointer variable is not needed | 41 | // TODO: pointer variable is not needed |
43 | //report_keyboard_t keyboard_report = {}; | 42 | // report_keyboard_t keyboard_report = {}; |
44 | report_keyboard_t *keyboard_report = &(report_keyboard_t){}; | 43 | report_keyboard_t *keyboard_report = &(report_keyboard_t){}; |
45 | 44 | ||
46 | extern inline void add_key(uint8_t key); | 45 | extern inline void add_key(uint8_t key); |
@@ -48,10 +47,10 @@ extern inline void del_key(uint8_t key); | |||
48 | extern inline void clear_keys(void); | 47 | extern inline void clear_keys(void); |
49 | 48 | ||
50 | #ifndef NO_ACTION_ONESHOT | 49 | #ifndef NO_ACTION_ONESHOT |
51 | static uint8_t oneshot_mods = 0; | 50 | static uint8_t oneshot_mods = 0; |
52 | static uint8_t oneshot_locked_mods = 0; | 51 | static uint8_t oneshot_locked_mods = 0; |
53 | uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } | 52 | uint8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } |
54 | void set_oneshot_locked_mods(uint8_t mods) { | 53 | void set_oneshot_locked_mods(uint8_t mods) { |
55 | if (mods != oneshot_locked_mods) { | 54 | if (mods != oneshot_locked_mods) { |
56 | oneshot_locked_mods = mods; | 55 | oneshot_locked_mods = mods; |
57 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); | 56 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); |
@@ -63,16 +62,12 @@ void clear_oneshot_locked_mods(void) { | |||
63 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); | 62 | oneshot_locked_mods_changed_kb(oneshot_locked_mods); |
64 | } | 63 | } |
65 | } | 64 | } |
66 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 65 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
67 | static uint16_t oneshot_time = 0; | 66 | static uint16_t oneshot_time = 0; |
68 | bool has_oneshot_mods_timed_out(void) { | 67 | bool has_oneshot_mods_timed_out(void) { return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; } |
69 | return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; | 68 | # else |
70 | } | 69 | bool has_oneshot_mods_timed_out(void) { return false; } |
71 | #else | 70 | # endif |
72 | bool has_oneshot_mods_timed_out(void) { | ||
73 | return false; | ||
74 | } | ||
75 | #endif | ||
76 | #endif | 71 | #endif |
77 | 72 | ||
78 | /* oneshot layer */ | 73 | /* oneshot layer */ |
@@ -88,44 +83,39 @@ static int8_t oneshot_layer_data = 0; | |||
88 | inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } | 83 | inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } |
89 | inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } | 84 | inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } |
90 | 85 | ||
91 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 86 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
92 | static uint16_t oneshot_layer_time = 0; | 87 | static uint16_t oneshot_layer_time = 0; |
93 | inline bool has_oneshot_layer_timed_out() { | 88 | inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); } |
94 | return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && | 89 | # endif |
95 | !(get_oneshot_layer_state() & ONESHOT_TOGGLED); | ||
96 | } | ||
97 | #endif | ||
98 | 90 | ||
99 | /** \brief Set oneshot layer | 91 | /** \brief Set oneshot layer |
100 | * | 92 | * |
101 | * FIXME: needs doc | 93 | * FIXME: needs doc |
102 | */ | 94 | */ |
103 | void set_oneshot_layer(uint8_t layer, uint8_t state) | 95 | void set_oneshot_layer(uint8_t layer, uint8_t state) { |
104 | { | ||
105 | oneshot_layer_data = layer << 3 | state; | 96 | oneshot_layer_data = layer << 3 | state; |
106 | layer_on(layer); | 97 | layer_on(layer); |
107 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 98 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
108 | oneshot_layer_time = timer_read(); | 99 | oneshot_layer_time = timer_read(); |
109 | #endif | 100 | # endif |
110 | oneshot_layer_changed_kb(get_oneshot_layer()); | 101 | oneshot_layer_changed_kb(get_oneshot_layer()); |
111 | } | 102 | } |
112 | /** \brief Reset oneshot layer | 103 | /** \brief Reset oneshot layer |
113 | * | 104 | * |
114 | * FIXME: needs doc | 105 | * FIXME: needs doc |
115 | */ | 106 | */ |
116 | void reset_oneshot_layer(void) { | 107 | void reset_oneshot_layer(void) { |
117 | oneshot_layer_data = 0; | 108 | oneshot_layer_data = 0; |
118 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 109 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
119 | oneshot_layer_time = 0; | 110 | oneshot_layer_time = 0; |
120 | #endif | 111 | # endif |
121 | oneshot_layer_changed_kb(get_oneshot_layer()); | 112 | oneshot_layer_changed_kb(get_oneshot_layer()); |
122 | } | 113 | } |
123 | /** \brief Clear oneshot layer | 114 | /** \brief Clear oneshot layer |
124 | * | 115 | * |
125 | * FIXME: needs doc | 116 | * FIXME: needs doc |
126 | */ | 117 | */ |
127 | void clear_oneshot_layer_state(oneshot_fullfillment_t state) | 118 | void clear_oneshot_layer_state(oneshot_fullfillment_t state) { |
128 | { | ||
129 | uint8_t start_state = oneshot_layer_data; | 119 | uint8_t start_state = oneshot_layer_data; |
130 | oneshot_layer_data &= ~state; | 120 | oneshot_layer_data &= ~state; |
131 | if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { | 121 | if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { |
@@ -137,10 +127,7 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state) | |||
137 | * | 127 | * |
138 | * FIXME: needs doc | 128 | * FIXME: needs doc |
139 | */ | 129 | */ |
140 | bool is_oneshot_layer_active(void) | 130 | bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); } |
141 | { | ||
142 | return get_oneshot_layer_state(); | ||
143 | } | ||
144 | #endif | 131 | #endif |
145 | 132 | ||
146 | /** \brief Send keyboard report | 133 | /** \brief Send keyboard report |
@@ -148,17 +135,17 @@ bool is_oneshot_layer_active(void) | |||
148 | * FIXME: needs doc | 135 | * FIXME: needs doc |
149 | */ | 136 | */ |
150 | void send_keyboard_report(void) { | 137 | void send_keyboard_report(void) { |
151 | keyboard_report->mods = real_mods; | 138 | keyboard_report->mods = real_mods; |
152 | keyboard_report->mods |= weak_mods; | 139 | keyboard_report->mods |= weak_mods; |
153 | keyboard_report->mods |= macro_mods; | 140 | keyboard_report->mods |= macro_mods; |
154 | #ifndef NO_ACTION_ONESHOT | 141 | #ifndef NO_ACTION_ONESHOT |
155 | if (oneshot_mods) { | 142 | if (oneshot_mods) { |
156 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 143 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
157 | if (has_oneshot_mods_timed_out()) { | 144 | if (has_oneshot_mods_timed_out()) { |
158 | dprintf("Oneshot: timeout\n"); | 145 | dprintf("Oneshot: timeout\n"); |
159 | clear_oneshot_mods(); | 146 | clear_oneshot_mods(); |
160 | } | 147 | } |
161 | #endif | 148 | # endif |
162 | keyboard_report->mods |= oneshot_mods; | 149 | keyboard_report->mods |= oneshot_mods; |
163 | if (has_anykey(keyboard_report)) { | 150 | if (has_anykey(keyboard_report)) { |
164 | clear_oneshot_mods(); | 151 | clear_oneshot_mods(); |
@@ -254,90 +241,72 @@ void clear_macro_mods(void) { macro_mods = 0; } | |||
254 | * FIXME: needs doc | 241 | * FIXME: needs doc |
255 | */ | 242 | */ |
256 | void set_oneshot_mods(uint8_t mods) { | 243 | void set_oneshot_mods(uint8_t mods) { |
257 | if (oneshot_mods != mods) { | 244 | if (oneshot_mods != mods) { |
258 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 245 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
259 | oneshot_time = timer_read(); | 246 | oneshot_time = timer_read(); |
260 | #endif | 247 | # endif |
261 | oneshot_mods = mods; | 248 | oneshot_mods = mods; |
262 | oneshot_mods_changed_kb(mods); | 249 | oneshot_mods_changed_kb(mods); |
263 | } | 250 | } |
264 | } | 251 | } |
265 | /** \brief clear oneshot mods | 252 | /** \brief clear oneshot mods |
266 | * | 253 | * |
267 | * FIXME: needs doc | 254 | * FIXME: needs doc |
268 | */ | 255 | */ |
269 | void clear_oneshot_mods(void) { | 256 | void clear_oneshot_mods(void) { |
270 | if (oneshot_mods) { | 257 | if (oneshot_mods) { |
271 | oneshot_mods = 0; | 258 | oneshot_mods = 0; |
272 | #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 259 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
273 | oneshot_time = 0; | 260 | oneshot_time = 0; |
274 | #endif | 261 | # endif |
275 | oneshot_mods_changed_kb(oneshot_mods); | 262 | oneshot_mods_changed_kb(oneshot_mods); |
276 | } | 263 | } |
277 | } | 264 | } |
278 | /** \brief get oneshot mods | 265 | /** \brief get oneshot mods |
279 | * | 266 | * |
280 | * FIXME: needs doc | 267 | * FIXME: needs doc |
281 | */ | 268 | */ |
282 | uint8_t get_oneshot_mods(void) | 269 | uint8_t get_oneshot_mods(void) { return oneshot_mods; } |
283 | { | ||
284 | return oneshot_mods; | ||
285 | } | ||
286 | #endif | 270 | #endif |
287 | 271 | ||
288 | /** \brief Called when the one shot modifiers have been changed. | 272 | /** \brief Called when the one shot modifiers have been changed. |
289 | * | 273 | * |
290 | * \param mods Contains the active modifiers active after the change. | 274 | * \param mods Contains the active modifiers active after the change. |
291 | */ | 275 | */ |
292 | __attribute__((weak)) | 276 | __attribute__((weak)) void oneshot_locked_mods_changed_user(uint8_t mods) {} |
293 | void oneshot_locked_mods_changed_user(uint8_t mods) { } | ||
294 | 277 | ||
295 | /** \brief Called when the locked one shot modifiers have been changed. | 278 | /** \brief Called when the locked one shot modifiers have been changed. |
296 | * | 279 | * |
297 | * \param mods Contains the active modifiers active after the change. | 280 | * \param mods Contains the active modifiers active after the change. |
298 | */ | 281 | */ |
299 | __attribute__((weak)) | 282 | __attribute__((weak)) void oneshot_locked_mods_changed_kb(uint8_t mods) { oneshot_locked_mods_changed_user(mods); } |
300 | void oneshot_locked_mods_changed_kb(uint8_t mods) { | ||
301 | oneshot_locked_mods_changed_user(mods); | ||
302 | } | ||
303 | 283 | ||
304 | /** \brief Called when the one shot modifiers have been changed. | 284 | /** \brief Called when the one shot modifiers have been changed. |
305 | * | 285 | * |
306 | * \param mods Contains the active modifiers active after the change. | 286 | * \param mods Contains the active modifiers active after the change. |
307 | */ | 287 | */ |
308 | __attribute__((weak)) | 288 | __attribute__((weak)) void oneshot_mods_changed_user(uint8_t mods) {} |
309 | void oneshot_mods_changed_user(uint8_t mods) { } | ||
310 | 289 | ||
311 | /** \brief Called when the one shot modifiers have been changed. | 290 | /** \brief Called when the one shot modifiers have been changed. |
312 | * | 291 | * |
313 | * \param mods Contains the active modifiers active after the change. | 292 | * \param mods Contains the active modifiers active after the change. |
314 | */ | 293 | */ |
315 | __attribute__((weak)) | 294 | __attribute__((weak)) void oneshot_mods_changed_kb(uint8_t mods) { oneshot_mods_changed_user(mods); } |
316 | void oneshot_mods_changed_kb(uint8_t mods) { | ||
317 | oneshot_mods_changed_user(mods); | ||
318 | } | ||
319 | 295 | ||
320 | /** \brief Called when the one shot layers have been changed. | 296 | /** \brief Called when the one shot layers have been changed. |
321 | * | 297 | * |
322 | * \param layer Contains the layer that is toggled on, or zero when toggled off. | 298 | * \param layer Contains the layer that is toggled on, or zero when toggled off. |
323 | */ | 299 | */ |
324 | __attribute__((weak)) | 300 | __attribute__((weak)) void oneshot_layer_changed_user(uint8_t layer) {} |
325 | void oneshot_layer_changed_user(uint8_t layer) { } | ||
326 | 301 | ||
327 | /** \brief Called when the one shot layers have been changed. | 302 | /** \brief Called when the one shot layers have been changed. |
328 | * | 303 | * |
329 | * \param layer Contains the layer that is toggled on, or zero when toggled off. | 304 | * \param layer Contains the layer that is toggled on, or zero when toggled off. |
330 | */ | 305 | */ |
331 | __attribute__((weak)) | 306 | __attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) { oneshot_layer_changed_user(layer); } |
332 | void oneshot_layer_changed_kb(uint8_t layer) { | ||
333 | oneshot_layer_changed_user(layer); | ||
334 | } | ||
335 | 307 | ||
336 | /** \brief inspect keyboard state | 308 | /** \brief inspect keyboard state |
337 | * | 309 | * |
338 | * FIXME: needs doc | 310 | * FIXME: needs doc |
339 | */ | 311 | */ |
340 | uint8_t has_anymod(void) | 312 | uint8_t has_anymod(void) { return bitpop(real_mods); } |
341 | { | ||
342 | return bitpop(real_mods); | ||
343 | } | ||