Bläddra i källkod

Revert header reorg.

Scott Lahteine 6 år sedan
förälder
incheckning
ee53f7d813

+ 2
- 2
Marlin/src/HAL/HAL_AVR/endstop_interrupts.h Visa fil

38
 #ifndef _ENDSTOP_INTERRUPTS_H_
38
 #ifndef _ENDSTOP_INTERRUPTS_H_
39
 #define _ENDSTOP_INTERRUPTS_H_
39
 #define _ENDSTOP_INTERRUPTS_H_
40
 
40
 
41
-#include "../../module/endstops.h"
42
-#include "../../inc/MarlinConfig.h"
41
+#include "../../core/macros.h"
43
 #include <stdint.h>
42
 #include <stdint.h>
43
+#include "../../module/endstops.h"
44
 
44
 
45
 // One ISR for all EXT-Interrupts
45
 // One ISR for all EXT-Interrupts
46
 void endstop_ISR(void) { endstops.update(); }
46
 void endstop_ISR(void) { endstops.update(); }

+ 2
- 2
Marlin/src/HAL/HAL_DUE/DebugMonitor_Due.cpp Visa fil

22
 
22
 
23
 #ifdef ARDUINO_ARCH_SAM
23
 #ifdef ARDUINO_ARCH_SAM
24
 
24
 
25
+#include "../../core/macros.h"
25
 #include "../../core/serial.h"
26
 #include "../../core/serial.h"
27
+#include <stdarg.h>
26
 
28
 
27
 #include "../shared/backtrace/unwinder.h"
29
 #include "../shared/backtrace/unwinder.h"
28
 #include "../shared/backtrace/unwmemaccess.h"
30
 #include "../shared/backtrace/unwmemaccess.h"
29
 
31
 
30
-#include <stdarg.h>
31
-
32
 // Debug monitor that dumps to the Programming port all status when
32
 // Debug monitor that dumps to the Programming port all status when
33
 // an exception or WDT timeout happens - And then resets the board
33
 // an exception or WDT timeout happens - And then resets the board
34
 
34
 

+ 3
- 2
Marlin/src/HAL/HAL_DUE/usb/conf_usb.h Visa fil

47
 #ifndef _CONF_USB_H_
47
 #ifndef _CONF_USB_H_
48
 #define _CONF_USB_H_
48
 #define _CONF_USB_H_
49
 
49
 
50
-#include "../../../core/macros.h"       /* For ENABLED, DISABLED, MIN, MAX */
51
-#include "../../../../Configuration.h"  /* For SDSUPPORT and CUSTOM_MACHINE_NAME definition - We just need the name, no C++ allowed! */
50
+#undef UNUSED                           /* To avoid a macro clash as macros.h already defines it */
51
+#include "../../../core/macros.h"       /* For ENABLED()/DISABLED() */
52
+#include "../../../../Configuration.h"  /* For CUSTOM_MACHINE_NAME definition - We just need the name, no C++ allowed! */
52
 #include "compiler.h"
53
 #include "compiler.h"
53
 
54
 
