Skip to content

Commit

Permalink
Update MCUdude corefiles
Browse files Browse the repository at this point in the history
Merge commit '1b385b01ec2632c5e8050fa5c6dab8f64b53dd35'
  • Loading branch information
MCUdude committed Jan 17, 2023
2 parents 9c3bc53 + 1b385b0 commit 4180eae
Showing 1 changed file with 60 additions and 18 deletions.
78 changes: 60 additions & 18 deletions avr/cores/MCUdude_corefiles/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,6 @@ void yield(void);

#endif

// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif

#define abs(x) ({ typeof (x) _x = (x); _x > 0 ? _x : -_x; })
#define sq(x) ({ typeof (x) _x = (x); _x * _x; })
#define min(a,b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
#define max(a,b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
#define round(x) ({ typeof (x) _x = (x); _x >= 0 ? (long)(_x + 0.5) : (long)(_x - 0.5); })
#define radians(deg) ((deg) * DEG_TO_RAD)
#define degrees(rad) ((rad) * RAD_TO_DEG)
#define constrain(x,low,high) ({ \
typeof (x) _x = (x); \
typeof (low) _l = (low); \
typeof (high) _h = (high); \
_x < _l ? _l : _x > _h ? _h : _x; })

#define interrupts() sei()
#define noInterrupts() cli()

Expand Down Expand Up @@ -316,6 +298,66 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
} // extern "C"
#endif

// Undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif

#ifdef __cplusplus
template<class T>
auto abs(const T& x) -> decltype(x > 0 ? x : -x) {
return x > 0 ? x : -x;
}

template<class T, class L>
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) {
return (b < a) ? b : a;
}

template<class T, class L>
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) {
return (a < b) ? b : a;
}

template<class T>
long round(const T& x) {
return (long)(x >= 0 ? (x + 0.5) : (x - 0.5));
}

template<class T>
auto sq(const T& x) -> decltype(x * x) {
return x * x;
}

template<class T>
auto radians(const T& deg) -> decltype(deg * DEG_TO_RAD) {
return deg * DEG_TO_RAD;
}

template<class T>
auto degrees(const T& rad) -> decltype(rad * RAD_TO_DEG) {
return rad * RAD_TO_DEG;
}

template<class T, class L, class H>
auto constrain(const T& x, const L& l, const H& h) -> decltype((x < l) ? l : (x > h) ? h : x) {
return (x < l) ? l : (x > h) ? h : x;
}

#else
#define abs(x) ({ typeof (x) _x = (x); _x > 0 ? _x : -_x; })
#define min(a,b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
#define max(a,b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
#define sq(x) ({ typeof (x) _x = (x); _x * _x; })
#define radians(deg) ((deg) * DEG_TO_RAD)
#define degrees(rad) ((rad) * RAD_TO_DEG)
#define constrain(x,low,high) ({ \
typeof (x) _x = (x); \
typeof (low) _l = (low); \
typeof (high) _h = (high); \
_x < _l ? _l : _x > _h ? _h : _x; })
#endif // __cplusplus

#ifdef __cplusplus
#include "WCharacter.h"
#include "WString.h"
Expand Down

0 comments on commit 4180eae

Please sign in to comment.