Add NO_PRINT and NO_DEBUG config options.

- NO_PRINT: disable print.h API(also disable debug.h)
- NO_DEBUG: disable debug.h API
This commit is contained in:
tmk 2013-03-19 14:08:40 +09:00
parent 8580c8d291
commit 9a106537f6
7 changed files with 77 additions and 32 deletions

View File

@ -31,6 +31,9 @@ endif
ifdef CONSOLE_ENABLE
OPT_DEFS += -DCONSOLE_ENABLE
else
OPT_DEFS += -DNO_PRINT
OPT_DEFS += -DNO_DEBUG
endif
ifdef NKRO_ENABLE

View File

@ -98,7 +98,6 @@ bool command_extra(uint8_t code)
***********************************************************/
static void command_common_help(void)
{
print_enable = true;
print("\n\n----- Command Help -----\n");
print("c: enter console mode\n");
print("d: toggle debug enable\n");
@ -137,7 +136,8 @@ static void print_eeprom_config(void)
eebyte = eeconfig_read_keyconf();
print("keyconf: "); print_hex8(eebyte); print("\n");
keyconf kc = (keyconf){ .raw = eebyte };
keyconf kc;
kc = (keyconf){ .raw = eebyte };
print("keyconf.swap_control_capslock: "); print_hex8(kc.swap_control_capslock); print("\n");
print("keyconf.capslock_to_control: "); print_hex8(kc.capslock_to_control); print("\n");
print("keyconf.swap_lalt_lgui: "); print_hex8(kc.swap_lalt_lgui); print("\n");
@ -173,7 +173,6 @@ static bool command_common(uint8_t code)
command_common_help();
break;
case KC_C:
print_enable = true;
debug_matrix = false;
debug_keyboard = false;
debug_mouse = false;
@ -239,15 +238,6 @@ static bool command_common(uint8_t code)
case KC_T: // print timer
print_val_hex32(timer_count);
break;
case KC_P: // print toggle
if (print_enable) {
print("print disabled.\n");
print_enable = false;
} else {
print_enable = true;
print("print enabled.\n");
}
break;
case KC_S:
print("\n\n----- Status -----\n");
print_val_hex8(host_keyboard_leds());
@ -320,7 +310,6 @@ static bool command_common(uint8_t code)
***********************************************************/
static void command_console_help(void)
{
print_enable = true;
print("\n\n----- Console Help -----\n");
print("ESC/q: quit\n");
#ifdef MOUSEKEY_ENABLE

View File

@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "print.h"
#ifndef NO_DEBUG
#define debug(s) do { if (debug_enable) print(s); } while (0)
#define debugln(s) do { if (debug_enable) println(s); } while (0)
#define debug_S(s) do { if (debug_enable) print_S(s); } while (0)
@ -31,9 +33,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
print(__FILE__); print(" at "); print_dec(__LINE__); print(" in "); print(": "); print(s); \
} \
} while (0)
#define debug_dec(data) do { if (debug_enable) print_dec(data); } while (0)
#define debug_decs(data) do { if (debug_enable) print_decs(data); } while (0)
#define debug_hex4(data) do { if (debug_enable) print_hex4(data); } while (0)
@ -46,11 +45,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define debug_bin_reverse8(data) do { if (debug_enable) print_bin_reverse8(data); } while (0)
#define debug_bin_reverse16(data) do { if (debug_enable) print_bin_reverse16(data); } while (0)
#define debug_bin_reverse32(data) do { if (debug_enable) print_bin_reverse32(data); } while (0)
#define debug_hex(data) debug_hex8(data)
#define debug_bin(data) debug_bin8(data)
#define debug_bin_reverse(data) debug_bin8(data)
#else
#define debug(s)
#define debugln(s)
#define debug_S(s)
#define debug_P(s)
#define debug_msg(s)
#define debug_dec(data)
#define debug_decs(data)
#define debug_hex4(data)
#define debug_hex8(data)
#define debug_hex16(data)
#define debug_hex32(data)
#define debug_bin8(data)
#define debug_bin16(data)
#define debug_bin32(data)
#define debug_bin_reverse8(data)
#define debug_bin_reverse16(data)
#define debug_bin_reverse32(data)
#define debug_hex(data)
#define debug_bin(data)
#define debug_bin_reverse(data)
#endif
#ifdef __cplusplus
extern "C" {

View File

@ -54,7 +54,7 @@ static bool has_ghost_in_row(uint8_t row)
void keyboard_init(void)
{
// TODO: configuration of sendchar impl
print_sendchar_func = sendchar;
print_set_sendchar(sendchar);
timer_init();
matrix_init();

View File

@ -27,12 +27,17 @@
#include "print.h"
#define sendchar(c) do { if (print_enable && print_sendchar_func) (print_sendchar_func)(c); } while (0)
#ifndef NO_PRINT
#define sendchar(c) do { if (print_sendchar_func) (print_sendchar_func)(c); } while (0)
int8_t (*print_sendchar_func)(uint8_t) = 0;
bool print_enable = true;
static int8_t (*print_sendchar_func)(uint8_t) = 0;
void print_set_sendchar(int8_t (*sendchar_func)(uint8_t))
{
print_sendchar_func = sendchar_func;
}
/* print string stored in data memory(SRAM)
* print_P("hello world");
@ -184,3 +189,5 @@ void print_bin_reverse32(uint32_t data)
print_bin_reverse8(data>>16);
print_bin_reverse8(data>>24);
}
#endif

View File

@ -30,13 +30,12 @@
#include <avr/pgmspace.h>
// avoid collision with arduino/Print.h
#ifndef __cplusplus
// this macro allows you to write print("some text") and
// the string is automatically placed into flash memory :)
// TODO: avoid collision with arduino/Print.h
#ifndef __cplusplus
#define print(s) print_P(PSTR(s))
#endif
#define println(s) print_P(PSTR(s "\n"))
/* for old name */
@ -49,15 +48,12 @@
#define pbin_reverse(data) print_bin_reverse8(data)
#define pbin_reverse16(data) print_bin_reverse16(data)
/* print value utility */
#define print_val_dec(v) do { print_P(PSTR(#v ": ")); print_dec(v); print_P(PSTR("\n")); } while (0)
#define print_val_decs(v) do { print_P(PSTR(#v ": ")); print_decs(v); print_P(PSTR("\n")); } while (0)
#define print_val_hex8(v) do { print_P(PSTR(#v ": ")); print_hex8(v); print_P(PSTR("\n")); } while (0)
#define print_val_hex16(v) do { print_P(PSTR(#v ": ")); print_hex16(v); print_P(PSTR("\n")); } while (0)
#define print_val_hex32(v) do { print_P(PSTR(#v ": ")); print_hex32(v); print_P(PSTR("\n")); } while (0)
#define print_val_bin8(v) do { print_P(PSTR(#v ": ")); print_bin8(v); print_P(PSTR("\n")); } while (0)
#define print_val_bin16(v) do { print_P(PSTR(#v ": ")); print_bin16(v); print_P(PSTR("\n")); } while (0)
#define print_val_bin32(v) do { print_P(PSTR(#v ": ")); print_bin32(v); print_P(PSTR("\n")); } while (0)
@ -67,13 +63,13 @@
#ifndef NO_PRINT
#ifdef __cplusplus
extern "C" {
#endif
/* function pointer of sendchar to be used by print utility */
extern int8_t (*print_sendchar_func)(uint8_t);
extern bool print_enable;
void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
/* print string stored in data memory(SRAM) */
void print_S(const char *s);
@ -100,9 +96,31 @@ void print_bin32(uint32_t data);
void print_bin_reverse8(uint8_t data);
void print_bin_reverse16(uint16_t data);
void print_bin_reverse32(uint32_t data);
#ifdef __cplusplus
}
#endif
#else
#define print_set_sendchar(func)
#define print_S(s)
#define print_P(s)
#define print_CRLF()
#define print_dec(data)
#define print_decs(data)
#define print_hex4(data)
#define print_hex8(data)
#define print_hex16(data)
#define print_hex32(data)
#define print_bin4(data)
#define print_bin8(data)
#define print_bin16(data)
#define print_bin32(data)
#define print_bin_reverse8(data)
#define print_bin_reverse16(data)
#define print_bin_reverse32(data)
#endif
#endif

View File

@ -56,5 +56,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define BOOTLOADER_SIZE 4096
/* disable debug print */
//#define NO_DEBUG
/* disable print */
//#define NO_PRINT
#endif