X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=include%2Faversive%2Fpgmspace.h;h=ff37bdfea201f279c8d9326fd161a6aa3fa230ea;hp=d6dadb8d28f244c3f0a444f215fdc2aab9c76f68;hb=4a33e94c3809e67674577509044653bac4a4d87a;hpb=eb515c9042bfd162fa9099ec2e7ae28d77868fde diff --git a/include/aversive/pgmspace.h b/include/aversive/pgmspace.h index d6dadb8..ff37bdf 100644 --- a/include/aversive/pgmspace.h +++ b/include/aversive/pgmspace.h @@ -30,28 +30,15 @@ #ifndef HOST_VERSION #include +#define PGMS_FMT "%S" #else #include - -#define printf_P printf -#define memcmp_P memcmp -#define strcat_P strcat -#define strcmp_P strcmp -#define strncmp_P strncmp -#define strlen_P strlen -#define vfprintf_P vfprintf -#define vsprintf_P vsprintf -#define PGM_P const char * -#define PSTR(x) x -#define PROGMEM - -/* XXX don't define it, it's dangerous because it can be used to read - * an address that have not the same size */ -/* #define pgm_read_word(x) (*(x)) */ -/* #define pgm_read_byte(x) (*(x)) */ +#include +#include +#include typedef void prog_void; typedef char prog_char; @@ -64,6 +51,87 @@ typedef int32_t prog_int32_t; typedef uint32_t prog_uint32_t; typedef int64_t prog_int64_t; + +static inline int memcmp_P(const void *s1, + const prog_void *s2, unsigned n) +{ + return memcmp(s1, s2, n); +} + +static inline void *memcpy_P(void *s1, + const prog_void *s2, unsigned n) +{ + return memcpy(s1, s2, n); +} + +static inline char *strcat_P(char *s1, const prog_char *s2) +{ + return strcat(s1, s2); +} + +static inline char *strcpy_P(char *s1, const prog_char *s2) +{ + return strcpy(s1, s2); +} + +static inline char *strncpy_P(char *s1, const prog_char *s2, + unsigned n) +{ + return strncpy(s1, s2, n); +} + +static inline int strcmp_P(const char *s1, const prog_char *s2) +{ + return strcmp(s1, s2); +} + +static inline int strncmp_P(const char *s1, const prog_char *s2, + unsigned n) +{ + return strncmp(s1, s2, n); +} + +static inline unsigned strlen_P(const prog_char *s) +{ + return strlen(s); +} + +static inline int vfprintf_P(FILE *stream, + const prog_char *s, va_list ap) +{ + return vfprintf(stream, s, ap); +} + +static inline int vsprintf_P(char *buf, const prog_char *s, + va_list ap) +{ + return vsprintf(buf, s, ap); +} + +#define PGM_P const char * +#define PSTR(x) x +#define PROGMEM +#define printf_P(arg...) printf(args) +#define sprintf_P(buf, args...) sprintf(buf, args) +#define snprintf_P(buf, n, args...) snprintf(buf, n, args) + +static inline uint32_t pgm_read_dword(const prog_void *x) +{ + return *(uint32_t *)x; +} + +static inline uint16_t pgm_read_word(const prog_void *x) +{ + return *(uint16_t *)x; +} + +static inline uint8_t pgm_read_byte(const prog_void *x) +{ + return *(uint8_t *)x; +} + +#define PGMS_FMT "%s" + #endif /* HOST_VERSION */ #endif /* _AVERSIVE_PGMSPACE_H_ */