Browse Source

Prettify some EEPROM code

Scott Lahteine 7 years ago
parent
commit
c07bbd4154
1 changed files with 61 additions and 6 deletions
  1. 61
    6
      Marlin/src/module/configuration_store.cpp

+ 61
- 6
Marlin/src/module/configuration_store.cpp View File

292
     EEPROM_WRITE(ver);     // invalidate data first
292
     EEPROM_WRITE(ver);     // invalidate data first
293
     EEPROM_SKIP(working_crc); // Skip the checksum slot
293
     EEPROM_SKIP(working_crc); // Skip the checksum slot
294
 
294
 
295
-    working_crc = 0; // clear before first "real data"
295
+    working_crc = 0;  // Init to 0. Accumulated by EEPROM_READ
296
 
296
 
297
     const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
297
     const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
298
     EEPROM_WRITE(esteppers);
298
     EEPROM_WRITE(esteppers);
699
       uint8_t esteppers;
699
       uint8_t esteppers;
700
       EEPROM_READ(esteppers);
700
       EEPROM_READ(esteppers);
701
 
701
 
702
+      //
703
+      // Planner Motion
704
+      //
705
+
702
       // Get only the number of E stepper parameters previously stored
706
       // Get only the number of E stepper parameters previously stored
703
       // Any steppers added later are set to their defaults
707
       // Any steppers added later are set to their defaults
704
       const float def1[] = DEFAULT_AXIS_STEPS_PER_UNIT, def2[] = DEFAULT_MAX_FEEDRATE;
708
       const float def1[] = DEFAULT_AXIS_STEPS_PER_UNIT, def2[] = DEFAULT_MAX_FEEDRATE;
722
       EEPROM_READ(planner.min_segment_time_us);
726
       EEPROM_READ(planner.min_segment_time_us);
723
       EEPROM_READ(planner.max_jerk);
727
       EEPROM_READ(planner.max_jerk);
724
 
728
 
729
+      //
730
+      // Home Offset (M206)
731
+      //
732
+
725
       #if !HAS_HOME_OFFSET
733
       #if !HAS_HOME_OFFSET
726
         float home_offset[XYZ];
734
         float home_offset[XYZ];
727
       #endif
735
       #endif
733
         home_offset[Z_AXIS] -= DELTA_HEIGHT;
741
         home_offset[Z_AXIS] -= DELTA_HEIGHT;
734
       #endif
742
       #endif
735
 
743
 
744
+      //
745
+      // Hotend Offsets, if any
746
+      //
747
+
736
       #if HOTENDS > 1
748
       #if HOTENDS > 1
737
         // Skip hotend 0 which must be 0
749
         // Skip hotend 0 which must be 0
738
         for (uint8_t e = 1; e < HOTENDS; e++)
750
         for (uint8_t e = 1; e < HOTENDS; e++)
816
           for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummy);
828
           for (uint16_t q = grid_max_x * grid_max_y; q--;) EEPROM_READ(dummy);
817
         }
829
         }
818
 
830
 
831
+      //
832
+      // Unified Bed Leveling active state
833
+      //
834
+
819
       #if ENABLED(AUTO_BED_LEVELING_UBL)
835
       #if ENABLED(AUTO_BED_LEVELING_UBL)
820
         EEPROM_READ(planner.leveling_active);
836
         EEPROM_READ(planner.leveling_active);
821
         EEPROM_READ(ubl.storage_slot);
837
         EEPROM_READ(ubl.storage_slot);
825
         EEPROM_READ(dummyui8);
841
         EEPROM_READ(dummyui8);
826
       #endif // AUTO_BED_LEVELING_UBL
842
       #endif // AUTO_BED_LEVELING_UBL
827
 
843
 
844
+      //
845
+      // DELTA Geometry or Dual Endstops offsets
846
+      //
847
+
828
       #if ENABLED(DELTA)
848
       #if ENABLED(DELTA)
829
         EEPROM_READ(delta_endstop_adj);         // 3 floats
849
         EEPROM_READ(delta_endstop_adj);         // 3 floats
830
         EEPROM_READ(delta_radius);              // 1 float
850
         EEPROM_READ(delta_radius);              // 1 float
861
 
881
 
862
       #endif
882
       #endif
863
 
883
 
884
+      //
885
+      // LCD Preheat settings
886
+      //
887
+
864
       #if DISABLED(ULTIPANEL)
888
       #if DISABLED(ULTIPANEL)
865
         int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
889
         int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
866
       #endif
890
       #endif
867
 
891
 
868
-      EEPROM_READ(lcd_preheat_hotend_temp);
869
-      EEPROM_READ(lcd_preheat_bed_temp);
870
-      EEPROM_READ(lcd_preheat_fan_speed);
892
+      EEPROM_READ(lcd_preheat_hotend_temp); // 2 floats
893
+      EEPROM_READ(lcd_preheat_bed_temp);    // 2 floats
894
+      EEPROM_READ(lcd_preheat_fan_speed);   // 2 floats
871
 
895
 
872
       //EEPROM_ASSERT(
896
       //EEPROM_ASSERT(
873
       //  WITHIN(lcd_preheat_fan_speed, 0, 255),
