Преглед изворни кода

Merge pull request #9056 from thinkyhead/bf2_new_eeprom_powers

[2.0.x] New EEPROM powers
Scott Lahteine пре 7 година
родитељ
комит
013c911a82
No account linked to committer's email address

+ 2
- 2
Marlin/src/HAL/HAL_AVR/persistent_store_impl.cpp Прегледај датотеку

38
   return false;
38
   return false;
39
 }
39
 }
40
 
40
 
41
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
41
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
42
   do {
42
   do {
43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
44
-    *value = c;
44
+    if (writing) *value = c;
45
     crc16(crc, &c, 1);
45
     crc16(crc, &c, 1);
46
     pos++;
46
     pos++;
47
     value++;
47
     value++;

+ 2
- 2
Marlin/src/HAL/HAL_DUE/persistent_store_impl.cpp Прегледај датотеку

43
   return false;
43
   return false;
44
 }
44
 }
45
 
45
 
46
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
46
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
47
   do {
47
   do {
48
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
48
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
49
-    *value = c;
49
+    if (writing) *value = c;
50
     crc16(crc, &c, 1);
50
     crc16(crc, &c, 1);
51
     pos++;
51
     pos++;
52
     value++;
52
     value++;

+ 10
- 3
Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp Прегледај датотеку

128
   return (bytes_written != size);  // return true for any error
128
   return (bytes_written != size);  // return true for any error
129
 }
129
 }
130
 
130
 
131
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
131
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
132
   UINT bytes_read = 0;
132
   UINT bytes_read = 0;
133
   FRESULT s;
133
   FRESULT s;
134
   s = f_lseek(&eeprom_file, pos);
134
   s = f_lseek(&eeprom_file, pos);
140
    SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
140
    SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
141
    return true;
141
    return true;
142
   }
142
   }
143
-  s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
143
+  if (writing) {
144
+    s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
145
+    crc16(crc, value, size);
146
+  }
147
+  else {
148
+    uint8_t temp[size];
149
+    s = f_read(&eeprom_file, (void *)temp, size, &bytes_read);
150
+    crc16(crc, temp, size);
151
+  }
144
   if (s) {
152
   if (s) {
145
    SERIAL_PROTOCOLPAIR(" read_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
153
    SERIAL_PROTOCOLPAIR(" read_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
146
    SERIAL_PROTOCOLPAIR(",", (int)value);           // right now to see errors that are happening in the
154
    SERIAL_PROTOCOLPAIR(",", (int)value);           // right now to see errors that are happening in the
151
    SERIAL_PROTOCOLLNPAIR("\n bytes_read=",  bytes_read);
159
    SERIAL_PROTOCOLLNPAIR("\n bytes_read=",  bytes_read);
152
    return true;
160
    return true;
153
   }
161
   }
154
-  crc16(crc, value, size);
155
   pos = pos + size;
162
   pos = pos + size;
156
   return bytes_read != size;  // return true for any error
163
   return bytes_read != size;  // return true for any error
157
 }
164
 }

+ 4
- 4
Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp Прегледај датотеку

93
   return true;
93
   return true;
94
 }
94
 }
95
 
95
 
96
-void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
96
+void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
97
   for (uint16_t i = 0; i < size; i++) {
97
   for (uint16_t i = 0; i < size; i++) {
98
     byte* accessPoint = (byte*)(pageBase + pos + i);
98
     byte* accessPoint = (byte*)(pageBase + pos + i);
99
-    value[i] = *accessPoint;
99
+    uint8_t c = *accessPoint;
100
+    if (writing) value[i] = c;
101
+    crc16(crc, &c, 1);
100
   }
102
   }
101
-
102
-  crc16(crc, value, size);
103
   pos += ((size + 1) & ~1);
103
   pos += ((size + 1) & ~1);
104
 }
104
 }
105
 
105
 

+ 4
- 4
Marlin/src/HAL/HAL_STM32F1/persistent_store_impl.cpp Прегледај датотеку

62
   return true;
62
   return true;
63
 }
63
 }
64
 
64
 
65
-
66
 bool access_finish(){
65
 bool access_finish(){
67
   if (!card.cardOK) return false;
66
   if (!card.cardOK) return false;
68
   int16_t bytes_written = 0;
67
   int16_t bytes_written = 0;
81
   return false;
80
   return false;
82
 }
81
 }
83
 
82
 
