@@ -37,6 +37,7 @@ extern "C" {
37
37
#include " binary.h"
38
38
#include " esp8266_peri.h"
39
39
#include " twi.h"
40
+
40
41
#include " core_esp8266_features.h"
41
42
#include " core_esp8266_version.h"
42
43
@@ -125,15 +126,11 @@ void timer0_isr_init(void);
125
126
void timer0_attachInterrupt (timercallback userFunc);
126
127
void timer0_detachInterrupt (void );
127
128
128
- // Use stdlib abs() and round() to avoid issues with the C++ libraries
129
129
#define constrain (amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
130
130
#define radians (deg ) ((deg)*DEG_TO_RAD)
131
131
#define degrees (rad ) ((rad)*RAD_TO_DEG)
132
132
#define sq (x ) ((x)*(x))
133
133
134
- void ets_intr_lock ();
135
- void ets_intr_unlock ();
136
-
137
134
#define interrupts () xt_rsil(0 )
138
135
#define noInterrupts () xt_rsil(15 )
139
136
@@ -162,11 +159,12 @@ typedef uint16_t word;
162
159
typedef bool boolean;
163
160
typedef uint8_t byte;
164
161
162
+ void ets_intr_lock ();
163
+ void ets_intr_unlock ();
164
+
165
165
void init (void );
166
166
void initVariant (void );
167
167
168
- int atexit (void (*func)()) __attribute__((weak));
169
-
170
168
void pinMode (uint8_t pin, uint8_t mode);
171
169
void digitalWrite (uint8_t pin, uint8_t val);
172
170
int digitalRead (uint8_t pin);
@@ -212,28 +210,31 @@ void optimistic_yield(uint32_t interval_us);
212
210
} // extern "C"
213
211
#endif
214
212
213
+ // undefine stdlib's definitions when encountered, provide abs that supports floating point for C code
214
+ #ifndef __cplusplus
215
+ #undef abs
216
+ #define abs (x ) ({ __typeof__ (x) _x = (x); _x > 0 ? _x : -_x; })
217
+ #undef round
218
+ #define round (x ) ({ __typeof__ (x) _x = (x); _x >= 0 ? (long )(_x + 0.5 ) : (long )(_x - 0.5 ); })
219
+ #endif // ifndef __cplusplus
215
220
216
-
221
+ // from this point onward, we need to configure the c++ environment
217
222
#ifdef __cplusplus
218
223
219
224
#include < algorithm>
225
+ #include < cstdlib>
220
226
#include < cmath>
221
- #include < pgmspace.h>
222
-
223
- #include " WCharacter.h"
224
- #include " WString.h"
225
-
226
- #include " HardwareSerial.h"
227
- #include " Esp.h"
228
- #include " Updater.h"
229
- #include " debug.h"
230
227
231
228
using std::min;
232
229
using std::max;
233
230
using std::round;
234
231
using std::isinf;
235
232
using std::isnan;
236
233
234
+ // Use float-compatible stl abs() and round(), we don't use Arduino macros to avoid issues with the C++ libraries
235
+ using std::abs;
236
+ using std::round;
237
+
237
238
#define _min (a,b ) ({ decltype (a) _a = (a); decltype (b) _b = (b); _a < _b? _a : _b; })
238
239
#define _max (a,b ) ({ decltype (a) _a = (a); decltype (b) _b = (b); _a > _b? _a : _b; })
239
240
@@ -273,8 +274,19 @@ inline void configTzTime(const char* tz, const char* server1,
273
274
configTime (tz, server1, server2, server3);
274
275
}
275
276
277
+ // Everything we expect to be implicitly loaded for the sketch
278
+ #include < pgmspace.h>
279
+
280
+ #include " WCharacter.h"
281
+ #include " WString.h"
282
+
283
+ #include " HardwareSerial.h"
284
+ #include " Esp.h"
285
+ #include " Updater.h"
286
+
276
287
#endif // __cplusplus
277
288
289
+ #include " debug.h"
278
290
#include " pins_arduino.h"
279
291
280
292
#endif
0 commit comments