/*********************************** * (C) 2007-2008 by Tomasz bla Fortuna . * License: GPL3+ (See Docs/LICENSE) * * Global settings ********************/ /*** Configuration ***/ #ifndef NOAVR #define F_CPU 20000000UL #include #endif #define DEBUG /* Enforce inlining */ #define inline inline __attribute__((always_inline)) /*** Types ***/ #define e_t(t) t typedef e_t(int32_t) Long; typedef e_t(int16_t) Int; typedef e_t(int8_t) Short; typedef e_t(uint32_t) ULong; typedef e_t(uint16_t) UInt; typedef e_t(uint8_t) UShort; typedef e_t(char) Char; typedef e_t(unsigned char) UChar; typedef e_t(float) Float; typedef e_t(bool) Bool; typedef void Void; /*** Utilities ***/ namespace Util { /* Diode signaling */ namespace Signal { #define S_PORT PORTD #define S_DDR DDRD #define S_RED PD2 #define S_GREEN PD3 #define S_BLUE PD4 enum Color {NONE=0, RED=1, GREEN=2, BLUE=4}; static inline void Set(const char A) { S_PORT |= (1< static inline T ABS(T a) { return a > T() ? a : -a; } template static inline T ABS_SUB(T x, T y) { return x > y ? x - y : y - x; } template static inline T SIGN(T x) { return x > T() ? 1 : -1; } template static inline T LIMIT(T x, T lim) { return x > lim ? lim : x; } template static inline T MAX(T x, T y) { return x > y ? x : y; } }