@@ -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
@@ -127,21 +128,26 @@ void timer0_isr_init(void);
127
128
void timer0_attachInterrupt (timercallback userFunc);
128
129
void timer0_detachInterrupt (void );
129
130
130
- // undefine stdlib's abs if encountered
131
+ // undefine stdlib's definitions when encountered, provide abs that supports floating point for C code
132
+ // in case we are using c++, these will either be:
133
+ // - undef'ed by the algorithm include down below, implicitly including cstdlib
134
+ // - undef'ed by the stdlib.h header up above in a more recent versions of gcc
131
135
#ifdef abs
132
136
#undef abs
137
+ #define abs (x ) ((x)>0 ?(x):-(x))
133
138
#endif
134
139
135
- #define abs (x ) ((x)>0 ?(x):-(x))
140
+ #ifdef round
141
+ #undef round
142
+ #define round (x ) ((x)>=0 ?(long )((x)+0.5 ):(long )((x)-0.5 ))
143
+ #endif
144
+
145
+ // the rest of math definitions are from Arduino
136
146
#define constrain (amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
137
- #define round (x ) ((x)>=0 ?(long )((x)+0.5 ):(long )((x)-0.5 ))
138
147
#define radians (deg ) ((deg)*DEG_TO_RAD)
139
148
#define degrees (rad ) ((rad)*RAD_TO_DEG)
140
149
#define sq (x ) ((x)*(x))
141
150
142
- void ets_intr_lock ();
143
- void ets_intr_unlock ();
144
-
145
151
#define interrupts () xt_rsil(0 )
146
152
#define noInterrupts () xt_rsil(15 )
147
153
@@ -170,11 +176,12 @@ typedef uint16_t word;
170
176
typedef bool boolean;
171
177
typedef uint8_t byte;
172
178
179
+ void ets_intr_lock ();
180
+ void ets_intr_unlock ();
181
+
173
182
void init (void );
174
183
void initVariant (void );
175
184
176
- int atexit (void (*func)()) __attribute__((weak));
177
-
178
185
void pinMode (uint8_t pin, uint8_t mode);
179
186
void digitalWrite (uint8_t pin, uint8_t val);
180
187
int digitalRead (uint8_t pin);
@@ -233,25 +240,22 @@ const int TIM_DIV265 __attribute__((deprecated, weak)) = TIM_DIV256;
233
240
234
241
235
242
243
+ // from this point onward, we need to configure the c++ environment
236
244
#ifdef __cplusplus
237
245
238
246
#include < algorithm>
247
+ #include < cstdlib>
239
248
#include < cmath>
240
- #include < pgmspace.h>
241
-
242
- #include " WCharacter.h"
243
- #include " WString.h"
244
-
245
- #include " HardwareSerial.h"
246
- #include " Esp.h"
247
- #include " Updater.h"
248
- #include " debug.h"
249
249
250
250
using std::min;
251
251
using std::max;
252
252
using std::isinf;
253
253
using std::isnan;
254
254
255
+ // these are important, as we may end up using C versions otherwise
256
+ using std::abs;
257
+ using std::round;
258
+
255
259
#define _min (a,b ) ({ decltype (a) _a = (a); decltype (b) _b = (b); _a < _b? _a : _b; })
256
260
#define _max (a,b ) ({ decltype (a) _a = (a); decltype (b) _b = (b); _a > _b? _a : _b; })
257
261
@@ -291,6 +295,16 @@ inline void configTzTime(const char* tz, const char* server1,
291
295
configTime (tz, server1, server2, server3);
292
296
}
293
297
298
+ // Everything we expect to be implicitly loaded for the sketch
299
+ #include < pgmspace.h>
300
+
301
+ #include " WCharacter.h"
302
+ #include " WString.h"
303
+
304
+ #include " HardwareSerial.h"
305
+ #include " Esp.h"
306
+ #include " Updater.h"
307
+
294
308
#endif // __cplusplus
295
309
296
310
#include " pins_arduino.h"
0 commit comments