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.2KB

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