54
 /**
55
 /**

+ 1
- 1
Marlin/src/HAL/HAL_LPC1768/spi_pins.h Visa fil

23
 #ifndef SPI_PINS_LPC1768_H
23
 #ifndef SPI_PINS_LPC1768_H
24
 #define SPI_PINS_LPC1768_H
24
 #define SPI_PINS_LPC1768_H
25
 
25
 
26
-#include "../../inc/MarlinConfigPre.h"
26
+#include "src/core/macros.h"
27
 
27
 
28
 #if ENABLED(SDSUPPORT) && ENABLED(DOGLCD) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
28
 #if ENABLED(SDSUPPORT) && ENABLED(DOGLCD) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
29
   #define LPC_SOFTWARE_SPI  // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
29
   #define LPC_SOFTWARE_SPI  // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently

+ 0
- 113
Marlin/src/core/config.h Visa fil

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
-#pragma once
23
-
24
-// Macros to make a string from a macro
25
-#define STRINGIFY_(M) #M
26
-#define STRINGIFY(M) STRINGIFY_(M)
27
-
28
-// Macros for bit masks
29
-#undef _BV
30
-#define _BV(n) (1<<(n))
31
-#define TEST(n,b) !!((n)&_BV(b))
32
-#define SBI(n,b) (n |= _BV(b))
33
-#define CBI(n,b) (n &= ~_BV(b))
34
-
35
-#define _BV32(b) (1UL << (b))
36
-#define TEST32(n,b) !!((n)&_BV32(b))
37
-#define SBI32(n,b) (n |= _BV32(b))
38
-#define CBI32(n,b) (n &= ~_BV32(b))
39
-
40
-// Macros for maths shortcuts
41
-#undef M_PI
42
-#define M_PI 3.14159265358979323846f
43
-
44
-// Macros to support option testing
45
-#define _CAT(a, ...) a ## __VA_ARGS__
46
-#define SWITCH_ENABLED_false 0
47
-#define SWITCH_ENABLED_true  1
48
-#define SWITCH_ENABLED_0     0
49
-#define SWITCH_ENABLED_1     1
50
-#define SWITCH_ENABLED_0x0   0
51
-#define SWITCH_ENABLED_0x1   1
52
-#define SWITCH_ENABLED_      1
53
-#define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
54
-#define DISABLED(b) !ENABLED(b)
55
-
56
-#define WITHIN(V,L,H) ((V) >= (L) && (V) <= (H))
57
-#define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))
58
-
59
-// Macros for initializing arrays
60
-#define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }
61
-#define ARRAY_5(v1, v2, v3, v4, v5, ...)     { v1, v2, v3, v4, v5 }
62
-#define ARRAY_4(v1, v2, v3, v4, ...)         { v1, v2, v3, v4 }
63
-#define ARRAY_3(v1, v2, v3, ...)             { v1, v2, v3 }
64
-#define ARRAY_2(v1, v2, ...)                 { v1, v2 }
65
-#define ARRAY_1(v1, ...)                     { v1 }
66
-#define _ARRAY_N(N, ...) ARRAY_ ##N(__VA_ARGS__)
67
-#define ARRAY_N(N, ...) _ARRAY_N(N, __VA_ARGS__)
68
-
69
-// Pins
70
-#define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0)
71
-
72
-// Increment/Decrement helper macros
73
-#define INC_0 1
74
-#define INC_1 2
75
-#define INC_2 3
76
-#define INC_3 4
77
-#define INC_4 5
78
-#define INC_5 6
79
-#define INC_6 7
80
-#define INC_7 8
81
-#define INC_8 9
82
-#define _INCREMENT(n) INC_ ##n
83
-#define INCREMENT(n) _INCREMENT(n)
84
-
85
-#define DEC_1 0
86
-#define DEC_2 1
87
-#define DEC_3 2
88
-#define DEC_4 3
89
-#define DEC_5 4
90
-#define DEC_6 5
91
-#define DEC_7 6
92
-#define DEC_8 7
93
-#define DEC_9 8
94
-#define DECREMENT_(n) DEC_ ##n
95
-#define DECREMENT(n) DECREMENT_(n)
96
-
97
-// Endstop plug identifiers
98
-#define _XMIN_ 100
99
-#define _YMIN_ 200
100
-#define _ZMIN_ 300
101
-#define _XMAX_ 101
102
-#define _YMAX_ 201
103
-#define _ZMAX_ 301
104
-
105
-// GCC properties for HAL headers
106
-#define _FORCE_INLINE_ __attribute__((__always_inline__)) __inline__
107
-#define  FORCE_INLINE  __attribute__((always_inline)) inline
108
-#define _UNUSED      __attribute__((unused))
109
-#define _O0          __attribute__((optimize("O0")))
110
-#define _Os          __attribute__((optimize("Os")))
111
-#define _O1          __attribute__((optimize("O1")))
112
-#define _O2          __attribute__((optimize("O2")))
113
-#define _O3          __attribute__((optimize("O3")))

+ 107
- 57
Marlin/src/core/macros.h Visa fil

19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
  *
20
  *
21
  */
21
  */
22
+
22
 #pragma once
23
 #pragma once
23
 
24
 
24
-#include "config.h"
25
+#include "minmax.h"
25
 
26
 
26
 #define NUM_AXIS 4
27
 #define NUM_AXIS 4
27
 #define ABCE 4
28
 #define ABCE 4
31
 
32
 
32
 #define _AXIS(A) (A##_AXIS)
33
 #define _AXIS(A) (A##_AXIS)
33
 
34
 
