Improve sanity checks with static_assert, organize

This commit is contained in:
Scott Lahteine 2017-06-06 07:19:27 -05:00
parent 6bb05c4543
commit 9128d9ab45

View File

@ -270,23 +270,6 @@
#endif #endif
#endif #endif
/**
* Delta requirements
*/
#if ENABLED(DELTA)
#if DISABLED(USE_XMAX_PLUG) && DISABLED(USE_YMAX_PLUG) && DISABLED(USE_ZMAX_PLUG)
#error "You probably want to use Max Endstops for DELTA!"
#elif ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_BILINEAR) && !UBL_DELTA
#error "ENABLE_LEVELING_FADE_HEIGHT on DELTA requires AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL."
#elif ABL_GRID
#if (GRID_MAX_POINTS_X & 1) == 0 || (GRID_MAX_POINTS_Y & 1) == 0
#error "DELTA requires GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y to be odd numbers."
#elif GRID_MAX_POINTS_X < 3
#error "DELTA requires GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y to be 3 or higher."
#endif
#endif
#endif
/** /**
* Babystepping * Babystepping
*/ */
@ -430,44 +413,57 @@
#endif #endif
/** /**
* Allow only one bed leveling option to be defined * Kinematics
*/
/**
* Allow only one kinematic type to be defined
*/ */
static_assert(1 >= 0 static_assert(1 >= 0
#if ENABLED(AUTO_BED_LEVELING_LINEAR) #if ENABLED(DELTA)
+ 1 + 1
#endif #endif
#if ENABLED(AUTO_BED_LEVELING_3POINT) #if ENABLED(MORGAN_SCARA)
+ 1 + 1
#endif #endif
#if ENABLED(AUTO_BED_LEVELING_BILINEAR) #if ENABLED(MAKERARM_SCARA)
+ 1 + 1
#endif #endif
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(COREXY)
+ 1 + 1
#endif #endif
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(COREXZ)
+ 1 + 1
#endif #endif
, "Select only one of: MESH_BED_LEVELING, AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL." #if ENABLED(COREYZ)
+ 1
#endif
#if ENABLED(COREYX)
+ 1
#endif
#if ENABLED(COREZX)
+ 1
#endif
#if ENABLED(COREZY)
+ 1
#endif
, "Please enable only one of DELTA, MORGAN_SCARA, MAKERARM_SCARA, COREXY, COREYX, COREXZ, COREZX, COREYZ, or COREZY."
); );
/** /**
* Mesh Bed Leveling * Delta requirements
*/ */
#if ENABLED(MESH_BED_LEVELING) #if ENABLED(DELTA)
#if ENABLED(DELTA) #if DISABLED(USE_XMAX_PLUG) && DISABLED(USE_YMAX_PLUG) && DISABLED(USE_ZMAX_PLUG)
#error "MESH_BED_LEVELING does not yet support DELTA printers." #error "You probably want to use Max Endstops for DELTA!"
#elif GRID_MAX_POINTS_X > 9 || GRID_MAX_POINTS_Y > 9 #elif ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_BILINEAR) && !UBL_DELTA
#error "GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y must be less than 10 for MBL." #error "ENABLE_LEVELING_FADE_HEIGHT on DELTA requires AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL."
#endif #elif ABL_GRID
#endif #if (GRID_MAX_POINTS_X & 1) == 0 || (GRID_MAX_POINTS_Y & 1) == 0
#error "DELTA requires GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y to be odd numbers."
/** #elif GRID_MAX_POINTS_X < 3
* Unified Bed Leveling #error "DELTA requires GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y to be 3 or higher."
*/ #endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
#if IS_SCARA
#error "AUTO_BED_LEVELING_UBL does not yet support SCARA printers."
#endif #endif
#endif #endif
@ -503,7 +499,6 @@ static_assert(1 >= 0
, "Please enable only one probe option: PROBE_MANUALLY, FIX_MOUNTED_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or Z Servo." , "Please enable only one probe option: PROBE_MANUALLY, FIX_MOUNTED_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or Z Servo."
); );
#if PROBE_SELECTED #if PROBE_SELECTED
/** /**
@ -593,6 +588,114 @@ static_assert(1 >= 0
#endif #endif
/**
* Allow only one bed leveling option to be defined
*/
static_assert(1 >= 0
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
+ 1
#endif
#if ENABLED(AUTO_BED_LEVELING_3POINT)
+ 1
#endif
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
+ 1
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
+ 1
#endif
#if ENABLED(MESH_BED_LEVELING)
+ 1
#endif
, "Select only one of: MESH_BED_LEVELING, AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL."
);
/**
* Bed Leveling Requirements
*/
#if ENABLED(AUTO_BED_LEVELING_UBL)
/**
* Unified Bed Leveling
*/
#if IS_SCARA
#error "AUTO_BED_LEVELING_UBL does not yet support SCARA printers."
#elif DISABLED(EEPROM_SETTINGS)
#error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS. Please update your configuration."
#elif !WITHIN(GRID_MAX_POINTS_X, 3, 15) || !WITHIN(GRID_MAX_POINTS_Y, 3, 15)
#error "GRID_MAX_POINTS_[XY] must be a whole number between 3 and 15."
#else
static_assert(WITHIN(UBL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X), "UBL_PROBE_PT_1_X can't be reached by the Z probe.");
static_assert(WITHIN(UBL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X), "UBL_PROBE_PT_2_X can't be reached by the Z probe.");
static_assert(WITHIN(UBL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X), "UBL_PROBE_PT_3_X can't be reached by the Z probe.");
static_assert(WITHIN(UBL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y), "UBL_PROBE_PT_1_Y can't be reached by the Z probe.");
static_assert(WITHIN(UBL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y), "UBL_PROBE_PT_2_Y can't be reached by the Z probe.");
static_assert(WITHIN(UBL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y), "UBL_PROBE_PT_3_Y can't be reached by the Z probe.");
#endif
#elif HAS_ABL
/**
* Auto Bed Leveling
*/
#if ENABLED(USE_RAW_KINEMATICS)
#error "USE_RAW_KINEMATICS is not compatible with AUTO_BED_LEVELING"
#endif
/**
* Delta and SCARA have limited bed leveling options
*/
#if IS_SCARA && DISABLED(AUTO_BED_LEVELING_BILINEAR)
#error "Only AUTO_BED_LEVELING_BILINEAR currently supports SCARA bed leveling."
#endif
/**
* Check auto bed leveling probe points
*/
#if ABL_GRID
#ifdef DELTA_PROBEABLE_RADIUS
static_assert(LEFT_PROBE_BED_POSITION >= -DELTA_PROBEABLE_RADIUS, "LEFT_PROBE_BED_POSITION must be within DELTA_PROBEABLE_RADIUS.");
static_assert(RIGHT_PROBE_BED_POSITION <= DELTA_PROBEABLE_RADIUS, "RIGHT_PROBE_BED_POSITION must be within DELTA_PROBEABLE_RADIUS.");
static_assert(FRONT_PROBE_BED_POSITION >= -DELTA_PROBEABLE_RADIUS, "FRONT_PROBE_BED_POSITION must be within DELTA_PROBEABLE_RADIUS.");
static_assert(BACK_PROBE_BED_POSITION <= DELTA_PROBEABLE_RADIUS, "BACK_PROBE_BED_POSITION must be within DELTA_PROBEABLE_RADIUS.");
#else
static_assert(LEFT_PROBE_BED_POSITION < RIGHT_PROBE_BED_POSITION, "LEFT_PROBE_BED_POSITION must be less than RIGHT_PROBE_BED_POSITION.");
static_assert(FRONT_PROBE_BED_POSITION < BACK_PROBE_BED_POSITION, "FRONT_PROBE_BED_POSITION must be less than BACK_PROBE_BED_POSITION.");
static_assert(LEFT_PROBE_BED_POSITION >= MIN_PROBE_X, "LEFT_PROBE_BED_POSITION can't be reached by the Z probe.");
static_assert(RIGHT_PROBE_BED_POSITION <= MAX_PROBE_X, "RIGHT_PROBE_BED_POSITION can't be reached by the Z probe.");
static_assert(FRONT_PROBE_BED_POSITION >= MIN_PROBE_Y, "FRONT_PROBE_BED_POSITION can't be reached by the Z probe.");
static_assert(BACK_PROBE_BED_POSITION <= MAX_PROBE_Y, "BACK_PROBE_BED_POSITION can't be reached by the Z probe.");
#endif
#else // AUTO_BED_LEVELING_3POINT
static_assert(WITHIN(ABL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X), "ABL_PROBE_PT_1_X can't be reached by the Z probe.");
static_assert(WITHIN(ABL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X), "ABL_PROBE_PT_2_X can't be reached by the Z probe.");
static_assert(WITHIN(ABL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X), "ABL_PROBE_PT_3_X can't be reached by the Z probe.");
static_assert(WITHIN(ABL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y), "ABL_PROBE_PT_1_Y can't be reached by the Z probe.");
static_assert(WITHIN(ABL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y), "ABL_PROBE_PT_2_Y can't be reached by the Z probe.");
static_assert(WITHIN(ABL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y), "ABL_PROBE_PT_3_Y can't be reached by the Z probe.");
#endif // AUTO_BED_LEVELING_3POINT
#elif ENABLED(MESH_BED_LEVELING)
/**
* Mesh Bed Leveling
*/
#if ENABLED(DELTA)
#error "MESH_BED_LEVELING does not yet support DELTA printers."
#elif GRID_MAX_POINTS_X > 9 || GRID_MAX_POINTS_Y > 9
#error "GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y must be less than 10 for MBL."
#endif
#endif
/** /**
* LCD_BED_LEVELING requirements * LCD_BED_LEVELING requirements
*/ */
@ -630,83 +733,6 @@ static_assert(1 >= 0
#endif #endif
#endif // Z_SAFE_HOMING #endif // Z_SAFE_HOMING
/**
* Auto Bed Leveling
*/
#if HAS_ABL
#if ENABLED(USE_RAW_KINEMATICS)
#error "USE_RAW_KINEMATICS is not compatible with AUTO_BED_LEVELING"
#endif
/**
* Delta and SCARA have limited bed leveling options
*/
#if IS_SCARA && DISABLED(AUTO_BED_LEVELING_BILINEAR)
#error "Only AUTO_BED_LEVELING_BILINEAR currently supports SCARA bed leveling."
#endif
/**
* Check auto bed leveling sub-options, especially probe points
*/
#if ABL_GRID
#ifndef DELTA_PROBEABLE_RADIUS
#if LEFT_PROBE_BED_POSITION > RIGHT_PROBE_BED_POSITION
#error "LEFT_PROBE_BED_POSITION must be less than RIGHT_PROBE_BED_POSITION."
#elif FRONT_PROBE_BED_POSITION > BACK_PROBE_BED_POSITION
#error "FRONT_PROBE_BED_POSITION must be less than BACK_PROBE_BED_POSITION."
#endif
#if LEFT_PROBE_BED_POSITION < MIN_PROBE_X
#error "The given LEFT_PROBE_BED_POSITION can't be reached by the Z probe."
#elif RIGHT_PROBE_BED_POSITION > MAX_PROBE_X
#error "The given RIGHT_PROBE_BED_POSITION can't be reached by the Z probe."
#elif FRONT_PROBE_BED_POSITION < MIN_PROBE_Y
#error "The given FRONT_PROBE_BED_POSITION can't be reached by the Z probe."
#elif BACK_PROBE_BED_POSITION > MAX_PROBE_Y
#error "The given BACK_PROBE_BED_POSITION can't be reached by the Z probe."
#endif
#endif
#elif ENABLED(AUTO_BED_LEVELING_UBL)
#if DISABLED(EEPROM_SETTINGS)
#error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS. Please update your configuration."
#elif !WITHIN(GRID_MAX_POINTS_X, 3, 15) || !WITHIN(GRID_MAX_POINTS_Y, 3, 15)
#error "GRID_MAX_POINTS_[XY] must be a whole number between 3 and 15."
#endif
#if IS_CARTESIAN
#if !WITHIN(GRID_MAX_POINTS_X, 3, 15) || !WITHIN(GRID_MAX_POINTS_Y, 3, 15)
#error "GRID_MAX_POINTS_[XY] must be a whole number between 3 and 15."
#elif !WITHIN(UBL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given UBL_PROBE_PT_1_X can't be reached by the Z probe."
#elif !WITHIN(UBL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given UBL_PROBE_PT_2_X can't be reached by the Z probe."
#elif !WITHIN(UBL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given UBL_PROBE_PT_3_X can't be reached by the Z probe."
#elif !WITHIN(UBL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given UBL_PROBE_PT_1_Y can't be reached by the Z probe."
#elif !WITHIN(UBL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given UBL_PROBE_PT_2_Y can't be reached by the Z probe."
#elif !WITHIN(UBL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given UBL_PROBE_PT_3_Y can't be reached by the Z probe."
#endif
#endif
#else // AUTO_BED_LEVELING_3POINT
#if !WITHIN(ABL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given ABL_PROBE_PT_1_X can't be reached by the Z probe."
#elif !WITHIN(ABL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given ABL_PROBE_PT_2_X can't be reached by the Z probe."
#elif !WITHIN(ABL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given ABL_PROBE_PT_3_X can't be reached by the Z probe."
#elif !WITHIN(ABL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given ABL_PROBE_PT_1_Y can't be reached by the Z probe."
#elif !WITHIN(ABL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given ABL_PROBE_PT_2_Y can't be reached by the Z probe."
#elif !WITHIN(ABL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given ABL_PROBE_PT_3_Y can't be reached by the Z probe."
#endif
#endif // AUTO_BED_LEVELING_3POINT
#endif // HAS_ABL
/** /**
* Advance Extrusion * Advance Extrusion
*/ */
@ -739,40 +765,6 @@ static_assert(1 >= 0
#error "Only enable one SAV_3DGLCD display type: U8GLIB_SSD1306 or U8GLIB_SH1106." #error "Only enable one SAV_3DGLCD display type: U8GLIB_SSD1306 or U8GLIB_SH1106."
#endif #endif
/**
* Don't set more than one kinematic type
*/
static_assert(1 >= 0
#if ENABLED(DELTA)
+ 1
#endif
#if ENABLED(MORGAN_SCARA)
+ 1
#endif
#if ENABLED(MAKERARM_SCARA)
+ 1
#endif
#if ENABLED(COREXY)
+ 1
#endif
#if ENABLED(COREXZ)
+ 1
#endif
#if ENABLED(COREYZ)
+ 1
#endif
#if ENABLED(COREYX)
+ 1
#endif
#if ENABLED(COREZX)
+ 1
#endif
#if ENABLED(COREZY)
+ 1
#endif
, "Please enable only one of DELTA, MORGAN_SCARA, MAKERARM_SCARA, COREXY, COREYX, COREXZ, COREZX, COREYZ, or COREZY."
);
/** /**
* Allen Key * Allen Key
* Deploying the Allen Key probe uses big moves in z direction. Too dangerous for an unhomed z-axis. * Deploying the Allen Key probe uses big moves in z direction. Too dangerous for an unhomed z-axis.
@ -1147,22 +1139,64 @@ static_assert(1 >= 0
, "Please select no more than one LCD controller option." , "Please select no more than one LCD controller option."
); );
#if ENABLED(HAVE_TMC2130) && !( \ /**
ENABLED( X_IS_TMC2130 ) \ * Make sure HAVE_TMCDRIVER is warranted
|| ENABLED( X2_IS_TMC2130 ) \ */
|| ENABLED( Y_IS_TMC2130 ) \ #if ENABLED(HAVE_TMCDRIVER) && !( \
|| ENABLED( Y2_IS_TMC2130 ) \ ENABLED( X_IS_TMC ) \
|| ENABLED( Z_IS_TMC2130 ) \ || ENABLED( X2_IS_TMC ) \
|| ENABLED( Z2_IS_TMC2130 ) \ || ENABLED( Y_IS_TMC ) \
|| ENABLED( E0_IS_TMC2130 ) \ || ENABLED( Y2_IS_TMC ) \
|| ENABLED( E1_IS_TMC2130 ) \ || ENABLED( Z_IS_TMC ) \
|| ENABLED( E2_IS_TMC2130 ) \ || ENABLED( Z2_IS_TMC ) \
|| ENABLED( E3_IS_TMC2130 ) ) || ENABLED( E0_IS_TMC ) \
#error "Choose at least one TMC2130 stepper." || ENABLED( E1_IS_TMC ) \
|| ENABLED( E2_IS_TMC ) \
|| ENABLED( E3_IS_TMC ) \
|| ENABLED( E4_IS_TMC ) \
)
#error "HAVE_TMCDRIVER requires at least one TMC stepper to be set."
#endif #endif
#if ENABLED(HYBRID_THRESHOLD) && DISABLED(STEALTHCHOP) /**
#error "Enable STEALTHCHOP to use HYBRID_THRESHOLD." * Make sure HAVE_TMC2130 is warranted
*/
#if ENABLED(HAVE_TMC2130)
#if !( ENABLED( X_IS_TMC2130 ) \
|| ENABLED( X2_IS_TMC2130 ) \
|| ENABLED( Y_IS_TMC2130 ) \
|| ENABLED( Y2_IS_TMC2130 ) \
|| ENABLED( Z_IS_TMC2130 ) \
|| ENABLED( Z2_IS_TMC2130 ) \
|| ENABLED( E0_IS_TMC2130 ) \
|| ENABLED( E1_IS_TMC2130 ) \
|| ENABLED( E2_IS_TMC2130 ) \
|| ENABLED( E3_IS_TMC2130 ) \
|| ENABLED( E4_IS_TMC2130 ) \
)
#error "HAVE_TMC2130 requires at least one TMC2130 stepper to be set."
#elif ENABLED(HYBRID_THRESHOLD) && DISABLED(STEALTHCHOP)
#error "Enable STEALTHCHOP to use HYBRID_THRESHOLD."
#endif
#endif
/**
* Make sure HAVE_L6470DRIVER is warranted
*/
#if ENABLED(HAVE_L6470DRIVER) && !( \
ENABLED( X_IS_L6470 ) \
|| ENABLED( X2_IS_L6470 ) \
|| ENABLED( Y_IS_L6470 ) \
|| ENABLED( Y2_IS_L6470 ) \
|| ENABLED( Z_IS_L6470 ) \
|| ENABLED( Z2_IS_L6470 ) \
|| ENABLED( E0_IS_L6470 ) \
|| ENABLED( E1_IS_L6470 ) \
|| ENABLED( E2_IS_L6470 ) \
|| ENABLED( E3_IS_L6470 ) \
|| ENABLED( E4_IS_L6470 ) \
)
#error "HAVE_L6470DRIVER requires at least one L6470 stepper to be set."
#endif #endif
/** /**