My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

persistent_store.cpp 1.1KB

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