35
+#define _XMIN_ 100
36
+#define _YMIN_ 200
37
+#define _ZMIN_ 300
38
+#define _XMAX_ 101
39
+#define _YMAX_ 201
40
+#define _ZMAX_ 301
41
+
42
+#define _FORCE_INLINE_ __attribute__((__always_inline__)) __inline__
43
+#define  FORCE_INLINE  __attribute__((always_inline)) inline
44
+#define _UNUSED      __attribute__((unused))
45
+#define _O0          __attribute__((optimize("O0")))
46
+#define _Os          __attribute__((optimize("Os")))
47
+#define _O1          __attribute__((optimize("O1")))
48
+#define _O2          __attribute__((optimize("O2")))
49
+#define _O3          __attribute__((optimize("O3")))
50
+
34
 // Clock speed factors
51
 // Clock speed factors
35
 #if !defined(CYCLES_PER_MICROSECOND) && !defined(__STM32F1__)
52
 #if !defined(CYCLES_PER_MICROSECOND) && !defined(__STM32F1__)
36
   #define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20 on AVR
53
   #define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20 on AVR
40
 #define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
57
 #define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
41
 
58
 
42
 // Remove compiler warning on an unused variable
59
 // Remove compiler warning on an unused variable
43
-#undef UNUSED
44
 #define UNUSED(x) ((void)(x))
60
 #define UNUSED(x) ((void)(x))
45
 
61
 
46
-// Assembly wrappers for code and labels
62
+// Macros to make a string from a macro
63
+#define STRINGIFY_(M) #M
64
+#define STRINGIFY(M) STRINGIFY_(M)
65
+
47
 #define A(CODE) " " CODE "\n\t"
66
 #define A(CODE) " " CODE "\n\t"
48
 #define L(CODE) CODE ":\n\t"
67
 #define L(CODE) CODE ":\n\t"
49
 
68
 
50
 // Macros for bit masks
69
 // Macros for bit masks
70
+#undef _BV
71
+#define _BV(n) (1<<(n))
72
+#define TEST(n,b) !!((n)&_BV(b))
73
+#define SBI(n,b) (n |= _BV(b))
74
+#define CBI(n,b) (n &= ~_BV(b))
51
 #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
75
 #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
52
 
76
 
77
+#define _BV32(b) (1UL << (b))
78
+#define TEST32(n,b) !!((n)&_BV32(b))
79
+#define SBI32(n,b) (n |= _BV32(b))
80
+#define CBI32(n,b) (n &= ~_BV32(b))
81
+
82
+// Macros for maths shortcuts
83
+#undef M_PI
84
+#define M_PI 3.14159265358979323846f
85
+
53
 #define RADIANS(d) ((d)*float(M_PI)/180.0f)
86
 #define RADIANS(d) ((d)*float(M_PI)/180.0f)
54
 #define DEGREES(r) ((r)*180.0f/float(M_PI))
87
 #define DEGREES(r) ((r)*180.0f/float(M_PI))
55
 #define HYPOT2(x,y) (sq(x)+sq(y))
88
 #define HYPOT2(x,y) (sq(x)+sq(y))
58
 #define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R))
91
 #define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R))
59
 
92
 
60
 #define SIGN(a) ((a>0)-(a<0))
93
 #define SIGN(a) ((a>0)-(a<0))
94
+#define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))
61
 
95
 
62
-// Convenience templates / macros
63
-#undef ABS
64
-#undef MIN
65
-#undef MAX
96
+// Macros to constrain values
66
 #ifdef __cplusplus
97
 #ifdef __cplusplus
67
 
98
 
68
-  // Standards-compliant C++11 solutions
69
-
70
-  extern "C++" {
71
-
72
-    template <class T> static inline constexpr const T ABS(const T v) { return v >= 0 ? v : -v; }
73
-
74
-    template <class V, class N> static inline constexpr void NOLESS(V& v, const N n) {
75
-      if (v < n) v = n;
76
-    }
77
-    template <class V, class N> static inline constexpr void NOMORE(V& v, const N n) {
78
-      if (v > n) v = n;
79
-    }
80
-    template <class V, class N1, class N2> static inline constexpr void LIMIT(V& v, const N1 n1, const N2 n2) {
81
-      if (v < n1) v = n1;
82
-      else if (v > n2) v = n2;
83
-    }
84
-
85
-    template <class L, class R> static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
86
-      return lhs < rhs ? lhs : rhs;
87
-    }
88
-    template <class L, class R> static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
89
-      return lhs > rhs ? lhs : rhs;
90
-    }
91
-    template<class T, class ... Ts> static inline constexpr const T MIN(T V, Ts... Vs) { return MIN(V, MIN(Vs...)); }
92
-    template<class T, class ... Ts> static inline constexpr const T MAX(T V, Ts... Vs) { return MAX(V, MAX(Vs...)); }
93
-
99
+  // C++11 solution that is standards compliant.
100
+  template <class V, class N> static inline constexpr void NOLESS(V& v, const N n) {
101
+    if (v < n) v = n;
102
+  }
103
+  template <class V, class N> static inline constexpr void NOMORE(V& v, const N n) {
104
+    if (v > n) v = n;
105
+  }
106
+  template <class V, class N1, class N2> static inline constexpr void LIMIT(V& v, const N1 n1, const N2 n2) {
107
+    if (v < n1) v = n1;
108
+    else if (v > n2) v = n2;
94
   }
