My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

macros.h 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 FORCE_INLINE __attribute__((always_inline)) inline
  25. // Bracket code that shouldn't be interrupted
  26. #ifndef CRITICAL_SECTION_START
  27. #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
  28. #define CRITICAL_SECTION_END SREG = _sreg;
  29. #endif
  30. // Remove compiler warning on an unused variable
  31. #define UNUSED(x) (void) (x)
  32. // Macros to make a string from a macro
  33. #define STRINGIFY_(M) #M
  34. #define STRINGIFY(M) STRINGIFY_(M)
  35. // Macros for bit masks
  36. #define TEST(n,b) (((n)&_BV(b))!=0)
  37. #define SBI(n,b) (n |= _BV(b))
  38. #define CBI(n,b) (n &= ~_BV(b))
  39. #define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (_BV(b))
  40. // Macros for maths shortcuts
  41. #ifndef M_PI
  42. #define M_PI 3.14159265358979323846
  43. #endif
  44. #define RADIANS(d) ((d)*M_PI/180.0)
  45. #define DEGREES(r) ((r)*180.0/M_PI)
  46. #define HYPOT(x,y) sqrt(sq(x)+sq(y))
  47. // Macros to contrain values
  48. #define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
  49. #define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
  50. // Macros to support option testing
  51. #define _CAT(a, ...) a ## __VA_ARGS__
  52. #define SWITCH_ENABLED_false 0
  53. #define SWITCH_ENABLED_true 1
  54. #define SWITCH_ENABLED_0 0
  55. #define SWITCH_ENABLED_1 1
  56. #define SWITCH_ENABLED_ 1
  57. #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
  58. #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
  59. #define NUMERIC(a) ((a) >= '0' && '9' >= (a))
  60. #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
  61. #define COUNT(a) (sizeof(a)/sizeof(*a))
  62. // Macros for initializing arrays
  63. #define ARRAY_6(v1, v2, v3, v4, v5, v6, args...) { v1, v2, v3, v4, v5, v6 }
  64. #define ARRAY_5(v1, v2, v3, v4, v5, args...) { v1, v2, v3, v4, v5 }
  65. #define ARRAY_4(v1, v2, v3, v4, args...) { v1, v2, v3, v4 }
  66. #define ARRAY_3(v1, v2, v3, args...) { v1, v2, v3 }
  67. #define ARRAY_2(v1, v2, args...) { v1, v2 }
  68. #define ARRAY_1(v1, args...) { v1 }
  69. #define _ARRAY_N(N, args...) ARRAY_ ##N(args)
  70. #define ARRAY_N(N, args...) _ARRAY_N(N, args)
  71. // Macros for adding
  72. #define INC_0 1
  73. #define INC_1 2
  74. #define INC_2 3
  75. #define INC_3 4
  76. #define INC_4 5
  77. #define INC_5 6
  78. #define INC_6 7
  79. #define INC_7 8
  80. #define INC_8 9
  81. #define INCREMENT_(n) INC_ ##n
  82. #define INCREMENT(n) INCREMENT_(n)
  83. // Macros for subtracting
  84. #define DEC_1 0
  85. #define DEC_2 1
  86. #define DEC_3 2
  87. #define DEC_4 3
  88. #define DEC_5 4
  89. #define DEC_6 5
  90. #define DEC_7 6
  91. #define DEC_8 7
  92. #define DEC_9 8
  93. #define DECREMENT_(n) DEC_ ##n
  94. #define DECREMENT(n) DECREMENT_(n)
  95. #define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0)
  96. #define PENDING(NOW,SOON) ((long)(NOW-(SOON))<0)
  97. #define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
  98. #define NOOP do{} while(0)
  99. #define CEILING(x,y) (((x) + (y) - 1) / (y))
  100. #endif //__MACROS_H