Browse Source

Merge Configuration Macros (PR#2495)

Richard Wackerbarth 10 years ago
parent
commit
72b9e3a6ac

+ 1
- 0
Marlin/Configuration.h View File

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

+ 0
- 8
Marlin/Marlin.h View File

28
 
28
 
29
 #include "Arduino.h"
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
 typedef unsigned long millis_t;
31
 typedef unsigned long millis_t;
40
 
32
 
41
 // Arduino < 1.0.0 does not define this, so we need to do it ourselves
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
     if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
3047
     if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
3048
       pin_number = code_value_short();
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
       if (sensitive_pins[i] == pin_number) {
3051
       if (sensitive_pins[i] == pin_number) {
3052
         pin_number = -1;
3052
         pin_number = -1;
3053
         break;
3053
         break;
4192
 
4192
 
4193
     if (pin_state >= -1 && pin_state <= 1) {
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
         if (sensitive_pins[i] == pin_number) {
4196
         if (sensitive_pins[i] == pin_number) {
4197
           pin_number = -1;
4197
           pin_number = -1;
4198
           break;
4198
           break;

+ 3
- 1
Marlin/Sd2PinMap.h View File

19
  */
19
  */
20
 // Warning this file was generated by a program.
20
 // Warning this file was generated by a program.
21
 #include "Marlin.h"
21
 #include "Marlin.h"
22
+#include "macros.h"
23
+
22
 #ifdef SDSUPPORT
24
 #ifdef SDSUPPORT
23
 
25
 
24
 #ifndef Sd2PinMap_h
26
 #ifndef Sd2PinMap_h
385
 #error unknown chip
387
 #error unknown chip
386
 #endif  // defined(__AVR_ATmega1280__)
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
 uint8_t badPinNumber(void)
392
 uint8_t badPinNumber(void)
391
   __attribute__((error("Pin number is too large or not a constant")));
393
   __attribute__((error("Pin number is too large or not a constant")));

+ 1
- 1
Marlin/configuration_store.cpp View File

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

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

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

+ 1
- 1
Marlin/digipot_mcp4451.cpp View File

50
   const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS;
50
   const float digipot_motor_current[] = DIGIPOT_I2C_MOTOR_CURRENTS;
51
   Wire.begin();
51
   Wire.begin();
52
   // setup initial currents as defined in Configuration_adv.h
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
     digipot_i2c_set_current(i, digipot_motor_current[i]);
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
 #define CONFIGURATION_H
2
 #define CONFIGURATION_H
3
 
3
 
4
 #include "boards.h"
4
 #include "boards.h"
5
+#include "macros.h"
5
 
6
 
6
 //===========================================================================
7
 //===========================================================================
7
 //============================= Getting Started =============================
8
 //============================= Getting Started =============================

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

+ 27
- 0
Marlin/macros.h View File

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
     pinMode(E0_MS1_PIN,OUTPUT);
1249
     pinMode(E0_MS1_PIN,OUTPUT);
1250
     pinMode(E0_MS2_PIN,OUTPUT);
1250
     pinMode(E0_MS2_PIN,OUTPUT);
1251
     const uint8_t microstep_modes[] = MICROSTEP_MODES;
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
       microstep_mode(i, microstep_modes[i]);
1253
       microstep_mode(i, microstep_modes[i]);
1254
   #endif
1254
   #endif
1255
 }
1255
 }

+ 2
- 0
Marlin/stepper_indirection.h View File

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

+ 6
- 5
Marlin/thermistortables.h View File

2
 #define THERMISTORTABLES_H_
2
 #define THERMISTORTABLES_H_
3
 
3
 
4
 #include "Marlin.h"
4
 #include "Marlin.h"
5
+#include "macros.h"
5
 
6
 
6
 #define OVERSAMPLENR 16
7
 #define OVERSAMPLENR 16
7
 
8
 
1123
 
1124
 
1124
 #ifdef THERMISTORHEATER_0
1125
 #ifdef THERMISTORHEATER_0
1125
 # define HEATER_0_TEMPTABLE TT_NAME(THERMISTORHEATER_0)
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
 #else
1128
 #else
1128
 # ifdef HEATER_0_USES_THERMISTOR
1129
 # ifdef HEATER_0_USES_THERMISTOR
1129
 #  error No heater 0 thermistor table specified
1130
 #  error No heater 0 thermistor table specified
1146
 
1147
 
1147
 #ifdef THERMISTORHEATER_1
1148
 #ifdef THERMISTORHEATER_1
1148
 # define HEATER_1_TEMPTABLE TT_NAME(THERMISTORHEATER_1)
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
 #else
1151
 #else
1151
 # ifdef HEATER_1_USES_THERMISTOR
1152
 # ifdef HEATER_1_USES_THERMISTOR
1152
 #  error No heater 1 thermistor table specified
1153
 #  error No heater 1 thermistor table specified
1169
 
1170
 
1170
 #ifdef THERMISTORHEATER_2
1171
 #ifdef THERMISTORHEATER_2
1171
 # define HEATER_2_TEMPTABLE TT_NAME(THERMISTORHEATER_2)
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
 #else
1174
 #else
1174
 # ifdef HEATER_2_USES_THERMISTOR
1175
 # ifdef HEATER_2_USES_THERMISTOR
1175
 #  error No heater 2 thermistor table specified
1176
 #  error No heater 2 thermistor table specified
1192
 
1193
 
1193
 #ifdef THERMISTORHEATER_3
1194
 #ifdef THERMISTORHEATER_3
1194
 # define HEATER_3_TEMPTABLE TT_NAME(THERMISTORHEATER_3)
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
 #else
1197
 #else
1197
 # ifdef HEATER_3_USES_THERMISTOR
1198
 # ifdef HEATER_3_USES_THERMISTOR
1198
 #  error No heater 3 thermistor table specified
1199
 #  error No heater 3 thermistor table specified
1215
 
1216
 
1216
 #ifdef THERMISTORBED
1217
 #ifdef THERMISTORBED
1217
 # define BEDTEMPTABLE TT_NAME(THERMISTORBED)
1218
 # define BEDTEMPTABLE TT_NAME(THERMISTORBED)
1218
-# define BEDTEMPTABLE_LEN (sizeof(BEDTEMPTABLE)/sizeof(*BEDTEMPTABLE))
1219
+# define BEDTEMPTABLE_LEN COUNT(BEDTEMPTABLE)
1219
 #else
1220
 #else
1220
 # ifdef BED_USES_THERMISTOR
1221
 # ifdef BED_USES_THERMISTOR
1221
 #  error No bed thermistor table specified
1222
 #  error No bed thermistor table specified

Loading…
Cancel
Save