109
   }
95
 
110
 
96
 #else
111
 #else
97
 
112
 
98
-  #define ABS(a) ({__typeof__(a) _a = (a); _a >= 0 ? _a : -_a;})
99
-
100
   // Using GCC extensions, but Travis GCC version does not like it and gives
113
   // Using GCC extensions, but Travis GCC version does not like it and gives
101
   //  "error: statement-expressions are not allowed outside functions nor in template-argument lists"
114
   //  "error: statement-expressions are not allowed outside functions nor in template-argument lists"
102
   #define NOLESS(v, n) \
115
   #define NOLESS(v, n) \
119
       else if (v > _n2) v = _n2; \
132
       else if (v > _n2) v = _n2; \
120
     } while(0)
133
     } while(0)
121
 
134
 
122
-  // NUM_ARGS(...) evaluates to the number of arguments
123
-  #define _NUM_ARGS(X,X6,X5,X4,X3,X2,X1,N,...) N
124
-  #define NUM_ARGS(...) _NUM_ARGS(0, __VA_ARGS__ ,6,5,4,3,2,1,0)
125
-
126
-  #define MIN_2(a,b)      ({__typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b;})
127
-  #define MIN_3(a,...)    MIN_2(a,MIN_2(__VA_ARGS__))
128
-  #define MIN_4(a,...)    MIN_2(a,MIN_3(__VA_ARGS__))
129
-  #define MIN_5(a,...)    MIN_2(a,MIN_4(__VA_ARGS__))
130
-  #define MIN_6(a,...)    MIN_2(a,MIN_5(__VA_ARGS__))
131
-  #define __MIN_N(N, ...) MIN_ ## N(__VA_ARGS__)
132
-  #define _MIN_N(N, ...)  __MIN_N(N, __VA_ARGS__)
133
-  #define MIN(...)        _MIN_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
134
-
135
-  #define MAX_2(a,b)      ({__typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b;})
136
-  #define MAX_3(a,...)    MAX_2(a,MAX_2(__VA_ARGS__))
137
-  #define MAX_4(a,...)    MAX_2(a,MAX_3(__VA_ARGS__))
138
-  #define MAX_5(a,...)    MAX_2(a,MAX_4(__VA_ARGS__))
139
-  #define MAX_6(a,...)    MAX_2(a,MAX_5(__VA_ARGS__))
140
-  #define __MAX_N(N, ...) MAX_ ## N(__VA_ARGS__)
141
-  #define _MAX_N(N, ...)  __MAX_N(N, __VA_ARGS__)
142
-  #define MAX(...)        _MAX_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
143
-
144
 #endif
135
 #endif
145
 
136
 
137
+// Macros to support option testing
138
+#define _CAT(a, ...) a ## __VA_ARGS__
139
+#define SWITCH_ENABLED_false 0
140
+#define SWITCH_ENABLED_true  1
141
+#define SWITCH_ENABLED_0     0
142
+#define SWITCH_ENABLED_1     1
143
+#define SWITCH_ENABLED_0x0   0
144
+#define SWITCH_ENABLED_0x1   1
145
+#define SWITCH_ENABLED_      1
146
+#define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
147
+#define DISABLED(b) !ENABLED(b)
148
+
149
+#define WITHIN(V,L,H) ((V) >= (L) && (V) <= (H))
146
 #define NUMERIC(a) WITHIN(a, '0', '9')
150
 #define NUMERIC(a) WITHIN(a, '0', '9')
147
 #define DECIMAL(a) (NUMERIC(a) || a == '.')
