From dedc54a328ab900f47da8478bd9c6b7d14891e15 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Thu, 15 Dec 2022 23:38:25 +0100 Subject: [Core] guard action related debug messages (#19348) --- quantum/action.c | 107 ++++++++++++++++++---------------------------- quantum/action.h | 14 +++++- quantum/action_layer.c | 22 ++++------ quantum/action_tapping.c | 88 ++++++++++++++++---------------------- quantum/logging/nodebug.h | 26 ----------- 5 files changed, 99 insertions(+), 158 deletions(-) delete mode 100644 quantum/logging/nodebug.h diff --git a/quantum/action.c b/quantum/action.c index ea6a24ea5c..2634dff18c 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -16,12 +16,6 @@ along with this program. If not, see . */ #include -#ifdef DEBUG_ACTION -# include "debug.h" -#else -# include "nodebug.h" -#endif - #include "host.h" #include "keycode.h" #include "keyboard.h" @@ -77,10 +71,10 @@ __attribute__((weak)) bool pre_process_record_quantum(keyrecord_t *record) { */ void action_exec(keyevent_t event) { if (!IS_NOEVENT(event)) { - dprint("\n---- action_exec: start -----\n"); - dprint("EVENT: "); + ac_dprintf("\n---- action_exec: start -----\n"); + ac_dprintf("EVENT: "); debug_event(event); - dprintln(); + ac_dprintf("\n"); #if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY) || (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) retro_tapping_counter++; #endif @@ -132,7 +126,7 @@ void action_exec(keyevent_t event) { process_record(&record); } if (!IS_NOEVENT(record.event)) { - dprint("processed: "); + ac_dprintf("processed: "); debug_record(record); dprintln(); } @@ -280,15 +274,15 @@ void process_record_handler(keyrecord_t *record) { #else action_t action = store_or_get_action(record->event.pressed, record->event.key); #endif - dprint("ACTION: "); + ac_dprintf("ACTION: "); debug_action(action); #ifndef NO_ACTION_LAYER - dprint(" layer_state: "); + ac_dprintf(" layer_state: "); layer_debug(); - dprint(" default_layer_state: "); + ac_dprintf(" default_layer_state: "); default_layer_debug(); #endif - dprintln(); + ac_dprintf("\n"); process_action(record, action); } @@ -432,14 +426,14 @@ void process_action(keyrecord_t *record, action_t action) { } else { if (event.pressed) { if (tap_count == 0) { - dprint("MODS_TAP: Oneshot: 0\n"); + ac_dprintf("MODS_TAP: Oneshot: 0\n"); register_mods(mods | get_oneshot_mods()); } else if (tap_count == 1) { - dprint("MODS_TAP: Oneshot: start\n"); + ac_dprintf("MODS_TAP: Oneshot: start\n"); set_oneshot_mods(mods | get_oneshot_mods()); # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 } else if (tap_count == ONESHOT_TAP_TOGGLE) { - dprint("MODS_TAP: Toggling oneshot"); + ac_dprintf("MODS_TAP: Toggling oneshot"); register_mods(mods); clear_oneshot_mods(); set_oneshot_locked_mods(mods | get_oneshot_locked_mods()); @@ -490,23 +484,23 @@ void process_action(keyrecord_t *record, action_t action) { get_hold_on_other_key_press(get_event_keycode(record->event, false), record) && # endif record->tap.interrupted) { - dprint("mods_tap: tap: cancel: add_mods\n"); + ac_dprintf("mods_tap: tap: cancel: add_mods\n"); // ad hoc: set 0 to cancel tap record->tap.count = 0; register_mods(mods); } else # endif { - dprint("MODS_TAP: Tap: register_code\n"); + ac_dprintf("MODS_TAP: Tap: register_code\n"); register_code(action.key.code); } } else { - dprint("MODS_TAP: No tap: add_mods\n"); + ac_dprintf("MODS_TAP: No tap: add_mods\n"); register_mods(mods); } } else { if (tap_count > 0) { - dprint("MODS_TAP: Tap: unregister_code\n"); + ac_dprintf("MODS_TAP: Tap: unregister_code\n"); if (action.layer_tap.code == KC_CAPS_LOCK) { wait_ms(TAP_HOLD_CAPS_DELAY); } else { @@ -514,7 +508,7 @@ void process_action(keyrecord_t *record, action_t action) { } unregister_code(action.key.code); } else { - dprint("MODS_TAP: No tap: add_mods\n"); + ac_dprintf("MODS_TAP: No tap: add_mods\n"); unregister_mods(mods); } } @@ -666,15 +660,15 @@ void process_action(keyrecord_t *record, action_t action) { /* tap key */ if (event.pressed) { if (tap_count > 0) { - dprint("KEYMAP_TAP_KEY: Tap: register_code\n"); + ac_dprintf("KEYMAP_TAP_KEY: Tap: register_code\n"); register_code(action.layer_tap.code); } else { - dprint("KEYMAP_TAP_KEY: No tap: On on press\n"); + ac_dprintf("KEYMAP_TAP_KEY: No tap: On on press\n"); layer_on(action.layer_tap.val); } } else { if (tap_count > 0) { - dprint("KEYMAP_TAP_KEY: Tap: unregister_code\n"); + ac_dprintf("KEYMAP_TAP_KEY: Tap: unregister_code\n"); if (action.layer_tap.code == KC_CAPS_LOCK) { wait_ms(TAP_HOLD_CAPS_DELAY); } else { @@ -682,7 +676,7 @@ void process_action(keyrecord_t *record, action_t action) { } unregister_code(action.layer_tap.code); } else { - dprint("KEYMAP_TAP_KEY: No tap: Off on release\n"); + ac_dprintf("KEYMAP_TAP_KEY: No tap: Off on release\n"); layer_off(action.layer_tap.val); } } @@ -882,32 +876,15 @@ __attribute__((weak)) void register_code(uint8_t code) { // TODO: should push command_proc out of this block? if (command_proc(code)) return; -#ifndef NO_ACTION_ONESHOT -/* TODO: remove - if (oneshot_state.mods && !oneshot_state.disabled) { - uint8_t tmp_mods = get_mods(); - add_mods(oneshot_state.mods); - - add_key(code); - send_keyboard_report(); - - set_mods(tmp_mods); - send_keyboard_report(); - oneshot_cancel(); - } else -*/ -#endif - { - // Force a new key press if the key is already pressed - // without this, keys with the same keycode, but different - // modifiers will be reported incorrectly, see issue #1708 - if (is_key_pressed(keyboard_report, code)) { - del_key(code); - send_keyboard_report(); - } - add_key(code); + // Force a new key press if the key is already pressed + // without this, keys with the same keycode, but different + // modifiers will be reported incorrectly, see issue #1708 + if (is_key_pressed(keyboard_report, code)) { + del_key(code); send_keyboard_report(); } + add_key(code); + send_keyboard_report(); } else if IS_MOD (code) { add_mods(MOD_BIT(code)); send_keyboard_report(); @@ -1139,7 +1116,7 @@ bool is_tap_action(action_t action) { * FIXME: Needs documentation. */ void debug_event(keyevent_t event) { - dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); + ac_dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time); } /** \brief Debug print (FIXME: Needs better description) * @@ -1148,7 +1125,7 @@ void debug_event(keyevent_t event) { void debug_record(keyrecord_t record) { debug_event(record.event); #ifndef NO_ACTION_TAPPING - dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' ')); + ac_dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' ')); #endif } @@ -1159,41 +1136,41 @@ void debug_record(keyrecord_t record) { void debug_action(action_t action) { switch (action.kind.id) { case ACT_LMODS: - dprint("ACT_LMODS"); + ac_dprintf("ACT_LMODS"); break; case ACT_RMODS: - dprint("ACT_RMODS"); + ac_dprintf("ACT_RMODS"); break; case ACT_LMODS_TAP: - dprint("ACT_LMODS_TAP"); + ac_dprintf("ACT_LMODS_TAP"); break; case ACT_RMODS_TAP: - dprint("ACT_RMODS_TAP"); + ac_dprintf("ACT_RMODS_TAP"); break; case ACT_USAGE: - dprint("ACT_USAGE"); + ac_dprintf("ACT_USAGE"); break; case ACT_MOUSEKEY: - dprint("ACT_MOUSEKEY"); + ac_dprintf("ACT_MOUSEKEY"); break; case ACT_LAYER: - dprint("ACT_LAYER"); + ac_dprintf("ACT_LAYER"); break; case ACT_LAYER_MODS: - dprint("ACT_LAYER_MODS"); + ac_dprintf("ACT_LAYER_MODS"); break; case ACT_LAYER_TAP: - dprint("ACT_LAYER_TAP"); + ac_dprintf("ACT_LAYER_TAP"); break; case ACT_LAYER_TAP_EXT: - dprint("ACT_LAYER_TAP_EXT"); + ac_dprintf("ACT_LAYER_TAP_EXT"); break; case ACT_SWAP_HANDS: - dprint("ACT_SWAP_HANDS"); + ac_dprintf("ACT_SWAP_HANDS"); break; default: - dprint("UNKNOWN"); + ac_dprintf("UNKNOWN"); break; } - dprintf("[%X:%02X]", action.kind.param >> 8, action.kind.param & 0xff); + ac_dprintf("[%X:%02X]", action.kind.param >> 8, action.kind.param & 0xff); } diff --git a/quantum/action.h b/quantum/action.h index 2bc46429b2..e4d28ba947 100644 --- a/quantum/action.h +++ b/quantum/action.h @@ -112,7 +112,19 @@ bool is_tap_action(action_t action); void process_record_tap_hint(keyrecord_t *record); #endif -/* debug */ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Helpers + +#ifdef ACTION_DEBUG +# include "debug.h" +# include "print.h" +# define ac_dprintf(...) dprintf(__VA_ARGS__) +#else +# define ac_dprintf(...) \ + do { \ + } while (0) +#endif + void debug_event(keyevent_t event); void debug_record(keyrecord_t record); void debug_action(action_t action); diff --git a/quantum/action_layer.c b/quantum/action_layer.c index 31cfdfe13a..74e8137920 100644 --- a/quantum/action_layer.c +++ b/quantum/action_layer.c @@ -1,12 +1,6 @@ #include #include -#ifdef DEBUG_ACTION -# include "debug.h" -#else -# include "nodebug.h" -#endif - #include "keyboard.h" #include "keymap.h" #include "action.h" @@ -39,12 +33,12 @@ __attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t sta */ static void default_layer_state_set(layer_state_t state) { state = default_layer_state_set_kb(state); - debug("default_layer_state: "); + ac_dprintf("default_layer_state: "); default_layer_debug(); - debug(" to "); + ac_dprintf(" to "); default_layer_state = state; default_layer_debug(); - debug("\n"); + ac_dprintf("\n"); #if defined(STRICT_LAYER_RELEASE) clear_keyboard_but_mods(); // To avoid stuck keys #elif defined(SEMI_STRICT_LAYER_RELEASE) @@ -57,7 +51,7 @@ static void default_layer_state_set(layer_state_t state) { * Print out the hex value of the 32-bit default layer state, as well as the value of the highest bit. */ void default_layer_debug(void) { - dprintf("%08lX(%u)", default_layer_state, get_highest_layer(default_layer_state)); + ac_dprintf("%08hX(%u)", default_layer_state, get_highest_layer(default_layer_state)); } /** \brief Default Layer Set @@ -119,12 +113,12 @@ __attribute__((weak)) layer_state_t layer_state_set_kb(layer_state_t state) { */ void layer_state_set(layer_state_t state) { state = layer_state_set_kb(state); - dprint("layer_state: "); + ac_dprintf("layer_state: "); layer_debug(); - dprint(" to "); + ac_dprintf(" to "); layer_state = state; layer_debug(); - dprintln(); + ac_dprintf("\n"); # if defined(STRICT_LAYER_RELEASE) clear_keyboard_but_mods(); // To avoid stuck keys # elif defined(SEMI_STRICT_LAYER_RELEASE) @@ -218,7 +212,7 @@ void layer_xor(layer_state_t state) { * Print out the hex value of the 32-bit layer state, as well as the value of the highest bit. */ void layer_debug(void) { - dprintf("%08lX(%u)", layer_state, get_highest_layer(layer_state)); + ac_dprintf("%08hX(%u)", layer_state, get_highest_layer(layer_state)); } #endif diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index 507b8144aa..3a9bc549ac 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c @@ -1,12 +1,6 @@ #include #include -#ifdef DEBUG_ACTION -# include "debug.h" -#else -# include "nodebug.h" -#endif - #include "action.h" #include "action_layer.h" #include "action_tapping.h" @@ -92,14 +86,14 @@ static void debug_waiting_buffer(void); void action_tapping_process(keyrecord_t record) { if (process_tapping(&record)) { if (!IS_NOEVENT(record.event)) { - debug("processed: "); + ac_dprintf("processed: "); debug_record(record); - debug("\n"); + ac_dprintf("\n"); } } else { if (!waiting_buffer_enq(record)) { // clear all in case of overflow. - debug("OVERFLOW: CLEAR ALL STATES\n"); + ac_dprintf("OVERFLOW: CLEAR ALL STATES\n"); clear_keyboard(); waiting_buffer_clear(); tapping_key = (keyrecord_t){}; @@ -108,21 +102,19 @@ void action_tapping_process(keyrecord_t record) { // process waiting_buffer if (!IS_NOEVENT(record.event) && waiting_buffer_head != waiting_buffer_tail) { - debug("---- action_exec: process waiting_buffer -----\n"); + ac_dprintf("---- action_exec: process waiting_buffer -----\n"); } for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) { if (process_tapping(&waiting_buffer[waiting_buffer_tail])) { - debug("processed: waiting_buffer["); - debug_dec(waiting_buffer_tail); - debug("] = "); + ac_dprintf("processed: waiting_buffer[%u] =", waiting_buffer_tail); debug_record(waiting_buffer[waiting_buffer_tail]); - debug("\n\n"); + ac_dprintf("\n\n"); } else { break; } } if (!IS_NOEVENT(record.event)) { - debug("\n"); + ac_dprintf("\n"); } } @@ -195,7 +187,7 @@ bool process_tapping(keyrecord_t *keyp) { retroshift_swap_times(); # endif // first tap! - debug("Tapping: First tap(0->1).\n"); + ac_dprintf("Tapping: First tap(0->1).\n"); tapping_key.tap.count = 1; debug_tapping_key(); process_record(&tapping_key); @@ -237,7 +229,7 @@ bool process_tapping(keyrecord_t *keyp) { ) ) { // clang-format on - debug("Tapping: End. No tap. Interfered by typing key\n"); + ac_dprintf("Tapping: End. No tap. Interfered by typing key\n"); process_record(&tapping_key); tapping_key = (keyrecord_t){}; debug_tapping_key(); @@ -274,7 +266,7 @@ bool process_tapping(keyrecord_t *keyp) { break; } // Release of key should be process immediately. - debug("Tapping: release event of a key pressed before tapping\n"); + ac_dprintf("Tapping: release event of a key pressed before tapping\n"); process_record(keyp); return true; } else { @@ -282,7 +274,7 @@ bool process_tapping(keyrecord_t *keyp) { if (event.pressed) { tapping_key.tap.interrupted = true; if (TAP_GET_HOLD_ON_OTHER_KEY_PRESS) { - debug("Tapping: End. No tap. Interfered by pressed key\n"); + ac_dprintf("Tapping: End. No tap. Interfered by pressed key\n"); process_record(&tapping_key); tapping_key = (keyrecord_t){}; debug_tapping_key(); @@ -297,9 +289,7 @@ bool process_tapping(keyrecord_t *keyp) { // tap_count > 0 else { if (IS_TAPPING_RECORD(keyp) && !event.pressed) { - debug("Tapping: Tap release("); - debug_dec(tapping_key.tap.count); - debug(")\n"); + ac_dprintf("Tapping: Tap release(%u)\n", tapping_key.tap.count); keyp->tap = tapping_key.tap; process_record(keyp); tapping_key = *keyp; @@ -307,7 +297,7 @@ bool process_tapping(keyrecord_t *keyp) { return true; } else if (is_tap_record(keyp) && event.pressed) { if (tapping_key.tap.count > 1) { - debug("Tapping: Start new tap with releasing last tap(>1).\n"); + ac_dprintf("Tapping: Start new tap with releasing last tap(>1).\n"); // unregister key process_record(&(keyrecord_t){ .tap = tapping_key.tap, @@ -319,7 +309,7 @@ bool process_tapping(keyrecord_t *keyp) { # endif }); } else { - debug("Tapping: Start while last tap(1).\n"); + ac_dprintf("Tapping: Start while last tap(1).\n"); } tapping_key = *keyp; waiting_buffer_scan_tap(); @@ -327,7 +317,7 @@ bool process_tapping(keyrecord_t *keyp) { return true; } else { if (!IS_NOEVENT(event)) { - debug("Tapping: key event while last tap(>0).\n"); + ac_dprintf("Tapping: key event while last tap(>0).\n"); } process_record(keyp); return true; @@ -337,23 +327,23 @@ bool process_tapping(keyrecord_t *keyp) { // after TAPPING_TERM else { if (tapping_key.tap.count == 0) { - debug("Tapping: End. Timeout. Not tap(0): "); + ac_dprintf("Tapping: End. Timeout. Not tap(0): "); debug_event(event); - debug("\n"); + ac_dprintf("\n"); process_record(&tapping_key); tapping_key = (keyrecord_t){}; debug_tapping_key(); return false; } else { if (IS_TAPPING_RECORD(keyp) && !event.pressed) { - debug("Tapping: End. last timeout tap release(>0)."); + ac_dprintf("Tapping: End. last timeout tap release(>0)."); keyp->tap = tapping_key.tap; process_record(keyp); tapping_key = (keyrecord_t){}; return true; } else if (is_tap_record(keyp) && event.pressed) { if (tapping_key.tap.count > 1) { - debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); + ac_dprintf("Tapping: Start new tap with releasing last timeout tap(>1).\n"); // unregister key process_record(&(keyrecord_t){ .tap = tapping_key.tap, @@ -365,7 +355,7 @@ bool process_tapping(keyrecord_t *keyp) { # endif }); } else { - debug("Tapping: Start while last timeout tap(1).\n"); + ac_dprintf("Tapping: Start while last timeout tap(1).\n"); } tapping_key = *keyp; waiting_buffer_scan_tap(); @@ -373,7 +363,7 @@ bool process_tapping(keyrecord_t *keyp) { return true; } else { if (!IS_NOEVENT(event)) { - debug("Tapping: key event while last timeout tap(>0).\n"); + ac_dprintf("Tapping: key event while last timeout tap(>0).\n"); } process_record(keyp); return true; @@ -388,9 +378,7 @@ bool process_tapping(keyrecord_t *keyp) { // sequential tap. keyp->tap = tapping_key.tap; if (keyp->tap.count < 15) keyp->tap.count += 1; - debug("Tapping: Tap press("); - debug_dec(keyp->tap.count); - debug(")\n"); + ac_dprintf("Tapping: Tap press(%u)\n", keyp->tap.count); process_record(keyp); tapping_key = *keyp; debug_tapping_key(); @@ -401,7 +389,7 @@ bool process_tapping(keyrecord_t *keyp) { return true; } else if (is_tap_record(keyp)) { // Sequential tap can be interfered with other tap key. - debug("Tapping: Start with interfering other tap.\n"); + ac_dprintf("Tapping: Start with interfering other tap.\n"); tapping_key = *keyp; waiting_buffer_scan_tap(); debug_tapping_key(); @@ -414,16 +402,16 @@ bool process_tapping(keyrecord_t *keyp) { return true; } } else { - if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n"); + if (!IS_NOEVENT(event)) ac_dprintf("Tapping: other key just after tap.\n"); process_record(keyp); return true; } } else { // FIX: process_action here? // timeout. no sequential tap. - debug("Tapping: End(Timeout after releasing last tap): "); + ac_dprintf("Tapping: End(Timeout after releasing last tap): "); debug_event(event); - debug("\n"); + ac_dprintf("\n"); tapping_key = (keyrecord_t){}; debug_tapping_key(); return false; @@ -432,7 +420,7 @@ bool process_tapping(keyrecord_t *keyp) { // not tapping state else { if (event.pressed && is_tap_record(keyp)) { - debug("Tapping: Start(Press tap key).\n"); + ac_dprintf("Tapping: Start(Press tap key).\n"); tapping_key = *keyp; process_record_tap_hint(&tapping_key); waiting_buffer_scan_tap(); @@ -455,14 +443,14 @@ bool waiting_buffer_enq(keyrecord_t record) { } if ((waiting_buffer_head + 1) % WAITING_BUFFER_SIZE == waiting_buffer_tail) { - debug("waiting_buffer_enq: Over flow.\n"); + ac_dprintf("waiting_buffer_enq: Over flow.\n"); return false; } waiting_buffer[waiting_buffer_head] = record; waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE; - debug("waiting_buffer_enq: "); + ac_dprintf("waiting_buffer_enq: "); debug_waiting_buffer(); return true; } @@ -516,9 +504,7 @@ void waiting_buffer_scan_tap(void) { waiting_buffer[i].tap.count = 1; process_record(&tapping_key); - debug("waiting_buffer_scan_tap: found at ["); - debug_dec(i); - debug("]\n"); + ac_dprintf("waiting_buffer_scan_tap: found at [%u]\n", i); debug_waiting_buffer(); return; } @@ -530,9 +516,9 @@ void waiting_buffer_scan_tap(void) { * FIXME: Needs docs */ static void debug_tapping_key(void) { - debug("TAPPING_KEY="); + ac_dprintf("TAPPING_KEY="); debug_record(tapping_key); - debug("\n"); + ac_dprintf("\n"); } /** \brief Waiting buffer debug print @@ -540,15 +526,13 @@ static void debug_tapping_key(void) { * FIXME: Needs docs */ static void debug_waiting_buffer(void) { - debug("{ "); + ac_dprintf("{ "); for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { - debug("["); - debug_dec(i); - debug("]="); + ac_dprintf("[%u]=", i); debug_record(waiting_buffer[i]); - debug(" "); + ac_dprintf(" "); } - debug("}\n"); + ac_dprintf("}\n"); } #endif diff --git a/quantum/logging/nodebug.h b/quantum/logging/nodebug.h deleted file mode 100644 index 0b176684bd..0000000000 --- a/quantum/logging/nodebug.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2013 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#pragma once - -#ifndef NO_DEBUG -# define NO_DEBUG -# include "debug.h" -# undef NO_DEBUG -#else -# include "debug.h" -#endif -- cgit v1.2.3