eeprom.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #ifndef EEPROM_H
  2. #define EEPROM_H
  3. #include <stdint.h>
  4. void eeprom_init();
  5. // The total size of the EEPROM is
  6. // 4096 for the Atmega2560
  7. #define EEPROM_TOP 4096
  8. #define EEPROM_SILENT 4095
  9. #define EEPROM_LANG 4094
  10. #define EEPROM_BABYSTEP_X 4092
  11. #define EEPROM_BABYSTEP_Y 4090
  12. #define EEPROM_BABYSTEP_Z 4088
  13. #define EEPROM_CALIBRATION_STATUS 4087
  14. #define EEPROM_BABYSTEP_Z0 4085
  15. #define EEPROM_FILAMENTUSED 4081
  16. // uint32_t
  17. #define EEPROM_TOTALTIME 4077
  18. #define EEPROM_BED_CALIBRATION_CENTER (EEPROM_TOTALTIME-2*4)
  19. #define EEPROM_BED_CALIBRATION_VEC_X (EEPROM_BED_CALIBRATION_CENTER-2*4)
  20. #define EEPROM_BED_CALIBRATION_VEC_Y (EEPROM_BED_CALIBRATION_VEC_X-2*4)
  21. // Offsets of the Z heiths of the calibration points from the first point.
  22. // The offsets are saved as 16bit signed int, scaled to tenths of microns.
  23. #define EEPROM_BED_CALIBRATION_Z_JITTER (EEPROM_BED_CALIBRATION_VEC_Y-2*8)
  24. #define EEPROM_FARM_MODE (EEPROM_BED_CALIBRATION_Z_JITTER-1)
  25. #define EEPROM_FARM_NUMBER (EEPROM_FARM_MODE-3)
  26. // Correction of the bed leveling, in micrometers.
  27. // Maximum 50 micrometers allowed.
  28. // Bed correction is valid if set to 1. If set to zero or 255, the successive 4 bytes are invalid.
  29. #define EEPROM_BED_CORRECTION_VALID (EEPROM_FARM_NUMBER-1)
  30. #define EEPROM_BED_CORRECTION_LEFT (EEPROM_BED_CORRECTION_VALID-1)
  31. #define EEPROM_BED_CORRECTION_RIGHT (EEPROM_BED_CORRECTION_LEFT-1)
  32. #define EEPROM_BED_CORRECTION_FRONT (EEPROM_BED_CORRECTION_RIGHT-1)
  33. #define EEPROM_BED_CORRECTION_REAR (EEPROM_BED_CORRECTION_FRONT-1)
  34. #define EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY (EEPROM_BED_CORRECTION_REAR-1)
  35. #define EEPROM_PRINT_FLAG (EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY-1)
  36. #define EEPROM_PROBE_TEMP_SHIFT (EEPROM_PRINT_FLAG - 2*5) //5 x int for storing pinda probe temp shift relative to 50 C; unit: motor steps
  37. #define EEPROM_TEMP_CAL_ACTIVE (EEPROM_PROBE_TEMP_SHIFT - 1)
  38. #define EEPROM_BOWDEN_LENGTH (EEPROM_TEMP_CAL_ACTIVE - 2*4) //4 x int for bowden lengths for multimaterial
  39. #define EEPROM_CALIBRATION_STATUS_PINDA (EEPROM_BOWDEN_LENGTH - 1) //0 - not calibrated; 1 - calibrated
  40. #define EEPROM_UVLO (EEPROM_CALIBRATION_STATUS_PINDA - 1) //1 - uvlo during print
  41. #define EEPROM_UVLO_CURRENT_POSITION (EEPROM_UVLO-2*4) // 2 x float for current_position in X and Y axes
  42. #define EEPROM_FILENAME (EEPROM_UVLO_CURRENT_POSITION - 8) //8chars to store filename without extension
  43. #define EEPROM_FILE_POSITION (EEPROM_FILENAME - 4) //32 bit for uint32_t file position
  44. #define EEPROM_UVLO_CURRENT_POSITION_Z (EEPROM_FILE_POSITION - 4) //float for current position in Z
  45. #define EEPROM_UVLO_TARGET_HOTEND (EEPROM_UVLO_CURRENT_POSITION_Z - 1)
  46. #define EEPROM_UVLO_TARGET_BED (EEPROM_UVLO_TARGET_HOTEND - 1)
  47. #define EEPROM_UVLO_FEEDRATE (EEPROM_UVLO_TARGET_BED - 2)
  48. #define EEPROM_UVLO_FAN_SPEED (EEPROM_UVLO_FEEDRATE - 1)
  49. #define EEPROM_FAN_CHECK_ENABLED (EEPROM_UVLO_FAN_SPEED - 1)
  50. #define EEPROM_UVLO_MESH_BED_LEVELING (EEPROM_FAN_CHECK_ENABLED - 9*2)
  51. #define EEPROM_UVLO_Z_MICROSTEPS (EEPROM_UVLO_MESH_BED_LEVELING - 2)
  52. #define EEPROM_UVLO_E_ABS (EEPROM_UVLO_Z_MICROSTEPS - 1)
  53. #define EEPROM_UVLO_CURRENT_POSITION_E (EEPROM_UVLO_E_ABS - 4) //float for current position in E
  54. // Crash detection mode EEPROM setting
  55. #define EEPROM_CRASH_DET (EEPROM_UVLO_CURRENT_POSITION_E - 5) // float (orig EEPROM_UVLO_MESH_BED_LEVELING-12)
  56. // Crash detection counter Y (last print)
  57. #define EEPROM_CRASH_COUNT_Y (EEPROM_CRASH_DET - 1) // uint8 (orig EEPROM_UVLO_MESH_BED_LEVELING-15)
  58. // Filament sensor on/off EEPROM setting
  59. #define EEPROM_FSENSOR (EEPROM_CRASH_COUNT_Y - 1) // uint8 (orig EEPROM_UVLO_MESH_BED_LEVELING-14)
  60. // Crash detection counter X (last print)
  61. #define EEPROM_CRASH_COUNT_X (EEPROM_FSENSOR - 1) // uint8 (orig EEPROM_UVLO_MESH_BED_LEVELING-15)
  62. // Filament runout/error coutner (last print)
  63. #define EEPROM_FERROR_COUNT (EEPROM_CRASH_COUNT_X - 1) // uint8 (orig EEPROM_UVLO_MESH_BED_LEVELING-16)
  64. // Power loss errors (last print)
  65. #define EEPROM_POWER_COUNT (EEPROM_FERROR_COUNT - 1) // uint8 (orig EEPROM_UVLO_MESH_BED_LEVELING-17)
  66. #define EEPROM_XYZ_CAL_SKEW (EEPROM_POWER_COUNT - 4) // float for skew backup
  67. #define EEPROM_WIZARD_ACTIVE (EEPROM_XYZ_CAL_SKEW - 1)
  68. #define EEPROM_BELTSTATUS_X (EEPROM_WIZARD_ACTIVE - 2) // uint16
  69. #define EEPROM_BELTSTATUS_Y (EEPROM_BELTSTATUS_X - 2) // uint16
  70. #define EEPROM_DIR_DEPTH (EEPROM_BELTSTATUS_Y-1)
  71. #define EEPROM_DIRS (EEPROM_DIR_DEPTH-80) //8 chars for each dir name, max 10 levels
  72. #define EEPROM_SD_SORT (EEPROM_DIRS - 1) //0 -time, 1-alpha, 2-none
  73. #define EEPROM_SECOND_SERIAL_ACTIVE (EEPROM_SD_SORT - 1)
  74. #define EEPROM_FSENS_AUTOLOAD_ENABLED (EEPROM_SECOND_SERIAL_ACTIVE - 1)
  75. // Crash detection counter X (total)
  76. #define EEPROM_CRASH_COUNT_X_TOT (EEPROM_FSENS_AUTOLOAD_ENABLED - 2) // uint16
  77. // Crash detection counter Y (total)
  78. #define EEPROM_CRASH_COUNT_Y_TOT (EEPROM_CRASH_COUNT_X_TOT - 2) // uint16
  79. // Filament runout/error coutner (total)
  80. #define EEPROM_FERROR_COUNT_TOT (EEPROM_CRASH_COUNT_Y_TOT - 2) // uint16
  81. // Power loss errors (total)
  82. #define EEPROM_POWER_COUNT_TOT (EEPROM_FERROR_COUNT_TOT - 2) // uint16
  83. ////////////////////////////////////////
  84. // TMC2130 Accurate sensorless homing
  85. // X-axis home origin (stepper phase in microsteps, 0..63 for 16ustep resolution)
  86. #define EEPROM_TMC2130_HOME_X_ORIGIN (EEPROM_POWER_COUNT_TOT - 1) // uint8
  87. // X-axis home bsteps (number of microsteps backward)
  88. #define EEPROM_TMC2130_HOME_X_BSTEPS (EEPROM_TMC2130_HOME_X_ORIGIN - 1) // uint8
  89. // X-axis home fsteps (number of microsteps forward)
  90. #define EEPROM_TMC2130_HOME_X_FSTEPS (EEPROM_TMC2130_HOME_X_BSTEPS - 1) // uint8
  91. // Y-axis home origin (stepper phase in microsteps, 0..63 for 16ustep resolution)
  92. #define EEPROM_TMC2130_HOME_Y_ORIGIN (EEPROM_TMC2130_HOME_X_FSTEPS - 1) // uint8
  93. // X-axis home bsteps (number of microsteps backward)
  94. #define EEPROM_TMC2130_HOME_Y_BSTEPS (EEPROM_TMC2130_HOME_Y_ORIGIN - 1) // uint8
  95. // X-axis home fsteps (number of microsteps forward)
  96. #define EEPROM_TMC2130_HOME_Y_FSTEPS (EEPROM_TMC2130_HOME_Y_BSTEPS - 1) // uint8
  97. // Accurate homing enabled
  98. #define EEPROM_TMC2130_HOME_ENABLED (EEPROM_TMC2130_HOME_Y_FSTEPS - 1) // uint8
  99. ////////////////////////////////////////
  100. // TMC2130 uStep linearity correction
  101. // Linearity correction factor (XYZE)
  102. #define EEPROM_TMC2130_WAVE_X_FAC (EEPROM_TMC2130_HOME_ENABLED - 1) // uint8
  103. #define EEPROM_TMC2130_WAVE_Y_FAC (EEPROM_TMC2130_WAVE_X_FAC - 1) // uint8
  104. #define EEPROM_TMC2130_WAVE_Z_FAC (EEPROM_TMC2130_WAVE_Y_FAC - 1) // uint8
  105. #define EEPROM_TMC2130_WAVE_E_FAC (EEPROM_TMC2130_WAVE_Z_FAC - 1) // uint8
  106. ////////////////////////////////////////
  107. // TMC2130 uStep resolution
  108. // microstep resolution (XYZE): usteps = (256 >> mres)
  109. #define EEPROM_TMC2130_X_MRES (EEPROM_TMC2130_WAVE_E_FAC - 1) // uint8
  110. #define EEPROM_TMC2130_Y_MRES (EEPROM_TMC2130_X_MRES - 1) // uint8
  111. #define EEPROM_TMC2130_Z_MRES (EEPROM_TMC2130_Y_MRES - 1) // uint8
  112. #define EEPROM_TMC2130_E_MRES (EEPROM_TMC2130_Z_MRES - 1) // uint8
  113. // HW
  114. #define EEPROM_PRINTER_TYPE (EEPROM_TMC2130_E_MRES - 2) // uint16
  115. #define EEPROM_BOARD_TYPE (EEPROM_PRINTER_TYPE - 2) // uint16
  116. // Extruder multiplier for power panic
  117. #define EEPROM_EXTRUDER_MULTIPLIER_0 (EEPROM_BOARD_TYPE - 4) //float
  118. #define EEPROM_EXTRUDER_MULTIPLIER_1 (EEPROM_EXTRUDER_MULTIPLIER_0 - 4) //float
  119. #define EEPROM_EXTRUDER_MULTIPLIER_2 (EEPROM_EXTRUDER_MULTIPLIER_1 - 4) //float
  120. #define EEPROM_EXTRUDEMULTIPLY (EEPROM_EXTRUDER_MULTIPLIER_2 - 2) // uint16
  121. //
  122. #define EEPROM_UVLO_TINY_CURRENT_POSITION_Z (EEPROM_EXTRUDEMULTIPLY-4) // float
  123. #define EEPROM_UVLO_TINY_Z_MICROSTEPS (EEPROM_UVLO_TINY_CURRENT_POSITION_Z-2) // uint16
  124. // Sound Mode
  125. //#define EEPROM_SOUND_MODE (EEPROM_EXTRUDEMULTIPLY-1) // uint8
  126. #define EEPROM_SOUND_MODE (EEPROM_UVLO_TINY_Z_MICROSTEPS-1) // uint8
  127. #define EEPROM_AUTO_DEPLETE (EEPROM_SOUND_MODE-1) //bool
  128. #define EEPROM_FSENS_OQ_MEASS_ENABLED (EEPROM_AUTO_DEPLETE - 1) //bool
  129. #define EEPROM_MMU_FAIL_TOT (EEPROM_FSENS_OQ_MEASS_ENABLED - 2) //uint16_t
  130. #define EEPROM_MMU_FAIL (EEPROM_MMU_FAIL_TOT - 1) //uint8_t
  131. #define EEPROM_MMU_LOAD_FAIL_TOT (EEPROM_MMU_FAIL - 2) //uint16_t
  132. #define EEPROM_MMU_LOAD_FAIL (EEPROM_MMU_LOAD_FAIL_TOT - 1) //uint8_t
  133. #define EEPROM_MMU_CUTTER_ENABLED (EEPROM_MMU_LOAD_FAIL - 1)
  134. #define EEPROM_UVLO_MESH_BED_LEVELING_FULL (EEPROM_MMU_CUTTER_ENABLED - 12*12*2) //allow 12 calibration points for future expansion
  135. #define EEPROM_MBL_TYPE (EEPROM_UVLO_MESH_BED_LEVELING_FULL-1) //uint8_t for mesh bed leveling precision
  136. #define EEPROM_MBL_MAGNET_ELIMINATION (EEPROM_MBL_TYPE -1)
  137. #define EEPROM_MBL_POINTS_NR (EEPROM_MBL_MAGNET_ELIMINATION -1) //uint8_t number of points in one exis for mesh bed leveling
  138. #define EEPROM_MBL_PROBE_NR (EEPROM_MBL_POINTS_NR-1) //number of measurements for each point
  139. #define EEPROM_MMU_STEALTH (EEPROM_MBL_PROBE_NR-1)
  140. #define EEPROM_CHECK_MODE (EEPROM_MMU_STEALTH-1) // uint8
  141. #define EEPROM_NOZZLE_DIAMETER (EEPROM_CHECK_MODE-1) // uint8
  142. #define EEPROM_NOZZLE_DIAMETER_uM (EEPROM_NOZZLE_DIAMETER-2) // uint16
  143. typedef struct
  144. {
  145. char name[7];
  146. } Sheet;
  147. typedef struct
  148. {
  149. Sheet s[3];
  150. uint8_t active_sheet;
  151. } Sheets;
  152. // sizeof(Sheets). Do not change it unless EEPROM_Sheets_base is last item in EEPROM.
  153. // Otherwise it would move following items.
  154. #define EEPROM_SHEETS_SIZEOF 22
  155. static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_NOZZLE_DIAMETER - EEPROM_SHEETS_SIZEOF);
  156. #ifdef __cplusplus
  157. static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEPROM_SHEETS_SIZEOF.");
  158. #endif
  159. //This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items.
  160. #define EEPROM_LAST_ITEM ((uint16_t)EEPROM_Sheets_base)
  161. // !!!!!
  162. // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!!
  163. // !!!!!
  164. // Currently running firmware, each digit stored as uint16_t.
  165. // The flavor differentiates a dev, alpha, beta, release candidate or a release version.
  166. #define EEPROM_FIRMWARE_VERSION_END (FW_PRUSA3D_MAGIC_LEN+8)
  167. #define EEPROM_FIRMWARE_VERSION_FLAVOR (FW_PRUSA3D_MAGIC_LEN+6)
  168. #define EEPROM_FIRMWARE_VERSION_REVISION (FW_PRUSA3D_MAGIC_LEN+4)
  169. #define EEPROM_FIRMWARE_VERSION_MINOR (FW_PRUSA3D_MAGIC_LEN+2)
  170. #define EEPROM_FIRMWARE_VERSION_MAJOR FW_PRUSA3D_MAGIC_LEN
  171. // Magic string, indicating that the current or the previous firmware running was the Prusa3D firmware.
  172. #define EEPROM_FIRMWARE_PRUSA_MAGIC 0
  173. #ifdef __cplusplus
  174. #include "ConfigurationStore.h"
  175. static_assert(EEPROM_FIRMWARE_VERSION_END < 20, "Firmware version EEPROM address conflicts with EEPROM_M500_base");
  176. static constexpr M500_conf * const EEPROM_M500_base = reinterpret_cast<M500_conf*>(20); //offset for storing settings using M500
  177. static_assert(((sizeof(M500_conf) + 20) < EEPROM_LAST_ITEM), "M500_conf address space conflicts with previous items.");
  178. #endif
  179. enum
  180. {
  181. EEPROM_MMU_CUTTER_ENABLED_enabled = 1,
  182. EEPROM_MMU_CUTTER_ENABLED_always = 2,
  183. };
  184. #endif // EEPROM_H