diff --git a/Makefile-ARM b/Makefile-ARM index ddb2932..6af50ac 100644 --- a/Makefile-ARM +++ b/Makefile-ARM @@ -97,7 +97,7 @@ TARGET = $(PROGRAM).hex #SOURCES = $(wildcard *.c) # Until the generic ARM port is completed, we'd have to wrap all sources # in #ifdef __AVR__. To avoid this, build only a selection for now: -SOURCES = mendel.c cpu.c serial.c sermsg.c +SOURCES = mendel.c cpu.c serial.c sermsg.c sersendf.c SOURCES += mbed-pinmap.c ifeq ($(MCU), lpc1114) SOURCES += mbed-system_LPC11xx.c diff --git a/mendel.c b/mendel.c index fd35061..a856a79 100644 --- a/mendel.c +++ b/mendel.c @@ -40,7 +40,6 @@ #include "temp.h" #include "watchdog.h" #include "debug.h" -#include "sersendf.h" #include "heater.h" #include "analog.h" #include "pinio.h" diff --git a/sersendf.c b/sersendf.c index 46af1d9..0149d6e 100644 --- a/sersendf.c +++ b/sersendf.c @@ -94,10 +94,15 @@ \code sersendf_P(PSTR("X:%ld Y:%ld temp:%u.%d flags:%sx Q%su/%su%c\n"), target.X, target.Y, current_temp >> 2, (current_temp & 3) * 25, dda.allflags, mb_head, mb_tail, (queue_full()?'F':(queue_empty()?'E':' '))) \endcode */ -#ifdef SIMULATOR - #define GET_ARG(T) (va_arg(args, int)) -#else +/** + va_arg() takes "fully promoted types" only, see example in Linux' va_arg + man page. This covers platforms >= 16 bits and arguments up to 32 bits. + 64 bit arguments on a 32 bit platform will produce a severe warning. +*/ +#if __SIZEOF_INT__ == 2 #define GET_ARG(T) (va_arg(args, T)) +#elif __SIZEOF_INT__ >= 4 + #define GET_ARG(T) ((T)va_arg(args, int)) #endif void sersendf_P(PGM_P format_P, ...) { @@ -130,7 +135,7 @@ void sersendf_P(PGM_P format_P, ...) { j = 0; break; case 'c': - serial_writechar(GET_ARG(uint16_t)); + serial_writechar((uint8_t)GET_ARG(uint16_t)); j = 0; break; case 'x': diff --git a/sersendf.h b/sersendf.h index 1ac2f90..a51760c 100644 --- a/sersendf.h +++ b/sersendf.h @@ -4,7 +4,8 @@ #include "arduino.h" -void sersendf(char *format, ...) __attribute__ ((format (printf, 1, 2))); -void sersendf_P(PGM_P format_P, ...) __attribute__ ((format (printf, 1, 2))); +// No __attribute__ ((format (printf, 1, 2)) here because %q isn't supported. +void sersendf(char *format, ...); +void sersendf_P(PGM_P format_P, ...); #endif /* _SERSENDF_H */