Browse Source

[2.0.x] Use the new const functions of the persistentStore api (#11544)

Nils Hasenbanck 6 years ago
parent
commit
b37bfeffeb

+ 4
- 2
Marlin/src/HAL/shared/persistent_store_api.h View File

33
   static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true);
33
   static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true);
34
   static size_t capacity();
34
   static size_t capacity();
35
 
35
 
36
-  static inline bool write_data(const int pos, uint8_t* value, const size_t size) {
36
+  static inline bool write_data(const int pos, const uint8_t* value, const size_t size=sizeof(uint8_t)) {
37
     int data_pos = pos;
37
     int data_pos = pos;
38
     uint16_t crc = 0;
38
     uint16_t crc = 0;
39
     return write_data(data_pos, value, size, &crc);
39
     return write_data(data_pos, value, size, &crc);
40
   }
40
   }
41
 
41
 
42
-  static inline bool read_data(const int pos, uint8_t* value, const size_t size) {
42
+  static inline bool write_data(const int pos, const uint8_t value) { return write_data(pos, &value); }
43
+
44
+  static inline bool read_data(const int pos, uint8_t* value, const size_t size=1) {
43
     int data_pos = pos;
45
     int data_pos = pos;
44
     uint16_t crc = 0;
46
     uint16_t crc = 0;
45
     return read_data(data_pos, value, size, &crc);
47
     return read_data(data_pos, value, size, &crc);

+ 1
- 4
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

1169
    */
1169
    */
1170
   void unified_bed_leveling::g29_eeprom_dump() {
1170
   void unified_bed_leveling::g29_eeprom_dump() {
1171
     uint8_t cccc;
1171
     uint8_t cccc;
1172
-    int kkkk;
1173
-    uint16_t crc = 0;
1174
 
1172
 
1175
     SERIAL_ECHO_START();
1173
     SERIAL_ECHO_START();
1176
     SERIAL_ECHOLNPGM("EEPROM Dump:");
1174
     SERIAL_ECHOLNPGM("EEPROM Dump:");
1180
       print_hex_word(i);
1178
       print_hex_word(i);
1181
       SERIAL_ECHOPGM(": ");
1179
       SERIAL_ECHOPGM(": ");
1182
       for (uint16_t j = 0; j < 16; j++) {
1180
       for (uint16_t j = 0; j < 16; j++) {
1183
-        kkkk = i + j;
1184
-        persistentStore.read_data(kkkk, &cccc, sizeof(uint8_t), &crc);
1181
+        persistentStore.read_data(i + j, &cccc, sizeof(uint8_t));
1185
         print_hex_byte(cccc);
1182
         print_hex_byte(cccc);
1186
         SERIAL_ECHO(' ');
1183
         SERIAL_ECHO(' ');
1187
       }
1184
       }

+ 8
- 15
Marlin/src/module/printcounter.cpp View File

75
 
75
 
76
   saveStats();
76
   saveStats();
77
 
77
 
78
-  uint16_t crc = 0;
79
-  int a = address;
80
   persistentStore.access_start();
78
   persistentStore.access_start();
81
-  persistentStore.write_data(a, (uint8_t*)0x16, sizeof(uint8_t), &crc);
79
+  persistentStore.write_data(address, (uint8_t)0x16);
82
   persistentStore.access_finish();
80
   persistentStore.access_finish();
83
 }
81
 }
84
 
82
 
88
   #endif
86
   #endif
89
 
87
 
90
   // Check if the EEPROM block is initialized
88
   // Check if the EEPROM block is initialized
91
-  uint16_t crc = 0;
92
-  int a = address;
93
-  uint8_t value;
89
+  uint8_t value = 0;
94
   persistentStore.access_start();
90
   persistentStore.access_start();
95
-  persistentStore.read_data(a, &value, sizeof(uint8_t), &crc);
96
-  if (value != 0x16) initStats();
97
-  else {
98
-    a = address + sizeof(uint8_t);
99
-    persistentStore.read_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
100
-  }
91
+  persistentStore.read_data(address, &value, sizeof(uint8_t));
92
+  if (value != 0x16)
93
+    initStats();
94
+  else
95
+    persistentStore.read_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
101
   persistentStore.access_finish();
96
   persistentStore.access_finish();
102
   loaded = true;
97
   loaded = true;
103
 }
98
 }
111
   if (!isLoaded()) return;
106
   if (!isLoaded()) return;
112
 
107
 
113
   // Saves the struct to EEPROM
108
   // Saves the struct to EEPROM
114
-  uint16_t crc = 0;
115
-  int a = (address + sizeof(uint8_t));
116
   persistentStore.access_start();
109
   persistentStore.access_start();
117
-  persistentStore.write_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
110
+  persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics));
118
   persistentStore.access_finish();
111
   persistentStore.access_finish();
119
 }
112
 }
120
 
113
 

Loading…
Cancel
Save