Skip to content

Commit 28d83e7

Browse files
committed
Add FlashStringHelper compilation
1 parent 7ea2483 commit 28d83e7

File tree

4 files changed

+105
-2
lines changed

4 files changed

+105
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- Yaml files support select/reject critera for paths of unit tests for targeted testing
1111
- Pins now track history and can report it in Ascii (big- or little-endian) for digital sequences
1212
- Pins now accept an array (or string) of input bits for providing pin values across multiple reads
13+
- FlashStringHelper (and related macros) compilation mocks
1314
- SoftwareSerial. That took a while.
1415

1516
### Changed

cpp/arduino/Print.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ class Print
3131

3232
virtual size_t write(uint8_t) = 0;
3333
size_t write(const char *str) { return str == NULL ? 0 : write((const uint8_t *)str, String(str).length()); }
34-
virtual size_t write(const uint8_t *buffer, size_t size)
35-
{
34+
35+
size_t write(const __FlashStringHelper *str) { return write((const char *)str); }
36+
37+
virtual size_t write(const uint8_t *buffer, size_t size) {
3638
size_t n;
3739
for (n = 0; size && write(*buffer++) && ++n; --size);
3840
return n;

cpp/arduino/WString.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
typedef std::string string;
1111

12+
//typedef const char __FlashStringHelper;
13+
class __FlashStringHelper;
14+
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
1215

1316
// Compatibility with string class
1417
class String: public string
@@ -51,6 +54,7 @@ class String: public string
5154

5255
public:
5356
~String(void) {}
57+
String(const __FlashStringHelper *str): string((const char *)str) {}
5458
String(const char *cstr = ""): string(cstr) {}
5559
String(const string &str): string(str) {}
5660
String(const String &str): string(str) {}
@@ -70,6 +74,7 @@ class String: public string
7074
String & operator = (const char *cstr) { assign(cstr); return *this; }
7175
String & operator = (const char c) { assign(1, c); return *this; }
7276

77+
unsigned char concat(const __FlashStringHelper *str) { append((const char *)str); return 1; }
7378
unsigned char concat(const String &str) { append(str); return 1; }
7479
unsigned char concat(const char *cstr) { append(cstr); return 1; }
7580
unsigned char concat(char c) { append(1, c); return 1; }
@@ -81,6 +86,7 @@ class String: public string
8186
unsigned char concat(float num) { append(String(num)); return 1; }
8287
unsigned char concat(double num) { append(String(num)); return 1; }
8388

89+
String & operator += (const __FlashStringHelper *rhs) { concat(rhs); return *this; }
8490
String & operator += (const String &rhs) { concat(rhs); return *this; }
8591
String & operator += (const char *cstr) { concat(cstr); return *this; }
8692
String & operator += (char c) { concat(c); return *this; }

cpp/arduino/avr/pgmspace.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#pragma once
2+
3+
4+
/*
5+
def d(var_raw)
6+
var = var_raw.split("_")[0]
7+
out = "#define #{var}_P(...) #{var}(__VA_ARGS__)\n"
8+
IO.popen('pbcopy', 'w') { |f| f << out }
9+
out
10+
end
11+
12+
text = File.open("arduino-1.8.5/hardware/tools/avr/avr/include/avr/pgmspace.h").read
13+
externs = text.split("\n").select {|l| l.start_with? "extern"}
14+
out = externs.map {|l| l.split("(")[0].split(" ")[-1].gsub("*", "") }.uniq
15+
out.each { |l| puts d(l) }
16+
*/
17+
18+
#include <avr/io.h>
19+
20+
#define PROGMEM
21+
22+
#ifndef PGM_P
23+
#define PGM_P const char *
24+
#endif
25+
26+
#ifndef PGM_VOID_P
27+
#define PGM_VOID_P const void *
28+
#endif
29+
30+
// everything's a no-op
31+
#define PSTR(s) ((const char *)(s))
32+
#define pgm_read_byte_near(x) (x)
33+
#define pgm_read_word_near(x) (x)
34+
#define pgm_read_dword_near(x) (x)
35+
#define pgm_read_float_near(x) (x)
36+
#define pgm_read_ptr_near(x) (x)
37+
38+
#define pgm_read_byte_far(x) (x)
39+
#define pgm_read_word_far(x) (x)
40+
#define pgm_read_dword_far(x) (x)
41+
#define pgm_read_float_far(x) (x)
42+
#define pgm_read_ptr_far(x) (x)
43+
44+
45+
#define pgm_read_byte(x) (x)
46+
#define pgm_read_word(x) (x)
47+
#define pgm_read_dword(x) (x)
48+
#define pgm_read_float(x) (x)
49+
#define pgm_read_ptr(x) (x)
50+
#define pgm_get_far_address(x) (x)
51+
52+
#define memchr_P(...) memchr(__VA_ARGS__)
53+
#define memcmp_P(...) memcmp(__VA_ARGS__)
54+
#define memccpy_P(...) memccpy(__VA_ARGS__)
55+
#define memcpy_P(...) memcpy(__VA_ARGS__)
56+
#define memmem_P(...) memmem(__VA_ARGS__)
57+
#define memrchr_P(...) memrchr(__VA_ARGS__)
58+
#define strcat_P(...) strcat(__VA_ARGS__)
59+
#define strchr_P(...) strchr(__VA_ARGS__)
60+
#define strchrnul_P(...) strchrnul(__VA_ARGS__)
61+
#define strcmp_P(...) strcmp(__VA_ARGS__)
62+
#define strcpy_P(...) strcpy(__VA_ARGS__)
63+
#define strcasecmp_P(...) strcasecmp(__VA_ARGS__)
64+
#define strcasestr_P(...) strcasestr(__VA_ARGS__)
65+
#define strcspn_P(...) strcspn(__VA_ARGS__)
66+
#define strlcat_P(...) strlcat(__VA_ARGS__)
67+
#define strlcpy_P(...) strlcpy(__VA_ARGS__)
68+
#define strnlen_P(...) strnlen(__VA_ARGS__)
69+
#define strncmp_P(...) strncmp(__VA_ARGS__)
70+
#define strncasecmp_P(...) strncasecmp(__VA_ARGS__)
71+
#define strncat_P(...) strncat(__VA_ARGS__)
72+
#define strncpy_P(...) strncpy(__VA_ARGS__)
73+
#define strpbrk_P(...) strpbrk(__VA_ARGS__)
74+
#define strrchr_P(...) strrchr(__VA_ARGS__)
75+
#define strsep_P(...) strsep(__VA_ARGS__)
76+
#define strspn_P(...) strspn(__VA_ARGS__)
77+
#define strstr_P(...) strstr(__VA_ARGS__)
78+
#define strtok_P(...) strtok(__VA_ARGS__)
79+
#define strtok_P(...) strtok(__VA_ARGS__)
80+
#define strlen_P(...) strlen(__VA_ARGS__)
81+
#define strnlen_P(...) strnlen(__VA_ARGS__)
82+
#define memcpy_P(...) memcpy(__VA_ARGS__)
83+
#define strcpy_P(...) strcpy(__VA_ARGS__)
84+
#define strncpy_P(...) strncpy(__VA_ARGS__)
85+
#define strcat_P(...) strcat(__VA_ARGS__)
86+
#define strlcat_P(...) strlcat(__VA_ARGS__)
87+
#define strncat_P(...) strncat(__VA_ARGS__)
88+
#define strcmp_P(...) strcmp(__VA_ARGS__)
89+
#define strncmp_P(...) strncmp(__VA_ARGS__)
90+
#define strcasecmp_P(...) strcasecmp(__VA_ARGS__)
91+
#define strncasecmp_P(...) strncasecmp(__VA_ARGS__)
92+
#define strstr_P(...) strstr(__VA_ARGS__)
93+
#define strlcpy_P(...) strlcpy(__VA_ARGS__)
94+
#define memcmp_P(...) memcmp(__VA_ARGS__)

0 commit comments

Comments
 (0)