From a9ea3861b679dd8bba1c74b31d5321835767e1ae Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 2 Oct 2018 00:51:09 -0500 Subject: [PATCH] Tweaks to EEPROM code --- Marlin/src/core/drivers.h | 2 +- Marlin/src/module/configuration_store.cpp | 60 ++++++++++------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/Marlin/src/core/drivers.h b/Marlin/src/core/drivers.h index 0b46adae03eb..15a449935618 100644 --- a/Marlin/src/core/drivers.h +++ b/Marlin/src/core/drivers.h @@ -45,7 +45,7 @@ #define AXIS_DRIVER_TYPE_X(T) _AXIS_DRIVER_TYPE(X,T) #define AXIS_DRIVER_TYPE_Y(T) _AXIS_DRIVER_TYPE(Y,T) #define AXIS_DRIVER_TYPE_Z(T) _AXIS_DRIVER_TYPE(Z,T) -#define AXIS_DRIVER_TYPE_X2(T) (ENABLED(X_DUAL_STEPPER_DRIVERS) || ENABLED(DUAL_X_CARRIAGE)) && _AXIS_DRIVER_TYPE(X2,T) +#define AXIS_DRIVER_TYPE_X2(T) ((ENABLED(X_DUAL_STEPPER_DRIVERS) || ENABLED(DUAL_X_CARRIAGE)) && _AXIS_DRIVER_TYPE(X2,T)) #define AXIS_DRIVER_TYPE_Y2(T) (ENABLED(Y_DUAL_STEPPER_DRIVERS) && _AXIS_DRIVER_TYPE(Y2,T)) #define AXIS_DRIVER_TYPE_Z2(T) (Z_MULTI_STEPPER_DRIVERS && _AXIS_DRIVER_TYPE(Z2,T)) #define AXIS_DRIVER_TYPE_Z3(T) (ENABLED(Z_TRIPLE_STEPPER_DRIVERS) && _AXIS_DRIVER_TYPE(Z3,T)) diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index c8e442399413..9a92e47d5368 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -83,9 +83,9 @@ #include "../feature/tmc_util.h" #define TMC_GET_PWMTHRS(A,Q) _tmc_thrs(stepper##Q.microsteps(), stepper##Q.TPWMTHRS(), planner.axis_steps_per_mm[_AXIS(A)]) #endif -struct tmc_stepper_current_t { uint16_t X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5; }; -struct tmc_hybrid_threshold_t { uint32_t X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5; }; -struct tmc_sgt_t { int16_t X, Y, Z; }; +typedef struct { uint16_t X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5; } tmc_stepper_current_t; +typedef struct { uint32_t X, Y, Z, X2, Y2, Z2, Z3, E0, E1, E2, E3, E4, E5; } tmc_hybrid_threshold_t; +typedef struct { int16_t X, Y, Z; } tmc_sgt_t; #if ENABLED(FWRETRACT) #include "../feature/fwretract.h" @@ -101,7 +101,7 @@ struct tmc_sgt_t { int16_t X, Y, Z; }; #pragma pack(push, 1) // No padding between variables -typedef struct PID { float Kp, Ki, Kd; } PID; +typedef struct PID { float Kp, Ki, Kd; } PID; typedef struct PIDC { float Kp, Ki, Kd, Kc; } PIDC; /** @@ -303,7 +303,7 @@ uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); } #endif void MarlinSettings::postprocess() { - const float oldpos[] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] }; + const float oldpos[XYZE] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS] }; // steps per s2 needs to be updated to agree with units per s2 planner.reset_acceleration_rates(); @@ -439,7 +439,7 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(dummy); #endif #else - const float planner_max_jerk[] = { float(DEFAULT_XJERK), float(DEFAULT_YJERK), float(DEFAULT_ZJERK), float(DEFAULT_EJERK) }; + const float planner_max_jerk[XYZE] = { float(DEFAULT_XJERK), float(DEFAULT_YJERK), float(DEFAULT_ZJERK), float(DEFAULT_EJERK) }; EEPROM_WRITE(planner_max_jerk); #endif @@ -467,11 +467,13 @@ void MarlinSettings::postprocess() { // Global Leveling // - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - const float zfh = planner.z_fade_height; - #else - const float zfh = 10.0; - #endif + const float zfh = ( + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + planner.z_fade_height + #else + 10.0 + #endif + ); EEPROM_WRITE(zfh); // @@ -481,7 +483,7 @@ void MarlinSettings::postprocess() { #if ENABLED(MESH_BED_LEVELING) // Compile time test that sizeof(mbl.z_values) is as expected static_assert( - sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]), + sizeof(mbl.z_values) == (GRID_MAX_POINTS) * sizeof(mbl.z_values[0][0]), "MBL Z array is the wrong size." ); const uint8_t mesh_num_x = GRID_MAX_POINTS_X, mesh_num_y = GRID_MAX_POINTS_Y; @@ -523,7 +525,7 @@ void MarlinSettings::postprocess() { #if ENABLED(AUTO_BED_LEVELING_BILINEAR) // Compile time test that sizeof(z_values) is as expected static_assert( - sizeof(z_values) == GRID_MAX_POINTS * sizeof(z_values[0][0]), + sizeof(z_values) == (GRID_MAX_POINTS) * sizeof(z_values[0][0]), "Bilinear Z array is the wrong size." ); const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y; @@ -727,7 +729,7 @@ void MarlinSettings::postprocess() { _FIELD_TEST(tmc_stepper_current); - tmc_stepper_current_t tmc_stepper_current{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + tmc_stepper_current_t tmc_stepper_current = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #if HAS_TRINAMIC #if AXIS_IS_TMC(X) @@ -788,13 +790,11 @@ void MarlinSettings::postprocess() { // Save TMC Hybrid Threshold, and placeholder values // - _FIELD_TEST(tmc_hybrid_threshold); - - tmc_hybrid_threshold_t tmc_hybrid_threshold{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #if ENABLED(HYBRID_THRESHOLD) - #if AXIS_HAS_STEALTHCHOP(X) + tmc_hybrid_threshold_t tmc_hybrid_threshold = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + #if AXIS_HAS_STEALTHCHOP(X) tmc_hybrid_threshold.X = TMC_GET_PWMTHRS(X, X); #endif #if AXIS_HAS_STEALTHCHOP(Y) @@ -846,19 +846,12 @@ void MarlinSettings::postprocess() { #endif // MAX_EXTRUDERS > 1 #endif // MAX_EXTRUDERS #else - tmc_hybrid_threshold.X = 100; - tmc_hybrid_threshold.Y = 100; - tmc_hybrid_threshold.Z = 3; - tmc_hybrid_threshold.X2 = 100; - tmc_hybrid_threshold.Y2 = 100; - tmc_hybrid_threshold.Z2 = 3; - tmc_hybrid_threshold.Z3 = 3; - tmc_hybrid_threshold.E0 = 30; - tmc_hybrid_threshold.E1 = 30; - tmc_hybrid_threshold.E2 = 30; - tmc_hybrid_threshold.E3 = 30; - tmc_hybrid_threshold.E4 = 30; - tmc_hybrid_threshold.E5 = 30; + const tmc_hybrid_threshold_t tmc_hybrid_threshold = { + .X = 100, .Y = 100, .Z = 3, + .X2 = 100, .Y2 = 100, .Z2 = 3, .Z3 = 3, + .E0 = 30, .E1 = 30, .E2 = 30, + .E3 = 30, .E4 = 30, .E5 = 30 + }; #endif EEPROM_WRITE(tmc_hybrid_threshold); @@ -866,7 +859,7 @@ void MarlinSettings::postprocess() { // TMC StallGuard threshold // - tmc_sgt_t tmc_sgt{ 0, 0, 0 }; + tmc_sgt_t tmc_sgt = { 0, 0, 0 }; #if USE_SENSORLESS #if X_SENSORLESS @@ -1893,8 +1886,7 @@ void MarlinSettings::reset(PORTARG_SOLO) { #endif // HAS_SERVOS && EDITABLE_SERVO_ANGLES #if ENABLED(DELTA) - const float adj[ABC] = DELTA_ENDSTOP_ADJ, - dta[ABC] = DELTA_TOWER_ANGLE_TRIM; + const float adj[ABC] = DELTA_ENDSTOP_ADJ, dta[ABC] = DELTA_TOWER_ANGLE_TRIM; delta_height = DELTA_HEIGHT; COPY(delta_endstop_adj, adj); delta_radius = DELTA_RADIUS;