Browse Source

Merge Configuration Macros (PR#2495)

Richard Wackerbarth 10 years ago
parent
commit
72b9e3a6ac

+ 1
- 0
Marlin/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 0
- 8
Marlin/Marlin.h View File

@@ -28,14 +28,6 @@
28 28
 
29 29
 #include "Arduino.h"
30 30
 
31
-#define BIT(b) (1<<(b))
32
-#define TEST(n,b) (((n)&BIT(b))!=0)
33
-#define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (BIT(b))
34
-#define RADIANS(d) ((d)*M_PI/180.0)
35
-#define DEGREES(r) ((r)*180.0/M_PI)
36
-#define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
37
-#define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
38
-
39 31
 typedef unsigned long millis_t;
40 32
 
41 33
 // Arduino < 1.0.0 does not define this, so we need to do it ourselves

+ 2
- 2
Marlin/Marlin_main.cpp View File

@@ -3047,7 +3047,7 @@ inline void gcode_M42() {
3047 3047
     if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
3048 3048
       pin_number = code_value_short();
3049 3049
 
3050
-    for (int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins) / sizeof(*sensitive_pins)); i++) {
3050
+    for (int8_t i = 0; i < COUNT(sensitive_pins); i++) {
3051 3051
       if (sensitive_pins[i] == pin_number) {
3052 3052
         pin_number = -1;
3053 3053
         break;
@@ -4192,7 +4192,7 @@ inline void gcode_M226() {
4192 4192
 
4193 4193
     if (pin_state >= -1 && pin_state <= 1) {
4194 4194
 
4195
-      for (int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(*sensitive_pins)); i++) {
4195
+      for (int8_t i = 0; i < COUNT(sensitive_pins); i++) {
4196 4196
         if (sensitive_pins[i] == pin_number) {
4197 4197
           pin_number = -1;
4198 4198
           break;

+ 3
- 1
Marlin/Sd2PinMap.h View File

@@ -19,6 +19,8 @@
19 19
  */
20 20
 // Warning this file was generated by a program.
21 21
 #include "Marlin.h"
22
+#include "macros.h"
23
+
22 24
 #ifdef SDSUPPORT
23 25
 
24 26
 #ifndef Sd2PinMap_h
@@ -385,7 +387,7 @@ static const pin_map_t digitalPinMap[] = {
385 387
 #error unknown chip
386 388
 #endif  // defined(__AVR_ATmega1280__)
387 389
 //------------------------------------------------------------------------------
388
-static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
390
+static const uint8_t digitalPinCount = COUNT(digitalPinMap);
389 391
 
390 392
 uint8_t badPinNumber(void)
391 393
   __attribute__((error("Pin number is too large or not a constant")));

+ 1
- 1
Marlin/configuration_store.cpp View File

@@ -475,7 +475,7 @@ void Config_ResetDefault() {
475 475
     max_feedrate[i] = tmp2[i];
476 476
     max_acceleration_units_per_sq_second[i] = tmp3[i];
477 477
     #ifdef SCARA
478
-      if (i < sizeof(axis_scaling) / sizeof(*axis_scaling))
478
+      if (i < COUNT(axis_scaling))
479 479
         axis_scaling[i] = 1;
480 480
     #endif
481 481
   }

+ 1
- 0
Marlin/configurator/config/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 1
Marlin/digipot_mcp4451.cpp View File

@@ -50,7 +50,7 @@ void digipot_i2c_init() {
50 50
   const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS;
51 51
   Wire.begin();
52 52
   // setup initial currents as defined in Configuration_adv.h
53
-  for(int i = 0; i <= sizeof(digipot_motor_current) / sizeof(float); i++) {
53
+  for(int i = 0; i < COUNT(digipot_motor_current); i++) {
54 54
     digipot_i2c_set_current(i, digipot_motor_current[i]);
55 55
   }
56 56
 }

+ 1
- 0
Marlin/example_configurations/Felix/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/Felix/Configuration_DUAL.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/Hephestos/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/K8200/Configuration.h View File

@@ -7,6 +7,7 @@
7 7
 #define CONFIGURATION_H
8 8
 
9 9
 #include "boards.h"
10
+#include "macros.h"
10 11
 
11 12
 //===========================================================================
12 13
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/RepRapWorld/Megatronics/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/RigidBot/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/SCARA/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/WITBOX/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/adafruit/ST7565/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/delta/biv2.5/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/delta/generic/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/delta/kossel_mini/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration.h View File

@@ -6,6 +6,7 @@
6 6
 #define CONFIGURATION_H
7 7
 
8 8
 #include "boards.h"
9
+#include "macros.h"
9 10
 
10 11
 //===========================================================================
11 12
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/makibox/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 1
- 0
Marlin/example_configurations/tvrrug/Round2/Configuration.h View File

@@ -2,6 +2,7 @@
2 2
 #define CONFIGURATION_H
3 3
 
4 4
 #include "boards.h"
5
+#include "macros.h"
5 6
 
6 7
 //===========================================================================
7 8
 //============================= Getting Started =============================

+ 27
- 0
Marlin/macros.h View File

@@ -0,0 +1,27 @@
1
+#ifndef MACROS_H
2
+#define MACROS_H
3
+
4
+// Macros for bit masks
5
+#define BIT(b) (1<<(b))
6
+#define TEST(n,b) (((n)&BIT(b))!=0)
7
+#define SET_BIT(n,b,value) (n) ^= ((-value)^(n)) & (BIT(b))
8
+
9
+// Macros for maths shortcuts
10
+#define RADIANS(d) ((d)*M_PI/180.0)
11
+#define DEGREES(r) ((r)*180.0/M_PI)
12
+
13
+// Macros to contrain values
14
+#define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
15
+#define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
16
+
17
+// Macros to support option testing
18
+#define _CAT(a, ...) a ## __VA_ARGS__
19
+#define SWITCH_ENABLED_0 0
20
+#define SWITCH_ENABLED_1 1
21
+#define SWITCH_ENABLED_  1
22
+#define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
23
+#define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
24
+
25
+#define COUNT(a) (sizeof(a)/sizeof(*a))
26
+
27
+#endif //__MACROS_H

+ 1
- 1
Marlin/stepper.cpp View File

@@ -1249,7 +1249,7 @@ void microstep_init() {
1249 1249
     pinMode(E0_MS1_PIN,OUTPUT);
1250 1250
     pinMode(E0_MS2_PIN,OUTPUT);
1251 1251
     const uint8_t microstep_modes[] = MICROSTEP_MODES;
1252
-    for (uint16_t i = 0; i < sizeof(microstep_modes) / sizeof(microstep_modes[0]); i++)
1252
+    for (uint16_t i = 0; i < COUNT(microstep_modes); i++)
1253 1253
       microstep_mode(i, microstep_modes[i]);
1254 1254
   #endif
1255 1255
 }

+ 2
- 0
Marlin/stepper_indirection.h View File

@@ -22,6 +22,8 @@
22 22
 #ifndef STEPPER_INDIRECTION_H
23 23
 #define STEPPER_INDIRECTION_H
24 24
 
25
+#include "macros.h"
26
+
25 27
 // X motor
26 28
 #define X_STEP_INIT SET_OUTPUT(X_STEP_PIN)
27 29
 #define X_STEP_WRITE(STATE) WRITE(X_STEP_PIN,STATE)

+ 6
- 5
Marlin/thermistortables.h View File

@@ -2,6 +2,7 @@
2 2
 #define THERMISTORTABLES_H_
3 3
 
4 4
 #include "Marlin.h"
5
+#include "macros.h"
5 6
 
6 7
 #define OVERSAMPLENR 16
7 8
 
@@ -1123,7 +1124,7 @@ const short temptable_1047[][2] PROGMEM = {
1123 1124
 
1124 1125
 #ifdef THERMISTORHEATER_0
1125 1126
 # define HEATER_0_TEMPTABLE TT_NAME(THERMISTORHEATER_0)
1126
-# define HEATER_0_TEMPTABLE_LEN (sizeof(HEATER_0_TEMPTABLE)/sizeof(*HEATER_0_TEMPTABLE))
1127
+# define HEATER_0_TEMPTABLE_LEN COUNT(HEATER_0_TEMPTABLE)
1127 1128
 #else
1128 1129
 # ifdef HEATER_0_USES_THERMISTOR
1129 1130
 #  error No heater 0 thermistor table specified
@@ -1146,7 +1147,7 @@ const short temptable_1047[][2] PROGMEM = {
1146 1147
 
1147 1148
 #ifdef THERMISTORHEATER_1
1148 1149
 # define HEATER_1_TEMPTABLE TT_NAME(THERMISTORHEATER_1)
1149
-# define HEATER_1_TEMPTABLE_LEN (sizeof(HEATER_1_TEMPTABLE)/sizeof(*HEATER_1_TEMPTABLE))
1150
+# define HEATER_1_TEMPTABLE_LEN COUNT(HEATER_1_TEMPTABLE)
1150 1151
 #else
1151 1152
 # ifdef HEATER_1_USES_THERMISTOR
1152 1153
 #  error No heater 1 thermistor table specified
@@ -1169,7 +1170,7 @@ const short temptable_1047[][2] PROGMEM = {
1169 1170
 
1170 1171
 #ifdef THERMISTORHEATER_2
1171 1172
 # define HEATER_2_TEMPTABLE TT_NAME(THERMISTORHEATER_2)
1172
-# define HEATER_2_TEMPTABLE_LEN (sizeof(HEATER_2_TEMPTABLE)/sizeof(*HEATER_2_TEMPTABLE))
1173
+# define HEATER_2_TEMPTABLE_LEN COUNT(HEATER_2_TEMPTABLE)
1173 1174
 #else
1174 1175
 # ifdef HEATER_2_USES_THERMISTOR
1175 1176
 #  error No heater 2 thermistor table specified
@@ -1192,7 +1193,7 @@ const short temptable_1047[][2] PROGMEM = {
1192 1193
 
1193 1194
 #ifdef THERMISTORHEATER_3
1194 1195
 # define HEATER_3_TEMPTABLE TT_NAME(THERMISTORHEATER_3)
1195
-# define HEATER_3_TEMPTABLE_LEN (sizeof(HEATER_3_TEMPTABLE)/sizeof(*HEATER_3_TEMPTABLE))
1196
+# define HEATER_3_TEMPTABLE_LEN COUNT(HEATER_3_TEMPTABLE)
1196 1197
 #else
1197 1198
 # ifdef HEATER_3_USES_THERMISTOR
1198 1199
 #  error No heater 3 thermistor table specified
@@ -1215,7 +1216,7 @@ const short temptable_1047[][2] PROGMEM = {
1215 1216
 
1216 1217
 #ifdef THERMISTORBED
1217 1218
 # define BEDTEMPTABLE TT_NAME(THERMISTORBED)
1218
-# define BEDTEMPTABLE_LEN (sizeof(BEDTEMPTABLE)/sizeof(*BEDTEMPTABLE))
1219
+# define BEDTEMPTABLE_LEN COUNT(BEDTEMPTABLE)
1219 1220
 #else
1220 1221
 # ifdef BED_USES_THERMISTOR
1221 1222
 #  error No bed thermistor table specified

Loading…
Cancel
Save