897
       //  WITHIN(lcd_preheat_fan_speed, 0, 255),
874
       //  "lcd_preheat_fan_speed out of range"
898
       //  "lcd_preheat_fan_speed out of range"
875
       //);
899
       //);
876
 
900
 
901
+      //
902
+      // Hotend PID
903
+      //
904
+
877
       #if ENABLED(PIDTEMP)
905
       #if ENABLED(PIDTEMP)
878
         for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
906
         for (uint8_t e = 0; e < MAX_EXTRUDERS; e++) {
879
           EEPROM_READ(dummy); // Kp
907
           EEPROM_READ(dummy); // Kp
897
         for (uint8_t q = MAX_EXTRUDERS * 4; q--;) EEPROM_READ(dummy);  // Kp, Ki, Kd, Kc
925
         for (uint8_t q = MAX_EXTRUDERS * 4; q--;) EEPROM_READ(dummy);  // Kp, Ki, Kd, Kc
898
       #endif // !PIDTEMP
926
       #endif // !PIDTEMP
899
 
927
 
928
+      //
929
+      // PID Extrusion Scaling
930
+      //
931
+
900
       #if DISABLED(PID_EXTRUSION_SCALING)
932
       #if DISABLED(PID_EXTRUSION_SCALING)
901
         int lpq_len;
933
         int lpq_len;
902
       #endif
934
       #endif
903
       EEPROM_READ(lpq_len);
935
       EEPROM_READ(lpq_len);
904
 
936
 
937
+      //
938
+      // Heated Bed PID
939
+      //
940
+
905
       #if ENABLED(PIDTEMPBED)
941
       #if ENABLED(PIDTEMPBED)
906
         EEPROM_READ(dummy); // bedKp
942
         EEPROM_READ(dummy); // bedKp
907
         if (dummy != DUMMY_PID_VALUE) {
943
         if (dummy != DUMMY_PID_VALUE) {
913
         for (uint8_t q=3; q--;) EEPROM_READ(dummy); // bedKp, bedKi, bedKd
949
         for (uint8_t q=3; q--;) EEPROM_READ(dummy); // bedKp, bedKi, bedKd
914
       #endif
950
       #endif
915
 
951
 
952
+      //
953
+      // LCD Contrast
954
+      //
955
+
916
       #if !HAS_LCD_CONTRAST
956
       #if !HAS_LCD_CONTRAST
917
         uint16_t lcd_contrast;
957
         uint16_t lcd_contrast;
918
       #endif
958
       #endif
919
       EEPROM_READ(lcd_contrast);
959
       EEPROM_READ(lcd_contrast);
920
 
960
 
961
+      //
962
+      // Firmware Retraction
963
+      //
964
+
921
       #if ENABLED(FWRETRACT)
965
       #if ENABLED(FWRETRACT)
922
         EEPROM_READ(fwretract.autoretract_enabled);
966
         EEPROM_READ(fwretract.autoretract_enabled);
923
         EEPROM_READ(fwretract.retract_length);
967
         EEPROM_READ(fwretract.retract_length);
933
         for (uint8_t q=8; q--;) EEPROM_READ(dummy);
977
         for (uint8_t q=8; q--;) EEPROM_READ(dummy);
934
       #endif
978
       #endif
935
 
979
 
936
-      EEPROM_READ(parser.volumetric_enabled);
980
+      //
981
+      // Volumetric & Filament Size
982
+      //
937
 
983
 
984
+      EEPROM_READ(parser.volumetric_enabled);
938
       for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
985
       for (uint8_t q = 0; q < MAX_EXTRUDERS; q++) {
939
         EEPROM_READ(dummy);
986
         EEPROM_READ(dummy);
940
         if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy;
987
         if (q < COUNT(planner.filament_size)) planner.filament_size[q] = dummy;
941
       }
988
       }
942
 
989
 
990
+      //
991
+      // TMC2130 Stepper Current
992
+      //
993
+
943
       uint16_t val;
994
       uint16_t val;
944
       #if ENABLED(HAVE_TMC2130)
995
       #if ENABLED(HAVE_TMC2130)
945
         EEPROM_READ(val);
996
         EEPROM_READ(val);
987
           stepperE4.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
1038
           stepperE4.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
988
         #endif
1039
         #endif
989
       #else
1040
       #else
990
-        for (uint8_t q = 0; q < 11; q++) EEPROM_READ(val);
1041
+        for (uint8_t q = 11; q--;) EEPROM_READ(val);
991
       #endif
1042
       #endif
992
 
1043
 
993
       //
1044
       //
1002
         EEPROM_READ(dummy);
1053
         EEPROM_READ(dummy);
1003
       #endif
1054
       #endif
1004
 
1055
 
1056
+      //
1057
+      // Motor Current PWM
1058
+      //
1059
+
1005
       #if HAS_MOTOR_CURRENT_PWM
1060
       #if HAS_MOTOR_CURRENT_PWM
1006
         for (uint8_t q = 3; q--;) EEPROM_READ(stepper.motor_current_setting[q]);
1061
         for (uint8_t q = 3; q--;) EEPROM_READ(stepper.motor_current_setting[q]);
1007
       #else
1062
       #else

Loading…
Cancel
Save