progmem_emulation.hpp 909 B

1234567891011121314151617181920212223242526272829
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #include <stdint.h> // uint8_t
  5. #define PROGMEM
  6. class __FlashStringHelper;
  7. inline const void* convertPtrToFlash(const void* s) {
  8. return reinterpret_cast<const char*>(s) + 42;
  9. }
  10. inline const void* convertFlashToPtr(const void* s) {
  11. return reinterpret_cast<const char*>(s) - 42;
  12. }
  13. #define PSTR(X) reinterpret_cast<const char*>(convertPtrToFlash(X))
  14. #define F(X) reinterpret_cast<const __FlashStringHelper*>(PSTR(X))
  15. inline uint8_t pgm_read_byte(const void* p) {
  16. return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p));
  17. }
  18. #define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
  19. static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \
  20. static type const* name = reinterpret_cast<type const*>( \
  21. convertPtrToFlash(ARDUINOJSON_CONCAT2(name, _progmem)));