diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 432055eb3..400d226e0 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 7bdb12b7a..ee05b4683 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -28,14 +28,6 @@ #include "Arduino.h" -#define BIT(b) (1<<(b)) -#define TEST(n,b) (((n)&BIT(b))!=0) -#define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (BIT(b)) -#define RADIANS(d) ((d)*M_PI/180.0) -#define DEGREES(r) ((r)*180.0/M_PI) -#define NOLESS(v,n) do{ if (v < n) v = n; }while(0) -#define NOMORE(v,n) do{ if (v > n) v = n; }while(0) - typedef unsigned long millis_t; // Arduino < 1.0.0 does not define this, so we need to do it ourselves diff --git a/Marlin/configurator/config/Configuration.h b/Marlin/configurator/config/Configuration.h index 432055eb3..400d226e0 100644 --- a/Marlin/configurator/config/Configuration.h +++ b/Marlin/configurator/config/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/Felix/Configuration.h b/Marlin/example_configurations/Felix/Configuration.h index a3806de99..8a5f2ee58 100644 --- a/Marlin/example_configurations/Felix/Configuration.h +++ b/Marlin/example_configurations/Felix/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/Felix/Configuration_DUAL.h b/Marlin/example_configurations/Felix/Configuration_DUAL.h index 81db1aae3..27c376f6d 100644 --- a/Marlin/example_configurations/Felix/Configuration_DUAL.h +++ b/Marlin/example_configurations/Felix/Configuration_DUAL.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/Hephestos/Configuration.h b/Marlin/example_configurations/Hephestos/Configuration.h index 4b0192a50..6b6fd731a 100644 --- a/Marlin/example_configurations/Hephestos/Configuration.h +++ b/Marlin/example_configurations/Hephestos/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/K8200/Configuration.h b/Marlin/example_configurations/K8200/Configuration.h index d7e781162..b50384485 100644 --- a/Marlin/example_configurations/K8200/Configuration.h +++ b/Marlin/example_configurations/K8200/Configuration.h @@ -7,6 +7,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h index 540019e45..aca519997 100644 --- a/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h +++ b/Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/RigidBot/Configuration.h b/Marlin/example_configurations/RigidBot/Configuration.h index 7c2d7f25b..6baf0c04f 100644 --- a/Marlin/example_configurations/RigidBot/Configuration.h +++ b/Marlin/example_configurations/RigidBot/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/SCARA/Configuration.h b/Marlin/example_configurations/SCARA/Configuration.h index a835a83b4..e0f79a9e4 100644 --- a/Marlin/example_configurations/SCARA/Configuration.h +++ b/Marlin/example_configurations/SCARA/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/WITBOX/Configuration.h b/Marlin/example_configurations/WITBOX/Configuration.h index 5fb542f6d..b4dfd588c 100644 --- a/Marlin/example_configurations/WITBOX/Configuration.h +++ b/Marlin/example_configurations/WITBOX/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/adafruit/ST7565/Configuration.h b/Marlin/example_configurations/adafruit/ST7565/Configuration.h index d9aef0431..19f93e99a 100644 --- a/Marlin/example_configurations/adafruit/ST7565/Configuration.h +++ b/Marlin/example_configurations/adafruit/ST7565/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/delta/biv2.5/Configuration.h b/Marlin/example_configurations/delta/biv2.5/Configuration.h index 378a454fa..a64641e3a 100644 --- a/Marlin/example_configurations/delta/biv2.5/Configuration.h +++ b/Marlin/example_configurations/delta/biv2.5/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/delta/generic/Configuration.h b/Marlin/example_configurations/delta/generic/Configuration.h index 646e3118b..c9560f15c 100644 --- a/Marlin/example_configurations/delta/generic/Configuration.h +++ b/Marlin/example_configurations/delta/generic/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/delta/kossel_mini/Configuration.h b/Marlin/example_configurations/delta/kossel_mini/Configuration.h index 129c1c1a2..643da2f71 100644 --- a/Marlin/example_configurations/delta/kossel_mini/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_mini/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/delta/kossel_pro/Configuration.h b/Marlin/example_configurations/delta/kossel_pro/Configuration.h index 0d065e903..112a6e77c 100644 --- a/Marlin/example_configurations/delta/kossel_pro/Configuration.h +++ b/Marlin/example_configurations/delta/kossel_pro/Configuration.h @@ -6,6 +6,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/makibox/Configuration.h b/Marlin/example_configurations/makibox/Configuration.h index ffb062a0a..5e486c01e 100644 --- a/Marlin/example_configurations/makibox/Configuration.h +++ b/Marlin/example_configurations/makibox/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/example_configurations/tvrrug/Round2/Configuration.h b/Marlin/example_configurations/tvrrug/Round2/Configuration.h index 79bcb76d3..2278f79b2 100644 --- a/Marlin/example_configurations/tvrrug/Round2/Configuration.h +++ b/Marlin/example_configurations/tvrrug/Round2/Configuration.h @@ -2,6 +2,7 @@ #define CONFIGURATION_H #include "boards.h" +#include "macros.h" //=========================================================================== //============================= Getting Started ============================= diff --git a/Marlin/macros.h b/Marlin/macros.h new file mode 100644 index 000000000..f6acf7eec --- /dev/null +++ b/Marlin/macros.h @@ -0,0 +1,25 @@ +#ifndef MACROS_H +#define MACROS_H + +// Macros for bit masks +#define BIT(b) (1<<(b)) +#define TEST(n,b) (((n)&BIT(b))!=0) +#define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (BIT(b)) + +// Macros for maths shortcuts +#define RADIANS(d) ((d)*M_PI/180.0) +#define DEGREES(r) ((r)*180.0/M_PI) + +// Macros to contrain values +#define NOLESS(v,n) do{ if (v < n) v = n; }while(0) +#define NOMORE(v,n) do{ if (v > n) v = n; }while(0) + +// Macros to support option testing +#define _CAT(a, ...) a ## __VA_ARGS__ +#define SWITCH_ENABLED_0 0 +#define SWITCH_ENABLED_1 1 +#define SWITCH_ENABLED_ 1 +#define ENABLED(b) _CAT(SWITCH_ENABLED_, b) +#define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b)) + +#endif //__MACROS_H diff --git a/Marlin/stepper_indirection.h b/Marlin/stepper_indirection.h index 408fccbec..04bb223e1 100644 --- a/Marlin/stepper_indirection.h +++ b/Marlin/stepper_indirection.h @@ -22,6 +22,8 @@ #ifndef STEPPER_INDIRECTION_H #define STEPPER_INDIRECTION_H +#include "macros.h" + // X motor #define X_STEP_INIT SET_OUTPUT(X_STEP_PIN) #define X_STEP_WRITE(STATE) WRITE(X_STEP_PIN,STATE)