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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. #ifndef MACROS_H
  23. #define MACROS_H
  24. #define NUM_AXIS 4
  25. #define XYZE 4
  26. #define ABC 3
  27. #define XYZ 3
  28. #define FORCE_INLINE __attribute__((always_inline)) inline
  29. // Bracket code that shouldn't be interrupted
  30. #ifndef CRITICAL_SECTION_START
  31. #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
  32. #define CRITICAL_SECTION_END SREG = _sreg;
  33. #endif
  34. // Clock speed factor
  35. #define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20
  36. // Remove compiler warning on an unused variable
  37. #define UNUSED(x) (void) (x)
  38. // Macros to make a string from a macro
  39. #define STRINGIFY_(M) #M
  40. #define STRINGIFY(M) STRINGIFY_(M)
  41. // Macros for bit masks
  42. #define TEST(n,b) (((n)&_BV(b))!=0)
  43. #define SBI(n,b) (n |= _BV(b))
  44. #define CBI(n,b) (n &= ~_BV(b))
  45. #define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (_BV(b))
  46. // Macros for maths shortcuts
  47. #ifndef M_PI
  48. #define M_PI 3.14159265358979323846
  49. #endif
  50. #define RADIANS(d) ((d)*M_PI/180.0)
  51. #define DEGREES(r) ((r)*180.0/M_PI)
  52. #define HYPOT2(x,y) (sq(x)+sq(y))
  53. #define HYPOT(x,y) sqrt(HYPOT2(x,y))
  54. // Macros to contrain values
  55. #define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
  56. #define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
  57. // Macros to support option testing
  58. #define _CAT(a, ...) a ## __VA_ARGS__
  59. #define SWITCH_ENABLED_false 0
  60. #define SWITCH_ENABLED_true 1
  61. #define SWITCH_ENABLED_0 0
  62. #define SWITCH_ENABLED_1 1
  63. #define SWITCH_ENABLED_ 1
  64. #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
  65. #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
  66. #define WITHIN(V,L,H) ((V) >= (L) && (V) <= (H))
  67. #define NUMERIC(a) WITHIN(a, '0', '9')
  68. #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
  69. #define COUNT(a) (sizeof(a)/sizeof(*a))
  70. #define ZERO(a) memset(a,0,sizeof(a))
  71. #define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b)))
  72. // Macros for initializing arrays
  73. #define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }
  74. #define ARRAY_5(v1, v2, v3, v4, v5, ...) { v1, v2, v3, v4, v5 }
  75. #define ARRAY_4(v1, v2, v3, v4, ...) { v1, v2, v3, v4 }
  76. #define ARRAY_3(v1, v2, v3, ...) { v1, v2, v3 }
  77. #define ARRAY_2(v1, v2, ...) { v1, v2 }
  78. #define ARRAY_1(v1, ...) { v1 }
  79. #define _ARRAY_N(N, ...) ARRAY_ ##N(__VA_ARGS__)
  80. #define ARRAY_N(N, ...) _ARRAY_N(N, __VA_ARGS__)
  81. // Macros for adding
  82. #define INC_0 1
  83. #define INC_1 2
  84. #define INC_2 3
  85. #define INC_3 4
  86. #define INC_4 5
  87. #define INC_5 6
  88. #define INC_6 7
  89. #define INC_7 8
  90. #define INC_8 9
  91. #define INCREMENT_(n) INC_ ##n
  92. #define INCREMENT(n) INCREMENT_(n)
  93. // Macros for subtracting
  94. #define DEC_1 0
  95. #define DEC_2 1
  96. #define DEC_3 2
  97. #define DEC_4 3
  98. #define DEC_5 4
  99. #define DEC_6 5
  100. #define DEC_7 6
  101. #define DEC_8 7
  102. #define DEC_9 8
  103. #define DECREMENT_(n) DEC_ ##n
  104. #define DECREMENT(n) DECREMENT_(n)
  105. #define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0)
  106. #define PENDING(NOW,SOON) ((long)(NOW-(SOON))<0)
  107. #define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
  108. #define NOOP do{} while(0)
  109. #define CEILING(x,y) (((x) + (y) - 1) / (y))
  110. #define MIN3(a, b, c) min(min(a, b), c)
  111. #define MIN4(a, b, c, d) min(min(a, b), min(c, d))
  112. #define MAX3(a, b, c) max(max(a, b), c)
  113. #define MAX4(a, b, c, d) max(max(a, b), max(c, d))
  114. #define UNEAR_ZERO(x) ((x) < 0.000001)
  115. #define NEAR_ZERO(x) WITHIN(x, -0.000001, 0.000001)
  116. #define NEAR(x,y) NEAR_ZERO((x)-(y))
  117. #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))
  118. #define FIXFLOAT(f) (f + 0.00001)
  119. #endif //__MACROS_H