151
 #define DECIMAL(a) (NUMERIC(a) || a == '.')
148
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+')
152
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-' || (a) == '+')
151
 #define ZERO(a) memset(a,0,sizeof(a))
155
 #define ZERO(a) memset(a,0,sizeof(a))
152
 #define COPY(a,b) memcpy(a,b,MIN(sizeof(a),sizeof(b)))
156
 #define COPY(a,b) memcpy(a,b,MIN(sizeof(a),sizeof(b)))
153
 
157
 
158
+// Macros for initializing arrays
159
+#define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }
160
+#define ARRAY_5(v1, v2, v3, v4, v5, ...)     { v1, v2, v3, v4, v5 }
161
+#define ARRAY_4(v1, v2, v3, v4, ...)         { v1, v2, v3, v4 }
162
+#define ARRAY_3(v1, v2, v3, ...)             { v1, v2, v3 }
163
+#define ARRAY_2(v1, v2, ...)                 { v1, v2 }
164
+#define ARRAY_1(v1, ...)                     { v1 }
165
+
166
+#define _ARRAY_N(N, ...) ARRAY_ ##N(__VA_ARGS__)
167
+#define ARRAY_N(N, ...) _ARRAY_N(N, __VA_ARGS__)
168
+
169
+// Macros for adding
170
+#define INC_0 1
171
+#define INC_1 2
172
+#define INC_2 3
173
+#define INC_3 4
174
+#define INC_4 5
175
+#define INC_5 6
176
+#define INC_6 7
177
+#define INC_7 8
178
+#define INC_8 9
179
+#define INCREMENT_(n) INC_ ##n
180
+#define INCREMENT(n) INCREMENT_(n)
181
+
182
+// Macros for subtracting
183
+#define DEC_1 0
184
+#define DEC_2 1
185
+#define DEC_3 2
186
+#define DEC_4 3
187
+#define DEC_5 4
188
+#define DEC_6 5
189
+#define DEC_7 6
190
+#define DEC_8 7
191
+#define DEC_9 8
192
+#define DECREMENT_(n) DEC_ ##n
193
+#define DECREMENT(n) DECREMENT_(n)
194
+
195
+#define PIN_EXISTS(PN) (defined(PN ##_PIN) && PN ##_PIN >= 0)
196
+
154
 #define PENDING(NOW,SOON) ((long)(NOW-(SOON))<0)
197
 #define PENDING(NOW,SOON) ((long)(NOW-(SOON))<0)
155
 #define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
198
 #define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
156
 
199
 
161
 
204
 
162
 #define CEILING(x,y) (((x) + (y) - 1) / (y))
205
 #define CEILING(x,y) (((x) + (y) - 1) / (y))
163
 
206
 
207
+#undef ABS
208
+#ifdef __cplusplus
209
+  template <class T> static inline constexpr const T ABS(const T v) { return v >= 0 ? v : -v; }
210
+#else
211
+  #define ABS(a) ({__typeof__(a) _a = (a); _a >= 0 ? _a : -_a;})
212
+#endif
213
+
164
 #define UNEAR_ZERO(x) ((x) < 0.000001f)
214
 #define UNEAR_ZERO(x) ((x) < 0.000001f)
165
 #define NEAR_ZERO(x) WITHIN(x, -0.000001f, 0.000001f)
215
 #define NEAR_ZERO(x) WITHIN(x, -0.000001f, 0.000001f)
166
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
216
 #define NEAR(x,y) NEAR_ZERO((x)-(y))

