My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

eeprom.cpp 2.1KB

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