Skip to content

Commit

Permalink
import use of __PROG_TYPES_COMPAT__ define for compatibility with old…
Browse files Browse the repository at this point in the history
… arduino code (#4619)

restrict usage of deprecated typedefs "prog_*", and cast "pgm_read_*"'s address parameters to "const void*"  only when __PROG_TYPES_COMPAT__ is defined.
also add <avr/pgmspace.h> compatibility
  • Loading branch information
d-a-v authored Apr 10, 2018
1 parent 1ca5838 commit 2315ac2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions cores/esp8266/avr/pgmspace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../pgmspace.h"
9 changes: 9 additions & 0 deletions cores/esp8266/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ extern "C" {

#define _SFR_BYTE(n) (n)

#ifdef __PROG_TYPES_COMPAT__

typedef void prog_void;
typedef char prog_char;
typedef unsigned char prog_uchar;
Expand All @@ -39,6 +41,8 @@ typedef uint16_t prog_uint16_t;
typedef int32_t prog_int32_t;
typedef uint32_t prog_uint32_t;

#endif // defined(__PROG_TYPES_COMPAT__)

#define SIZE_IRRELEVANT 0x7fffffff

// memchr_P and memrchr_P are not implemented due to danger in its use, and
Expand Down Expand Up @@ -112,8 +116,13 @@ static inline uint16_t pgm_read_word_inlined(const void* addr) {
}

// Make sure, that libraries checking existence of this macro are not failing
#ifdef __PROG_TYPES_COMPAT__
#define pgm_read_byte(addr) pgm_read_byte_inlined((const void*)(addr))
#define pgm_read_word(addr) pgm_read_word_inlined((const void*)(addr))
#else
#define pgm_read_byte(addr) pgm_read_byte_inlined(addr)
#define pgm_read_word(addr) pgm_read_word_inlined(addr)
#endif

#else //__ets__
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))
Expand Down

0 comments on commit 2315ac2

Please sign in to comment.