diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 27f5bb8..0318f0d 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -43,7 +43,7 @@ #define USB_CRC_CHECK 0x01 #define TRANSFER_BUFFER_SIZE 0x200 - +#define FORMAT_BUFFER_LEN 0x0FF #define HW_VERSION "2.6" #define SW_VERSION "1.0" diff --git a/avr/usbload/debug.c b/avr/usbload/debug.c index 4026500..9a25ad7 100644 --- a/avr/usbload/debug.c +++ b/avr/usbload/debug.c @@ -20,11 +20,11 @@ #include #include +#include #include "debug.h" #include "uart.h" - - +#include "config.h" extern FILE uart_stdout; @@ -46,4 +46,23 @@ void debug(int level, char* format, ...) { } #endif +#ifndef NO_INFO + uint8_t buffer_debug[FORMAT_BUFFER_LEN]; +#endif +#if defined(NO_DEBUG) && defined(__GNUC__) +#else +void debug_P(int level, PGM_P format, ...) { +#ifdef NO_DEBUG + +#else + va_list args; + if (!(debug_level & level)) + return; + strlcpy_P(buffer_debug,format,FORMAT_BUFFER_LEN); + va_start(args, format); + vprintf(buffer_debug, args); + va_end(args); +#endif +} +#endif \ No newline at end of file diff --git a/avr/usbload/debug.h b/avr/usbload/debug.h index e62384b..56403b4 100644 --- a/avr/usbload/debug.h +++ b/avr/usbload/debug.h @@ -26,7 +26,7 @@ #include #include #include - +#include #if defined(NO_DEBUG) && defined(__GNUC__) /* gcc's cpp has extensions; it allows for macros with a variable number of @@ -39,5 +39,17 @@ void debug(int level, char *format, ...); #endif + +#if defined(NO_DEBUG) && defined(__GNUC__) +/* gcc's cpp has extensions; it allows for macros with a variable number of + arguments. We use this extension here to preprocess pmesg away. */ +#define debug_P(level, format, args...) ((void)0) +#else +void debug_P(int level, PGM_P format, ...); +/* print a message, if it is considered significant enough. + Adapted from [K&R2], p. 174 */ +#endif + + #endif /* DEBUG_H */ diff --git a/avr/usbload/info.c b/avr/usbload/info.c index e86dde6..bcfc7b8 100644 --- a/avr/usbload/info.c +++ b/avr/usbload/info.c @@ -20,9 +20,12 @@ #include #include +#include #include "info.h" #include "uart.h" +#include "config.h" + @@ -46,4 +49,26 @@ void info(char* format, ...) { } #endif + +#ifndef NO_INFO + uint8_t buffer_info[FORMAT_BUFFER_LEN]; +#endif + +#if defined(NO_INFO) && defined(__GNUC__) + +#define info(format, args...) ((void)0) + +#else +void info_P(PGM_P format, ...) { +#ifdef NO_INFO + +#else + strlcpy_P(buffer_info,format,FORMAT_BUFFER_LEN); + va_list args; + va_start(args, format); + vprintf(buffer_info, args); + va_end(args); +#endif +} +#endif diff --git a/avr/usbload/info.h b/avr/usbload/info.h index ef17f71..b98f980 100644 --- a/avr/usbload/info.h +++ b/avr/usbload/info.h @@ -26,7 +26,7 @@ #include #include #include - +#include #if defined(NO_INFO) && defined(__GNUC__) /* gcc's cpp has extensions; it allows for macros with a variable number of @@ -39,4 +39,15 @@ void info(char *format, ...); #endif +#if defined(NO_INFO) && defined(__GNUC__) +/* gcc's cpp has extensions; it allows for macros with a variable number of + arguments. We use this extension here to preprocess pmesg away. */ +#define info_P(format, args...) ((void)0) +#else +void info_P(PGM_P format, ...); +/* print a message, if it is considered significant enough. + Adapted from [K&R2], p. 174 */ +#endif + + #endif