1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

import use of __PROG_TYPES_COMPAT__ define for compatibility with old 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
This commit is contained in:
david gauchard 2018-04-10 12:23:33 +02:00 committed by GitHub
parent 1ca5838bed
commit 2315ac20bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -0,0 +1 @@
#include "../pgmspace.h"

View File

@ -29,6 +29,8 @@ extern "C" {
#define _SFR_BYTE(n) (n) #define _SFR_BYTE(n) (n)
#ifdef __PROG_TYPES_COMPAT__
typedef void prog_void; typedef void prog_void;
typedef char prog_char; typedef char prog_char;
typedef unsigned char prog_uchar; typedef unsigned char prog_uchar;
@ -39,6 +41,8 @@ typedef uint16_t prog_uint16_t;
typedef int32_t prog_int32_t; typedef int32_t prog_int32_t;
typedef uint32_t prog_uint32_t; typedef uint32_t prog_uint32_t;
#endif // defined(__PROG_TYPES_COMPAT__)
#define SIZE_IRRELEVANT 0x7fffffff #define SIZE_IRRELEVANT 0x7fffffff
// memchr_P and memrchr_P are not implemented due to danger in its use, and // memchr_P and memrchr_P are not implemented due to danger in its use, and
@ -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 // 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_byte(addr) pgm_read_byte_inlined(addr)
#define pgm_read_word(addr) pgm_read_word_inlined(addr) #define pgm_read_word(addr) pgm_read_word_inlined(addr)
#endif
#else //__ets__ #else //__ets__
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr)) #define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))