Skip to content

Commit c52b0da

Browse files
wkraft-fablabkaigrr
authored andcommitted
Fix according to the discussion of issue #3140 #3140
pgm_read_byte() and pgm_read_word() need to be macros, as some third party libraries and sketches testing macro existence.
1 parent db8868d commit c52b0da

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cores/esp8266/pgmspace.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,23 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
9999
:"1"(addr) \
100100
:);
101101

102-
static inline uint8_t pgm_read_byte(const void* addr) {
102+
static inline uint8_t pgm_read_byte_inlined(const void* addr) {
103103
register uint32_t res;
104104
pgm_read_with_offset(addr, res);
105105
return (uint8_t) res; /* This masks the lower byte from the returned word */
106106
}
107107

108108
/* Although this says "word", it's actually 16 bit, i.e. half word on Xtensa */
109-
static inline uint16_t pgm_read_word(const void* addr) {
109+
static inline uint16_t pgm_read_word_inlined(const void* addr) {
110110
register uint32_t res;
111111
pgm_read_with_offset(addr, res);
112112
return (uint16_t) res; /* This masks the lower half-word from the returned word */
113113
}
114114

115+
// Make sure, that libraries checking existence of this macro are not failing
116+
#define pgm_read_byte(addr) pgm_read_byte_inlined(addr)
117+
#define pgm_read_word(addr) pgm_read_word_inlined(addr)
118+
115119
#else //__ets__
116120
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))
117121
#define pgm_read_word(addr) (*reinterpret_cast<const uint16_t*>(addr))

0 commit comments

Comments
 (0)