My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

persistent_store_impl.cpp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifdef __AVR__
  2. #include "../persistent_store_api.h"
  3. #include "../../inc/MarlinConfig.h"
  4. #if ENABLED(EEPROM_SETTINGS)
  5. namespace HAL {
  6. namespace PersistentStore {
  7. bool access_start() { return true; }
  8. bool access_finish() { return true; }
  9. bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
  10. while (size--) {
  11. uint8_t * const p = (uint8_t * const)pos;
  12. uint8_t v = *value;
  13. // EEPROM has only ~100,000 write cycles,
  14. // so only write bytes that have changed!
  15. if (v != eeprom_read_byte(p)) {
  16. eeprom_write_byte(p, v);
  17. if (eeprom_read_byte(p) != v) {
  18. SERIAL_ECHO_START();
  19. SERIAL_ECHOLNPGM(MSG_ERR_EEPROM_WRITE);
  20. return true;
  21. }
  22. }
  23. crc16(crc, &v, 1);
  24. pos++;
  25. value++;
  26. };
  27. return false;
  28. }
  29. bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
  30. do {
  31. uint8_t c = eeprom_read_byte((unsigned char*)pos);
  32. if (writing) *value = c;
  33. crc16(crc, &c, 1);
  34. pos++;
  35. value++;
  36. } while (--size);
  37. return false; // always assume success for AVR's
  38. }
  39. }
  40. }
  41. #endif // EEPROM_SETTINGS
  42. #endif // __AVR__