|
@@ -0,0 +1,66 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ *
|
|
4
|
+ * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
5
|
+ *
|
|
6
|
+ * This program is free software: you can redistribute it and/or modify
|
|
7
|
+ * it under the terms of the GNU General Public License as published by
|
|
8
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+ * (at your option) any later version.
|
|
10
|
+ *
|
|
11
|
+ * This program is distributed in the hope that it will be useful,
|
|
12
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+ * GNU General Public License for more details.
|
|
15
|
+ *
|
|
16
|
+ * You should have received a copy of the GNU General Public License
|
|
17
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+ *
|
|
19
|
+ */
|
|
20
|
+
|
|
21
|
+#ifdef __STM32F1__
|
|
22
|
+
|
|
23
|
+#include "../../inc/MarlinConfig.h"
|
|
24
|
+
|
|
25
|
+#if ENABLED(EEPROM_SETTINGS) && EITHER(SPI_EEPROM, I2C_EEPROM)
|
|
26
|
+
|
|
27
|
+#include "../shared/persistent_store_api.h"
|
|
28
|
+
|
|
29
|
+bool PersistentStore::access_start() { return true; }
|
|
30
|
+bool PersistentStore::access_finish() { return true; }
|
|
31
|
+
|
|
32
|
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
|
33
|
+ while (size--) {
|
|
34
|
+ uint8_t * const p = (uint8_t * const)pos;
|
|
35
|
+ uint8_t v = *value;
|
|
36
|
+ // EEPROM has only ~100,000 write cycles,
|
|
37
|
+ // so only write bytes that have changed!
|
|
38
|
+ if (v != eeprom_read_byte(p)) {
|
|
39
|
+ eeprom_write_byte(p, v);
|
|
40
|
+ if (eeprom_read_byte(p) != v) {
|
|
41
|
+ SERIAL_ECHO_MSG(MSG_ERR_EEPROM_WRITE);
|
|
42
|
+ return true;
|
|
43
|
+ }
|
|
44
|
+ }
|
|
45
|
+ crc16(crc, &v, 1);
|
|
46
|
+ pos++;
|
|
47
|
+ value++;
|
|
48
|
+ };
|
|
49
|
+ return false;
|
|
50
|
+}
|
|
51
|
+
|
|
52
|
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool set/*=true*/) {
|
|
53
|
+ do {
|
|
54
|
+ uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
|
55
|
+ if (set && value) *value = c;
|
|
56
|
+ crc16(crc, &c, 1);
|
|
57
|
+ pos++;
|
|
58
|
+ value++;
|
|
59
|
+ } while (--size);
|
|
60
|
+ return false;
|
|
61
|
+}
|
|
62
|
+
|
|
63
|
+size_t PersistentStore::capacity() { return E2END + 1; }
|
|
64
|
+
|
|
65
|
+#endif // EEPROM_SETTINGS && EITHER(SPI_EEPROM, I2C_EEPROM)
|
|
66
|
+#endif // __STM32F1__
|