+ 71
- 0
Marlin/src/core/minmax.h Visa fil

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
+
23
+#undef MIN
24
+#undef MAX
25
+
26
+#ifdef __cplusplus
27
+
28
+  #ifndef _MINMAX_H_
29
+  #define _MINMAX_H_
30
+
31
+    extern "C++" {
32
+
33
+      // C++11 solution that is standards compliant. Return type is deduced automatically
34
+      template <class L, class R> static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
35
+        return lhs < rhs ? lhs : rhs;
36
+      }
37
+      template <class L, class R> static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs) {
38
+        return lhs > rhs ? lhs : rhs;
39
+      }
40
+      template<class T, class ... Ts> static inline constexpr const T MIN(T V, Ts... Vs) { return MIN(V, MIN(Vs...)); }
41
+      template<class T, class ... Ts> static inline constexpr const T MAX(T V, Ts... Vs) { return MAX(V, MAX(Vs...)); }
42
+
43
+    }
44
+
45
+  #endif
46
+
47
+#else
48
+
49
+  // NUM_ARGS(...) evaluates to the number of arguments
50
+  #define _NUM_ARGS(X,X6,X5,X4,X3,X2,X1,N,...) N
51
+  #define NUM_ARGS(...) _NUM_ARGS(0, __VA_ARGS__ ,6,5,4,3,2,1,0)
52
+
53
+  #define MIN_2(a,b)      ({__typeof__(a) _a = (a); __typeof__(b) _b = (b); _a < _b ? _a : _b;})
54
+  #define MIN_3(a,...)    MIN_2(a,MIN_2(__VA_ARGS__))
55
+  #define MIN_4(a,...)    MIN_2(a,MIN_3(__VA_ARGS__))
56
+  #define MIN_5(a,...)    MIN_2(a,MIN_4(__VA_ARGS__))
57
+  #define MIN_6(a,...)    MIN_2(a,MIN_5(__VA_ARGS__))
58
+  #define __MIN_N(N, ...) MIN_ ## N(__VA_ARGS__)
59
+  #define _MIN_N(N, ...)  __MIN_N(N, __VA_ARGS__)
60
+  #define MIN(...)        _MIN_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
61
+
62
+  #define MAX_2(a,b)      ({__typeof__(a) _a = (a); __typeof__(b) _b = (b); _a > _b ? _a : _b;})
63
+  #define MAX_3(a,...)    MAX_2(a,MAX_2(__VA_ARGS__))
64
+  #define MAX_4(a,...)    MAX_2(a,MAX_3(__VA_ARGS__))
65
+  #define MAX_5(a,...)    MAX_2(a,MAX_4(__VA_ARGS__))
66
+  #define MAX_6(a,...)    MAX_2(a,MAX_5(__VA_ARGS__))
67
+  #define __MAX_N(N, ...) MAX_ ## N(__VA_ARGS__)
68
+  #define _MAX_N(N, ...)  __MAX_N(N, __VA_ARGS__)
69
+  #define MAX(...)        _MAX_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
70
+
71
+#endif

+ 1
- 1
Marlin/src/feature/twibus.h Visa fil

23
 #ifndef TWIBUS_H
23
 #ifndef TWIBUS_H
24
 #define TWIBUS_H
24
 #define TWIBUS_H
25
 
25
 
26
-#include "../inc/MarlinConfigPre.h"
26
+#include "../core/macros.h"
27
 
27
 
28
 #include <Wire.h>
28
 #include <Wire.h>
29
 
29
 

+ 1
- 0
Marlin/src/inc/MarlinConfig.h Visa fil

45
 #include "../core/language.h"
45
 #include "../core/language.h"
46
 #include "../core/utility.h"
46
 #include "../core/utility.h"
47
 #include "../core/serial.h"
47
 #include "../core/serial.h"
48
+#include "../core/minmax.h"

+ 1
- 2
Marlin/src/inc/MarlinConfigPre.h Visa fil

27
 
27
 
28
 #include "../HAL/platforms.h"
28
 #include "../HAL/platforms.h"
29
 #include "../core/boards.h"
29
 #include "../core/boards.h"
30
+#include "../core/macros.h"
30
 #include "../core/types.h"
31
 #include "../core/types.h"
31
-#include "../core/config.h"
32
 #include "Version.h"
32
 #include "Version.h"
33
 #include "../../Configuration.h"
33
 #include "../../Configuration.h"
34
 #include "Conditionals_LCD.h"
34
 #include "Conditionals_LCD.h"
35
 #include "../core/drivers.h"
35
 #include "../core/drivers.h"
36
 #include "../../Configuration_adv.h"
36
 #include "../../Configuration_adv.h"
37
 #include "Conditionals_adv.h"
37
 #include "Conditionals_adv.h"
38
-#include "../core/macros.h"

+ 1
- 1
Marlin/src/inc/Version.h Visa fil

23
 #ifndef _VERSION_H_
23
 #ifndef _VERSION_H_
24
 #define _VERSION_H_
24
 #define _VERSION_H_
25
 
25
 
26
-#include "../core/config.h" // for ENABLED
26
+#include "../core/macros.h" // for ENABLED
27
 
27
 
28
 /**
28
 /**
29
  * This file is the standard Marlin version identifier file.
29
  * This file is the standard Marlin version identifier file.

Laddar…
Avbryt
Spara