diff --git a/cores/esp32/Arduino.h b/cores/esp32/Arduino.h index c8be9222b39..d2f641c5882 100644 --- a/cores/esp32/Arduino.h +++ b/cores/esp32/Arduino.h @@ -69,7 +69,12 @@ #define __STRINGIFY(a) #a #endif +// can't define max() / min() because of conflicts with C++ +#define _min(a,b) ((a)<(b)?(a):(b)) +#define _max(a,b) ((a)>(b)?(a):(b)) +#define _abs(x) ((x)>0?(x):-(x)) // abs() comes from STL #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define _round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) // round() comes from STL #define radians(deg) ((deg)*DEG_TO_RAD) #define degrees(rad) ((rad)*RAD_TO_DEG) #define sq(x) ((x)*(x)) @@ -89,6 +94,7 @@ #define bitRead(value, bit) (((value) >> (bit)) & 0x01) #define bitSet(value, bit) ((value) |= (1UL << (bit))) #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) #define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit)) // avr-libc defines _NOP() since 1.6.2 @@ -168,12 +174,13 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val); #include "Esp.h" #include "esp32/spiram.h" +// Use float-compatible stl abs() and round(), we don't use Arduino macros to avoid issues with the C++ libraries using std::abs; using std::isinf; using std::isnan; using std::max; using std::min; -using ::round; +using std::round; uint16_t makeWord(uint16_t w); uint16_t makeWord(uint8_t h, uint8_t l); @@ -203,9 +210,6 @@ void noTone(uint8_t _pin); long random(long); #endif /* __cplusplus */ -#define _min(a,b) ((a)<(b)?(a):(b)) -#define _max(a,b) ((a)>(b)?(a):(b)) - #include "pins_arduino.h" #endif /* _ESP32_CORE_ARDUINO_H_ */