Add a polyfill for pgm_read_ptr() (issue #1433)

This commit is contained in:
Benoit Blanchon
2021-12-31 13:09:53 +01:00
parent a2e1021d7d
commit 29ba744d64
2 changed files with 8 additions and 4 deletions

View File

@ -23,10 +23,6 @@ inline uint8_t pgm_read_byte(const void* p) {
return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p)); return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p));
} }
inline void* pgm_read_ptr(const void* p) {
return *reinterpret_cast<void* const*>(convertFlashToPtr(p));
}
#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \ #define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \ static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \
static type const* name = reinterpret_cast<type const*>( \ static type const* name = reinterpret_cast<type const*>( \

View File

@ -103,3 +103,11 @@ inline uint32_t pgm_read_dword(ARDUINOJSON_NAMESPACE::pgm_p p) {
return result; return result;
} }
#endif #endif
#ifndef pgm_read_ptr
inline void* pgm_read_ptr(ARDUINOJSON_NAMESPACE::pgm_p p) {
void* result;
memcpy_P(&result, p, sizeof(result));
return result;
}
#endif