You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.8 KiB
72 lines
1.8 KiB
5 years ago
|
/**
|
||
|
* Marlin 3D Printer Firmware
|
||
|
*
|
||
5 years ago
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||
|
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||
5 years ago
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
5 years ago
|
#ifdef __SAMD51__
|
||
5 years ago
|
|
||
|
#include "../../inc/MarlinConfig.h"
|
||
|
|
||
5 years ago
|
#if ENABLED(QSPI_EEPROM)
|
||
|
|
||
|
#include "../shared/eeprom_api.h"
|
||
5 years ago
|
|
||
5 years ago
|
#include "QSPIFlash.h"
|
||
5 years ago
|
|
||
5 years ago
|
static bool initialized;
|
||
|
|
||
|
size_t PersistentStore::capacity() { return qspi.size(); }
|
||
5 years ago
|
|
||
|
bool PersistentStore::access_start() {
|
||
5 years ago
|
if (!initialized) {
|
||
|
qspi.begin();
|
||
|
initialized = true;
|
||
|
}
|
||
|
return true;
|
||
5 years ago
|
}
|
||
|
|
||
|
bool PersistentStore::access_finish() {
|
||
5 years ago
|
qspi.flush();
|
||
5 years ago
|
return true;
|
||
|
}
|
||
|
|
||
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||
5 years ago
|
while (size--) {
|
||
|
const uint8_t v = *value;
|
||
|
qspi.writeByte(pos, v);
|
||
|
crc16(crc, &v, 1);
|
||
|
pos++;
|
||
|
value++;
|
||
5 years ago
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||
5 years ago
|
while (size--) {
|
||
|
uint8_t c = qspi.readByte(pos);
|
||
|
if (writing) *value = c;
|
||
5 years ago
|
crc16(crc, &c, 1);
|
||
5 years ago
|
pos++;
|
||
|
value++;
|
||
5 years ago
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
5 years ago
|
#endif // QSPI_EEPROM
|
||
|
#endif // __SAMD51__
|