@@ -37,6 +37,7 @@ extern "C" {
3737#include " binary.h"
3838#include " esp8266_peri.h"
3939#include " twi.h"
40+
4041#include " core_esp8266_features.h"
4142#include " core_esp8266_version.h"
4243
@@ -125,15 +126,11 @@ void timer0_isr_init(void);
125126void timer0_attachInterrupt (timercallback userFunc);
126127void timer0_detachInterrupt (void );
127128
128- // Use stdlib abs() and round() to avoid issues with the C++ libraries
129129#define constrain (amt,low,high ) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
130130#define radians (deg ) ((deg)*DEG_TO_RAD)
131131#define degrees (rad ) ((rad)*RAD_TO_DEG)
132132#define sq (x ) ((x)*(x))
133133
134- void ets_intr_lock ();
135- void ets_intr_unlock ();
136-
137134#define interrupts () xt_rsil(0 )
138135#define noInterrupts () xt_rsil(15 )
139136
@@ -162,11 +159,12 @@ typedef uint16_t word;
162159typedef bool boolean;
163160typedef uint8_t byte;
164161
162+ void ets_intr_lock ();
163+ void ets_intr_unlock ();
164+
165165void init (void );
166166void initVariant (void );
167167
168- int atexit (void (*func)()) __attribute__((weak));
169-
170168void pinMode (uint8_t pin, uint8_t mode);
171169void digitalWrite (uint8_t pin, uint8_t val);
172170int digitalRead (uint8_t pin);
@@ -212,28 +210,31 @@ void optimistic_yield(uint32_t interval_us);
212210} // extern "C"
213211#endif
214212
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
215220
216-
221+ // from this point onward, we need to configure the c++ environment
217222#ifdef __cplusplus
218223
219224#include < algorithm>
225+ #include < cstdlib>
220226#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"
230227
231228using std::min;
232229using std::max;
233230using std::round;
234231using std::isinf;
235232using std::isnan;
236233
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+
237238#define _min (a,b ) ({ decltype (a) _a = (a); decltype (b) _b = (b); _a < _b? _a : _b; })
238239#define _max (a,b ) ({ decltype (a) _a = (a); decltype (b) _b = (b); _a > _b? _a : _b; })
239240
@@ -273,8 +274,19 @@ inline void configTzTime(const char* tz, const char* server1,
273274 configTime (tz, server1, server2, server3);
274275}
275276
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+
276287#endif // __cplusplus
277288
289+ #include " debug.h"
278290#include " pins_arduino.h"
279291
280292#endif
0 commit comments