My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

macros.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. #define NUM_AXIS 4
  24. #define ABCE 4
  25. #define XYZE 4
  26. #define ABC 3
  27. #define XYZ 3
  28. #define _AXIS(A) (A##_AXIS)
  29. #define _XMIN_ 100
  30. #define _YMIN_ 200
  31. #define _ZMIN_ 300
  32. #define _XMAX_ 101
  33. #define _YMAX_ 201
  34. #define _ZMAX_ 301
  35. #define _FORCE_INLINE_ __attribute__((__always_inline__)) __inline__
  36. #define FORCE_INLINE __attribute__((always_inline)) inline
  37. #define _UNUSED __attribute__((unused))
  38. #define _O0 __attribute__((optimize("O0")))
  39. #define _Os __attribute__((optimize("Os")))
  40. #define _O1 __attribute__((optimize("O1")))
  41. #define _O2 __attribute__((optimize("O2")))
  42. #define _O3 __attribute__((optimize("O3")))
  43. #ifndef UNUSED
  44. #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
  45. #define UNUSED(X) (void)X
  46. #else
  47. #define UNUSED(x) ((void)(x))
  48. #endif
  49. #endif
  50. // Clock speed factors
  51. #if !defined(CYCLES_PER_MICROSECOND) && !defined(__STM32F1__)
  52. #define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20 on AVR
  53. #endif
  54. // Nanoseconds per cycle
  55. #define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
  56. // Macros to make a string from a macro
  57. #define STRINGIFY_(M) #M
  58. #define STRINGIFY(M) STRINGIFY_(M)
  59. #define A(CODE) " " CODE "\n\t"
  60. #define L(CODE) CODE ":\n\t"
  61. // Macros for bit masks
  62. #undef _BV
  63. #define _BV(n) (1<<(n))
  64. #define TEST(n,b) (!!((n)&_BV(b)))
  65. #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
  66. #ifndef SBI
  67. #define SBI(A,B) (A |= (1 << (B)))
  68. #endif
  69. #ifndef CBI
  70. #define CBI(A,B) (A &= ~(1 << (B)))
  71. #endif
  72. #define _BV32(b) (1UL << (b))
  73. #define TEST32(n,b) !!((n)&_BV32(b))
  74. #define SBI32(n,b) (n |= _BV32(b))
  75. #define CBI32(n,b) (n &= ~_BV32(b))
  76. #define cu(x) ((x)*(x)*(x))
  77. #define RADIANS(d) ((d)*float(M_PI)/180.0f)
  78. #define DEGREES(r) ((r)*180.0f/float(M_PI))
  79. #define HYPOT2(x,y) (sq(x)+sq(y))
  80. #define CIRCLE_AREA(R) (float(M_PI) * sq(float(R)))
  81. #define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R))
  82. #define SIGN(a) ((a>0)-(a<0))
  83. #define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))
  84. // Macros to constrain values
  85. #ifdef __cplusplus
  86. // C++11 solution that is standards compliant.
  87. template <class V, class N> static inline constexpr void NOLESS(V& v, const N n) {
  88. if (v < n) v = n;
  89. }
  90. template <class V, class N> static inline constexpr void NOMORE(V& v, const N n) {
  91. if (v > n) v = n;
  92. }
  93. template <class V, class N1, class N2> static inline constexpr void LIMIT(V& v, const N1 n1, const N2 n2) {
  94. if (v < n1) v = n1;
  95. else if (v > n2) v = n2;
  96. }
  97. #else
  98. // Using GCC extensions, but Travis GCC version does not like it and gives
  99. // "error: statement-expressions are not allowed outside functions nor in template-argument lists"
  100. #define NOLESS(v, n) \
  101. do{ \
  102. __typeof__(n) _n = (n); \
  103. if (v < _n) v = _n; \
  104. }while(0)
  105. #define NOMORE(v, n) \
  106. do{ \
  107. __typeof__(n) _n = (n); \
  108. if (v > _n) v = _n; \
  109. }while(0)
  110. #define LIMIT(v, n1, n2) \
  111. do{ \
  112. __typeof__(n1) _n1 = (n1); \
  113. __typeof__(n2) _n2 = (n2); \
  114. if (v < _n1) v = _n1; \
  115. else if (v > _n2) v = _n2; \
  116. }while(0)
  117. #endif
  118. // Macros to chain up to 12 conditions
  119. #define _DO_1(W,C,A) (_##W##_1(A))
  120. #define _DO_2(W,C,A,B) (_##W##_1(A) C _##W##_1(B))
  121. #define _DO_3(W,C,A,V...) (_##W##_1(A) C _DO_2(W,C,V))
  122. #define _DO_4(W,C,A,V...) (_##W##_1(A) C _DO_3(W,C,V))
  123. #define _DO_5(W,C,A,V...) (_##W##_1(A) C _DO_4(W,C,V))
  124. #define _DO_6(W,C,A,V...) (_##W##_1(A) C _DO_5(W,C,V))
  125. #define _DO_7(W,C,A,V...) (_##W##_1(A) C _DO_6(W,C,V))
  126. #define _DO_8(W,C,A,V...) (_##W##_1(A) C _DO_7(W,C,V))
  127. #define _DO_9(W,C,A,V...) (_##W##_1(A) C _DO_8(W,C,V))
  128. #define _DO_10(W,C,A,V...) (_##W##_1(A) C _DO_9(W,C,V))
  129. #define _DO_11(W,C,A,V...) (_##W##_1(A) C _DO_10(W,C,V))
  130. #define _DO_12(W,C,A,V...) (_##W##_1(A) C _DO_11(W,C,V))
  131. #define __DO_N(W,C,N,V...) _DO_##N(W,C,V)
  132. #define _DO_N(W,C,N,V...) __DO_N(W,C,N,V)
  133. #define DO(W,C,V...) _DO_N(W,C,NUM_ARGS(V),V)
  134. // Macros to support option testing
  135. #define _CAT(a,V...) a##V
  136. #define SWITCH_ENABLED_false 0
  137. #define SWITCH_ENABLED_true 1
  138. #define SWITCH_ENABLED_0 0
  139. #define SWITCH_ENABLED_1 1
  140. #define SWITCH_ENABLED_0x0 0
  141. #define SWITCH_ENABLED_0x1 1
  142. #define SWITCH_ENABLED_ 1
  143. #define _ENA_1(O) _CAT(SWITCH_ENABLED_, O)
  144. #define _DIS_1(O) !_ENA_1(O)
  145. #define ENABLED(V...) DO(ENA,&&,V)
  146. #define DISABLED(V...) DO(DIS,&&,V)
  147. #define ANY(V...) !DISABLED(V)
  148. #define NONE(V...) DISABLED(V)
  149. #define ALL(V...) ENABLED(V)
  150. #define BOTH(V1,V2) ALL(V1,V2)
  151. #define EITHER(V1,V2) ANY(V1,V2)
  152. // Macros to support pins/buttons exist testing
  153. #define _PINEX_1(PN) (defined(PN##_PIN) && PN##_PIN >= 0)
  154. #define PIN_EXISTS(V...) DO(PINEX,&&,V)
  155. #define ANY_PIN(V...) DO(PINEX,||,V)
  156. #define _BTNEX_1(BN) (defined(BTN_##BN) && BTN_##BN >= 0)
  157. #define BUTTON_EXISTS(V...) DO(BTNEX,&&,V)
  158. #define ANY_BUTTON(V...) DO(BTNEX,||,V)
  159. #define WITHIN(N,L,H) ((N) >= (L) && (N) <= (H))
  160. #define NUMERIC(a) WITHIN(a, '0', '9')
  161. #define DECIMAL(a) (NUMERIC(a) || a == '.')
  162. #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+')
  163. #define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
  164. #define COUNT(a) (sizeof(a)/sizeof(*a))
  165. #define ZERO(a) memset(a,0,sizeof(a))
  166. #define COPY(a,b) do{ \
  167. static_assert(sizeof(a[0]) == sizeof(b[0]), "COPY: '" STRINGIFY(a) "' and '" STRINGIFY(b) "' types (sizes) don't match!"); \
  168. memcpy(&a[0],&b[0],_MIN(sizeof(a),sizeof(b))); \
  169. }while(0)
  170. // Macros for initializing arrays
  171. #define ARRAY_16(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,...) { A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P }
  172. #define ARRAY_15(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,...) { A,B,C,D,E,F,G,H,I,J,K,L,M,N,O }
  173. #define ARRAY_14(A,B,C,D,E,F,G,H,I,J,K,L,M,N,...) { A,B,C,D,E,F,G,H,I,J,K,L,M,N }
  174. #define ARRAY_13(A,B,C,D,E,F,G,H,I,J,K,L,M,...) { A,B,C,D,E,F,G,H,I,J,K,L,M }
  175. #define ARRAY_12(A,B,C,D,E,F,G,H,I,J,K,L,...) { A,B,C,D,E,F,G,H,I,J,K,L }
  176. #define ARRAY_11(A,B,C,D,E,F,G,H,I,J,K,...) { A,B,C,D,E,F,G,H,I,J,K }
  177. #define ARRAY_10(A,B,C,D,E,F,G,H,I,J,...) { A,B,C,D,E,F,G,H,I,J }
  178. #define ARRAY_9( A,B,C,D,E,F,G,H,I,...) { A,B,C,D,E,F,G,H,I }
  179. #define ARRAY_8( A,B,C,D,E,F,G,H,...) { A,B,C,D,E,F,G,H }
  180. #define ARRAY_7( A,B,C,D,E,F,G,...) { A,B,C,D,E,F,G }
  181. #define ARRAY_6( A,B,C,D,E,F,...) { A,B,C,D,E,F }
  182. #define ARRAY_5( A,B,C,D,E,...) { A,B,C,D,E }
  183. #define ARRAY_4( A,B,C,D,...) { A,B,C,D }
  184. #define ARRAY_3( A,B,C,...) { A,B,C }
  185. #define ARRAY_2( A,B,...) { A,B }
  186. #define ARRAY_1( A,...) { A }
  187. #define _ARRAY_N(N,V...) ARRAY_##N(V)
  188. #define ARRAY_N(N,V...) _ARRAY_N(N,V)
  189. // Macros for adding
  190. #define INC_0 1
  191. #define INC_1 2
  192. #define INC_2 3
  193. #define INC_3 4
  194. #define INC_4 5
  195. #define INC_5 6
  196. #define INC_6 7
  197. #define INC_7 8
  198. #define INC_8 9
  199. #define INCREMENT_(n) INC_##n
  200. #define INCREMENT(n) INCREMENT_(n)
  201. // Macros for subtracting
  202. #define DEC_1 0
  203. #define DEC_2 1
  204. #define DEC_3 2
  205. #define DEC_4 3
  206. #define DEC_5 4
  207. #define DEC_6 5
  208. #define DEC_7 6
  209. #define DEC_8 7
  210. #define DEC_9 8
  211. #define DECREMENT_(n) DEC_##n
  212. #define DECREMENT(n) DECREMENT_(n)
  213. #define MMM_TO_MMS(MM_M) ((MM_M)/60.0f)
  214. #define MMS_TO_MMM(MM_S) ((MM_S)*60.0f)
  215. #define NOOP (void(0))
  216. #define CEILING(x,y) (((x) + (y) - 1) / (y))
  217. #undef ABS
  218. #ifdef __cplusplus
  219. template <class T> static inline constexpr const T ABS(const T v) { return v >= 0 ? v : -v; }
  220. #else
  221. #define ABS(a) ({__typeof__(a) _a = (a); _a >= 0 ? _a : -_a;})
  222. #endif
  223. #define UNEAR_ZERO(x) ((x) < 0.000001f)
  224. #define NEAR_ZERO(x) WITHIN(x, -0.000001f, 0.000001f)
  225. #define NEAR(x,y) NEAR_ZERO((x)-(y))
  226. #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0 : (1 / float(x)))
  227. #define FIXFLOAT(f) (f + (f < 0 ? -0.00005f : 0.00005f))
  228. //
  229. // Maths macros that can be overridden by HAL
  230. //
  231. #define ATAN2(y, x) atan2f(y, x)
  232. #define POW(x, y) powf(x, y)
  233. #define SQRT(x) sqrtf(x)
  234. #define RSQRT(x) (1 / sqrtf(x))
  235. #define CEIL(x) ceilf(x)
  236. #define FLOOR(x) floorf(x)
  237. #define LROUND(x) lroundf(x)
  238. #define FMOD(x, y) fmodf(x, y)
  239. #define HYPOT(x,y) SQRT(HYPOT2(x,y))
  240. #ifdef TARGET_LPC1768
  241. #define I2C_ADDRESS(A) ((A) << 1)
  242. #else
  243. #define I2C_ADDRESS(A) A
  244. #endif
  245. // Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
  246. #define _NUM_ARGS(_0,_24_,_23,_22,_21,_20,_19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,N,...) N
  247. #define NUM_ARGS(V...) _NUM_ARGS(0,V,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
  248. #ifdef __cplusplus
  249. #ifndef _MINMAX_H_
  250. #define _MINMAX_H_
  251. extern "C++" {
  252. // C++11 solution that is standards compliant. Return type is deduced automatically
  253. template <class L, class R> static inline constexpr auto _MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
  254. return lhs < rhs ? lhs : rhs;
  255. }
  256. template <class L, class R> static inline constexpr auto _MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
  257. return lhs > rhs ? lhs : rhs;
  258. }
  259. template<class T, class ... Ts> static inline constexpr const T _MIN(T V, Ts... Vs) { return _MIN(V, _MIN(Vs...)); }
  260. template<class T, class ... Ts> static inline constexpr const T _MAX(T V, Ts... Vs) { return _MAX(V, _MAX(Vs...)); }
  261. }
  262. #endif
  263. #else
  264. #define MIN_2(a,b) ((a)<(b)?(a):(b))
  265. #define MIN_3(a,...) MIN_2(a,MIN_2(__VA_ARGS__))
  266. #define MIN_4(a,...) MIN_2(a,MIN_3(__VA_ARGS__))
  267. #define MIN_5(a,...) MIN_2(a,MIN_4(__VA_ARGS__))
  268. #define MIN_6(a,...) MIN_2(a,MIN_5(__VA_ARGS__))
  269. #define MIN_7(a,...) MIN_2(a,MIN_6(__VA_ARGS__))
  270. #define MIN_8(a,...) MIN_2(a,MIN_7(__VA_ARGS__))
  271. #define MIN_9(a,...) MIN_2(a,MIN_8(__VA_ARGS__))
  272. #define MIN_10(a,...) MIN_2(a,MIN_9(__VA_ARGS__))
  273. #define __MIN_N(N, ...) MIN_##N(__VA_ARGS__)
  274. #define _MIN_N(N, ...) __MIN_N(N,__VA_ARGS__)
  275. #define _MIN(...) _MIN_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
  276. #define MAX_2(a,b) ((a)>(b)?(a):(b))
  277. #define MAX_3(a,...) MAX_2(a,MAX_2(__VA_ARGS__))
  278. #define MAX_4(a,...) MAX_2(a,MAX_3(__VA_ARGS__))
  279. #define MAX_5(a,...) MAX_2(a,MAX_4(__VA_ARGS__))
  280. #define MAX_6(a,...) MAX_2(a,MAX_5(__VA_ARGS__))
  281. #define MAX_7(a,...) MAX_2(a,MAX_6(__VA_ARGS__))
  282. #define MAX_8(a,...) MAX_2(a,MAX_7(__VA_ARGS__))
  283. #define MAX_9(a,...) MAX_2(a,MAX_8(__VA_ARGS__))
  284. #define MAX_10(a,...) MAX_2(a,MAX_9(__VA_ARGS__))
  285. #define __MAX_N(N, ...) MAX_##N(__VA_ARGS__)
  286. #define _MAX_N(N, ...) __MAX_N(N,__VA_ARGS__)
  287. #define _MAX(...) _MAX_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
  288. #endif