From 0f5a5259ec038537ea51de0059e711fdeebc6ece Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 15 Mar 2013 12:39:04 +0100 Subject: [PATCH] Added avr/pgmspace.h compatibility layer for Due Boards Fixes #1317 --- build/shared/revisions.txt | 1 + hardware/arduino/sam/cores/arduino/Arduino.h | 6 +++ .../arduino/sam/cores/arduino/avr/interrupt.h | 0 .../arduino/sam/cores/arduino/avr/pgmspace.h | 43 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 hardware/arduino/sam/cores/arduino/avr/interrupt.h create mode 100644 hardware/arduino/sam/cores/arduino/avr/pgmspace.h diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index 9ec12e161..118678623 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -10,6 +10,7 @@ ARDUINO 1.5.3 BETA [arduino core] * sam: Fixed delayMicrosecond() when interrupts are disabled * sam: Upgraded libsam, and added missing modules (CAN, ETH, etc.) (Thibaut Viard) +* sam: Added compatibility for avr/pgmspace.h (Paul Stoffregen) [libraries] * sam: Added CAN library (still in early stage of development) (Palliser) diff --git a/hardware/arduino/sam/cores/arduino/Arduino.h b/hardware/arduino/sam/cores/arduino/Arduino.h index a1682a36c..12685a600 100644 --- a/hardware/arduino/sam/cores/arduino/Arduino.h +++ b/hardware/arduino/sam/cores/arduino/Arduino.h @@ -24,6 +24,12 @@ #include #include +// some libraries and sketches depend on this +// AVR stuff, assuming Arduino.h or WProgram.h +// automatically includes it... +#include +#include + #include "binary.h" #ifdef __cplusplus diff --git a/hardware/arduino/sam/cores/arduino/avr/interrupt.h b/hardware/arduino/sam/cores/arduino/avr/interrupt.h new file mode 100644 index 000000000..e69de29bb diff --git a/hardware/arduino/sam/cores/arduino/avr/pgmspace.h b/hardware/arduino/sam/cores/arduino/avr/pgmspace.h new file mode 100644 index 000000000..aef5b9598 --- /dev/null +++ b/hardware/arduino/sam/cores/arduino/avr/pgmspace.h @@ -0,0 +1,43 @@ +#ifndef __PGMSPACE_H_ +#define __PGMSPACE_H_ 1 + +#include + +#define PROGMEM +#define PGM_P const char * +#define PSTR(str) (str) + +#define _SFR_BYTE(n) (n) + +typedef void prog_void; +typedef char prog_char; +typedef unsigned char prog_uchar; +typedef int8_t prog_int8_t; +typedef uint8_t prog_uint8_t; +typedef int16_t prog_int16_t; +typedef uint16_t prog_uint16_t; +typedef int32_t prog_int32_t; +typedef uint32_t prog_uint32_t; + +#define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) +#define strcpy_P(dest, src) strcpy((dest), (src)) +#define strcat_P(dest, src) strcat((dest), (src)) +#define strcmp_P(a, b) strcmp((a), (b)) +#define strstr_P(a, b) strstr((a), (b)) +#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) + +#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) +#define pgm_read_word(addr) (*(const unsigned short *)(addr)) +#define pgm_read_dword(addr) (*(const unsigned long *)(addr)) +#define pgm_read_float(addr) (*(const float *)(addr)) + +#define pgm_read_byte_near(addr) pgm_read_byte(addr) +#define pgm_read_word_near(addr) pgm_read_word(addr) +#define pgm_read_dword_near(addr) pgm_read_dword(addr) +#define pgm_read_float_near(addr) pgm_read_float(addr) +#define pgm_read_byte_far(addr) pgm_read_byte(addr) +#define pgm_read_word_far(addr) pgm_read_word(addr) +#define pgm_read_dword_far(addr) pgm_read_dword(addr) +#define pgm_read_float_far(addr) pgm_read_float(addr) + +#endif