#pragma once #include #include #define F(str) (reinterpret_cast(PSTR(str))) #define GF(name, str) \ const char __##name[] PROGMEM = str; \ const auto *name = reinterpret_cast(__##name) namespace detail { // Only used for C++ type safety, because otherwise a PSTR would be indistinguishable from a normal c-string struct FlashString; } // namespace detail namespace flash { template static T load(const T &object) { auto buffer = T{}; auto rawBuffer = reinterpret_cast(&buffer); for (auto i = std::size_t{0}; i < sizeof(T); ++i) { rawBuffer[i] = static_cast(pgm_read_byte(&reinterpret_cast(&object)[i])); } return buffer; } } // namespace flash