My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

eeprom.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * HAL PersistentStore for Teensy 3.2 (MK20DX256)
  24. */
  25. #include "../shared/eeprom_api.h"
  26. #include <avr/eeprom.h>
  27. #ifndef MARLIN_EEPROM_SIZE
  28. #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
  29. #endif
  30. size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
  31. bool PersistentStore::access_start() { return true; }
  32. bool PersistentStore::access_finish() { return true; }
  33. bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
  34. while (size--) {
  35. uint8_t * const p = (uint8_t * const)pos;
  36. uint8_t v = *value;
  37. // EEPROM has only ~100,000 write cycles,
  38. // so only write bytes that have changed!
  39. if (v != eeprom_read_byte(p)) {
  40. eeprom_write_byte(p, v);
  41. if (eeprom_read_byte(p) != v) {
  42. SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
  43. return true;
  44. }
  45. }
  46. crc16(crc, &v, 1);
  47. pos++;
  48. value++;
  49. }
  50. return false;
  51. }
  52. bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
  53. do {
  54. uint8_t c = eeprom_read_byte((uint8_t*)pos);
  55. if (writing) *value = c;
  56. crc16(crc, &c, 1);
  57. pos++;
  58. value++;
  59. } while (--size);
  60. return false;
  61. }
  62. #endif // USE_WIRED_EEPROM
  63. #endif // __MK20DX256__