84
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
83
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
85
   for (int i = 0; i < size; i++) {
84
   for (int i = 0; i < size; i++) {
86
-    value[i] = HAL_STM32F1_eeprom_content [pos + i];
85
+    uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
86
+    if (writing) value[i] = c`;
87
+    crc16(crc, &c, 1);
87
   }
88
   }
88
-  crc16(crc, value, size);
89
   pos += size;
89
   pos += size;
90
   return false;
90
   return false;
91
 }
91
 }

+ 2
- 2
Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_impl.cpp Прегледај датотеку

38
   return false;
38
   return false;
39
 }
39
 }
40
 
40
 
41
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
41
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
42
   do {
42
   do {
43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
43
     uint8_t c = eeprom_read_byte((unsigned char*)pos);
44
-    *value = c;
44
+    if (writing) *value = c;
45
     crc16(crc, &c, 1);
45
     crc16(crc, &c, 1);
46
     pos++;
46
     pos++;
47
     value++;
47
     value++;

+ 1
- 1
Marlin/src/HAL/persistent_store_api.h Прегледај датотеку

10
 bool access_start();
10
 bool access_start();
11
 bool access_finish();
11
 bool access_finish();
12
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
12
 bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
13
-bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc);
13
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing=true);
14
 
14
 
15
 } // PersistentStore
15
 } // PersistentStore
16
 } // HAL
16
 } // HAL

+ 3
- 9
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp Прегледај датотеку

309
 
309
 
310
   void unified_bed_leveling::G29() {
310
   void unified_bed_leveling::G29() {
311
 
311
 
312
-    if (!settings.calc_num_meshes()) {
313
-      SERIAL_PROTOCOLLNPGM("?Enable EEPROM and init with");
314
-      SERIAL_PROTOCOLLNPGM("M502, M500, M501 in that order.\n");
315
-      return;
316
-    }
317
-
318
     if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,
312
     if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,
319
 
313
 
320
     // Check for commands that require the printer to be homed
314
     // Check for commands that require the printer to be homed
1272
       SERIAL_EOL();
1266
       SERIAL_EOL();
1273
       safe_delay(50);
1267
       safe_delay(50);
1274
 
1268
 
1275
-      SERIAL_PROTOCOLPAIR("Meshes go from ", hex_address((void*)settings.get_start_of_meshes()));
1276
-      SERIAL_PROTOCOLLNPAIR(" to ", hex_address((void*)settings.get_end_of_meshes()));
1269
+      SERIAL_PROTOCOLPAIR("Meshes go from ", hex_address((void*)settings.meshes_start_index()));
1270
+      SERIAL_PROTOCOLLNPAIR(" to ", hex_address((void*)settings.meshes_end_index()));
1277
       safe_delay(50);
1271
       safe_delay(50);
1278
 
1272
 
1279
       SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1273
       SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1282
       SERIAL_EOL();
1276
       SERIAL_EOL();
1283
       safe_delay(25);
1277
       safe_delay(25);
1284
 
1278
 
1285
-      SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.get_end_of_meshes() - settings.get_start_of_meshes())));
1279
+      SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.meshes_end_index() - settings.meshes_start_index())));
1286
       safe_delay(50);
1280
       safe_delay(50);
1287
 
1281
 
1288
       SERIAL_PROTOCOLPAIR("EEPROM can hold ", settings.calc_num_meshes());
1282
       SERIAL_PROTOCOLPAIR("EEPROM can hold ", settings.calc_num_meshes());

Marlin/src/gcode/eeprom/M500-M503.cpp → Marlin/src/gcode/eeprom/M500-M504.cpp Прегледај датотеку

55
   }
55
   }
56
 
56
 
57
 #endif // !DISABLE_M503
57
 #endif // !DISABLE_M503
58
+
59
+#if ENABLED(EEPROM_SETTINGS)
60
+  /**
61
+   * M504: Validate EEPROM Contents
62
+   */
63
+  void GcodeSuite::M504() {
64
+    if (settings.validate()) {
65
+      SERIAL_ECHO_START();
66
+      SERIAL_ECHOLNPGM("EEPROM OK");
67
+    }
68
+  }
69
+#endif

+ 3
- 0
Marlin/src/gcode/gcode.cpp Прегледај датотеку

610
       #if DISABLED(DISABLE_M503)
610
       #if DISABLED(DISABLE_M503)
611
         case 503: M503(); break;  // M503: print settings currently in memory
611
         case 503: M503(); break;  // M503: print settings currently in memory
612
       #endif
612
       #endif
613
+      #if ENABLED(EEPROM_SETTINGS)
614
+        case 504: M504(); break;  // M504: Validate EEPROM contents
615
+      #endif
613
 
616
 
614
       #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
617
       #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
615
         case 540: M540(); break;  // M540: Set abort on endstop hit for SD printing
618
         case 540: M540(); break;  // M540: Set abort on endstop hit for SD printing

+ 4
- 1
Marlin/src/gcode/gcode.h Прегледај датотеку

271
     static WorkspacePlane workspace_plane;
271
     static WorkspacePlane workspace_plane;
272
   #endif
272
   #endif
273
 
273
 
274
+  #define MAX_COORDINATE_SYSTEMS 9
274
   #if ENABLED(CNC_COORDINATE_SYSTEMS)
275
   #if ENABLED(CNC_COORDINATE_SYSTEMS)
275
-    #define MAX_COORDINATE_SYSTEMS 9
276
     static int8_t active_coordinate_system;
276
     static int8_t active_coordinate_system;
277
     static float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
277
     static float coordinate_system[MAX_COORDINATE_SYSTEMS][XYZ];
278
     static bool select_coordinate_system(const int8_t _new);
278
     static bool select_coordinate_system(const int8_t _new);
681
   #if DISABLED(DISABLE_M503)
681
   #if DISABLED(DISABLE_M503)
682
     static void M503();
682
     static void M503();
683
   #endif
683
   #endif
684
+  #if ENABLED(EEPROM_SETTINGS)
685
+    static void M504();
686
+  #endif
684
 
687
 
685
   #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
688
   #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
686
     static void M540();
689
     static void M540();

+ 0
- 1
Marlin/src/lcd/ultralcd.cpp Прегледај датотеку

2309
       MENU_BACK(MSG_UBL_LEVEL_BED);
2309
       MENU_BACK(MSG_UBL_LEVEL_BED);
2310
       if (!WITHIN(ubl_storage_slot, 0, a - 1)) {
2310
       if (!WITHIN(ubl_storage_slot, 0, a - 1)) {
2311
         STATIC_ITEM(MSG_NO_STORAGE);
2311
         STATIC_ITEM(MSG_NO_STORAGE);
2312
-        STATIC_ITEM(MSG_INIT_EEPROM);
2313
       }
2312
       }
2314
       else {
2313
       else {
2315
         MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
2314
         MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);

+ 475
- 372
Marlin/src/module/configuration_store.cpp
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 15
- 13
Marlin/src/module/configuration_store.h Прегледај датотеку

29
   public:
29
   public:
30
     MarlinSettings() { }
30
     MarlinSettings() { }
31
 
31
 
32
+    static uint16_t datasize();
33
+
32
     static void reset();
34
     static void reset();
33
-    static bool save();
35
+    static bool save();   // Return 'true' if data was saved
34
 
36
 
35
     FORCE_INLINE static bool init_eeprom() {
37
     FORCE_INLINE static bool init_eeprom() {
36
       bool success = true;
38
       bool success = true;
37
       reset();
39
       reset();
38
       #if ENABLED(EEPROM_SETTINGS)
40
       #if ENABLED(EEPROM_SETTINGS)
39
-        if ((success = save())) {
40
-          #if ENABLED(AUTO_BED_LEVELING_UBL)
41
-            success = load(); // UBL uses load() to know the end of EEPROM
42
-          #elif ENABLED(EEPROM_CHITCHAT)
43
-            report();
44
-          #endif
45
-        }
41
+        success = save();
42
+        #if ENABLED(EEPROM_CHITCHAT)
43
+          if (success) report();
44
+        #endif
46
       #endif
45
       #endif
47
       return success;
46
       return success;
48
     }
47
     }
49
 
48
 
50
     #if ENABLED(EEPROM_SETTINGS)
49
     #if ENABLED(EEPROM_SETTINGS)
51
-      static bool load();
50
+      static bool load();     // Return 'true' if data was loaded ok
51
+      static bool validate(); // Return 'true' if EEPROM data is ok
52
 
52
 
53
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
53
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
54
                                          // That can store is enabled
54
                                          // That can store is enabled
55
-        FORCE_INLINE static int16_t get_start_of_meshes() { return meshes_begin; }
56
-        FORCE_INLINE static int16_t get_end_of_meshes() { return meshes_end; }
55
+        static int16_t meshes_start_index();
56
+        FORCE_INLINE static int16_t meshes_end_index() { return meshes_end; }
57
         static uint16_t calc_num_meshes();
57
         static uint16_t calc_num_meshes();
58
         static void store_mesh(const int8_t slot);
58
         static void store_mesh(const int8_t slot);
59
         static void load_mesh(const int8_t slot, void * const into=NULL);
59
         static void load_mesh(const int8_t slot, void * const into=NULL);
77
     static void postprocess();
77
     static void postprocess();
78
 
78
 
79
     #if ENABLED(EEPROM_SETTINGS)
79
     #if ENABLED(EEPROM_SETTINGS)
80
-      static bool eeprom_error;
80
+
81
+      static bool eeprom_error, validating;
81
 
82
 
82
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
83
       #if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
83
                                          // That can store is enabled
84
                                          // That can store is enabled
84
-        static int16_t meshes_begin;
85
         const static int16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
85
         const static int16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
86
                                                        // live at the very end of the eeprom
86
                                                        // live at the very end of the eeprom
87
 
87
 
88
       #endif
88
       #endif
89
 
89
 
90
+      static bool _load();
91
+      static bool size_error(const uint16_t size);
90
     #endif
92
     #endif
91
 };
93
 };
92
 
94
 

Loading…
Откажи
Сачувај