|
69 | 69 | #define __STRINGIFY(a) #a |
70 | 70 | #endif |
71 | 71 |
|
| 72 | +// can't define max() / min() because of conflicts with C++ |
| 73 | +#define _min(a,b) ((a)<(b)?(a):(b)) |
| 74 | +#define _max(a,b) ((a)>(b)?(a):(b)) |
| 75 | +#define _abs(x) ((x)>0?(x):-(x)) // abs() comes from STL |
72 | 76 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) |
| 77 | +#define _round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) // round() comes from STL |
73 | 78 | #define radians(deg) ((deg)*DEG_TO_RAD) |
74 | 79 | #define degrees(rad) ((rad)*RAD_TO_DEG) |
75 | 80 | #define sq(x) ((x)*(x)) |
|
89 | 94 | #define bitRead(value, bit) (((value) >> (bit)) & 0x01) |
90 | 95 | #define bitSet(value, bit) ((value) |= (1UL << (bit))) |
91 | 96 | #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) |
| 97 | +#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) |
92 | 98 | #define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit)) |
93 | 99 |
|
94 | 100 | // 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); |
168 | 174 | #include "Esp.h" |
169 | 175 | #include "esp32/spiram.h" |
170 | 176 |
|
| 177 | +// Use float-compatible stl abs() and round(), we don't use Arduino macros to avoid issues with the C++ libraries |
171 | 178 | using std::abs; |
172 | 179 | using std::isinf; |
173 | 180 | using std::isnan; |
174 | 181 | using std::max; |
175 | 182 | using std::min; |
176 | | -using ::round; |
| 183 | +using std::round; |
177 | 184 |
|
178 | 185 | uint16_t makeWord(uint16_t w); |
179 | 186 | uint16_t makeWord(uint8_t h, uint8_t l); |
@@ -203,9 +210,6 @@ void noTone(uint8_t _pin); |
203 | 210 | long random(long); |
204 | 211 | #endif /* __cplusplus */ |
205 | 212 |
|
206 | | -#define _min(a,b) ((a)<(b)?(a):(b)) |
207 | | -#define _max(a,b) ((a)>(b)?(a):(b)) |
208 | | - |
209 | 213 | #include "pins_arduino.h" |
210 | 214 |
|
211 | 215 | #endif /* _ESP32_CORE_ARDUINO_H_ */ |
0 commit comments