Skip to content

Commit f3f233d

Browse files
Fix host test using the newlib generic pgmspace.h
Host tests now use the sys/pgmspace.h for compiles instead of the ESP8266-specific version.
1 parent 14b18ac commit f3f233d

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

cores/esp8266/Arduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256;
253253
#ifdef __cplusplus
254254

255255
#include <algorithm>
256-
#include "pgmspace.h"
256+
#include <pgmspace.h>
257257

258258
#include "WCharacter.h"
259259
#include "WString.h"

tests/host/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ CORE_CPP_FILES := $(addprefix $(CORE_PATH)/,\
2020
Print.cpp \
2121
FS.cpp \
2222
spiffs_api.cpp \
23-
pgmspace.cpp \
2423
MD5Builder.cpp \
2524
)
2625

@@ -45,6 +44,7 @@ MOCK_C_FILES := $(addprefix common/,\
4544
)
4645

4746
INC_PATHS += $(addprefix -I, \
47+
. \
4848
common \
4949
$(CORE_PATH) \
5050
)
@@ -96,7 +96,7 @@ valgrind: $(OUTPUT_BINARY)
9696
$(LCOV) --directory ../../cores/esp8266/ --zerocounters
9797
$(VALGRIND) $(VALGRINDFLAGS) $(OUTPUT_BINARY)
9898
$(LCOV) --directory $(CORE_PATH) --capture --output-file $(LCOV_DIRECTORY)/app.info
99-
$(GENHTML) $(LCOV_DIRECTORY)/app.info -o $(LCOV_DIRECTORY)
99+
-$(GENHTML) $(LCOV_DIRECTORY)/app.info -o $(LCOV_DIRECTORY)
100100

101101
build-info:
102102
@echo "-------- build tools info --------"

tests/host/common/Arduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ extern "C" {
236236

237237
#ifdef __cplusplus
238238

239-
#include "pgmspace.h"
239+
#include <pgmspace.h>
240240

241241
#include "WCharacter.h"
242242
#include "WString.h"

tests/host/sys/pgmspace.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* PGMSPACE.H - Accessor utilities/types for accessing PROGMEM data */
2+
3+
#ifndef _PGMSPACE_H_
4+
#define _PGMSPACE_H_
5+
6+
// These are no-ops in anything but the ESP8266, where they are defined in
7+
// a custom sys/pgmspace.h header
8+
9+
#ifndef ICACHE_RODATA_ATTR
10+
#define ICACHE_RODATA_ATTR
11+
#endif
12+
13+
#ifndef PROGMEM
14+
#define PROGMEM
15+
#endif
16+
17+
#ifndef PGM_P
18+
#define PGM_P const char *
19+
#endif
20+
21+
#ifndef PGM_VOID_P
22+
#define PGM_VOID_P const void *
23+
#endif
24+
25+
#ifndef PSTR
26+
#define PSTR
27+
#endif
28+
29+
#ifdef __cplusplus
30+
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))
31+
#define pgm_read_word(addr) (*reinterpret_cast<const uint16_t*>(addr))
32+
#define pgm_read_dword(addr) (*reinterpret_cast<const uint32_t*>(addr))
33+
#define pgm_read_float(addr) (*reinterpret_cast<const float>(addr))
34+
#define pgm_read_ptr(addr) (*reinterpret_cast<const void const *>(addr))
35+
#else
36+
#define pgm_read_byte(addr) (*(const uint8_t*)(addr))
37+
#define pgm_read_word(addr) (*(const uint16_t*)(addr))
38+
#define pgm_read_dword(addr) (*(const uint32_t*)(addr))
39+
#define pgm_read_float(addr) (*(const float)(addr))
40+
#define pgm_read_ptr(addr) (*(const void const *)(addr))
41+
#endif
42+
43+
#define pgm_read_byte_near(addr) pgm_read_byte(addr)
44+
#define pgm_read_word_near(addr) pgm_read_word(addr)
45+
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
46+
#define pgm_read_float_near(addr) pgm_read_float(addr)
47+
#define pgm_read_ptr_near(addr) pgm_read_ptr(addr)
48+
#define pgm_read_byte_far(addr) pgm_read_byte(addr)
49+
#define pgm_read_word_far(addr) pgm_read_word(addr)
50+
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
51+
#define pgm_read_float_far(addr) pgm_read_float(addr)
52+
#define pgm_read_ptr_far(addr) pgm_read_ptr(addr)
53+
54+
// Wrapper inlines for _P functions
55+
#include <stdio.h>
56+
#include <string.h>
57+
inline const char *strstr_P(const char *haystack, const char *needle) { return strstr(haystack, needle); }
58+
inline char *strcpy_P(char *dest, const char *src) { return strcpy(dest, src); }
59+
inline size_t strlen_P(const char *s) { return strlen(s); }
60+
inline int vsnprintf_P(char *str, size_t size, const char *format, va_list ap) { return vsnprintf(str, size, format, ap); }
61+
62+
63+
#endif

0 commit comments

Comments
 (0)