My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

macros.h 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "minmax.h"
  24. #define NUM_AXIS 4
  25. #define ABCE 4
  26. #define XYZE 4
  27. #define ABC 3
  28. #define XYZ 3
  29. #define _AXIS(A) (A##_AXIS)
  30. #define _XMIN_ 100
  31. #define _YMIN_ 200
  32. #define _ZMIN_ 300
  33. #define _XMAX_ 101
  34. #define _YMAX_ 201
  35. #define _ZMAX_ 301
  36. #define _FORCE_INLINE_ __attribute__((__always_inline__)) __inline__
  37. #define FORCE_INLINE __attribute__((always_inline)) inline
  38. #define _UNUSED __attribute__((unused))
  39. #define _O0 __attribute__((optimize("O0")))
  40. #define _Os __attribute__((optimize("Os")))
  41. #define _O1 __attribute__((optimize("O1")))
  42. #define _O2 __attribute__((optimize("O2")))
  43. #define _O3 __attribute__((optimize("O3")))
  44. // Clock speed factors
  45. #if !defined(CYCLES_PER_MICROSECOND) && !defined(__STM32F1__)
  46. #define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20 on AVR
  47. #endif
  48. // Nanoseconds per cycle
  49. #define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
  50. // Remove compiler warning on an unused variable
  51. #define UNUSED(x) ((void)(x))
  52. // Macros to make a string from a macro
  53. #define STRINGIFY_(M) #M
  54. #define STRINGIFY(M) STRINGIFY_(M)
  55. #define A(CODE) " " CODE "\n\t"
  56. #define L(CODE) CODE ":\n\t"
  57. // Macros for bit masks
  58. #undef _BV
  59. #define _BV(n) (1<<(n))
  60. #define TEST(n,b) !!((n)&_BV(b))
  61. #define SBI(n,b) (n |= _BV(b))
  62. #define CBI(n,b) (n &= ~_BV(b))
  63. #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
  64. #define _BV32(b) (1UL << (b))
  65. #define TEST32(n,b) !!((n)&_BV32(b))
  66. #define SBI32(n,b) (n |= _BV32(b))
  67. #define CBI32(n,b) (n &= ~_BV32(b))
  68. // Macros for maths shortcuts
  69. #undef M_PI
  70. #define M_PI 3.14159265358979323846f
  71. #define RADIANS(d) ((d)*float(M_PI)/180.0f)
  72. #define DEGREES(r) ((r)*180.0f/float(M_PI))
  73. #define HYPOT2(x,y) (sq(x)+sq(y))
  74. #define CIRCLE_AREA(R) (float(M_PI) * sq(float(R)))
  75. #define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R))
  76. #define SIGN(a) ((a>0)-(a<0))
  77. #define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))
  78. // Macros to constrain values
  79. #ifdef __cplusplus
  80. // C++11 solution that is standards compliant.
  81. template <class V, class N> static inline constexpr void NOLESS(V& v, const N n) {
  82. if (v < n) v = n;
  83. }
  84. template <class V, class N> static inline constexpr void NOMORE(V& v, const N n) {
  85. if (v > n) v = n;
  86. }
  87. template <class V, class N1, class N2> static inline constexpr void LIMIT(V& v, const N1 n1, const N2 n2) {
  88. if (v < n1) v = n1;
  89. else if (v > n2) v = n2;
  90. }
  91. #else
  92. // Using GCC extensions, but Travis GCC version does not like it and gives
  93. // "error: statement-expressions are not allowed outside functions nor in template-argument lists"
  94. #define NOLESS(v, n) \
  95. do { \
  96. __typeof__(n) _n = (n); \
  97. if (v < _n) v = _n; \
  98. } while(0)
  99. #define NOMORE(v, n) \
  100. do { \
  101. __typeof__(n) _n = (n); \
  102. if (v > _n) v = _n; \
  103. } while(0)
  104. #define LIMIT(v, n1, n2) \
  105. do { \
  106. __typeof__(n1) _n1 = (n1); \
  107. __typeof__(n2) _n2 = (n2); \
  108. if (v < _n1) v = _n1; \
  109. else if (v > _n2) v = _n2; \
  110. } while(0)
  111. #endif
  112. // Macros to support option testing
  113. #define _CAT(a, ...) a ## __VA_ARGS__
  114. #define SWITCH_ENABLED_false 0
  115. #define SWITCH_ENABLED_true 1
  116. #define SWITCH_ENABLED_0 0
  117. #define SWITCH_ENABLED_1 1
  118. #define SWITCH_ENABLED_0x0 0
  119. #define SWITCH_ENABLED_0x1 1
  120. #define SWITCH_ENABLED_ 1
  121. #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
  122. #define DISABLED(b) !ENABLED(b)
  123. #define WITHIN(V,L,H) ((V) >= (L) && (V) <= (H))
  124. #define NUMERIC(a) WITHIN(a, '0', '9')
  125. #define DECIMAL(a) (NUMERIC(a) || a == '.')
  126. #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+')
  127. #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
  128. #define COUNT(a) (sizeof(a)/sizeof(*a))
  129. #define ZERO(a) memset(a,0,sizeof(a))
  130. #define COPY(a,b) do{ \
  131. static_assert(sizeof(a[0]) == sizeof(b[0]), "COPY: '" STRINGIFY(a) "' and '" STRINGIFY(b) "' types (sizes) don't match!"); \
  132. memcpy(&a[0],&b[0],MIN(sizeof(a),sizeof(b))); \
  133. }while(0)
  134. // Macros for initializing arrays
  135. #define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }
  136. #define ARRAY_5(v1, v2, v3, v4, v5, ...) { v1, v2, v3, v4, v5 }
  137. #define ARRAY_4(v1, v2, v3, v4, ...) { v1, v2, v3, v4 }
  138. #define ARRAY_3(v1, v2, v3, ...) { v1, v2, v3 }
  139. #define ARRAY_2(v1, v2, ...) { v1, v2 }
  140. #define ARRAY_1(v1, ...) { v1 }
  141. #define _ARRAY_N(N, ...) ARRAY_ ##N(__VA_ARGS__)
  142. #define ARRAY_N(N, ...) _ARRAY_N(N, __VA_ARGS__)
  143. // Macros for adding
  144. #define INC_0 1
  145. #define INC_1 2
  146. #define INC_2 3
  147. #define INC_3 4
  148. #define INC_4 5
  149. #define INC_5 6
  150. #define INC_6 7
  151. #define INC_7 8
  152. #define INC_8 9
  153. #define INCREMENT_(n) INC_ ##n
  154. #define INCREMENT(n) INCREMENT_(n)
  155. // Macros for subtracting
  156. #define DEC_1 0
  157. #define DEC_2 1
  158. #define DEC_3 2
  159. #define DEC_4 3
  160. #define DEC_5 4
  161. #define DEC_6 5
  162. #define DEC_7 6
  163. #define DEC_8 7
  164. #define DEC_9 8
  165. #define DECREMENT_(n) DEC_ ##n
  166. #define DECREMENT(n) DECREMENT_(n)
  167. #define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0)
  168. #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
  169. #define MMM_TO_MMS(MM_M) ((MM_M)/60.0f)
  170. #define MMS_TO_MMM(MM_S) ((MM_S)*60.0f)
  171. #define NOOP (void(0))
  172. #define CEILING(x,y) (((x) + (y) - 1) / (y))
  173. #undef ABS
  174. #ifdef __cplusplus
  175. template <class T> static inline constexpr const T ABS(const T v) { return v >= 0 ? v : -v; }
  176. #else
  177. #define ABS(a) ({__typeof__(a) _a = (a); _a >= 0 ? _a : -_a;})
  178. #endif
  179. #define UNEAR_ZERO(x) ((x) < 0.000001f)
  180. #define NEAR_ZERO(x) WITHIN(x, -0.000001f, 0.000001f)
  181. #define NEAR(x,y) NEAR_ZERO((x)-(y))
  182. #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0 : (1 / float(x)))
  183. #define FIXFLOAT(f) (f + (f < 0 ? -0.00005f : 0.00005f))
  184. //
  185. // Maths macros that can be overridden by HAL
  186. //
  187. #define ATAN2(y, x) atan2f(y, x)
  188. #define POW(x, y) powf(x, y)
  189. #define SQRT(x) sqrtf(x)
  190. #define RSQRT(x) (1 / sqrtf(x))
  191. #define CEIL(x) ceilf(x)
  192. #define FLOOR(x) floorf(x)
  193. #define LROUND(x) lroundf(x)
  194. #define FMOD(x, y) fmodf(x, y)
  195. #define HYPOT(x,y) SQRT(HYPOT2(x,y))
  196. #ifdef TARGET_LPC1768
  197. #define I2C_ADDRESS(A) ((A) << 1)
  198. #else
  199. #define I2C_ADDRESS(A) A
  200. #endif