PaulStoffregen 10 years ago
parent
commit
2746714809
1 changed files with 28 additions and 7 deletions
  1. +28
    -7
      teensy3/wiring.h

+ 28
- 7
teensy3/wiring.h View File

@@ -57,15 +57,36 @@ extern "C"{
#undef abs
#endif

#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#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))
#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 abs(x) ({ \
typeof(x) _x = (x); \
(_x > 0) ? _x : -_x; \
})
#define constrain(amt, low, high) ({ \
typeof(amt) _amt = (amt); \
typeof(low) _low = (low); \
typeof(high) _high = (high); \
(_amt < _low) ? _low : ((_amt > _high) ? _high : _amt); \
})
#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 sq(x) ((x)*(x))

#define sq(x) ({ \
typeof(x) _x = (x); \
_x * _x; \
})
#define sei() __enable_irq()
#define cli() __disable_irq()
#define interrupts() __enable_irq()

Loading…
Cancel
Save